mirror of
https://gitlab.com/raylibtemplates/rt.git
synced 2026-06-10 10:45:12 -04:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
439ba4478d | ||
|
|
a21cc3c1f4 | ||
|
|
2e78dbd9df | ||
|
|
8600517c12 | ||
|
|
4d94c9b4b7 |
@@ -5,15 +5,15 @@ project(game C CXX)
|
|||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
set(RAYLIB_VERSION 5.5)
|
find_package(raylib QUIET) # QUIET or REQUIRED
|
||||||
find_package(raylib ${RAYLIB_VERSION} QUIET) # QUIET or REQUIRED
|
|
||||||
if(NOT raylib_FOUND) # If there's none, fetch and build raylib
|
if(NOT raylib_FOUND) # If there's none, fetch and build raylib
|
||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
raylib
|
raylib
|
||||||
DOWNLOAD_EXTRACT_TIMESTAMP OFF
|
DOWNLOAD_EXTRACT_TIMESTAMP OFF
|
||||||
URL https://github.com/raysan5/raylib/archive/refs/tags/${RAYLIB_VERSION}.tar.gz
|
GIT_REPOSITORY https://github.com/raysan5/raylib.git
|
||||||
)
|
GIT_TAG master
|
||||||
|
)
|
||||||
FetchContent_GetProperties(raylib)
|
FetchContent_GetProperties(raylib)
|
||||||
if(NOT raylib_POPULATED) # Have we downloaded raylib yet?
|
if(NOT raylib_POPULATED) # Have we downloaded raylib yet?
|
||||||
set(FETCHCONTENT_QUIET NO)
|
set(FETCHCONTENT_QUIET NO)
|
||||||
|
|||||||
7
src/consts.c
Normal file
7
src/consts.c
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#include "consts.h"
|
||||||
|
|
||||||
|
const int SCREEN_WIDTH = 320;
|
||||||
|
const int SCREEN_HEIGHT = 240;
|
||||||
|
|
||||||
|
const int WIN_WIDTH = 1280;
|
||||||
|
const int WIN_HEIGHT = 720;
|
||||||
5
src/consts.h
Normal file
5
src/consts.h
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
extern const int SCREEN_WIDTH;
|
||||||
|
extern const int SCREEN_HEIGHT;
|
||||||
|
|
||||||
|
extern const int WIN_WIDTH;
|
||||||
|
extern const int WIN_HEIGHT;
|
||||||
14
src/draw.c
Normal file
14
src/draw.c
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#include "draw.h"
|
||||||
|
#include "main.h"
|
||||||
|
#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();
|
||||||
|
}
|
||||||
1
src/draw.h
Normal file
1
src/draw.h
Normal file
@@ -0,0 +1 @@
|
|||||||
|
extern void Draw();
|
||||||
27
src/main.c
27
src/main.c
@@ -1,7 +1,10 @@
|
|||||||
|
#include "main.h"
|
||||||
|
#include "consts.h"
|
||||||
|
#include "draw.h"
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
#include "raymath.h"
|
#include "raymath.h"
|
||||||
|
#include "update.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include "../data/cube.png.h"
|
#include "../data/cube.png.h"
|
||||||
|
|
||||||
@@ -9,15 +12,10 @@
|
|||||||
#include <emscripten/emscripten.h>
|
#include <emscripten/emscripten.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SCREEN_WIDTH (320)
|
|
||||||
#define SCREEN_HEIGHT (240)
|
|
||||||
#define WIN_WIDTH (1280)
|
|
||||||
#define WIN_HEIGHT (720)
|
|
||||||
|
|
||||||
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||||
|
|
||||||
void MainLoop();
|
static void MainLoop();
|
||||||
|
|
||||||
RenderTexture2D target;
|
RenderTexture2D target;
|
||||||
|
|
||||||
@@ -60,25 +58,16 @@ int main(void) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainLoop() {
|
static void MainLoop() {
|
||||||
int winWidth = GetScreenWidth(), winHeight = GetScreenHeight();
|
int winWidth = GetScreenWidth(), winHeight = GetScreenHeight();
|
||||||
float scale =
|
float scale =
|
||||||
MIN((float)winWidth / SCREEN_WIDTH, (float)winHeight / SCREEN_HEIGHT);
|
MIN((float)winWidth / SCREEN_WIDTH, (float)winHeight / SCREEN_HEIGHT);
|
||||||
|
|
||||||
cube.transform =
|
Update();
|
||||||
MatrixMultiply(MatrixRotateXYZ(Vector3Scale((Vector3){1.0f, 1.5f, 2.5f},
|
|
||||||
GetFrameTime())),
|
|
||||||
cube.transform);
|
|
||||||
|
|
||||||
BeginTextureMode(target);
|
BeginTextureMode(target);
|
||||||
{
|
{
|
||||||
ClearBackground(BLACK);
|
Draw();
|
||||||
DrawCircleV((Vector2){160.0f, 120.0f}, 120.0f, WHITE);
|
|
||||||
BeginMode3D(cam);
|
|
||||||
{
|
|
||||||
DrawModel(cube, Vector3Zero(), 1.0f, WHITE);
|
|
||||||
}
|
|
||||||
EndMode3D();
|
|
||||||
}
|
}
|
||||||
EndTextureMode();
|
EndTextureMode();
|
||||||
|
|
||||||
|
|||||||
9
src/main.h
Normal file
9
src/main.h
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#include "raylib.h"
|
||||||
|
|
||||||
|
extern RenderTexture2D target;
|
||||||
|
|
||||||
|
extern Image texImg;
|
||||||
|
extern Texture2D texture;
|
||||||
|
|
||||||
|
extern Camera3D cam;
|
||||||
|
extern Model cube;
|
||||||
11
src/update.c
Normal file
11
src/update.c
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#include "update.h"
|
||||||
|
#include "main.h"
|
||||||
|
#include "raylib.h"
|
||||||
|
#include "raymath.h"
|
||||||
|
|
||||||
|
void Update() {
|
||||||
|
cube.transform =
|
||||||
|
MatrixMultiply(MatrixRotateXYZ(Vector3Scale((Vector3){1.0f, 1.5f, 2.5f},
|
||||||
|
GetFrameTime())),
|
||||||
|
cube.transform);
|
||||||
|
}
|
||||||
1
src/update.h
Normal file
1
src/update.h
Normal file
@@ -0,0 +1 @@
|
|||||||
|
extern void Update();
|
||||||
Reference in New Issue
Block a user