mirror of
https://github.com/raysan5/raylib.git
synced 2025-12-06 06:13:10 +00:00
Compare commits
6 Commits
c22b1d84d5
...
84737a9fc1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
84737a9fc1 | ||
|
|
727a90c5d1 | ||
|
|
6c3ef8d9b4 | ||
|
|
97707d7a6b | ||
|
|
12cce1766f | ||
|
|
dddc94dc7a |
@ -41,6 +41,7 @@ while (!WindowShouldClose())
|
||||
|
||||
}
|
||||
|
||||
// Always use accumulators as `x++` instead of `++x`
|
||||
for (int i = 0; i < NUM_VALUES; i++) printf("%i", i);
|
||||
|
||||
// Be careful with the switch formatting!
|
||||
|
||||
@ -148,7 +148,7 @@ int main(void)
|
||||
CaptureFrame(&fft, audioSamples);
|
||||
RenderFrame(&fft, &fftImage);
|
||||
UpdateTexture(fftTexture, fftImage.data);
|
||||
//------------------------------------------------------------------------------
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
@ -278,11 +278,8 @@ static void RenderFrame(const FFTData *fftData, Image *fftImage)
|
||||
framesSinceTapback = Clamp(framesSinceTapback, 0.0, fftData->fftHistoryLen - 1);
|
||||
|
||||
int historyPosition = (fftData->historyPos - 1 - (int)framesSinceTapback)%fftData->fftHistoryLen;
|
||||
if (historyPosition < 0)
|
||||
historyPosition += fftData->fftHistoryLen;
|
||||
if (historyPosition < 0) historyPosition += fftData->fftHistoryLen;
|
||||
|
||||
const float *amplitude = fftData->fftHistory[historyPosition];
|
||||
for (int bin = 0; bin < BUFFER_SIZE; bin++) {
|
||||
ImageDrawPixel(fftImage, bin, FFT_ROW, ColorFromNormalized((Vector4){ amplitude[bin], UNUSED_CHANNEL, UNUSED_CHANNEL, UNUSED_CHANNEL }));
|
||||
}
|
||||
for (int bin = 0; bin < BUFFER_SIZE; bin++) ImageDrawPixel(fftImage, bin, FFT_ROW, ColorFromNormalized((Vector4){ amplitude[bin], UNUSED_CHANNEL, UNUSED_CHANNEL, UNUSED_CHANNEL }));
|
||||
}
|
||||
@ -27,9 +27,10 @@ int main(void)
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
|
||||
SetConfigFlags(FLAG_WINDOW_HIGHDPI | FLAG_WINDOW_RESIZABLE);
|
||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - highdpi testbed");
|
||||
|
||||
// TODO: Load resources / Initialize variables at this point
|
||||
int gridSpacing = 40; // Grid spacing in pixels
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
@ -48,11 +49,12 @@ int main(void)
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
// TODO: Draw everything that requires to be drawn at this point
|
||||
// Draw grid
|
||||
for (int h = 0; h < 20; h++) DrawLine(0, h*gridSpacing, GetRenderWidth(), h*gridSpacing, LIGHTGRAY);
|
||||
for (int v = 0; v < 40; v++) DrawLine(v*gridSpacing, 0, v*gridSpacing, GetScreenHeight(), LIGHTGRAY);
|
||||
|
||||
DrawLineEx((Vector2){ 0, 0 }, (Vector2){ screenWidth, screenHeight }, 2.0f, RED);
|
||||
DrawLineEx((Vector2){ 0, screenHeight }, (Vector2){ screenWidth, 0 }, 2.0f, RED);
|
||||
DrawText("example base code template", 260, 400, 20, LIGHTGRAY);
|
||||
// Draw UI info
|
||||
DrawText(TextFormat("SCREEN SIZE: %ix%i", GetScreenWidth(), GetScreenHeight()), 10, 10, 20, BLACK);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
@ -46,7 +46,7 @@ int main(void)
|
||||
// Clamp touch points available ( set the maximum touch points allowed )
|
||||
if (tCount > MAX_TOUCH_POINTS) tCount = MAX_TOUCH_POINTS;
|
||||
// Get touch points positions
|
||||
for (int i = 0; i < tCount; ++i) touchPositions[i] = GetTouchPosition(i);
|
||||
for (int i = 0; i < tCount; i++) touchPositions[i] = GetTouchPosition(i);
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
@ -55,7 +55,7 @@ int main(void)
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
for (int i = 0; i < tCount; ++i)
|
||||
for (int i = 0; i < tCount; i++)
|
||||
{
|
||||
// Make sure point is not (0, 0) as this means there is no touch for it
|
||||
if ((touchPositions[i].x > 0) && (touchPositions[i].y > 0))
|
||||
|
||||
@ -17,11 +17,9 @@
|
||||
|
||||
#include "raylib.h"
|
||||
|
||||
// For itteration purposes and teaching example
|
||||
#define RESOLUTION_COUNT 4
|
||||
#define RESOLUTION_COUNT 4 // For iteration purposes and teaching example
|
||||
|
||||
enum ViewportType
|
||||
{
|
||||
typedef enum {
|
||||
// Only upscale, useful for pixel art
|
||||
KEEP_ASPECT_INTEGER,
|
||||
KEEP_HEIGHT_INTEGER,
|
||||
@ -32,24 +30,28 @@ enum ViewportType
|
||||
KEEP_WIDTH,
|
||||
// For itteration purposes and as a teaching example
|
||||
VIEWPORT_TYPE_COUNT,
|
||||
} ViewportType;
|
||||
|
||||
// For displaying on GUI
|
||||
const char *ViewportTypeNames[VIEWPORT_TYPE_COUNT] = {
|
||||
"KEEP_ASPECT_INTEGER",
|
||||
"KEEP_HEIGHT_INTEGER",
|
||||
"KEEP_WIDTH_INTEGER",
|
||||
"KEEP_ASPECT",
|
||||
"KEEP_HEIGHT",
|
||||
"KEEP_WIDTH",
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Module Functions Declaration
|
||||
//--------------------------------------------------------------------------------------
|
||||
static void KeepAspectCenteredInteger(int screenWidth, int screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect);
|
||||
|
||||
static void KeepHeightCenteredInteger(int screenWidth, int screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect);
|
||||
|
||||
static void KeepWidthCenteredInteger(int screenWidth, int screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect);
|
||||
|
||||
static void KeepAspectCentered(int screenWidth, int screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect);
|
||||
|
||||
static void KeepHeightCentered(int screenWidth, int screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect);
|
||||
|
||||
static void KeepWidthCentered(int screenWidth, int screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect);
|
||||
|
||||
static void ResizeRenderSize(enum ViewportType viewportType, int *screenWidth, int *screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect, RenderTexture2D *target);
|
||||
static void ResizeRenderSize(ViewportType viewportType, int *screenWidth, int *screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect, RenderTexture2D *target);
|
||||
|
||||
// Example how to calculate position on RenderTexture
|
||||
static Vector2 Screen2RenderTexturePosition(Vector2 point, Rectangle *textureRect, Rectangle *scaledRect);
|
||||
@ -61,6 +63,12 @@ int main(void)
|
||||
{
|
||||
// Initialization
|
||||
//---------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
|
||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - viewport scaling");
|
||||
|
||||
// Preset resolutions that could be created by subdividing screen resolution
|
||||
Vector2 resolutionList[RESOLUTION_COUNT] = {
|
||||
(Vector2){ 64, 64 },
|
||||
@ -69,10 +77,8 @@ int main(void)
|
||||
// 4K doesn't work with integer scaling but included for example purposes with non-integer scaling
|
||||
(Vector2){ 3840, 2160 },
|
||||
};
|
||||
int resolutionIndex = 0;
|
||||
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
int resolutionIndex = 0;
|
||||
int gameWidth = 64;
|
||||
int gameHeight = 64;
|
||||
|
||||
@ -80,72 +86,66 @@ int main(void)
|
||||
Rectangle sourceRect = (Rectangle){ 0 };
|
||||
Rectangle destRect = (Rectangle){ 0 };
|
||||
|
||||
// For displaying on GUI
|
||||
const char *ViewportTypeNames[VIEWPORT_TYPE_COUNT] = {
|
||||
"KEEP_ASPECT_INTEGER",
|
||||
"KEEP_HEIGHT_INTEGER",
|
||||
"KEEP_WIDTH_INTEGER",
|
||||
"KEEP_ASPECT",
|
||||
"KEEP_HEIGHT",
|
||||
"KEEP_WIDTH",
|
||||
};
|
||||
enum ViewportType viewportType = KEEP_ASPECT_INTEGER;
|
||||
|
||||
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
|
||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - viewport scaling");
|
||||
ViewportType viewportType = KEEP_ASPECT_INTEGER;
|
||||
ResizeRenderSize(viewportType, &screenWidth, &screenHeight, gameWidth, gameHeight, &sourceRect, &destRect, &target);
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//----------------------------------------------------------
|
||||
|
||||
// Button rectangles
|
||||
Rectangle decreaseResolutionButton = (Rectangle){ 200, 30, 10, 10 };
|
||||
Rectangle increaseResolutionButton = (Rectangle){ 215, 30, 10, 10 };
|
||||
Rectangle decreaseTypeButton = (Rectangle){ 200, 45, 10, 10 };
|
||||
Rectangle increaseTypeButton = (Rectangle){ 215, 45, 10, 10 };
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//----------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//-----------------------------------------------------
|
||||
if (IsWindowResized()){
|
||||
ResizeRenderSize(viewportType, &screenWidth, &screenHeight, gameWidth, gameHeight, &sourceRect, &destRect, &target);
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
if (IsWindowResized()) ResizeRenderSize(viewportType, &screenWidth, &screenHeight, gameWidth, gameHeight, &sourceRect, &destRect, &target);
|
||||
|
||||
Vector2 mousePosition = GetMousePosition();
|
||||
bool mousePressed = IsMouseButtonPressed(MOUSE_BUTTON_LEFT);
|
||||
|
||||
// Check buttons and rescale
|
||||
if (CheckCollisionPointRec(mousePosition, decreaseResolutionButton) && mousePressed){
|
||||
if (CheckCollisionPointRec(mousePosition, decreaseResolutionButton) && mousePressed)
|
||||
{
|
||||
resolutionIndex = (resolutionIndex + RESOLUTION_COUNT - 1)%RESOLUTION_COUNT;
|
||||
gameWidth = resolutionList[resolutionIndex].x;
|
||||
gameHeight = resolutionList[resolutionIndex].y;
|
||||
ResizeRenderSize(viewportType, &screenWidth, &screenHeight, gameWidth, gameHeight, &sourceRect, &destRect, &target);
|
||||
}
|
||||
if (CheckCollisionPointRec(mousePosition, increaseResolutionButton) && mousePressed){
|
||||
|
||||
if (CheckCollisionPointRec(mousePosition, increaseResolutionButton) && mousePressed)
|
||||
{
|
||||
resolutionIndex = (resolutionIndex + 1)%RESOLUTION_COUNT;
|
||||
gameWidth = resolutionList[resolutionIndex].x;
|
||||
gameHeight = resolutionList[resolutionIndex].y;
|
||||
ResizeRenderSize(viewportType, &screenWidth, &screenHeight, gameWidth, gameHeight, &sourceRect, &destRect, &target);
|
||||
}
|
||||
if (CheckCollisionPointRec(mousePosition, decreaseTypeButton) && mousePressed){
|
||||
|
||||
if (CheckCollisionPointRec(mousePosition, decreaseTypeButton) && mousePressed)
|
||||
{
|
||||
viewportType = (viewportType + VIEWPORT_TYPE_COUNT - 1)%VIEWPORT_TYPE_COUNT;
|
||||
ResizeRenderSize(viewportType, &screenWidth, &screenHeight, gameWidth, gameHeight, &sourceRect, &destRect, &target);
|
||||
}
|
||||
if (CheckCollisionPointRec(mousePosition, increaseTypeButton) && mousePressed){
|
||||
|
||||
if (CheckCollisionPointRec(mousePosition, increaseTypeButton) && mousePressed)
|
||||
{
|
||||
viewportType = (viewportType + 1)%VIEWPORT_TYPE_COUNT;
|
||||
ResizeRenderSize(viewportType, &screenWidth, &screenHeight, gameWidth, gameHeight, &sourceRect, &destRect, &target);
|
||||
}
|
||||
|
||||
Vector2 textureMousePosition = Screen2RenderTexturePosition(mousePosition, &sourceRect, &destRect);
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//-----------------------------------------------------
|
||||
//----------------------------------------------------------------------------------
|
||||
// Draw our scene to the render texture
|
||||
BeginTextureMode(target);
|
||||
ClearBackground(WHITE);
|
||||
DrawCircle(textureMousePosition.x, textureMousePosition.y, 20.f, LIME);
|
||||
|
||||
|
||||
DrawCircle(textureMousePosition.x, textureMousePosition.y, 20.0f, LIME);
|
||||
EndTextureMode();
|
||||
|
||||
// Draw render texture to main framebuffer
|
||||
@ -153,9 +153,7 @@ int main(void)
|
||||
ClearBackground(BLACK);
|
||||
|
||||
// Draw our render texture with rotation applied
|
||||
const Vector2 ORIGIN_POSITION = (Vector2){ 0.0f, 0.0f };
|
||||
const float ROTATION = 0.f;
|
||||
DrawTexturePro(target.texture, sourceRect, destRect, ORIGIN_POSITION, ROTATION, WHITE);
|
||||
DrawTexturePro(target.texture, sourceRect, destRect, (Vector2){ 0.0f, 0.0f }, 0.0f, WHITE);
|
||||
|
||||
// Draw Native resolution (GUI or anything)
|
||||
// Draw info box
|
||||
@ -167,15 +165,10 @@ int main(void)
|
||||
DrawText(TextFormat("Game Resolution: %d x %d", gameWidth, gameHeight), 15, 30, 10, BLACK);
|
||||
|
||||
DrawText(TextFormat("Type: %s", ViewportTypeNames[viewportType]), 15, 45, 10, BLACK);
|
||||
Vector2 scaleRatio = (Vector2){destRect.width / sourceRect.width, destRect.height / -sourceRect.height};
|
||||
if (scaleRatio.x < 0.001f || scaleRatio.y < 0.001f)
|
||||
{
|
||||
DrawText(TextFormat("Scale ratio: INVALID"), 15, 60, 10, BLACK);
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawText(TextFormat("Scale ratio: %.2f x %.2f", scaleRatio.x, scaleRatio.y), 15, 60, 10, BLACK);
|
||||
}
|
||||
Vector2 scaleRatio = (Vector2){destRect.width/sourceRect.width, -destRect.height/sourceRect.height};
|
||||
if (scaleRatio.x < 0.001f || scaleRatio.y < 0.001f) DrawText(TextFormat("Scale ratio: INVALID"), 15, 60, 10, BLACK);
|
||||
else DrawText(TextFormat("Scale ratio: %.2f x %.2f", scaleRatio.x, scaleRatio.y), 15, 60, 10, BLACK);
|
||||
|
||||
DrawText(TextFormat("Source size: %.2f x %.2f", sourceRect.width, -sourceRect.height), 15, 75, 10, BLACK);
|
||||
DrawText(TextFormat("Destination size: %.2f x %.2f", destRect.width, destRect.height), 15, 90, 10, BLACK);
|
||||
|
||||
@ -190,13 +183,13 @@ int main(void)
|
||||
DrawText(">", increaseResolutionButton.x + 3, increaseResolutionButton.y + 1, 10, BLACK);
|
||||
|
||||
EndDrawing();
|
||||
//-----------------------------------------------------
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//---------------------------------------------------------
|
||||
//----------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//----------------------------------------------------------
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -206,17 +199,17 @@ int main(void)
|
||||
//--------------------------------------------------------------------------------------
|
||||
static void KeepAspectCenteredInteger(int screenWidth, int screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect)
|
||||
{
|
||||
sourceRect->x = 0.f;
|
||||
sourceRect->x = 0.0f;
|
||||
sourceRect->y = (float)gameHeight;
|
||||
sourceRect->width = (float)gameWidth;
|
||||
sourceRect->height = (float)-gameHeight;
|
||||
|
||||
const int ratio_x = (screenWidth/gameWidth);
|
||||
const int ratio_y = (screenHeight/gameHeight);
|
||||
const float resizeRatio = (float)(ratio_x < ratio_y ? ratio_x : ratio_y);
|
||||
const float resizeRatio = (float)((ratio_x < ratio_y)? ratio_x : ratio_y);
|
||||
|
||||
destRect->x = (float)(int)((screenWidth - (gameWidth * resizeRatio)) * 0.5);
|
||||
destRect->y = (float)(int)((screenHeight - (gameHeight * resizeRatio)) * 0.5);
|
||||
destRect->x = (float)(int)((screenWidth - (gameWidth*resizeRatio))*0.5f);
|
||||
destRect->y = (float)(int)((screenHeight - (gameHeight*resizeRatio))*0.5f);
|
||||
destRect->width = (float)(int)(gameWidth*resizeRatio);
|
||||
destRect->height = (float)(int)(gameHeight*resizeRatio);
|
||||
}
|
||||
@ -224,13 +217,13 @@ static void KeepAspectCenteredInteger(int screenWidth, int screenHeight, int gam
|
||||
static void KeepHeightCenteredInteger(int screenWidth, int screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect)
|
||||
{
|
||||
const float resizeRatio = (float)(screenHeight/gameHeight);
|
||||
sourceRect->x = 0.f;
|
||||
sourceRect->y = 0.f;
|
||||
sourceRect->x = 0.0f;
|
||||
sourceRect->y = 0.0f;
|
||||
sourceRect->width = (float)(int)(screenWidth/resizeRatio);
|
||||
sourceRect->height = (float)-gameHeight;
|
||||
|
||||
destRect->x = (float)(int)((screenWidth - (sourceRect->width * resizeRatio)) * 0.5);
|
||||
destRect->y = (float)(int)((screenHeight - (gameHeight * resizeRatio)) * 0.5);
|
||||
destRect->x = (float)(int)((screenWidth - (sourceRect->width*resizeRatio))*0.5f);
|
||||
destRect->y = (float)(int)((screenHeight - (gameHeight*resizeRatio))*0.5f);
|
||||
destRect->width = (float)(int)(sourceRect->width*resizeRatio);
|
||||
destRect->height = (float)(int)(gameHeight*resizeRatio);
|
||||
}
|
||||
@ -238,22 +231,22 @@ static void KeepHeightCenteredInteger(int screenWidth, int screenHeight, int gam
|
||||
static void KeepWidthCenteredInteger(int screenWidth, int screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect)
|
||||
{
|
||||
const float resizeRatio = (float)(screenWidth/gameWidth);
|
||||
sourceRect->x = 0.f;
|
||||
sourceRect->y = 0.f;
|
||||
sourceRect->x = 0.0f;
|
||||
sourceRect->y = 0.0f;
|
||||
sourceRect->width = (float)gameWidth;
|
||||
sourceRect->height = (float)(int)(screenHeight/resizeRatio);
|
||||
|
||||
destRect->x = (float)(int)((screenWidth - (gameWidth * resizeRatio)) * 0.5);
|
||||
destRect->y = (float)(int)((screenHeight - (sourceRect->height * resizeRatio)) * 0.5);
|
||||
destRect->x = (float)(int)((screenWidth - (gameWidth*resizeRatio))*0.5f);
|
||||
destRect->y = (float)(int)((screenHeight - (sourceRect->height*resizeRatio))*0.5f);
|
||||
destRect->width = (float)(int)(gameWidth*resizeRatio);
|
||||
destRect->height = (float)(int)(sourceRect->height*resizeRatio);
|
||||
|
||||
sourceRect->height *= -1.f;
|
||||
sourceRect->height *= -1.0f;
|
||||
}
|
||||
|
||||
static void KeepAspectCentered(int screenWidth, int screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect)
|
||||
{
|
||||
sourceRect->x = 0.f;
|
||||
sourceRect->x = 0.0f;
|
||||
sourceRect->y = (float)gameHeight;
|
||||
sourceRect->width = (float)gameWidth;
|
||||
sourceRect->height = (float)-gameHeight;
|
||||
@ -262,8 +255,8 @@ static void KeepAspectCentered(int screenWidth, int screenHeight, int gameWidth,
|
||||
const float ratio_y = ((float)screenHeight/(float)gameHeight);
|
||||
const float resizeRatio = (ratio_x < ratio_y ? ratio_x : ratio_y);
|
||||
|
||||
destRect->x = (float)(int)((screenWidth - (gameWidth * resizeRatio)) * 0.5);
|
||||
destRect->y = (float)(int)((screenHeight - (gameHeight * resizeRatio)) * 0.5);
|
||||
destRect->x = (float)(int)((screenWidth - (gameWidth*resizeRatio))*0.5f);
|
||||
destRect->y = (float)(int)((screenHeight - (gameHeight*resizeRatio))*0.5f);
|
||||
destRect->width = (float)(int)(gameWidth*resizeRatio);
|
||||
destRect->height = (float)(int)(gameHeight*resizeRatio);
|
||||
}
|
||||
@ -271,13 +264,13 @@ static void KeepAspectCentered(int screenWidth, int screenHeight, int gameWidth,
|
||||
static void KeepHeightCentered(int screenWidth, int screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect)
|
||||
{
|
||||
const float resizeRatio = ((float)screenHeight/(float)gameHeight);
|
||||
sourceRect->x = 0.f;
|
||||
sourceRect->y = 0.f;
|
||||
sourceRect->x = 0.0f;
|
||||
sourceRect->y = 0.0f;
|
||||
sourceRect->width = (float)(int)((float)screenWidth/resizeRatio);
|
||||
sourceRect->height = (float)-gameHeight;
|
||||
|
||||
destRect->x = (float)(int)((screenWidth - (sourceRect->width * resizeRatio)) * 0.5);
|
||||
destRect->y = (float)(int)((screenHeight - (gameHeight * resizeRatio)) * 0.5);
|
||||
destRect->x = (float)(int)((screenWidth - (sourceRect->width*resizeRatio))*0.5f);
|
||||
destRect->y = (float)(int)((screenHeight - (gameHeight*resizeRatio))*0.5f);
|
||||
destRect->width = (float)(int)(sourceRect->width*resizeRatio);
|
||||
destRect->height = (float)(int)(gameHeight*resizeRatio);
|
||||
}
|
||||
@ -285,58 +278,35 @@ static void KeepHeightCentered(int screenWidth, int screenHeight, int gameWidth,
|
||||
static void KeepWidthCentered(int screenWidth, int screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect)
|
||||
{
|
||||
const float resizeRatio = ((float)screenWidth/(float)gameWidth);
|
||||
sourceRect->x = 0.f;
|
||||
sourceRect->y = 0.f;
|
||||
sourceRect->x = 0.0f;
|
||||
sourceRect->y = 0.0f;
|
||||
sourceRect->width = (float)gameWidth;
|
||||
sourceRect->height = (float)(int)((float)screenHeight/resizeRatio);
|
||||
|
||||
destRect->x = (float)(int)((screenWidth - (gameWidth * resizeRatio)) * 0.5);
|
||||
destRect->y = (float)(int)((screenHeight - (sourceRect->height * resizeRatio)) * 0.5);
|
||||
destRect->x = (float)(int)((screenWidth - (gameWidth*resizeRatio))*0.5f);
|
||||
destRect->y = (float)(int)((screenHeight - (sourceRect->height*resizeRatio))*0.5f);
|
||||
destRect->width = (float)(int)(gameWidth*resizeRatio);
|
||||
destRect->height = (float)(int)(sourceRect->height*resizeRatio);
|
||||
|
||||
sourceRect->height *= -1.f;
|
||||
}
|
||||
|
||||
static void ResizeRenderSize(enum ViewportType viewportType, int *screenWidth, int *screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect, RenderTexture2D *target)
|
||||
static void ResizeRenderSize(ViewportType viewportType, int *screenWidth, int *screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect, RenderTexture2D *target)
|
||||
{
|
||||
*screenWidth = GetScreenWidth();
|
||||
*screenHeight = GetScreenHeight();
|
||||
|
||||
switch(viewportType)
|
||||
{
|
||||
case KEEP_ASPECT_INTEGER:
|
||||
{
|
||||
KeepAspectCenteredInteger(*screenWidth, *screenHeight, gameWidth, gameHeight, sourceRect, destRect);
|
||||
break;
|
||||
}
|
||||
case KEEP_HEIGHT_INTEGER:
|
||||
{
|
||||
KeepHeightCenteredInteger(*screenWidth, *screenHeight, gameWidth, gameHeight, sourceRect, destRect);
|
||||
break;
|
||||
}
|
||||
case KEEP_WIDTH_INTEGER:
|
||||
{
|
||||
KeepWidthCenteredInteger(*screenWidth, *screenHeight, gameWidth, gameHeight, sourceRect, destRect);
|
||||
break;
|
||||
}
|
||||
case KEEP_ASPECT:
|
||||
{
|
||||
KeepAspectCentered(*screenWidth, *screenHeight, gameWidth, gameHeight, sourceRect, destRect);
|
||||
break;
|
||||
}
|
||||
case KEEP_HEIGHT:
|
||||
{
|
||||
KeepHeightCentered(*screenWidth, *screenHeight, gameWidth, gameHeight, sourceRect, destRect);
|
||||
break;
|
||||
}
|
||||
case KEEP_WIDTH:
|
||||
{
|
||||
KeepWidthCentered(*screenWidth, *screenHeight, gameWidth, gameHeight, sourceRect, destRect);
|
||||
break;
|
||||
}
|
||||
default: {}
|
||||
case KEEP_ASPECT_INTEGER: KeepAspectCenteredInteger(*screenWidth, *screenHeight, gameWidth, gameHeight, sourceRect, destRect); break;
|
||||
case KEEP_HEIGHT_INTEGER: KeepHeightCenteredInteger(*screenWidth, *screenHeight, gameWidth, gameHeight, sourceRect, destRect); break;
|
||||
case KEEP_WIDTH_INTEGER: KeepWidthCenteredInteger(*screenWidth, *screenHeight, gameWidth, gameHeight, sourceRect, destRect); break;
|
||||
case KEEP_ASPECT: KeepAspectCentered(*screenWidth, *screenHeight, gameWidth, gameHeight, sourceRect, destRect); break;
|
||||
case KEEP_HEIGHT: KeepHeightCentered(*screenWidth, *screenHeight, gameWidth, gameHeight, sourceRect, destRect); break;
|
||||
case KEEP_WIDTH: KeepWidthCentered(*screenWidth, *screenHeight, gameWidth, gameHeight, sourceRect, destRect); break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
UnloadRenderTexture(*target);
|
||||
*target = LoadRenderTexture(sourceRect->width, -sourceRect->height);
|
||||
}
|
||||
|
||||
@ -97,7 +97,8 @@ int main(void)
|
||||
if (IsWindowState(FLAG_WINDOW_MINIMIZED))
|
||||
{
|
||||
framesCounter++;
|
||||
if (framesCounter >= 240) {
|
||||
if (framesCounter >= 240)
|
||||
{
|
||||
RestoreWindow(); // Restore window after 3 seconds
|
||||
framesCounter = 0;
|
||||
}
|
||||
|
||||
@ -138,7 +138,7 @@ int main(void)
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
for (int i = 0; i < MAX_TEXTURES; ++i) UnloadTexture(texture[i]);
|
||||
for (int i = 0; i < MAX_TEXTURES; i++) UnloadTexture(texture[i]);
|
||||
UnloadShader(shdrColorCorrection);
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
|
||||
@ -14,9 +14,6 @@
|
||||
* Copyright (c) 2025 JP Mortiboys (@themushroompirates)
|
||||
*
|
||||
********************************************************************************************/
|
||||
#if defined(WIN32)
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#include "raylib.h"
|
||||
|
||||
@ -63,24 +60,16 @@ int main(void)
|
||||
/* 8 */ { TL,HH,HH,TR, /* */ VV,TL,TR,VV,/* */ VV,BL,BR,VV,/* */ VV,TL,TR,VV,/* */ VV,BL,BR,VV,/* */ BL,HH,HH,BR },
|
||||
/* 9 */ { TL,HH,HH,TR, /* */ VV,TL,TR,VV,/* */ VV,BL,BR,VV,/* */ BL,HH,TR,VV,/* */ TL,HH,BR,VV,/* */ BL,HH,HH,BR },
|
||||
};
|
||||
|
||||
// Time for the hands to move to the new position (in seconds); this must be <1s
|
||||
const float handsMoveDuration = .5f;
|
||||
const float handsMoveDuration = 0.5f;
|
||||
|
||||
// We store the previous seconds value so we can see if the time has changed
|
||||
int prevSeconds = -1;
|
||||
|
||||
// This represents the real position where the hands are right now
|
||||
Vector2 currentAngles[6][24] = { 0 };
|
||||
|
||||
// This is the position where the hands were moving from
|
||||
Vector2 srcAngles[6][24] = { 0 };
|
||||
// This is the position where the hands are moving to
|
||||
Vector2 dstAngles[6][24] = { 0 };
|
||||
|
||||
// Current animation timer
|
||||
float handsMoveTimer = 0.0f;
|
||||
|
||||
// 12 or 24 hour mode
|
||||
int hourMode = 24;
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
@ -91,7 +80,6 @@ int main(void)
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Get the current time
|
||||
time_t rawtime;
|
||||
struct tm *timeinfo;
|
||||
@ -99,7 +87,8 @@ int main(void)
|
||||
time(&rawtime);
|
||||
timeinfo = localtime(&rawtime);
|
||||
|
||||
if (timeinfo->tm_sec != prevSeconds) {
|
||||
if (timeinfo->tm_sec != prevSeconds)
|
||||
{
|
||||
// The time has changed, so we need to move the hands to the new positions
|
||||
prevSeconds = timeinfo->tm_sec;
|
||||
|
||||
@ -107,22 +96,17 @@ int main(void)
|
||||
const char *clockDigits = TextFormat("%02d%02d%02d", timeinfo->tm_hour%hourMode, timeinfo->tm_min, timeinfo->tm_sec);
|
||||
|
||||
// Fetch where we want all the hands to be
|
||||
for (int digit = 0; digit < 6; digit++) {
|
||||
for (int cell = 0; cell < 24; cell++) {
|
||||
for (int digit = 0; digit < 6; digit++)
|
||||
{
|
||||
for (int cell = 0; cell < 24; cell++)
|
||||
{
|
||||
srcAngles[digit][cell] = currentAngles[digit][cell];
|
||||
dstAngles[digit][cell] = digitAngles[clockDigits[digit] - '0'][cell];
|
||||
|
||||
// Quick exception for 12h mode
|
||||
if (digit == 0 && hourMode == 12 && clockDigits[0] == '0') {
|
||||
dstAngles[digit][cell] = ZZ;
|
||||
}
|
||||
|
||||
if (srcAngles[digit][cell].x > dstAngles[digit][cell].x) {
|
||||
srcAngles[digit][cell].x -= 360.0f;
|
||||
}
|
||||
if (srcAngles[digit][cell].y > dstAngles[digit][cell].y) {
|
||||
srcAngles[digit][cell].y -= 360.0f;
|
||||
}
|
||||
if ((digit == 0) && (hourMode == 12) && (clockDigits[0] == '0')) dstAngles[digit][cell] = ZZ;
|
||||
if (srcAngles[digit][cell].x > dstAngles[digit][cell].x) srcAngles[digit][cell].x -= 360.0f;
|
||||
if (srcAngles[digit][cell].y > dstAngles[digit][cell].y) srcAngles[digit][cell].y -= 360.0f;
|
||||
}
|
||||
}
|
||||
|
||||
@ -131,7 +115,8 @@ int main(void)
|
||||
}
|
||||
|
||||
// Now let's animate all the hands if we need to
|
||||
if (handsMoveTimer < handsMoveDuration) {
|
||||
if (handsMoveTimer < handsMoveDuration)
|
||||
{
|
||||
// Increase the timer but don't go above the maximum
|
||||
handsMoveTimer = Clamp(handsMoveTimer + GetFrameTime(), 0, handsMoveDuration);
|
||||
|
||||
@ -141,27 +126,18 @@ int main(void)
|
||||
// A little cheeky smoothstep
|
||||
t = t*t*(3.0f - 2.0f*t);
|
||||
|
||||
for (int digit = 0; digit < 6; digit++) {
|
||||
for (int cell = 0; cell < 24; cell++) {
|
||||
for (int digit = 0; digit < 6; digit++)
|
||||
{
|
||||
for (int cell = 0; cell < 24; cell++)
|
||||
{
|
||||
currentAngles[digit][cell].x = Lerp(srcAngles[digit][cell].x, dstAngles[digit][cell].x, t);
|
||||
currentAngles[digit][cell].y = Lerp(srcAngles[digit][cell].y, dstAngles[digit][cell].y, t);
|
||||
}
|
||||
}
|
||||
|
||||
if (handsMoveTimer == handsMoveDuration) {
|
||||
// The animation has now finished
|
||||
}
|
||||
}
|
||||
|
||||
// Handle input
|
||||
|
||||
// Toggle between 12 and 24 hour mode with space
|
||||
if (IsKeyPressed(KEY_SPACE)) {
|
||||
hourMode = 36 - hourMode;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (IsKeyPressed(KEY_SPACE)) hourMode = 36 - hourMode; // Toggle between 12 and 24 hour mode with space
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
@ -174,19 +150,22 @@ int main(void)
|
||||
|
||||
float xOffset = 4.0f;
|
||||
|
||||
for (int digit = 0; digit < 6; digit++) {
|
||||
|
||||
for (int row = 0; row < 6; row++) {
|
||||
for (int col = 0; col < 4; col++) {
|
||||
for (int digit = 0; digit < 6; digit++)
|
||||
{
|
||||
for (int row = 0; row < 6; row++)
|
||||
{
|
||||
for (int col = 0; col < 4; col++)
|
||||
{
|
||||
Vector2 centre = (Vector2){
|
||||
xOffset + col*(clockFaceSize+clockFaceSpacing) + clockFaceSize * .5f,
|
||||
100 + row*(clockFaceSize+clockFaceSpacing) + clockFaceSize * .5f
|
||||
xOffset + col*(clockFaceSize+clockFaceSpacing) + clockFaceSize*0.5f,
|
||||
100 + row*(clockFaceSize+clockFaceSpacing) + clockFaceSize*0.5f
|
||||
};
|
||||
|
||||
DrawRing(centre, clockFaceSize*0.5f - 2.0f, clockFaceSize*0.5f, 0, 360, 24, DARKGRAY);
|
||||
|
||||
// Big hand
|
||||
DrawRectanglePro(
|
||||
(Rectangle){centre.x, centre.y, clockFaceSize*.5f+4.0f, 4.0f},
|
||||
(Rectangle){centre.x, centre.y, clockFaceSize*0.5f+4.0f, 4.0f},
|
||||
(Vector2){ 2.0f, 2.0f },
|
||||
currentAngles[digit][row*4+col].x,
|
||||
handsColor
|
||||
@ -194,7 +173,7 @@ int main(void)
|
||||
|
||||
// Little hand
|
||||
DrawRectanglePro(
|
||||
(Rectangle){centre.x, centre.y, clockFaceSize*.5f+2.0f, 4.0f},
|
||||
(Rectangle){centre.x, centre.y, clockFaceSize*0.5f+2.0f, 4.0f},
|
||||
(Vector2){ 2.0f, 2.0f },
|
||||
currentAngles[digit][row*4+col].y,
|
||||
handsColor
|
||||
@ -203,26 +182,22 @@ int main(void)
|
||||
}
|
||||
|
||||
xOffset += (clockFaceSize+clockFaceSpacing)*4;
|
||||
if (digit % 2 == 1) {
|
||||
|
||||
if (digit%2 == 1)
|
||||
{
|
||||
DrawRing((Vector2){xOffset + 4.0f, 160.0f}, 6.0f, 8.0f, 0.0f, 360.0f, 24, handsColor);
|
||||
DrawRing((Vector2){xOffset + 4.0f, 225.0f}, 6.0f, 8.0f, 0.0f, 360.0f, 24, handsColor);
|
||||
|
||||
xOffset += sectionSpacing;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@ -76,7 +76,7 @@ int main(void)
|
||||
float step = dt/SIMULATION_STEPS, step2 = step*step;
|
||||
|
||||
// Update Physics - larger steps = better approximation
|
||||
for (int i = 0; i < SIMULATION_STEPS; ++i)
|
||||
for (int i = 0; i < SIMULATION_STEPS; i++)
|
||||
{
|
||||
float delta = theta1 - theta2;
|
||||
float sinD = sinf(delta), cosD = cosf(delta), cos2D = cosf(2*delta);
|
||||
|
||||
@ -40,8 +40,8 @@ int main(void)
|
||||
|
||||
Vector2 sinePoints[WAVE_POINTS];
|
||||
Vector2 cosPoints[WAVE_POINTS];
|
||||
Vector2 center = { (screenWidth/2.0f) - 30.f, screenHeight/2.0f };
|
||||
Rectangle start = { 20.f, screenHeight - 120.f , 200.0f, 100.0f};
|
||||
Vector2 center = { (screenWidth/2.0f) - 30.0f, screenHeight/2.0f };
|
||||
Rectangle start = { 20.0f, screenHeight - 120.f , 200.0f, 100.0f};
|
||||
float radius = 130.0f;
|
||||
float angle = 0.0f;
|
||||
bool pause = false;
|
||||
@ -98,7 +98,7 @@ int main(void)
|
||||
// Base circle and axes
|
||||
DrawCircleLinesV(center, radius, GRAY);
|
||||
DrawLineEx((Vector2){ center.x, limitMin.y }, (Vector2){ center.x, limitMax.y }, 1.0f, GRAY);
|
||||
DrawLineEx((Vector2){ limitMin.x, center.y }, (Vector2){ limitMax.x, center.y }, 1.f, GRAY);
|
||||
DrawLineEx((Vector2){ limitMin.x, center.y }, (Vector2){ limitMax.x, center.y }, 1.0f, GRAY);
|
||||
|
||||
// Wave graph axes
|
||||
DrawLineEx((Vector2){ start.x , start.y }, (Vector2){ start.x , start.y + start.height }, 2.0f, GRAY);
|
||||
@ -135,19 +135,19 @@ int main(void)
|
||||
DrawText(TextFormat("Cotangent %.2f", cotangent), 640, 250, 6, ORANGE);
|
||||
|
||||
// Complementary angle (beige)
|
||||
DrawCircleSectorLines(center, radius*0.6f , -angle, -90.f , 36.0f, BEIGE);
|
||||
DrawCircleSectorLines(center, radius*0.6f , -angle, -90.0f , 36.0f, BEIGE);
|
||||
DrawText(TextFormat("Complementary %0.f°",complementary), 640, 150, 6, BEIGE);
|
||||
|
||||
// Supplementary angle (darkblue)
|
||||
DrawCircleSectorLines(center, radius*0.5f , -angle, -180.f , 36.0f, DARKBLUE);
|
||||
DrawCircleSectorLines(center, radius*0.5f , -angle, -180.0f , 36.0f, DARKBLUE);
|
||||
DrawText(TextFormat("Supplementary %0.f°",supplementary), 640, 130, 6, DARKBLUE);
|
||||
|
||||
// Explementary angle (pink)
|
||||
DrawCircleSectorLines(center, radius*0.4f , -angle, -360.f , 36.0f, PINK);
|
||||
DrawCircleSectorLines(center, radius*0.4f , -angle, -360.0f , 36.0f, PINK);
|
||||
DrawText(TextFormat("Explementary %0.f°",explementary), 640, 170, 6, PINK);
|
||||
|
||||
// Current angle - arc (lime), radius (black), endpoint (black)
|
||||
DrawCircleSectorLines(center, radius*0.7f , -angle, 0.f, 36.0f, LIME);
|
||||
DrawCircleSectorLines(center, radius*0.7f , -angle, 0.0f, 36.0f, LIME);
|
||||
DrawLineEx((Vector2){ center.x , center.y }, point, 2.0f, BLACK);
|
||||
DrawCircleV(point, 4.0f, BLACK);
|
||||
|
||||
@ -156,11 +156,12 @@ int main(void)
|
||||
GuiSetStyle(LABEL, TEXT_COLOR_NORMAL, ColorToInt(GRAY));
|
||||
GuiToggle((Rectangle){ 640, 70, 120, 20}, TextFormat("Pause"), &pause);
|
||||
GuiSetStyle(LABEL, TEXT_COLOR_NORMAL, ColorToInt(LIME));
|
||||
GuiSliderBar((Rectangle){ 640, 40, 120, 20}, "Angle", TextFormat("%.0f°", angle), &angle, 0.0f, 360.f);
|
||||
GuiSliderBar((Rectangle){ 640, 40, 120, 20}, "Angle", TextFormat("%.0f°", angle), &angle, 0.0f, 360.0f);
|
||||
|
||||
// Angle values panel
|
||||
GuiGroupBox((Rectangle){ 620, 110, 140, 170}, "Angle Values");
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
EndDrawing();
|
||||
|
||||
@ -112,7 +112,7 @@ int main(void)
|
||||
GuiSliderBar((Rectangle){ 640, 40, 120, 20}, "Angle", TextFormat("%.0f", angle), &angle, 0, 180);
|
||||
GuiSliderBar((Rectangle){ 640, 70, 120, 20 }, "Length", TextFormat("%.0f", length), &length, 12.0f, 240.0f);
|
||||
GuiSliderBar((Rectangle){ 640, 100, 120, 20}, "Decay", TextFormat("%.2f", branchDecay), &branchDecay, 0.1f, 0.78f);
|
||||
GuiSliderBar((Rectangle){ 640, 130, 120, 20 }, "Depth", TextFormat("%.0f", treeDepth), &treeDepth, 1.0f, 10.f);
|
||||
GuiSliderBar((Rectangle){ 640, 130, 120, 20 }, "Depth", TextFormat("%.0f", treeDepth), &treeDepth, 1.0f, 10.0f);
|
||||
GuiSliderBar((Rectangle){ 640, 160, 120, 20}, "Thick", TextFormat("%.0f", thick), &thick, 1, 8);
|
||||
GuiCheckBox((Rectangle){ 640, 190, 20, 20 }, "Bezier", &bezier);
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@ -152,21 +152,15 @@ int main(void)
|
||||
// If the slider or the wheel was clicked, update the current color
|
||||
if (settingColor || sliderClicked)
|
||||
{
|
||||
if (settingColor) {
|
||||
circlePosition = GetMousePosition();
|
||||
}
|
||||
if (settingColor) circlePosition = GetMousePosition();
|
||||
|
||||
float distance = Vector2Distance(center, circlePosition)/pointScale;
|
||||
|
||||
float angle = ((Vector2Angle((Vector2){ 0.0f, -pointScale }, Vector2Subtract(center, circlePosition))/PI + 1.0f)/2.0f);
|
||||
if (settingColor && distance > 1.0f) {
|
||||
circlePosition = Vector2Add((Vector2){ sinf(angle*(PI*2.0f))*pointScale, -cosf(angle*(PI* 2.0f))*pointScale }, center);
|
||||
}
|
||||
if (settingColor && distance > 1.0f) circlePosition = Vector2Add((Vector2){ sinf(angle*(PI*2.0f))*pointScale, -cosf(angle*(PI* 2.0f))*pointScale }, center);
|
||||
|
||||
float angle360 = angle*360.0f;
|
||||
|
||||
float valueActual = Clamp(distance, 0.0f, 1.0f);
|
||||
|
||||
color = ColorLerp((Color){ (int)(value*255.0f), (int)(value*255.0f), (int)(value*255.0f), 255 }, ColorFromHSV(angle360, Clamp(distance, 0.0f, 1.0f), 1.0f), valueActual);
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
@ -95,7 +95,7 @@ int main(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i <= emissionRate; ++i) EmitParticle(&circularBuffer, emitterPosition, currentType);
|
||||
for (int i = 0; i <= emissionRate; i++) EmitParticle(&circularBuffer, emitterPosition, currentType);
|
||||
}
|
||||
|
||||
// Update the parameters of each particle
|
||||
|
||||
@ -34,7 +34,7 @@ int main(void)
|
||||
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - triangle strip");
|
||||
|
||||
Vector2 points[122] = { 0 };
|
||||
Vector2 center = { (screenWidth/2.0f) - 125.f, screenHeight/2.0f };
|
||||
Vector2 center = { (screenWidth/2.0f) - 125.0f, screenHeight/2.0f };
|
||||
float segments = 6.0f;
|
||||
float insideRadius = 100.0f;
|
||||
float outsideRadius = 150.0f;
|
||||
@ -92,7 +92,7 @@ int main(void)
|
||||
|
||||
// Draw GUI controls
|
||||
//------------------------------------------------------------------------------
|
||||
GuiSliderBar((Rectangle){ 640, 40, 120, 20}, "Segments", TextFormat("%.0f", segments), &segments, 6.0f, 60.f);
|
||||
GuiSliderBar((Rectangle){ 640, 40, 120, 20}, "Segments", TextFormat("%.0f", segments), &segments, 6.0f, 60.0f);
|
||||
GuiCheckBox((Rectangle){ 640, 70, 20, 20 }, "Outline", &outline);
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@ -231,7 +231,7 @@ int main(void)
|
||||
if (multicolor)
|
||||
{
|
||||
// Fill color array with random colors
|
||||
for (int i = 0; i < TEXT_MAX_LAYERS; ++i)
|
||||
for (int i = 0; i < TEXT_MAX_LAYERS; i++)
|
||||
{
|
||||
multi[i] = GenerateRandomColor(0.5f, 0.8f);
|
||||
multi[i].a = GetRandomValue(0, 255);
|
||||
@ -296,7 +296,7 @@ int main(void)
|
||||
rlRotatef(90.0f, 1.0f, 0.0f, 0.0f);
|
||||
rlRotatef(90.0f, 0.0f, 0.0f, -1.0f);
|
||||
|
||||
for (int i = 0; i < layers; ++i)
|
||||
for (int i = 0; i < layers; i++)
|
||||
{
|
||||
Color clr = light;
|
||||
if (multicolor) clr = multi[i];
|
||||
|
||||
@ -210,7 +210,7 @@ int main(void)
|
||||
|
||||
// Draw random emojis in the background
|
||||
//------------------------------------------------------------------------------
|
||||
for (int i = 0; i < SIZEOF(emoji); ++i)
|
||||
for (int i = 0; i < SIZEOF(emoji); i++)
|
||||
{
|
||||
const char *txt = &emojiCodepoints[emoji[i].index];
|
||||
Rectangle emojiRect = { position.x, position.y, (float)fontEmoji.baseSize, (float)fontEmoji.baseSize };
|
||||
@ -316,7 +316,7 @@ static void RandomizeEmoji(void)
|
||||
hovered = selected = -1;
|
||||
int start = GetRandomValue(45, 360);
|
||||
|
||||
for (int i = 0; i < SIZEOF(emoji); ++i)
|
||||
for (int i = 0; i < SIZEOF(emoji); i++)
|
||||
{
|
||||
// 0-179 emoji codepoints (from emoji char array) each 4bytes + null char
|
||||
emoji[i].index = GetRandomValue(0, 179)*5;
|
||||
|
||||
@ -70,27 +70,32 @@ int main(void)
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
if (IsKeyPressed(KEY_LEFT)) {
|
||||
if (IsKeyPressed(KEY_LEFT))
|
||||
{
|
||||
hAlign = hAlign - 1;
|
||||
if (hAlign < 0) hAlign = 0;
|
||||
}
|
||||
if (IsKeyPressed(KEY_RIGHT)) {
|
||||
|
||||
if (IsKeyPressed(KEY_RIGHT))
|
||||
{
|
||||
hAlign = hAlign + 1;
|
||||
if (hAlign > 2) hAlign = 2;
|
||||
}
|
||||
if (IsKeyPressed(KEY_UP)) {
|
||||
|
||||
if (IsKeyPressed(KEY_UP))
|
||||
{
|
||||
vAlign = vAlign - 1;
|
||||
if (vAlign < 0) vAlign = 0;
|
||||
}
|
||||
if (IsKeyPressed(KEY_DOWN)) {
|
||||
|
||||
if (IsKeyPressed(KEY_DOWN))
|
||||
{
|
||||
vAlign = vAlign + 1;
|
||||
if (vAlign > 2) vAlign = 2;
|
||||
}
|
||||
|
||||
// One word per second
|
||||
wordIndex = (int)GetTime()%wordCount;
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
|
||||
@ -17,16 +17,10 @@
|
||||
|
||||
#include "raylib.h"
|
||||
|
||||
#define MAX_COLORS 256
|
||||
#define SCREEN_WIDTH 800
|
||||
#define SCREEN_HEIGHT 450
|
||||
#define SCALE_FACTOR 2
|
||||
// buffer size at least for screenImage pixel count
|
||||
#define INDEX_BUFFER_SIZE ((SCREEN_WIDTH * SCREEN_HEIGHT) / SCALE_FACTOR)
|
||||
#define FLAME_WIDTH (SCREEN_WIDTH / SCALE_FACTOR)
|
||||
#include <stdlib.h> // Required for: calloc(), free()
|
||||
|
||||
static void GeneretePalette(Color *palette);
|
||||
static void ClearIndexBuffer(unsigned char *buffer, int count);
|
||||
#define MAX_COLORS 256
|
||||
#define SCALE_FACTOR 2
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Program main entry point
|
||||
@ -35,22 +29,31 @@ int main(void)
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
const int screenWidth = SCREEN_WIDTH;
|
||||
const int screenHeight = SCREEN_HEIGHT;
|
||||
const int pixelScale = SCALE_FACTOR;
|
||||
const int imageWidth = screenWidth / pixelScale;
|
||||
const int imageHeight = screenHeight / pixelScale;
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [textures] example - screen buffer");
|
||||
|
||||
int imageWidth = screenWidth/SCALE_FACTOR;
|
||||
int imageHeight = screenHeight/SCALE_FACTOR;
|
||||
int flameWidth = screenWidth/SCALE_FACTOR;
|
||||
|
||||
Color palette[MAX_COLORS] = { 0 };
|
||||
unsigned char indexBuffer[INDEX_BUFFER_SIZE] = {0};
|
||||
unsigned char flameRootBuffer[FLAME_WIDTH] = {0};
|
||||
unsigned char *indexBuffer = RL_CALLOC(imageWidth*imageWidth, sizeof(unsigned char));
|
||||
unsigned char *flameRootBuffer = RL_CALLOC(flameWidth, sizeof(unsigned char));
|
||||
|
||||
Image screenImage = GenImageColor(imageWidth, imageHeight, BLACK);
|
||||
Texture screenTexture = LoadTextureFromImage(screenImage);
|
||||
GeneretePalette(palette);
|
||||
ClearIndexBuffer(indexBuffer, INDEX_BUFFER_SIZE);
|
||||
ClearIndexBuffer(flameRootBuffer, FLAME_WIDTH);
|
||||
|
||||
// Generate flame color palette
|
||||
for (int i = 0; i < MAX_COLORS; i++)
|
||||
{
|
||||
float t = (float)i/(float)(MAX_COLORS - 1);
|
||||
float hue = t*t;
|
||||
float saturation = t;
|
||||
float value = t;
|
||||
palette[i] = ColorFromHSV(250.0f + 150.0f*hue, saturation, value);
|
||||
}
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
@ -58,8 +61,10 @@ int main(void)
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
// Grow flameRoot
|
||||
for (int x = 2; x < FLAME_WIDTH; ++x)
|
||||
for (int x = 2; x < flameWidth; x++)
|
||||
{
|
||||
unsigned short flame = flameRootBuffer[x];
|
||||
if (flame == 255) continue;
|
||||
@ -68,26 +73,26 @@ int main(void)
|
||||
flameRootBuffer[x] = flame;
|
||||
}
|
||||
|
||||
// transfer flameRoot to indexBuffer
|
||||
for (int x = 0; x < FLAME_WIDTH; ++x)
|
||||
// Transfer flameRoot to indexBuffer
|
||||
for (int x = 0; x < flameWidth; x++)
|
||||
{
|
||||
int i = x + (imageHeight - 1)*imageWidth;
|
||||
indexBuffer[i] = flameRootBuffer[x];
|
||||
}
|
||||
|
||||
// Clear top row, because it can't move any higher
|
||||
for (int x = 0; x < imageWidth; ++x)
|
||||
for (int x = 0; x < imageWidth; x++)
|
||||
{
|
||||
if (indexBuffer[x] == 0) continue;
|
||||
indexBuffer[x] = 0;
|
||||
}
|
||||
|
||||
// Skip top row, it is already cleared
|
||||
for (int y = 1; y < imageHeight; ++y)
|
||||
for (int y = 1; y < imageHeight; y++)
|
||||
{
|
||||
for (int x = 0; x < imageWidth; ++x)
|
||||
for (int x = 0; x < imageWidth; x++)
|
||||
{
|
||||
unsigned i = x + y * imageWidth;
|
||||
unsigned int i = x + y*imageWidth;
|
||||
unsigned char colorIndex = indexBuffer[i];
|
||||
if (colorIndex == 0) continue;
|
||||
|
||||
@ -97,19 +102,19 @@ int main(void)
|
||||
int newX = x + moveX;
|
||||
if (newX < 0 || newX >= imageWidth) continue;
|
||||
|
||||
unsigned i_above = i - imageWidth + moveX;
|
||||
unsigned int iabove = i - imageWidth + moveX;
|
||||
int decay = GetRandomValue(0, 3);
|
||||
colorIndex -= (decay < colorIndex)? decay : colorIndex;
|
||||
indexBuffer[i_above] = colorIndex;
|
||||
indexBuffer[iabove] = colorIndex;
|
||||
}
|
||||
}
|
||||
|
||||
// Update screenImage with palette colors
|
||||
for (int y = 1; y < imageHeight; ++y)
|
||||
for (int y = 1; y < imageHeight; y++)
|
||||
{
|
||||
for (int x = 0; x < imageWidth; ++x)
|
||||
for (int x = 0; x < imageWidth; x++)
|
||||
{
|
||||
unsigned i = x + y * imageWidth;
|
||||
unsigned int i = x + y*imageWidth;
|
||||
unsigned char colorIndex = indexBuffer[i];
|
||||
Color col = palette[colorIndex];
|
||||
ImageDrawPixel(&screenImage, x, y, col);
|
||||
@ -117,19 +122,24 @@ int main(void)
|
||||
}
|
||||
|
||||
UpdateTexture(screenTexture, screenImage.data);
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
const Vector2 origin = (Vector2){0, 0};
|
||||
const float rotation = 0.f;
|
||||
DrawTextureEx(screenTexture, origin, rotation, pixelScale, WHITE);
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
DrawTextureEx(screenTexture, (Vector2){ 0, 0 }, 0.0f, 2.0f, WHITE);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
RL_FREE(indexBuffer);
|
||||
RL_FREE(flameRootBuffer);
|
||||
UnloadTexture(screenTexture);
|
||||
UnloadImage(screenImage);
|
||||
|
||||
@ -138,24 +148,3 @@ int main(void)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void GeneretePalette(Color *palette)
|
||||
{
|
||||
for (int i = 0; i < MAX_COLORS; ++i)
|
||||
{
|
||||
float t = (float)i/(float)(MAX_COLORS - 1);
|
||||
float hue = t * t;
|
||||
float saturation = t;
|
||||
float value = t;
|
||||
palette[i] = ColorFromHSV(250.f + 150.f * hue, saturation, value);
|
||||
}
|
||||
}
|
||||
|
||||
static void ClearIndexBuffer(unsigned char *buffer, int count)
|
||||
{
|
||||
// Use memset to set to ZERO, but for demonstration a plain for loop is used
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
buffer[i] = 0;
|
||||
}
|
||||
}
|
||||
@ -100,7 +100,7 @@ int main(void)
|
||||
}
|
||||
|
||||
// Check to see which color was clicked and set it as the active color
|
||||
for (int i = 0; i < MAX_COLORS; ++i)
|
||||
for (int i = 0; i < MAX_COLORS; i++)
|
||||
{
|
||||
if (CheckCollisionPointRec(mouse, colorRec[i]))
|
||||
{
|
||||
|
||||
@ -17,7 +17,6 @@ Example automated testing elements validated:
|
||||
| **EXAMPLE NAME** | [CWARN] | [LWARN] | [INIT] | [CLOSE] | [ASSETS] | [RLGL] | [PLAT] | [FONT] | [TIMER] |
|
||||
|:---------------------------------|:-------:|:-------:|:------:|:-------:|:--------:|:------:|:------:|:------:|:-------:|
|
||||
| core_monitor_detector | 0 | 1 | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
|
||||
| textures_screen_buffer | 0 | 0 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
|
||||
| textures_sprite_stacking | 0 | 0 | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ❌ |
|
||||
| text_sprite_fonts | 0 | 0 | ✔ | ❌ | ✔ | ✔ | ✔ | ✔ | ❌ |
|
||||
| text_font_loading | 0 | 3 | ✔ | ✔ | ❌ | ✔ | ✔ | ✔ | ✔ |
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user