From e0445fb15085ba3d5ff0be71942f5529d378a256 Mon Sep 17 00:00:00 2001 From: Dima Marhitych Date: Tue, 5 Dec 2023 16:43:57 +0100 Subject: [PATCH] Full on rewrite to C (done) --- CMakeLists.txt | 25 +++-- include/vuelto/Vuelto.h | 18 ++++ include/vuelto/Vuelto.hpp | 10 -- include/vuelto/vuelto/core/app.h | 11 ++ include/vuelto/vuelto/core/app.hpp | 30 ------ include/vuelto/vuelto/core/renderer.h | 10 ++ include/vuelto/vuelto/core/renderer.hpp | 35 ------- include/vuelto/vuelto/event/event.h | 9 ++ include/vuelto/vuelto/event/event.hpp | 20 ---- include/vuelto/vuelto/event/keys.h | 96 +++++++++++++++++ include/vuelto/vuelto/event/keys.hpp | 103 ------------------- include/vuelto/vuelto/tools/definitions.h | 35 +++++++ include/vuelto/vuelto/tools/definitions.hpp | 13 --- src/Vuelto.h | 18 ++++ src/Vuelto.hpp | 10 -- src/vuelto/core/{app.cpp => app.c} | 47 ++++----- src/vuelto/core/app.h | 11 ++ src/vuelto/core/app.hpp | 32 ------ src/vuelto/core/{renderer.cpp => renderer.c} | 53 ++++------ src/vuelto/core/renderer.h | 10 ++ src/vuelto/core/renderer.hpp | 35 ------- src/vuelto/event/event.c | 19 ++++ src/vuelto/event/event.cpp | 31 ------ src/vuelto/event/event.h | 9 ++ src/vuelto/event/event.hpp | 20 ---- src/vuelto/event/keys.h | 96 +++++++++++++++++ src/vuelto/event/keys.hpp | 103 ------------------- src/vuelto/tools/definitions.h | 35 +++++++ src/vuelto/tools/definitions.hpp | 15 --- test/test.cpp | 21 ++-- 30 files changed, 442 insertions(+), 538 deletions(-) create mode 100644 include/vuelto/Vuelto.h delete mode 100644 include/vuelto/Vuelto.hpp create mode 100644 include/vuelto/vuelto/core/app.h delete mode 100644 include/vuelto/vuelto/core/app.hpp create mode 100644 include/vuelto/vuelto/core/renderer.h delete mode 100644 include/vuelto/vuelto/core/renderer.hpp create mode 100644 include/vuelto/vuelto/event/event.h delete mode 100644 include/vuelto/vuelto/event/event.hpp create mode 100644 include/vuelto/vuelto/event/keys.h delete mode 100644 include/vuelto/vuelto/event/keys.hpp create mode 100644 include/vuelto/vuelto/tools/definitions.h delete mode 100644 include/vuelto/vuelto/tools/definitions.hpp create mode 100644 src/Vuelto.h delete mode 100644 src/Vuelto.hpp rename src/vuelto/core/{app.cpp => app.c} (51%) create mode 100644 src/vuelto/core/app.h delete mode 100644 src/vuelto/core/app.hpp rename src/vuelto/core/{renderer.cpp => renderer.c} (55%) create mode 100644 src/vuelto/core/renderer.h delete mode 100644 src/vuelto/core/renderer.hpp create mode 100644 src/vuelto/event/event.c delete mode 100644 src/vuelto/event/event.cpp create mode 100644 src/vuelto/event/event.h delete mode 100644 src/vuelto/event/event.hpp create mode 100644 src/vuelto/event/keys.h delete mode 100644 src/vuelto/event/keys.hpp create mode 100644 src/vuelto/tools/definitions.h delete mode 100644 src/vuelto/tools/definitions.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 260e97d..af26b8b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,15 +6,15 @@ add_subdirectory(libs/glfw) # Set the source files for the library file(GLOB LIBRARY_SOURCES - "src/vuelto/core/*.cpp" - "src/vuelto/event/*.cpp" + "src/vuelto/core/*.c" + "src/vuelto/event/*.c" ) file(GLOB LIBRARY_HEADERS - "src/Vuelto.hpp" - "src/vuelto/core/*.hpp" - "src/vuelto/event/*.hpp" - "src/vuelto/tools/*.hpp" + "src/Vuelto.h" + "src/vuelto/core/*.h" + "src/vuelto/event/*.h" + "src/vuelto/tools/*.h" "src/vuelto/vendor/GLFW/*.h" "src/vuelto/vendor/stb_image/*.h" ) @@ -22,7 +22,7 @@ file(GLOB LIBRARY_HEADERS # Create the shared library add_library(vuelto SHARED ${LIBRARY_SOURCES} ${LIBRARY_HEADERS}) -set_property(TARGET vuelto PROPERTY CXX_STANDARD 11) +set_property(TARGET vuelto PROPERTY C_STANDARD 99) # Set the include directories for the library target_include_directories(vuelto PUBLIC @@ -31,6 +31,17 @@ target_include_directories(vuelto PUBLIC $ ) +# Copy header files with folder structure under src +foreach(HEADER ${LIBRARY_HEADERS}) + file(RELATIVE_PATH HEADER_RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/src ${HEADER}) + get_filename_component(HEADER_NAME ${HEADER} NAME) + get_filename_component(HEADER_PATH ${HEADER_RELATIVE} DIRECTORY) + + file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/vuelto/${HEADER_PATH}) + file(COPY ${HEADER} DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/include/vuelto/${HEADER_PATH}) +endforeach() + + # Link GLFW to the library target_link_libraries(vuelto PUBLIC glfw) diff --git a/include/vuelto/Vuelto.h b/include/vuelto/Vuelto.h new file mode 100644 index 0000000..a9ace19 --- /dev/null +++ b/include/vuelto/Vuelto.h @@ -0,0 +1,18 @@ +#ifdef __cplusplus +extern "C" { +#endif + +// core +#include "vuelto/core/app.h" +#include "vuelto/core/renderer.h" + +// event +#include "vuelto/event/event.h" +#include "vuelto/event/keys.h" + +// tools +#include "vuelto/tools/definitions.h" + +#ifdef __cplusplus +} +#endif diff --git a/include/vuelto/Vuelto.hpp b/include/vuelto/Vuelto.hpp deleted file mode 100644 index add647f..0000000 --- a/include/vuelto/Vuelto.hpp +++ /dev/null @@ -1,10 +0,0 @@ -// core -#include "vuelto/core/app.hpp" -#include "vuelto/core/renderer.hpp" - -// event -#include "vuelto/event/event.hpp" -#include "vuelto/event/keys.hpp" - -// tools -#include "vuelto/tools/definitions.hpp" diff --git a/include/vuelto/vuelto/core/app.h b/include/vuelto/vuelto/core/app.h new file mode 100644 index 0000000..8c5c83f --- /dev/null +++ b/include/vuelto/vuelto/core/app.h @@ -0,0 +1,11 @@ +#include "../tools/definitions.h" + +void vueltoInit(); +void vueltoInitMultipleWindows(); +Vuelto_Window vueltoCreateWindow(int width, int height, const char *title, bool resizable); +void vueltoDestroyWindow(Vuelto_Window win); +void vueltoTerminate(); + +bool vueltoWindowShouldClose(Vuelto_Window win); +void vueltoRefresh(Vuelto_Window win); +void vueltoMakeContextCurrent(Vuelto_Window win); diff --git a/include/vuelto/vuelto/core/app.hpp b/include/vuelto/vuelto/core/app.hpp deleted file mode 100644 index 68c64a5..0000000 --- a/include/vuelto/vuelto/core/app.hpp +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once - -#include "../tools/definitions.hpp" - -namespace Vuelto { - -class Window; - -namespace Application { - -void Init(); -void InitMultipleWindows(); -Window CreateWindow(int width, int height, const char *title, bool resizable); -void DestroyWindow(Window win); -void Terminate(); - -} // namespace Application - -class Window { - public: - GLFWwindow *window; - int width; - int height; - const char *title; - bool WindowShouldClose(); - void Refresh(); - void MakeContextCurrent(); -}; - -} // namespace Vuelto diff --git a/include/vuelto/vuelto/core/renderer.h b/include/vuelto/vuelto/core/renderer.h new file mode 100644 index 0000000..7ee2613 --- /dev/null +++ b/include/vuelto/vuelto/core/renderer.h @@ -0,0 +1,10 @@ +#include "../tools/definitions.h" + +void vueltoDrawRect(float x, float y, float width, float height, float r, float g, float b); +void vueltoSetBackgroundColor(float color1, float color2, float color3); +void vueltoDrawLine(int x1, int x2, int y1, int y2, float color1, float color2, float color3); + +Vuelto_Image vueltoLoadImage(const char* imagePath, float x, float y, float width, float height); +void vueltoDrawImage(Vuelto_Image img); + +void vueltoCleanUp(); diff --git a/include/vuelto/vuelto/core/renderer.hpp b/include/vuelto/vuelto/core/renderer.hpp deleted file mode 100644 index 1c7d11c..0000000 --- a/include/vuelto/vuelto/core/renderer.hpp +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#include "app.hpp" - -namespace Vuelto { - -class Renderer2D; - -namespace Application { - -Vuelto::Renderer2D CreateRenderer2D(Window win); - -} // namespace Application - -class Renderer2D { - public: - class Image; - - void DrawRect(float x, float y, float width, float height, float r, float g, float b); - void SetBackgroundColor(float color1, float color2, float color3); - void DrawLine(int x1, int x2, int y1, int y2, float color1, float color2, float color3); - - Image LoadImage(const char* imagePath, float x, float y, float width, float height); - void CleanUp(); -}; - -class Renderer2D::Image { - public: - float width, height, x, y; - GLuint texture; - - void DrawImage(); -}; - -} // namespace Vuelto diff --git a/include/vuelto/vuelto/event/event.h b/include/vuelto/vuelto/event/event.h new file mode 100644 index 0000000..847f87b --- /dev/null +++ b/include/vuelto/vuelto/event/event.h @@ -0,0 +1,9 @@ +#pragma once + +#include "../core/app.h" +#include "../tools/definitions.h" + +void vueltoPollEvents(); + +bool vueltoKeyPressed(Vuelto_Window window, int keyCode); +bool vueltoKeyPressedOnce(Vuelto_Window window, int key); diff --git a/include/vuelto/vuelto/event/event.hpp b/include/vuelto/vuelto/event/event.hpp deleted file mode 100644 index d7c49bb..0000000 --- a/include/vuelto/vuelto/event/event.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include "../tools/definitions.hpp" -#include "../core/app.hpp" - -namespace Vuelto { -namespace Events { - -void PollEvents(); - -} - -namespace Input { - -bool IsKeyPressed(Vuelto::Window window, int keyCode); -bool IsKeyPressedOnce(Vuelto::Window window, int key); - -} - -} // namespace Vuelto diff --git a/include/vuelto/vuelto/event/keys.h b/include/vuelto/vuelto/event/keys.h new file mode 100644 index 0000000..577ddbe --- /dev/null +++ b/include/vuelto/vuelto/event/keys.h @@ -0,0 +1,96 @@ +#include "../tools/definitions.h" + +#define VUELTO_KEY_SPACE GLFW_KEY_SPACE +#define VUELTO_KEY_APOSTROPHE GLFW_KEY_APOSTROPHE +#define VUELTO_KEY_COMMA GLFW_KEY_COMMA +#define VUELTO_KEY_MINUS GLFW_KEY_MINUS +#define VUELTO_KEY_PERIOD GLFW_KEY_PERIOD +#define VUELTO_KEY_SLASH GLFW_KEY_SLASH +#define VUELTO_KEY_0 GLFW_KEY_0 +#define VUELTO_KEY_1 GLFW_KEY_1 +#define VUELTO_KEY_2 GLFW_KEY_2 +#define VUELTO_KEY_3 GLFW_KEY_3 +#define VUELTO_KEY_4 GLFW_KEY_4 +#define VUELTO_KEY_5 GLFW_KEY_5 +#define VUELTO_KEY_6 GLFW_KEY_6 +#define VUELTO_KEY_7 GLFW_KEY_7 +#define VUELTO_KEY_8 GLFW_KEY_8 +#define VUELTO_KEY_9 GLFW_KEY_9 +#define VUELTO_KEY_SEMICOLON GLFW_KEY_SEMICOLON +#define VUELTO_KEY_EQUAL GLFW_KEY_EQUAL +#define VUELTO_KEY_A GLFW_KEY_A +#define VUELTO_KEY_B GLFW_KEY_B +#define VUELTO_KEY_C GLFW_KEY_C +#define VUELTO_KEY_D GLFW_KEY_D +#define VUELTO_KEY_E GLFW_KEY_E +#define VUELTO_KEY_F GLFW_KEY_F +#define VUELTO_KEY_G GLFW_KEY_G +#define VUELTO_KEY_H GLFW_KEY_H +#define VUELTO_KEY_I GLFW_KEY_I +#define VUELTO_KEY_J GLFW_KEY_J +#define VUELTO_KEY_K GLFW_KEY_K +#define VUELTO_KEY_L GLFW_KEY_L +#define VUELTO_KEY_M GLFW_KEY_M +#define VUELTO_KEY_N GLFW_KEY_N +#define VUELTO_KEY_O GLFW_KEY_O +#define VUELTO_KEY_P GLFW_KEY_P +#define VUELTO_KEY_Q GLFW_KEY_Q +#define VUELTO_KEY_R GLFW_KEY_R +#define VUELTO_KEY_S GLFW_KEY_S +#define VUELTO_KEY_T GLFW_KEY_T +#define VUELTO_KEY_U GLFW_KEY_U +#define VUELTO_KEY_V GLFW_KEY_V +#define VUELTO_KEY_W GLFW_KEY_W +#define VUELTO_KEY_X GLFW_KEY_X +#define VUELTO_KEY_Y GLFW_KEY_Y +#define VUELTO_KEY_Z GLFW_KEY_Z +#define VUELTO_KEY_LEFT_BRACKET GLFW_KEY_LEFT_BRACKET +#define VUELTO_KEY_BACKSLASH GLFW_KEY_BACKSLASH +#define VUELTO_KEY_RIGHT_BRACKET GLFW_KEY_RIGHT_BRACKET +#define VUELTO_KEY_GRAVE_ACCENT GLFW_KEY_GRAVE_ACCENT +#define VUELTO_KEY_WORLD_1 GLFW_KEY_WORLD_1 +#define VUELTO_KEY_WORLD_2 GLFW_KEY_WORLD_2 +#define VUELTO_KEY_ESCAPE GLFW_KEY_ESCAPE +#define VUELTO_KEY_ENTER GLFW_KEY_ENTER +#define VUELTO_KEY_TAB GLFW_KEY_TAB +#define VUELTO_KEY_BACKSPACE GLFW_KEY_BACKSPACE +#define VUELTO_KEY_INSERT GLFW_KEY_INSERT +#define VUELTO_KEY_DELETE GLFW_KEY_DELETE +#define VUELTO_KEY_RIGHT GLFW_KEY_RIGHT +#define VUELTO_KEY_LEFT GLFW_KEY_LEFT +#define VUELTO_KEY_DOWN GLFW_KEY_DOWN +#define VUELTO_KEY_UP GLFW_KEY_UP +#define VUELTO_KEY_PAGE_UP GLFW_KEY_PAGE_UP +#define VUELTO_KEY_PAGE_DOWN GLFW_KEY_PAGE_DOWN +#define VUELTO_KEY_HOME GLFW_KEY_HOME +#define VUELTO_KEY_END GLFW_KEY_END +#define VUELTO_KEY_CAPS_LOCK GLFW_KEY_CAPS_LOCK +#define VUELTO_KEY_SCROLL_LOCK GLFW_KEY_SCROLL_LOCK +#define VUELTO_KEY_NUM_LOCK GLFW_KEY_NUM_LOCK +#define VUELTO_KEY_PRINT_SCREEN GLFW_KEY_PRINT_SCREEN +#define VUELTO_KEY_PAUSE GLFW_KEY_PAUSE +#define VUELTO_KEY_F1 GLFW_KEY_F1 +#define VUELTO_KEY_F2 GLFW_KEY_F2 +#define VUELTO_KEY_F3 GLFW_KEY_F3 +#define VUELTO_KEY_F4 GLFW_KEY_F4 +#define VUELTO_KEY_F5 GLFW_KEY_F5 +#define VUELTO_KEY_F6 GLFW_KEY_F6 +#define VUELTO_KEY_F7 GLFW_KEY_F7 +#define VUELTO_KEY_F8 GLFW_KEY_F8 +#define VUELTO_KEY_F9 GLFW_KEY_F9 +#define VUELTO_KEY_F10 GLFW_KEY_F10 +#define VUELTO_KEY_F11 GLFW_KEY_F11 +#define VUELTO_KEY_F12 GLFW_KEY_F12 +#define VUELTO_KEY_F13 GLFW_KEY_F13 +#define VUELTO_KEY_F14 GLFW_KEY_F14 +#define VUELTO_KEY_F15 GLFW_KEY_F15 +#define VUELTO_KEY_F16 GLFW_KEY_F16 +#define VUELTO_KEY_F17 GLFW_KEY_F17 +#define VUELTO_KEY_F18 GLFW_KEY_F18 +#define VUELTO_KEY_F19 GLFW_KEY_F19 +#define VUELTO_KEY_F20 GLFW_KEY_F20 +#define VUELTO_KEY_F21 GLFW_KEY_F21 +#define VUELTO_KEY_F22 GLFW_KEY_F22 +#define VUELTO_KEY_F23 GLFW_KEY_F23 +#define VUELTO_KEY_F24 GLFW_KEY_F24 +#define VUELTO_KEY_F25 GLFW_KEY_F25 diff --git a/include/vuelto/vuelto/event/keys.hpp b/include/vuelto/vuelto/event/keys.hpp deleted file mode 100644 index 4dde5db..0000000 --- a/include/vuelto/vuelto/event/keys.hpp +++ /dev/null @@ -1,103 +0,0 @@ -#include "../tools/definitions.hpp" - -namespace Vuelto { -namespace Keys { - -const int Space = GLFW_KEY_SPACE; -const int Apostrophe = GLFW_KEY_APOSTROPHE; -const int Comma = GLFW_KEY_COMMA; -const int Minus = GLFW_KEY_MINUS; -const int Period = GLFW_KEY_PERIOD; -const int Slash = GLFW_KEY_SLASH; -const int Key0 = GLFW_KEY_0; -const int Key1 = GLFW_KEY_1; -const int Key2 = GLFW_KEY_2; -const int Key3 = GLFW_KEY_3; -const int Key4 = GLFW_KEY_4; -const int Key5 = GLFW_KEY_5; -const int Key6 = GLFW_KEY_6; -const int Key7 = GLFW_KEY_7; -const int Key8 = GLFW_KEY_8; -const int Key9 = GLFW_KEY_9; -const int Semicolon = GLFW_KEY_SEMICOLON; -const int Equal = GLFW_KEY_EQUAL; -const int A = GLFW_KEY_A; -const int B = GLFW_KEY_B; -const int C = GLFW_KEY_C; -const int D = GLFW_KEY_D; -const int E = GLFW_KEY_E; -const int F = GLFW_KEY_F; -const int G = GLFW_KEY_G; -const int H = GLFW_KEY_H; -const int I = GLFW_KEY_I; -const int J = GLFW_KEY_J; -const int K = GLFW_KEY_K; -const int L = GLFW_KEY_L; -const int M = GLFW_KEY_M; -const int N = GLFW_KEY_N; -const int O = GLFW_KEY_O; -const int P = GLFW_KEY_P; -const int Q = GLFW_KEY_Q; -const int R = GLFW_KEY_R; -const int S = GLFW_KEY_S; -const int T = GLFW_KEY_T; -const int U = GLFW_KEY_U; -const int V = GLFW_KEY_V; -const int W = GLFW_KEY_W; -const int X = GLFW_KEY_X; -const int Y = GLFW_KEY_Y; -const int Z = GLFW_KEY_Z; -const int LeftBracket = GLFW_KEY_LEFT_BRACKET; -const int Backslash = GLFW_KEY_BACKSLASH; -const int RightBracket = GLFW_KEY_RIGHT_BRACKET; -const int GraveAccent = GLFW_KEY_GRAVE_ACCENT; -const int World1 = GLFW_KEY_WORLD_1; -const int World2 = GLFW_KEY_WORLD_2; -const int Escape = GLFW_KEY_ESCAPE; -const int Enter = GLFW_KEY_ENTER; -const int Tab = GLFW_KEY_TAB; -const int Backspace = GLFW_KEY_BACKSPACE; -const int Insert = GLFW_KEY_INSERT; -const int Delete = GLFW_KEY_DELETE; -const int Right = GLFW_KEY_RIGHT; -const int Left = GLFW_KEY_LEFT; -const int Down = GLFW_KEY_DOWN; -const int Up = GLFW_KEY_UP; -const int PageUp = GLFW_KEY_PAGE_UP; -const int PageDown = GLFW_KEY_PAGE_DOWN; -const int Home = GLFW_KEY_HOME; -const int End = GLFW_KEY_END; -const int CapsLock = GLFW_KEY_CAPS_LOCK; -const int ScrollLock = GLFW_KEY_SCROLL_LOCK; -const int NumLock = GLFW_KEY_NUM_LOCK; -const int PrintScreen = GLFW_KEY_PRINT_SCREEN; -const int Pause = GLFW_KEY_PAUSE; -const int F1 = GLFW_KEY_F1; -const int F2 = GLFW_KEY_F2; -const int F3 = GLFW_KEY_F3; -const int F4 = GLFW_KEY_F4; -const int F5 = GLFW_KEY_F5; -const int F6 = GLFW_KEY_F6; -const int F7 = GLFW_KEY_F7; -const int F8 = GLFW_KEY_F8; -const int F9 = GLFW_KEY_F9; -const int F10 = GLFW_KEY_F10; -const int F11 = GLFW_KEY_F11; -const int F12 = GLFW_KEY_F12; -const int F13 = GLFW_KEY_F13; -const int F14 = GLFW_KEY_F14; -const int F15 = GLFW_KEY_F15; -const int F16 = GLFW_KEY_F16; -const int F17 = GLFW_KEY_F17; -const int F18 = GLFW_KEY_F18; -const int F19 = GLFW_KEY_F19; -const int F20 = GLFW_KEY_F20; -const int F21 = GLFW_KEY_F21; -const int F22 = GLFW_KEY_F22; -const int F23 = GLFW_KEY_F23; -const int F24 = GLFW_KEY_F24; -const int F25 = GLFW_KEY_F25; - - -} -} \ No newline at end of file diff --git a/include/vuelto/vuelto/tools/definitions.h b/include/vuelto/vuelto/tools/definitions.h new file mode 100644 index 0000000..26cfe85 --- /dev/null +++ b/include/vuelto/vuelto/tools/definitions.h @@ -0,0 +1,35 @@ +#pragma once + +#ifdef __APPLE__ +#define GL_SILENCE_DEPRECATION +#include +#elif __linux__ +#define GL_SILENCE_DEPRECATION +#include +#elif _WIN32 +#define GL_CLAMP_TO_EDGE 0x812f +#elif _WIN64 +#define GL_CLAMP_TO_EDGE 0x812f +#else +#include +#endif + +#define vueltoForEach(item, array) \ + for (int keep = 1, count = 0, size = sizeof(array) / sizeof *(array); keep && count != size; keep = !keep, count++) \ + for (item = (array) + count; keep; keep = !keep) + +#include +#include +#include + +typedef struct { + GLFWwindow *window; + int width; + int height; + const char *title; +} Vuelto_Window; + +typedef struct { + float width, height, x, y; + GLuint texture; +} Vuelto_Image; diff --git a/include/vuelto/vuelto/tools/definitions.hpp b/include/vuelto/vuelto/tools/definitions.hpp deleted file mode 100644 index c569103..0000000 --- a/include/vuelto/vuelto/tools/definitions.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#ifdef __APPLE__ -// #define GL_SILENCE_DEPRECATION -#include -#elif __linux__ -#define GL_SILENCE_DEPRECATION -#include -#elif _WIN32 -#elif _WIN64 -#else -#include -#endif - -#include diff --git a/src/Vuelto.h b/src/Vuelto.h new file mode 100644 index 0000000..a9ace19 --- /dev/null +++ b/src/Vuelto.h @@ -0,0 +1,18 @@ +#ifdef __cplusplus +extern "C" { +#endif + +// core +#include "vuelto/core/app.h" +#include "vuelto/core/renderer.h" + +// event +#include "vuelto/event/event.h" +#include "vuelto/event/keys.h" + +// tools +#include "vuelto/tools/definitions.h" + +#ifdef __cplusplus +} +#endif diff --git a/src/Vuelto.hpp b/src/Vuelto.hpp deleted file mode 100644 index add647f..0000000 --- a/src/Vuelto.hpp +++ /dev/null @@ -1,10 +0,0 @@ -// core -#include "vuelto/core/app.hpp" -#include "vuelto/core/renderer.hpp" - -// event -#include "vuelto/event/event.hpp" -#include "vuelto/event/keys.hpp" - -// tools -#include "vuelto/tools/definitions.hpp" diff --git a/src/vuelto/core/app.cpp b/src/vuelto/core/app.c similarity index 51% rename from src/vuelto/core/app.cpp rename to src/vuelto/core/app.c index 9bcf4bb..4900ed9 100644 --- a/src/vuelto/core/app.cpp +++ b/src/vuelto/core/app.c @@ -1,22 +1,18 @@ -#include "app.hpp" +#include "app.h" -#include - -#include "../tools/definitions.hpp" - -namespace Vuelto { -namespace Application { +#include "../tools/definitions.h" +#include "renderer.h" bool MultipleWindowsEnabled = false; -void Init() { +void vueltoInit() { if (!glfwInit()) { - std::cout << "GLFW Init failed\n"; + printf("GLFW Init failed\n"); } } -void InitMultipleWindows() { - Init(); +void vueltoInitMultipleWindows() { + vueltoInit(); MultipleWindowsEnabled = true; } @@ -24,13 +20,13 @@ void framebuffer_size_callback(GLFWwindow *window, int newWidth, int newHeight) glViewport(0, 0, newWidth, newHeight); } -Window CreateWindow(int width, int height, const char *title, bool resizable) { +Vuelto_Window vueltoCreateWindow(int width, int height, const char *title, bool resizable) { glfwWindowHint(GLFW_RESIZABLE, resizable); GLFWwindow *glfw_window = glfwCreateWindow(width, height, title, NULL, NULL); if (!glfw_window) { glfwTerminate(); - std::cout << "GLFW Window creation failed\n"; + printf("GLFW Window creation failed\n"); } glfwSetFramebufferSizeCallback(glfw_window, framebuffer_size_callback); @@ -42,7 +38,7 @@ Window CreateWindow(int width, int height, const char *title, bool resizable) { glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - Window window; + Vuelto_Window window; window.width = width; window.height = height; window.title = title; @@ -51,26 +47,23 @@ Window CreateWindow(int width, int height, const char *title, bool resizable) { return window; } -void DestroyWindow(Window win) { glfwDestroyWindow(win.window); } +void vueltoDestroyWindow(Vuelto_Window win) { glfwDestroyWindow(win.window); } -void Terminate() { glfwTerminate(); } +void vueltoTerminate() { glfwTerminate(); } -} // namespace Application - -bool Window::WindowShouldClose() { - while (!glfwWindowShouldClose(window)) { +bool vueltoWindowShouldClose(Vuelto_Window win) { + while (!glfwWindowShouldClose(win.window)) { return false; } - glfwDestroyWindow(window); + vueltoCleanUp(); + glfwDestroyWindow(win.window); return true; } -void Window::MakeContextCurrent() { glfwMakeContextCurrent(window); } +void vueltoMakeContextCurrent(Vuelto_Window win) { glfwMakeContextCurrent(win.window); } -void Window::Refresh() { - glfwSwapBuffers(window); - if (!Application::MultipleWindowsEnabled) glfwPollEvents(); +void vueltoRefresh(Vuelto_Window win) { + glfwSwapBuffers(win.window); + if (!MultipleWindowsEnabled) glfwPollEvents(); glClear(GL_COLOR_BUFFER_BIT); } - -} // namespace Vuelto diff --git a/src/vuelto/core/app.h b/src/vuelto/core/app.h new file mode 100644 index 0000000..8c5c83f --- /dev/null +++ b/src/vuelto/core/app.h @@ -0,0 +1,11 @@ +#include "../tools/definitions.h" + +void vueltoInit(); +void vueltoInitMultipleWindows(); +Vuelto_Window vueltoCreateWindow(int width, int height, const char *title, bool resizable); +void vueltoDestroyWindow(Vuelto_Window win); +void vueltoTerminate(); + +bool vueltoWindowShouldClose(Vuelto_Window win); +void vueltoRefresh(Vuelto_Window win); +void vueltoMakeContextCurrent(Vuelto_Window win); diff --git a/src/vuelto/core/app.hpp b/src/vuelto/core/app.hpp deleted file mode 100644 index 02a41f9..0000000 --- a/src/vuelto/core/app.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include - -#include "../tools/definitions.hpp" - -namespace Vuelto { - -class Window; - -namespace Application { - -void Init(); -void InitMultipleWindows(); -Window CreateWindow(int width, int height, const char *title, bool resizable); -void DestroyWindow(Window win); -void Terminate(); - -} // namespace Application - -class Window { - public: - GLFWwindow *window; - int width; - int height; - const char *title; - bool WindowShouldClose(); - void Refresh(); - void MakeContextCurrent(); -}; - -} // namespace Vuelto diff --git a/src/vuelto/core/renderer.cpp b/src/vuelto/core/renderer.c similarity index 55% rename from src/vuelto/core/renderer.cpp rename to src/vuelto/core/renderer.c index 0177bfb..3bd3733 100644 --- a/src/vuelto/core/renderer.cpp +++ b/src/vuelto/core/renderer.c @@ -1,26 +1,15 @@ -#include "renderer.hpp" +#include "renderer.h" -#include +#include -#include "../tools/definitions.hpp" +#include "../tools/definitions.h" #define STB_IMAGE_IMPLEMENTATION #include "../vendor/stb_image/stb_image.h" -#include "app.hpp" -namespace Vuelto { -namespace Application { - -Vuelto::Renderer2D CreateRenderer2D(Window win) { - Vuelto::Renderer2D renderer; - return renderer; -} - -} // namespace Application - -Renderer2D::Image image_array[5]; +Vuelto_Image image_array[5]; int size = 0; -void Renderer2D::DrawRect(float x, float y, float height, float width, float color1, float color2, float color3) { +void vueltoDrawRect(float x, float y, float height, float width, float color1, float color2, float color3) { glBegin(GL_QUADS); glColor3f(color1, color2, color3); glVertex2f(x, y); @@ -32,11 +21,9 @@ void Renderer2D::DrawRect(float x, float y, float height, float width, float col glColor3f(1.0f, 1.0f, 1.0f); } -void Renderer2D::SetBackgroundColor(float color1, float color2, float color3) { - glClearColor(color1, color2, color3, 1); -} +void vueltoSetBackgroundColor(float color1, float color2, float color3) { glClearColor(color1, color2, color3, 1); } -void Renderer2D::DrawLine(int x1, int x2, int y1, int y2, float color1, float color2, float color3) { +void vueltoDrawLine(int x1, int x2, int y1, int y2, float color1, float color2, float color3) { glLineWidth(1); glBegin(GL_LINES); glColor3f(color1, color2, color3); @@ -45,14 +32,14 @@ void Renderer2D::DrawLine(int x1, int x2, int y1, int y2, float color1, float co glEnd(); } -Renderer2D::Image Renderer2D::LoadImage(const char* imagePath, float x, float y, float width, float height) { - Image image; +Vuelto_Image vueltoLoadImage(const char* imagePath, float x, float y, float width, float height) { + Vuelto_Image image; int imgWidth, imgHeight, channels; unsigned char* imageData = stbi_load(imagePath, &imgWidth, &imgHeight, &channels, 4); // Force 4 channels (RGBA) if (!imageData) { - std::cerr << "Failed to load image: " << imagePath << std::endl; + printf("Failed to load image: %s \n", imagePath); return image; } @@ -77,27 +64,23 @@ Renderer2D::Image Renderer2D::LoadImage(const char* imagePath, float x, float y, return image; } -void Renderer2D::Image::DrawImage() { - glBindTexture(GL_TEXTURE_2D, texture); +void vueltoDrawImage(Vuelto_Image img) { + glBindTexture(GL_TEXTURE_2D, img.texture); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); - glVertex2f(x, y); + glVertex2f(img.x, img.y); glTexCoord2f(1.0f, 0.0f); - glVertex2f(x + width, y); + glVertex2f(img.x + img.width, img.y); glTexCoord2f(1.0f, 1.0f); - glVertex2f(x + width, y + height); + glVertex2f(img.x + img.width, img.y + img.height); glTexCoord2f(0.0f, 1.0f); - glVertex2f(x, y + height); + glVertex2f(img.x, img.y + img.height); glEnd(); glBindTexture(GL_TEXTURE_2D, 0); } -void Renderer2D::CleanUp() { - for (auto& image : image_array) { - glDeleteTextures(1, &image.texture); - } +void vueltoCleanUp() { + vueltoForEach(Vuelto_Image * i, image_array) { glDeleteTextures(1, &i->texture); } } - -} // namespace Vuelto diff --git a/src/vuelto/core/renderer.h b/src/vuelto/core/renderer.h new file mode 100644 index 0000000..7ee2613 --- /dev/null +++ b/src/vuelto/core/renderer.h @@ -0,0 +1,10 @@ +#include "../tools/definitions.h" + +void vueltoDrawRect(float x, float y, float width, float height, float r, float g, float b); +void vueltoSetBackgroundColor(float color1, float color2, float color3); +void vueltoDrawLine(int x1, int x2, int y1, int y2, float color1, float color2, float color3); + +Vuelto_Image vueltoLoadImage(const char* imagePath, float x, float y, float width, float height); +void vueltoDrawImage(Vuelto_Image img); + +void vueltoCleanUp(); diff --git a/src/vuelto/core/renderer.hpp b/src/vuelto/core/renderer.hpp deleted file mode 100644 index 1c7d11c..0000000 --- a/src/vuelto/core/renderer.hpp +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#include "app.hpp" - -namespace Vuelto { - -class Renderer2D; - -namespace Application { - -Vuelto::Renderer2D CreateRenderer2D(Window win); - -} // namespace Application - -class Renderer2D { - public: - class Image; - - void DrawRect(float x, float y, float width, float height, float r, float g, float b); - void SetBackgroundColor(float color1, float color2, float color3); - void DrawLine(int x1, int x2, int y1, int y2, float color1, float color2, float color3); - - Image LoadImage(const char* imagePath, float x, float y, float width, float height); - void CleanUp(); -}; - -class Renderer2D::Image { - public: - float width, height, x, y; - GLuint texture; - - void DrawImage(); -}; - -} // namespace Vuelto diff --git a/src/vuelto/event/event.c b/src/vuelto/event/event.c new file mode 100644 index 0000000..03f14ee --- /dev/null +++ b/src/vuelto/event/event.c @@ -0,0 +1,19 @@ +#include "event.h" + +#include "../tools/definitions.h" + +void vueltoPollEvents() { glfwPollEvents(); } + +bool vueltoKeyPressed(Vuelto_Window window, int keyCode) { return (glfwGetKey(window.window, keyCode) == GLFW_PRESS); } + +bool vueltoKeyPressedOnce(Vuelto_Window window, int key) { + static int keyStates[GLFW_KEY_LAST] = {GLFW_RELEASE}; + + if (glfwGetKey(window.window, key) == GLFW_PRESS && keyStates[key] == GLFW_RELEASE) { + keyStates[key] = GLFW_PRESS; + return true; + } else if (glfwGetKey(window.window, key) == GLFW_RELEASE && keyStates[key] == GLFW_PRESS) { + keyStates[key] = GLFW_RELEASE; + } + return false; +} diff --git a/src/vuelto/event/event.cpp b/src/vuelto/event/event.cpp deleted file mode 100644 index 6f2b5c3..0000000 --- a/src/vuelto/event/event.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "event.hpp" -#include "../core/app.hpp" - -namespace Vuelto { -namespace Events { - -void PollEvents() { glfwPollEvents(); } - -} // namespace Events - -namespace Input { - -bool IsKeyPressed(Vuelto::Window window, int keyCode) { - return (glfwGetKey(window.window, keyCode) == GLFW_PRESS); -} - -bool IsKeyPressedOnce(Vuelto::Window window, int key) { - static int keyStates[GLFW_KEY_LAST] = {GLFW_RELEASE}; - - if (glfwGetKey(window.window, key) == GLFW_PRESS && keyStates[key] == GLFW_RELEASE) { - keyStates[key] = GLFW_PRESS; - return true; - } else if (glfwGetKey(window.window, key) == GLFW_RELEASE && keyStates[key] == GLFW_PRESS) { - keyStates[key] = GLFW_RELEASE; - } - return false; -} - -} // namespace Keyboard - -} // namespace Vuelto diff --git a/src/vuelto/event/event.h b/src/vuelto/event/event.h new file mode 100644 index 0000000..847f87b --- /dev/null +++ b/src/vuelto/event/event.h @@ -0,0 +1,9 @@ +#pragma once + +#include "../core/app.h" +#include "../tools/definitions.h" + +void vueltoPollEvents(); + +bool vueltoKeyPressed(Vuelto_Window window, int keyCode); +bool vueltoKeyPressedOnce(Vuelto_Window window, int key); diff --git a/src/vuelto/event/event.hpp b/src/vuelto/event/event.hpp deleted file mode 100644 index d7c49bb..0000000 --- a/src/vuelto/event/event.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include "../tools/definitions.hpp" -#include "../core/app.hpp" - -namespace Vuelto { -namespace Events { - -void PollEvents(); - -} - -namespace Input { - -bool IsKeyPressed(Vuelto::Window window, int keyCode); -bool IsKeyPressedOnce(Vuelto::Window window, int key); - -} - -} // namespace Vuelto diff --git a/src/vuelto/event/keys.h b/src/vuelto/event/keys.h new file mode 100644 index 0000000..577ddbe --- /dev/null +++ b/src/vuelto/event/keys.h @@ -0,0 +1,96 @@ +#include "../tools/definitions.h" + +#define VUELTO_KEY_SPACE GLFW_KEY_SPACE +#define VUELTO_KEY_APOSTROPHE GLFW_KEY_APOSTROPHE +#define VUELTO_KEY_COMMA GLFW_KEY_COMMA +#define VUELTO_KEY_MINUS GLFW_KEY_MINUS +#define VUELTO_KEY_PERIOD GLFW_KEY_PERIOD +#define VUELTO_KEY_SLASH GLFW_KEY_SLASH +#define VUELTO_KEY_0 GLFW_KEY_0 +#define VUELTO_KEY_1 GLFW_KEY_1 +#define VUELTO_KEY_2 GLFW_KEY_2 +#define VUELTO_KEY_3 GLFW_KEY_3 +#define VUELTO_KEY_4 GLFW_KEY_4 +#define VUELTO_KEY_5 GLFW_KEY_5 +#define VUELTO_KEY_6 GLFW_KEY_6 +#define VUELTO_KEY_7 GLFW_KEY_7 +#define VUELTO_KEY_8 GLFW_KEY_8 +#define VUELTO_KEY_9 GLFW_KEY_9 +#define VUELTO_KEY_SEMICOLON GLFW_KEY_SEMICOLON +#define VUELTO_KEY_EQUAL GLFW_KEY_EQUAL +#define VUELTO_KEY_A GLFW_KEY_A +#define VUELTO_KEY_B GLFW_KEY_B +#define VUELTO_KEY_C GLFW_KEY_C +#define VUELTO_KEY_D GLFW_KEY_D +#define VUELTO_KEY_E GLFW_KEY_E +#define VUELTO_KEY_F GLFW_KEY_F +#define VUELTO_KEY_G GLFW_KEY_G +#define VUELTO_KEY_H GLFW_KEY_H +#define VUELTO_KEY_I GLFW_KEY_I +#define VUELTO_KEY_J GLFW_KEY_J +#define VUELTO_KEY_K GLFW_KEY_K +#define VUELTO_KEY_L GLFW_KEY_L +#define VUELTO_KEY_M GLFW_KEY_M +#define VUELTO_KEY_N GLFW_KEY_N +#define VUELTO_KEY_O GLFW_KEY_O +#define VUELTO_KEY_P GLFW_KEY_P +#define VUELTO_KEY_Q GLFW_KEY_Q +#define VUELTO_KEY_R GLFW_KEY_R +#define VUELTO_KEY_S GLFW_KEY_S +#define VUELTO_KEY_T GLFW_KEY_T +#define VUELTO_KEY_U GLFW_KEY_U +#define VUELTO_KEY_V GLFW_KEY_V +#define VUELTO_KEY_W GLFW_KEY_W +#define VUELTO_KEY_X GLFW_KEY_X +#define VUELTO_KEY_Y GLFW_KEY_Y +#define VUELTO_KEY_Z GLFW_KEY_Z +#define VUELTO_KEY_LEFT_BRACKET GLFW_KEY_LEFT_BRACKET +#define VUELTO_KEY_BACKSLASH GLFW_KEY_BACKSLASH +#define VUELTO_KEY_RIGHT_BRACKET GLFW_KEY_RIGHT_BRACKET +#define VUELTO_KEY_GRAVE_ACCENT GLFW_KEY_GRAVE_ACCENT +#define VUELTO_KEY_WORLD_1 GLFW_KEY_WORLD_1 +#define VUELTO_KEY_WORLD_2 GLFW_KEY_WORLD_2 +#define VUELTO_KEY_ESCAPE GLFW_KEY_ESCAPE +#define VUELTO_KEY_ENTER GLFW_KEY_ENTER +#define VUELTO_KEY_TAB GLFW_KEY_TAB +#define VUELTO_KEY_BACKSPACE GLFW_KEY_BACKSPACE +#define VUELTO_KEY_INSERT GLFW_KEY_INSERT +#define VUELTO_KEY_DELETE GLFW_KEY_DELETE +#define VUELTO_KEY_RIGHT GLFW_KEY_RIGHT +#define VUELTO_KEY_LEFT GLFW_KEY_LEFT +#define VUELTO_KEY_DOWN GLFW_KEY_DOWN +#define VUELTO_KEY_UP GLFW_KEY_UP +#define VUELTO_KEY_PAGE_UP GLFW_KEY_PAGE_UP +#define VUELTO_KEY_PAGE_DOWN GLFW_KEY_PAGE_DOWN +#define VUELTO_KEY_HOME GLFW_KEY_HOME +#define VUELTO_KEY_END GLFW_KEY_END +#define VUELTO_KEY_CAPS_LOCK GLFW_KEY_CAPS_LOCK +#define VUELTO_KEY_SCROLL_LOCK GLFW_KEY_SCROLL_LOCK +#define VUELTO_KEY_NUM_LOCK GLFW_KEY_NUM_LOCK +#define VUELTO_KEY_PRINT_SCREEN GLFW_KEY_PRINT_SCREEN +#define VUELTO_KEY_PAUSE GLFW_KEY_PAUSE +#define VUELTO_KEY_F1 GLFW_KEY_F1 +#define VUELTO_KEY_F2 GLFW_KEY_F2 +#define VUELTO_KEY_F3 GLFW_KEY_F3 +#define VUELTO_KEY_F4 GLFW_KEY_F4 +#define VUELTO_KEY_F5 GLFW_KEY_F5 +#define VUELTO_KEY_F6 GLFW_KEY_F6 +#define VUELTO_KEY_F7 GLFW_KEY_F7 +#define VUELTO_KEY_F8 GLFW_KEY_F8 +#define VUELTO_KEY_F9 GLFW_KEY_F9 +#define VUELTO_KEY_F10 GLFW_KEY_F10 +#define VUELTO_KEY_F11 GLFW_KEY_F11 +#define VUELTO_KEY_F12 GLFW_KEY_F12 +#define VUELTO_KEY_F13 GLFW_KEY_F13 +#define VUELTO_KEY_F14 GLFW_KEY_F14 +#define VUELTO_KEY_F15 GLFW_KEY_F15 +#define VUELTO_KEY_F16 GLFW_KEY_F16 +#define VUELTO_KEY_F17 GLFW_KEY_F17 +#define VUELTO_KEY_F18 GLFW_KEY_F18 +#define VUELTO_KEY_F19 GLFW_KEY_F19 +#define VUELTO_KEY_F20 GLFW_KEY_F20 +#define VUELTO_KEY_F21 GLFW_KEY_F21 +#define VUELTO_KEY_F22 GLFW_KEY_F22 +#define VUELTO_KEY_F23 GLFW_KEY_F23 +#define VUELTO_KEY_F24 GLFW_KEY_F24 +#define VUELTO_KEY_F25 GLFW_KEY_F25 diff --git a/src/vuelto/event/keys.hpp b/src/vuelto/event/keys.hpp deleted file mode 100644 index 4dde5db..0000000 --- a/src/vuelto/event/keys.hpp +++ /dev/null @@ -1,103 +0,0 @@ -#include "../tools/definitions.hpp" - -namespace Vuelto { -namespace Keys { - -const int Space = GLFW_KEY_SPACE; -const int Apostrophe = GLFW_KEY_APOSTROPHE; -const int Comma = GLFW_KEY_COMMA; -const int Minus = GLFW_KEY_MINUS; -const int Period = GLFW_KEY_PERIOD; -const int Slash = GLFW_KEY_SLASH; -const int Key0 = GLFW_KEY_0; -const int Key1 = GLFW_KEY_1; -const int Key2 = GLFW_KEY_2; -const int Key3 = GLFW_KEY_3; -const int Key4 = GLFW_KEY_4; -const int Key5 = GLFW_KEY_5; -const int Key6 = GLFW_KEY_6; -const int Key7 = GLFW_KEY_7; -const int Key8 = GLFW_KEY_8; -const int Key9 = GLFW_KEY_9; -const int Semicolon = GLFW_KEY_SEMICOLON; -const int Equal = GLFW_KEY_EQUAL; -const int A = GLFW_KEY_A; -const int B = GLFW_KEY_B; -const int C = GLFW_KEY_C; -const int D = GLFW_KEY_D; -const int E = GLFW_KEY_E; -const int F = GLFW_KEY_F; -const int G = GLFW_KEY_G; -const int H = GLFW_KEY_H; -const int I = GLFW_KEY_I; -const int J = GLFW_KEY_J; -const int K = GLFW_KEY_K; -const int L = GLFW_KEY_L; -const int M = GLFW_KEY_M; -const int N = GLFW_KEY_N; -const int O = GLFW_KEY_O; -const int P = GLFW_KEY_P; -const int Q = GLFW_KEY_Q; -const int R = GLFW_KEY_R; -const int S = GLFW_KEY_S; -const int T = GLFW_KEY_T; -const int U = GLFW_KEY_U; -const int V = GLFW_KEY_V; -const int W = GLFW_KEY_W; -const int X = GLFW_KEY_X; -const int Y = GLFW_KEY_Y; -const int Z = GLFW_KEY_Z; -const int LeftBracket = GLFW_KEY_LEFT_BRACKET; -const int Backslash = GLFW_KEY_BACKSLASH; -const int RightBracket = GLFW_KEY_RIGHT_BRACKET; -const int GraveAccent = GLFW_KEY_GRAVE_ACCENT; -const int World1 = GLFW_KEY_WORLD_1; -const int World2 = GLFW_KEY_WORLD_2; -const int Escape = GLFW_KEY_ESCAPE; -const int Enter = GLFW_KEY_ENTER; -const int Tab = GLFW_KEY_TAB; -const int Backspace = GLFW_KEY_BACKSPACE; -const int Insert = GLFW_KEY_INSERT; -const int Delete = GLFW_KEY_DELETE; -const int Right = GLFW_KEY_RIGHT; -const int Left = GLFW_KEY_LEFT; -const int Down = GLFW_KEY_DOWN; -const int Up = GLFW_KEY_UP; -const int PageUp = GLFW_KEY_PAGE_UP; -const int PageDown = GLFW_KEY_PAGE_DOWN; -const int Home = GLFW_KEY_HOME; -const int End = GLFW_KEY_END; -const int CapsLock = GLFW_KEY_CAPS_LOCK; -const int ScrollLock = GLFW_KEY_SCROLL_LOCK; -const int NumLock = GLFW_KEY_NUM_LOCK; -const int PrintScreen = GLFW_KEY_PRINT_SCREEN; -const int Pause = GLFW_KEY_PAUSE; -const int F1 = GLFW_KEY_F1; -const int F2 = GLFW_KEY_F2; -const int F3 = GLFW_KEY_F3; -const int F4 = GLFW_KEY_F4; -const int F5 = GLFW_KEY_F5; -const int F6 = GLFW_KEY_F6; -const int F7 = GLFW_KEY_F7; -const int F8 = GLFW_KEY_F8; -const int F9 = GLFW_KEY_F9; -const int F10 = GLFW_KEY_F10; -const int F11 = GLFW_KEY_F11; -const int F12 = GLFW_KEY_F12; -const int F13 = GLFW_KEY_F13; -const int F14 = GLFW_KEY_F14; -const int F15 = GLFW_KEY_F15; -const int F16 = GLFW_KEY_F16; -const int F17 = GLFW_KEY_F17; -const int F18 = GLFW_KEY_F18; -const int F19 = GLFW_KEY_F19; -const int F20 = GLFW_KEY_F20; -const int F21 = GLFW_KEY_F21; -const int F22 = GLFW_KEY_F22; -const int F23 = GLFW_KEY_F23; -const int F24 = GLFW_KEY_F24; -const int F25 = GLFW_KEY_F25; - - -} -} \ No newline at end of file diff --git a/src/vuelto/tools/definitions.h b/src/vuelto/tools/definitions.h new file mode 100644 index 0000000..26cfe85 --- /dev/null +++ b/src/vuelto/tools/definitions.h @@ -0,0 +1,35 @@ +#pragma once + +#ifdef __APPLE__ +#define GL_SILENCE_DEPRECATION +#include +#elif __linux__ +#define GL_SILENCE_DEPRECATION +#include +#elif _WIN32 +#define GL_CLAMP_TO_EDGE 0x812f +#elif _WIN64 +#define GL_CLAMP_TO_EDGE 0x812f +#else +#include +#endif + +#define vueltoForEach(item, array) \ + for (int keep = 1, count = 0, size = sizeof(array) / sizeof *(array); keep && count != size; keep = !keep, count++) \ + for (item = (array) + count; keep; keep = !keep) + +#include +#include +#include + +typedef struct { + GLFWwindow *window; + int width; + int height; + const char *title; +} Vuelto_Window; + +typedef struct { + float width, height, x, y; + GLuint texture; +} Vuelto_Image; diff --git a/src/vuelto/tools/definitions.hpp b/src/vuelto/tools/definitions.hpp deleted file mode 100644 index cfc896c..0000000 --- a/src/vuelto/tools/definitions.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#ifdef __APPLE__ -#define GL_SILENCE_DEPRECATION -#include -#elif __linux__ -#define GL_SILENCE_DEPRECATION -#include -#elif _WIN32 -#define GL_CLAMP_TO_EDGE 0x812f -#elif _WIN64 -#define GL_CLAMP_TO_EDGE 0x812f -#else -#include -#endif - -#include diff --git a/test/test.cpp b/test/test.cpp index 33153c9..112dabe 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -1,22 +1,19 @@ -#include "../src/Vuelto.hpp" +#include "../src/Vuelto.h" int main() { - Vuelto::Application::Init(); + vueltoInit(); - Vuelto::Window win = Vuelto::Application::CreateWindow(800, 600, "test", false); + Vuelto_Window win = vueltoCreateWindow(800, 600, "test", true); - Vuelto::Renderer2D renderer = Vuelto::Application::CreateRenderer2D(win); + Vuelto_Image img = vueltoLoadImage("test/coin.png", -0.2, -0.2, 0.7, 0.7); - Vuelto::Renderer2D::Image img = renderer.LoadImage("test/image.png", -0.2, -0.2, 0.7, 0.7); + while (!vueltoWindowShouldClose(win)) { + // vueltoDrawRect(-1, -1, 0.5, 0.5, 0.5, 0.1, 0.8); + vueltoDrawImage(img); - while (!win.WindowShouldClose()) { - renderer.DrawRect(-1, -1, 0.5, 0.5, 0.5, 0.1, 0.8); - img.DrawImage(); - win.Refresh(); + vueltoRefresh(win); } - renderer.CleanUp(); - - Vuelto::Application::Terminate(); + vueltoTerminate(); return 0; }