diff --git a/build.sh b/build.sh index 60ccd66..2f1883a 100755 --- a/build.sh +++ b/build.sh @@ -10,6 +10,7 @@ clang -I./include/ -o build/core_input_keys ./examples/core_input_keys.c -L./lib clang -I./include/ -o build/shapes_colors_palette ./examples/shapes_colors_palette.c -L./lib/ -lraylib -lm clang -I./include/ -o build/game ./game.c -L./lib/ -lraylib -lm clang -I./include/ -o ./build/core_input_mouse_wheel ./examples/core_input_mouse_wheel.c -L./lib/ -lraylib -lm +clang -I./include/ -o ./build/textures_logo_raylib ./examples/textures_logo_raylib.c -L./lib/ -lraylib -lm clang --target=wasm32 -I./include --no-standard-libraries -Wl,--export-table -Wl,--no-entry -Wl,--allow-undefined -Wl,--export=main -o wasm/core_basic_window.wasm ./examples/core_basic_window.c -DPLATFORM_WEB clang --target=wasm32 -I./include --no-standard-libraries -Wl,--export-table -Wl,--no-entry -Wl,--allow-undefined -Wl,--export=main -o wasm/core_basic_screen_manager.wasm ./examples/core_basic_screen_manager.c -DPLATFORM_WEB @@ -17,3 +18,7 @@ clang --target=wasm32 -I./include --no-standard-libraries -Wl,--export-table -Wl clang --target=wasm32 -I./include --no-standard-libraries -Wl,--export-table -Wl,--no-entry -Wl,--allow-undefined -Wl,--export=main -o wasm/shapes_colors_palette.wasm ./examples/shapes_colors_palette.c -DPLATFORM_WEB clang --target=wasm32 -I./include --no-standard-libraries -Wl,--export-table -Wl,--no-entry -Wl,--allow-undefined -Wl,--export=main -o wasm/game.wasm game.c -DPLATFORM_WEB clang --target=wasm32 -I./include --no-standard-libraries -Wl,--export-table -Wl,--no-entry -Wl,--allow-undefined -Wl,--export=main -o wasm/core_input_mouse_wheel.wasm ./examples/core_input_mouse_wheel.c -DPLATFORM_WEB +clang --target=wasm32 -I./include --no-standard-libraries -Wl,--export-table -Wl,--no-entry -Wl,--allow-undefined -Wl,--export=main -o wasm/textures_logo_raylib.wasm ./examples/textures_logo_raylib.c -DPLATFORM_WEB + +# Instrument all wasm files with Asyncify +ls wasm | xargs -I{} wasm-opt --asyncify wasm/{} --pass-arg=asyncify-imports@env.WindowShouldClose,env.LoadTexture -o wasm/{} diff --git a/examples/core_basic_screen_manager.c b/examples/core_basic_screen_manager.c index 6220c35..728ef12 100644 --- a/examples/core_basic_screen_manager.c +++ b/examples/core_basic_screen_manager.c @@ -15,117 +15,11 @@ #include "raylib.h" -void raylib_js_set_entry(void (*entry)(void)); - //------------------------------------------------------------------------------------------ // Types and Structures Definition //------------------------------------------------------------------------------------------ typedef enum GameScreen { LOGO = 0, TITLE, GAMEPLAY, ENDING } GameScreen; -const int screenWidth = 800; -const int screenHeight = 450; -GameScreen currentScreen = LOGO; -int framesCounter = 0; // Useful to count frames - -void GameFrame(void) -{ - // Update - //---------------------------------------------------------------------------------- - switch(currentScreen) - { - case LOGO: - { - // TODO: Update LOGO screen variables here! - - framesCounter++; // Count frames - - // Wait for 2 seconds (120 frames) before jumping to TITLE screen - if (framesCounter > 120) - { - currentScreen = TITLE; - } - } break; - case TITLE: - { - // TODO: Update TITLE screen variables here! - - // Press enter to change to GAMEPLAY screen - if (IsKeyPressed(KEY_ENTER) || IsGestureDetected(GESTURE_TAP)) - { - currentScreen = GAMEPLAY; - } - } break; - case GAMEPLAY: - { - // TODO: Update GAMEPLAY screen variables here! - - // Press enter to change to ENDING screen - if (IsKeyPressed(KEY_ENTER) || IsGestureDetected(GESTURE_TAP)) - { - currentScreen = ENDING; - } - } break; - case ENDING: - { - // TODO: Update ENDING screen variables here! - - // Press enter to return to TITLE screen - if (IsKeyPressed(KEY_ENTER) || IsGestureDetected(GESTURE_TAP)) - { - currentScreen = TITLE; - } - } break; - default: break; - } - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - switch(currentScreen) - { - case LOGO: - { - // TODO: Draw LOGO screen here! - DrawText("LOGO SCREEN", 20, 20, 40, LIGHTGRAY); - DrawText("WAIT for 2 SECONDS...", 290, 220, 20, GRAY); - - } break; - case TITLE: - { - // TODO: Draw TITLE screen here! - DrawRectangle(0, 0, screenWidth, screenHeight, GREEN); - DrawText("TITLE SCREEN", 20, 20, 40, DARKGREEN); - DrawText("PRESS ENTER or TAP to JUMP to GAMEPLAY SCREEN", 120, 220, 20, DARKGREEN); - - } break; - case GAMEPLAY: - { - // TODO: Draw GAMEPLAY screen here! - DrawRectangle(0, 0, screenWidth, screenHeight, PURPLE); - DrawText("GAMEPLAY SCREEN", 20, 20, 40, MAROON); - DrawText("PRESS ENTER or TAP to JUMP to ENDING SCREEN", 130, 220, 20, MAROON); - - } break; - case ENDING: - { - // TODO: Draw ENDING screen here! - DrawRectangle(0, 0, screenWidth, screenHeight, BLUE); - DrawText("ENDING SCREEN", 20, 20, 40, DARKBLUE); - DrawText("PRESS ENTER or TAP to RETURN to TITLE SCREEN", 120, 220, 20, DARKBLUE); - - } break; - default: break; - } - - EndDrawing(); - //---------------------------------------------------------------------------------- -} - - //------------------------------------------------------------------------------------ // Program main entry point //------------------------------------------------------------------------------------ @@ -133,21 +27,117 @@ int main(void) { // Initialization //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [core] example - basic screen manager"); + GameScreen currentScreen = LOGO; + // TODO: Initialize all required variables and load all required data here! + int framesCounter = 0; // Useful to count frames + SetTargetFPS(60); // Set desired framerate (frames-per-second) //-------------------------------------------------------------------------------------- -#ifdef PLATFORM_WEB - raylib_js_set_entry(GameFrame); -#else // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { - GameFrame(); + // Update + //---------------------------------------------------------------------------------- + switch(currentScreen) + { + case LOGO: + { + // TODO: Update LOGO screen variables here! + + framesCounter++; // Count frames + + // Wait for 2 seconds (120 frames) before jumping to TITLE screen + if (framesCounter > 120) + { + currentScreen = TITLE; + } + } break; + case TITLE: + { + // TODO: Update TITLE screen variables here! + + // Press enter to change to GAMEPLAY screen + if (IsKeyPressed(KEY_ENTER) || IsGestureDetected(GESTURE_TAP)) + { + currentScreen = GAMEPLAY; + } + } break; + case GAMEPLAY: + { + // TODO: Update GAMEPLAY screen variables here! + + // Press enter to change to ENDING screen + if (IsKeyPressed(KEY_ENTER) || IsGestureDetected(GESTURE_TAP)) + { + currentScreen = ENDING; + } + } break; + case ENDING: + { + // TODO: Update ENDING screen variables here! + + // Press enter to return to TITLE screen + if (IsKeyPressed(KEY_ENTER) || IsGestureDetected(GESTURE_TAP)) + { + currentScreen = TITLE; + } + } break; + default: break; + } + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + switch(currentScreen) + { + case LOGO: + { + // TODO: Draw LOGO screen here! + DrawText("LOGO SCREEN", 20, 20, 40, LIGHTGRAY); + DrawText("WAIT for 2 SECONDS...", 290, 220, 20, GRAY); + + } break; + case TITLE: + { + // TODO: Draw TITLE screen here! + DrawRectangle(0, 0, screenWidth, screenHeight, GREEN); + DrawText("TITLE SCREEN", 20, 20, 40, DARKGREEN); + DrawText("PRESS ENTER or TAP to JUMP to GAMEPLAY SCREEN", 120, 220, 20, DARKGREEN); + + } break; + case GAMEPLAY: + { + // TODO: Draw GAMEPLAY screen here! + DrawRectangle(0, 0, screenWidth, screenHeight, PURPLE); + DrawText("GAMEPLAY SCREEN", 20, 20, 40, MAROON); + DrawText("PRESS ENTER or TAP to JUMP to ENDING SCREEN", 130, 220, 20, MAROON); + + } break; + case ENDING: + { + // TODO: Draw ENDING screen here! + DrawRectangle(0, 0, screenWidth, screenHeight, BLUE); + DrawText("ENDING SCREEN", 20, 20, 40, DARKBLUE); + DrawText("PRESS ENTER or TAP to RETURN to TITLE SCREEN", 120, 220, 20, DARKBLUE); + + } break; + default: break; + } + + EndDrawing(); + //---------------------------------------------------------------------------------- } // De-Initialization @@ -157,7 +147,6 @@ int main(void) CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- -#endif return 0; } diff --git a/examples/core_basic_window.c b/examples/core_basic_window.c index 2790222..a925a39 100644 --- a/examples/core_basic_window.c +++ b/examples/core_basic_window.c @@ -23,19 +23,6 @@ #include "raylib.h" -void raylib_js_set_entry(void (*entry)(void)); - -void GameFrame(void) -{ - BeginDrawing(); - - ClearBackground(RAYWHITE); - - DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY); - - EndDrawing(); -} - //------------------------------------------------------------------------------------ // Program main entry point //------------------------------------------------------------------------------------ @@ -51,9 +38,6 @@ int main(void) SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- -#ifdef PLATFORM_WEB - raylib_js_set_entry(GameFrame); -#else // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { @@ -64,7 +48,13 @@ int main(void) // Draw //---------------------------------------------------------------------------------- - GameFrame(); + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY); + + EndDrawing(); //---------------------------------------------------------------------------------- } @@ -72,7 +62,6 @@ int main(void) //-------------------------------------------------------------------------------------- CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- -#endif return 0; } diff --git a/examples/core_input_keys.c b/examples/core_input_keys.c index cdc45e2..511e101 100644 --- a/examples/core_input_keys.c +++ b/examples/core_input_keys.c @@ -13,33 +13,6 @@ #include "raylib.h" -void raylib_js_set_entry(void (*entry)(void)); -Vector2 ballPosition = { 0 }; - -void GameFrame() -{ - // Update - //---------------------------------------------------------------------------------- - if (IsKeyDown(KEY_RIGHT)) ballPosition.x += 2.0f; - if (IsKeyDown(KEY_LEFT)) ballPosition.x -= 2.0f; - if (IsKeyDown(KEY_UP)) ballPosition.y -= 2.0f; - if (IsKeyDown(KEY_DOWN)) ballPosition.y += 2.0f; - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - DrawText("move the ball with arrow keys", 10, 10, 20, DARKGRAY); - - DrawCircleV(ballPosition, 50, MAROON); - - EndDrawing(); - //---------------------------------------------------------------------------------- -} - //------------------------------------------------------------------------------------ // Program main entry point //------------------------------------------------------------------------------------ @@ -52,24 +25,40 @@ int main(void) InitWindow(screenWidth, screenHeight, "raylib [core] example - keyboard input"); - ballPosition.x = (float)screenWidth/2; - ballPosition.y = (float)screenHeight/2; + Vector2 ballPosition = { (float)screenWidth/2, (float)screenHeight/2 }; SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- -#ifdef PLATFORM_WEB - raylib_js_set_entry(GameFrame); -#else + // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { - GameFrame(); + // Update + //---------------------------------------------------------------------------------- + if (IsKeyDown(KEY_RIGHT)) ballPosition.x += 2.0f; + if (IsKeyDown(KEY_LEFT)) ballPosition.x -= 2.0f; + if (IsKeyDown(KEY_UP)) ballPosition.y -= 2.0f; + if (IsKeyDown(KEY_DOWN)) ballPosition.y += 2.0f; + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawText("move the ball with arrow keys", 10, 10, 20, DARKGRAY); + + DrawCircleV(ballPosition, 50, MAROON); + + EndDrawing(); + //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- -#endif + return 0; -} \ No newline at end of file +} diff --git a/examples/core_input_mouse_wheel.c b/examples/core_input_mouse_wheel.c index 84350f0..e8152d1 100644 --- a/examples/core_input_mouse_wheel.c +++ b/examples/core_input_mouse_wheel.c @@ -1,8 +1,8 @@ /******************************************************************************************* * -* raylib [core] example - Keyboard input +* raylib [core] example - Mouse input * -* Example originally created with raylib 1.0, last time updated with raylib 1.0 +* Example originally created with raylib 1.0, last time updated with raylib 4.0 * * Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, * BSD-like license that allows static linking with closed source software @@ -13,35 +13,6 @@ #include "raylib.h" -void raylib_js_set_entry(void (*entry)(void)); - -const int screenWidth = 800; -const int screenHeight = 450; -int boxPositionY = screenHeight/2 - 40; -int scrollSpeed = 4; // Scrolling speed in pixels -Vector2 ballPosition = { 0 }; - -void GameFrame() -{ - // Update - //---------------------------------------------------------------------------------- - boxPositionY -= (GetMouseWheelMove()*scrollSpeed); - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - DrawRectangle(screenWidth/2 - 40, boxPositionY, 80, 80, MAROON); - - DrawText("Use mouse wheel to move the cube up and down!", 10, 10, 20, GRAY); - DrawText(TextFormat("Box position Y: %03i", boxPositionY), 10, 40, 20, LIGHTGRAY); - - EndDrawing(); -} - //------------------------------------------------------------------------------------ // Program main entry point //------------------------------------------------------------------------------------ @@ -49,23 +20,45 @@ int main(void) { // Initialization //-------------------------------------------------------------------------------------- - InitWindow(screenWidth, screenHeight, "raylib [core] example - input mouse wheel"); + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [core] example - mouse input"); + + int boxPositionY = screenHeight / 2 - 40; + int scrollSpeed = 4; // Scrolling speed in pixels + Vector2 ballPosition = { 0 }; SetTargetFPS(60); // Set our game to run at 60 frames-per-second - //-------------------------------------------------------------------------------------- -#ifdef PLATFORM_WEB - raylib_js_set_entry(GameFrame); -#else + //--------------------------------------------------------------------------------------- + // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { - GameFrame(); + // Update + //---------------------------------------------------------------------------------- + boxPositionY -= (GetMouseWheelMove()*scrollSpeed); + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawRectangle(screenWidth/2 - 40, boxPositionY, 80, 80, MAROON); + + DrawText("Use mouse wheel to move the cube up and down!", 10, 10, 20, GRAY); + DrawText(TextFormat("Box position Y: %03i", boxPositionY), 10, 40, 20, LIGHTGRAY); + + EndDrawing(); + //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- -#endif + return 0; } diff --git a/examples/resources/raylib_logo.png b/examples/resources/raylib_logo.png new file mode 100644 index 0000000..15bbaa2 Binary files /dev/null and b/examples/resources/raylib_logo.png differ diff --git a/examples/shapes_colors_palette.c b/examples/shapes_colors_palette.c index 3cd0e00..34248eb 100644 --- a/examples/shapes_colors_palette.c +++ b/examples/shapes_colors_palette.c @@ -12,66 +12,8 @@ ********************************************************************************************/ #include "raylib.h" -#define MAX_COLORS_COUNT 21 // Number of colors available - -void raylib_js_set_entry(void (*entry)(void)); - -Color colors[MAX_COLORS_COUNT] = { - DARKGRAY, MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, DARKBROWN, - GRAY, RED, GOLD, LIME, BLUE, VIOLET, BROWN, LIGHTGRAY, PINK, YELLOW, - GREEN, SKYBLUE, PURPLE, BEIGE }; - -const char *colorNames[MAX_COLORS_COUNT] = { - "DARKGRAY", "MAROON", "ORANGE", "DARKGREEN", "DARKBLUE", "DARKPURPLE", - "DARKBROWN", "GRAY", "RED", "GOLD", "LIME", "BLUE", "VIOLET", "BROWN", - "LIGHTGRAY", "PINK", "YELLOW", "GREEN", "SKYBLUE", "PURPLE", "BEIGE" }; - -Rectangle colorsRecs[MAX_COLORS_COUNT] = { 0 }; // Rectangles array - -int colorState[MAX_COLORS_COUNT] = { 0 }; // Color state: 0-DEFAULT, 1-MOUSE_HOVER - -Vector2 mousePoint = { 0.0f, 0.0f }; - - -void GameFrame() -{ - // Update - //---------------------------------------------------------------------------------- - mousePoint = GetMousePosition(); - - for (int i = 0; i < MAX_COLORS_COUNT; i++) - { - if (CheckCollisionPointRec(mousePoint, colorsRecs[i])) colorState[i] = 1; - else colorState[i] = 0; - } - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - DrawText("raylib colors palette", 28, 42, 20, BLACK); - DrawText("press SPACE to see all colors", GetScreenWidth() - 180, GetScreenHeight() - 40, 10, GRAY); - - for (int i = 0; i < MAX_COLORS_COUNT; i++) // Draw all rectangles - { - DrawRectangleRec(colorsRecs[i], Fade(colors[i], colorState[i]? 0.6f : 1.0f)); - - if (IsKeyDown(KEY_SPACE) || colorState[i]) - { - DrawRectangle((int)colorsRecs[i].x, (int)(colorsRecs[i].y + colorsRecs[i].height - 26), (int)colorsRecs[i].width, 20, BLACK); - DrawRectangleLinesEx(colorsRecs[i], 6, Fade(BLACK, 0.3f)); - DrawText(colorNames[i], (int)(colorsRecs[i].x + colorsRecs[i].width - MeasureText(colorNames[i], 10) - 12), - (int)(colorsRecs[i].y + colorsRecs[i].height - 20), 10, colors[i]); - } - } - - EndDrawing(); - //---------------------------------------------------------------------------------- -} +#define MAX_COLORS_COUNT 21 // Number of colors available //------------------------------------------------------------------------------------ // Program main entry point @@ -85,6 +27,17 @@ int main(void) InitWindow(screenWidth, screenHeight, "raylib [shapes] example - colors palette"); + static Color colors[MAX_COLORS_COUNT] = { + DARKGRAY, MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, DARKBROWN, + GRAY, RED, GOLD, LIME, BLUE, VIOLET, BROWN, LIGHTGRAY, PINK, YELLOW, + GREEN, SKYBLUE, PURPLE, BEIGE }; + + static const char *colorNames[MAX_COLORS_COUNT] = { + "DARKGRAY", "MAROON", "ORANGE", "DARKGREEN", "DARKBLUE", "DARKPURPLE", + "DARKBROWN", "GRAY", "RED", "GOLD", "LIME", "BLUE", "VIOLET", "BROWN", + "LIGHTGRAY", "PINK", "YELLOW", "GREEN", "SKYBLUE", "PURPLE", "BEIGE" }; + + static Rectangle colorsRecs[MAX_COLORS_COUNT] = { 0 }; // Rectangles array // Fills colorsRecs data (for every rectangle) for (int i = 0; i < MAX_COLORS_COUNT; i++) @@ -95,23 +48,57 @@ int main(void) colorsRecs[i].height = 100.0f; } + int colorState[MAX_COLORS_COUNT] = { 0 }; // Color state: 0-DEFAULT, 1-MOUSE_HOVER + Vector2 mousePoint = { 0.0f, 0.0f }; SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- -#ifdef PLATFORM_WEB - raylib_js_set_entry(GameFrame); -#else // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { - GameFrame(); + // Update + //---------------------------------------------------------------------------------- + mousePoint = GetMousePosition(); + + for (int i = 0; i < MAX_COLORS_COUNT; i++) + { + if (CheckCollisionPointRec(mousePoint, colorsRecs[i])) colorState[i] = 1; + else colorState[i] = 0; + } + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawText("raylib colors palette", 28, 42, 20, BLACK); + DrawText("press SPACE to see all colors", GetScreenWidth() - 180, GetScreenHeight() - 40, 10, GRAY); + + for (int i = 0; i < MAX_COLORS_COUNT; i++) // Draw all rectangles + { + DrawRectangleRec(colorsRecs[i], Fade(colors[i], colorState[i]? 0.6f : 1.0f)); + + if (IsKeyDown(KEY_SPACE) || colorState[i]) + { + DrawRectangle((int)colorsRecs[i].x, (int)(colorsRecs[i].y + colorsRecs[i].height - 26), (int)colorsRecs[i].width, 20, BLACK); + DrawRectangleLinesEx(colorsRecs[i], 6, Fade(BLACK, 0.3f)); + DrawText(colorNames[i], (int)(colorsRecs[i].x + colorsRecs[i].width - MeasureText(colorNames[i], 10) - 12), + (int)(colorsRecs[i].y + colorsRecs[i].height - 20), 10, colors[i]); + } + } + + EndDrawing(); + //---------------------------------------------------------------------------------- } + // De-Initialization //-------------------------------------------------------------------------------------- CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- -#endif + return 0; -} \ No newline at end of file +} diff --git a/examples/textures_logo_raylib.c b/examples/textures_logo_raylib.c new file mode 100644 index 0000000..f170dab --- /dev/null +++ b/examples/textures_logo_raylib.c @@ -0,0 +1,62 @@ +/******************************************************************************************* +* +* raylib [textures] example - Texture loading and drawing +* +* Example originally created with raylib 1.0, last time updated with raylib 1.0 +* +* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, +* BSD-like license that allows static linking with closed source software +* +* Copyright (c) 2014-2024 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture loading and drawing"); + + // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) + Texture2D texture = LoadTexture("resources/raylib_logo.png"); // Texture loading + //--------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + // TODO: Update your variables here + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2, WHITE); + + DrawText("this IS a texture!", 360, 370, 10, GRAY); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadTexture(texture); // Texture unloading + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} \ No newline at end of file diff --git a/game.c b/game.c index d3f9da1..52c616b 100644 --- a/game.c +++ b/game.c @@ -7,8 +7,6 @@ static Vector2 ball_position = {0}; static Vector2 ball_velocity = {200, 200}; -void raylib_js_set_entry(void (*entry)(void)); - void GameFrame() { BeginDrawing(); @@ -41,13 +39,9 @@ int main() ball_position.x = w/2; ball_position.y = h/2; -#ifdef PLATFORM_WEB - raylib_js_set_entry(GameFrame); -#else while (!WindowShouldClose()) { GameFrame(); } CloseWindow(); -#endif return 0; } diff --git a/index.html b/index.html index 5f29ff6..6a3dc0a 100644 --- a/index.html +++ b/index.html @@ -34,23 +34,27 @@ src: url(fonts/acme_7_wide_xtnd.woff); } -
-