forked from SasLuca/raylib-cmake-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
edd9f6f
commit 7575e86
Showing
4 changed files
with
89 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include "app.hpp" | ||
#include "../libs/raylib/src/raylib.h" | ||
#include "helper.hpp" | ||
|
||
Texture2D texture; | ||
|
||
void init_app() | ||
{ | ||
texture = LoadTexture("assets/test.png"); | ||
} | ||
|
||
bool app_loop() | ||
{ | ||
|
||
BeginDrawing(); | ||
|
||
ClearBackground(RAYWHITE); | ||
|
||
const int texture_x = getWindowWidth() / 2 - texture.width / 2; | ||
const int texture_y = getWindowHeight() / 2 - texture.height / 2; | ||
DrawTexture(texture, texture_x, texture_y, WHITE); | ||
|
||
const char *text = "OMG! IT WORKS!"; | ||
const Vector2 text_size = MeasureTextEx(GetFontDefault(), text, 20, 1); | ||
DrawText(text, getWindowWidth() / 2.0 - text_size.x / 2, texture_y + texture.height + text_size.y + 10, 20, BLACK); | ||
|
||
EndDrawing(); | ||
|
||
return true; | ||
} | ||
|
||
void deinit_app() | ||
{ | ||
UnloadTexture(texture); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#ifndef APP_HPP | ||
#define APP_HPP | ||
|
||
// Load asset and initialized stuffs here | ||
void init_app(); | ||
|
||
// The main loop (return false to end loop) | ||
bool app_loop(); | ||
|
||
// Free up allocated memory | ||
void deinit_app(); | ||
|
||
#endif |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include "../libs/raylib/src/raylib.h" | ||
#include "helper.hpp" | ||
#include "app.hpp" | ||
|
||
void web_loop() | ||
{ | ||
static int old_w = 0, old_h = 0; | ||
|
||
int w = getWindowWidth(); | ||
int h = getWindowHeight(); | ||
if (w != old_w || h != old_h) | ||
{ | ||
SetWindowSize(w, h); | ||
} | ||
app_loop(); | ||
} | ||
|
||
int main(void) | ||
{ | ||
// Setup window | ||
#if defined(PLATFORM_WEB) | ||
InitWindow(getBrowserWindowWidth(), getBrowserWindowHeight(), PROJECT_NAME); | ||
#else | ||
InitWindow(800, 500, PROJECT_NAME); | ||
#endif | ||
SetWindowState(FLAG_WINDOW_RESIZABLE | FLAG_WINDOW_MAXIMIZED); | ||
init_app(); | ||
|
||
#if defined(PLATFORM_WEB) | ||
emscripten_set_main_loop(web_loop, 0, 1); | ||
#else | ||
while (app_loop() && !WindowShouldClose()) | ||
{ | ||
} | ||
#endif | ||
deinit_app(); | ||
|
||
// Cleanup | ||
CloseWindow(); | ||
return 0; | ||
} |