generated from It-Club/RaylibTemplate-C
Slim down project
This commit is contained in:
@@ -1,7 +1,4 @@
|
||||
#include "consts.h"
|
||||
|
||||
const int SCREEN_WIDTH = 320;
|
||||
const int SCREEN_HEIGHT = 240;
|
||||
|
||||
const int WIN_WIDTH = 1280;
|
||||
const int WIN_HEIGHT = 720;
|
||||
|
||||
@@ -1,5 +1,2 @@
|
||||
extern const int SCREEN_WIDTH;
|
||||
extern const int SCREEN_HEIGHT;
|
||||
|
||||
extern const int WIN_WIDTH;
|
||||
extern const int WIN_HEIGHT;
|
||||
|
||||
10
src/draw.c
10
src/draw.c
@@ -3,12 +3,4 @@
|
||||
#include "raylib.h"
|
||||
#include "raymath.h"
|
||||
|
||||
void Draw() {
|
||||
ClearBackground(BLACK);
|
||||
DrawCircleV((Vector2){160.0f, 120.0f}, 120.0f, WHITE);
|
||||
BeginMode3D(cam);
|
||||
{
|
||||
DrawModel(cube, Vector3Zero(), 1.0f, WHITE);
|
||||
}
|
||||
EndMode3D();
|
||||
}
|
||||
void Draw() { ClearBackground(BLACK); }
|
||||
|
||||
51
src/main.c
51
src/main.c
@@ -2,50 +2,20 @@
|
||||
#include "consts.h"
|
||||
#include "draw.h"
|
||||
#include "raylib.h"
|
||||
#include "raymath.h"
|
||||
#include "update.h"
|
||||
#include <math.h>
|
||||
|
||||
#include "../data/cube.png.h"
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
|
||||
static 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;
|
||||
SetExitKey(KEY_LEFT_ALT);
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
emscripten_set_main_loop(MainLoop, 0, 1);
|
||||
@@ -59,28 +29,11 @@ int main(void) {
|
||||
}
|
||||
|
||||
static void MainLoop() {
|
||||
int winWidth = GetScreenWidth(), winHeight = GetScreenHeight();
|
||||
float scale =
|
||||
MIN((float)winWidth / SCREEN_WIDTH, (float)winHeight / SCREEN_HEIGHT);
|
||||
|
||||
Update();
|
||||
|
||||
BeginTextureMode(target);
|
||||
{
|
||||
Draw();
|
||||
}
|
||||
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);
|
||||
Draw();
|
||||
}
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
@@ -1,9 +1 @@
|
||||
#include "raylib.h"
|
||||
|
||||
extern RenderTexture2D target;
|
||||
|
||||
extern Image texImg;
|
||||
extern Texture2D texture;
|
||||
|
||||
extern Camera3D cam;
|
||||
extern Model cube;
|
||||
|
||||
@@ -3,9 +3,4 @@
|
||||
#include "raylib.h"
|
||||
#include "raymath.h"
|
||||
|
||||
void Update() {
|
||||
cube.transform =
|
||||
MatrixMultiply(MatrixRotateXYZ(Vector3Scale((Vector3){1.0f, 1.5f, 2.5f},
|
||||
GetFrameTime())),
|
||||
cube.transform);
|
||||
}
|
||||
void Update() {}
|
||||
|
||||
Reference in New Issue
Block a user