#include "consts.h" #include "raylib.h" #include "raymath.h" #include #include #include "../data/cube.png.h" #if defined(PLATFORM_WEB) #include #endif #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b)) void MainLoop(); RenderTexture2D target; Image texImg; Texture2D texture; Camera3D cam; Model cube; int main(void) { SetConfigFlags(FLAG_WINDOW_RESIZABLE | FLAG_VSYNC_HINT); InitWindow(WIN_WIDTH, WIN_HEIGHT, "game"); SetTargetFPS(60); SetExitKey(KEY_BACKSPACE); target = LoadRenderTexture(SCREEN_WIDTH, SCREEN_HEIGHT); SetTextureFilter(target.texture, TEXTURE_FILTER_POINT); texImg = LoadImageFromMemory(".png", cube_png, cube_png_len); texture = LoadTextureFromImage(texImg); cam = (Camera3D){0}; cam.position = (Vector3){0.0f, 0.0f, sqrtf(3.0f)}; cam.target = (Vector3){0.0f, 0.0f, 0.0f}; cam.up = (Vector3){0.0f, 1.0f, 0.0f}; cam.fovy = 60.0f; cam.projection = CAMERA_PERSPECTIVE; cube = LoadModelFromMesh(GenMeshCube(1.0f, 1.0f, 1.0f)); cube.materials[0].maps[MATERIAL_MAP_ALBEDO].texture = texture; #if defined(PLATFORM_WEB) emscripten_set_main_loop(MainLoop, 0, 1); #else while (!WindowShouldClose()) MainLoop(); #endif CloseWindow(); return 0; } void MainLoop() { int winWidth = GetScreenWidth(), winHeight = GetScreenHeight(); float scale = MIN((float)winWidth / SCREEN_WIDTH, (float)winHeight / SCREEN_HEIGHT); cube.transform = MatrixMultiply(MatrixRotateXYZ(Vector3Scale((Vector3){1.0f, 1.5f, 2.5f}, GetFrameTime())), cube.transform); BeginTextureMode(target); { ClearBackground(BLACK); DrawCircleV((Vector2){160.0f, 120.0f}, 120.0f, WHITE); BeginMode3D(cam); { DrawModel(cube, Vector3Zero(), 1.0f, WHITE); } EndMode3D(); } EndTextureMode(); BeginDrawing(); { ClearBackground(BLACK); DrawTexturePro( target.texture, (Rectangle){0.0f, 0.0f, (float)SCREEN_WIDTH, (float)-SCREEN_HEIGHT}, (Rectangle){(winWidth - ((float)SCREEN_WIDTH * scale)) * 0.5f, (winHeight - ((float)SCREEN_HEIGHT * scale)) * 0.5f, (float)SCREEN_WIDTH * scale, (float)SCREEN_HEIGHT * scale}, (Vector2){0, 0}, 0.0f, WHITE); } EndDrawing(); }