diff --git a/engine/GLFW_draw.c b/engine/GLFW_draw.c deleted file mode 100644 index 85bc99a..0000000 --- a/engine/GLFW_draw.c +++ /dev/null @@ -1,72 +0,0 @@ -#define NB_EXPOSE_DRAW_PLATFORM - -#include "nb_pre.h" - -/* External library */ -#include -#include -#include - -/* Interface */ -#include "nb_draw_platform.h" - -/* NishBox */ -#include "nb_log.h" -#include "nb_draw.h" - -/* Standard */ -#include - -void _nb_draw_init(void) { - glfwInit(); - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 1); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); - glfwWindowHint(GLFW_DOUBLEBUFFER, GLFW_TRUE); - glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_ANY_PROFILE); -} - -int _nb_draw_has_extension(nb_draw_t* draw, const char* query) { - const char* ext = NULL; - const char* ptr; - const int len = strlen(query); - - glfwMakeContextCurrent(draw->window); - - return glfwExtensionSupported(query); -} - -int _nb_draw_step(nb_draw_t* draw) { - int ret = 0; - glfwMakeContextCurrent(draw->window); - draw->close = glfwWindowShouldClose(draw->window); - if(draw->close) glfwSetWindowShouldClose(draw->window, GLFW_FALSE); - glfwPollEvents(); - if(ret == 0) { - nb_draw_frame(draw); - - glFlush(); - glfwSwapBuffers(draw->window); - } - return ret; -} - -void _nb_draw_create(nb_draw_t** pdraw) { - nb_draw_t* draw = *pdraw; - - draw->window = glfwCreateWindow(draw->width, draw->height, "NishBox (GLFW)", NULL, NULL); - if(draw->window == NULL) { - nb_function_log("Failed to create window", ""); - nb_draw_destroy(draw); - *pdraw = NULL; - return; - } - - glfwMakeContextCurrent(draw->window); - glfwSwapInterval(1); -} - -void _nb_draw_destroy(nb_draw_t* draw) { - if(draw->window != NULL) { - glfwDestroyWindow(draw->window); - } -} diff --git a/engine/GLX_draw.c b/engine/GLX_draw.c deleted file mode 100644 index dbf9022..0000000 --- a/engine/GLX_draw.c +++ /dev/null @@ -1,191 +0,0 @@ -#define NB_EXPOSE_DRAW_PLATFORM - -#include "nb_pre.h" - -/* External library */ -#include -#include -#include -#include -#include - -/* Interface */ -#include "nb_draw_platform.h" - -/* NishBox */ -#include "nb_log.h" -#include "nb_draw.h" - -/* Standard */ -#include - -#ifndef GLX_MESA_swap_control -#define GLX_MESA_swap_control 1 -typedef int (*PFNGLXGETSWAPINTERVALMESAPROC)(void); -typedef void (*PFNGLXSWAPINTERVALMESAPROC)(int); -#endif - -#ifndef GLX_EXT_swap_control -#define GLX_EXT_swap_control 1 -typedef void (*PFNGLXSWAPINTERVALEXTPROC)(Display*, GLXDrawable, int); -#endif - -#ifndef GLX_SGI_swap_control -#define GLX_SGI_swap_control 1 -typedef void (*PFNGLXSWAPINTERVALSGIPROC)(int); -#endif - -void _nb_draw_init(void) {} - -int _nb_draw_has_extension(nb_draw_t* draw, const char* query) { - const char* ext = NULL; - const char* ptr; - const int len = strlen(query); - - glXMakeCurrent(draw->display, draw->window, draw->context); - - ext = glXQueryExtensionsString(draw->display, DefaultScreen(draw->display)); - ptr = strstr(ext, query); - return ((ptr != NULL) && ((ptr[len] == ' ') || (ptr[len] == '\0'))); -} - -void _nb_draw_create(nb_draw_t** pdraw) { - nb_draw_t* draw = *pdraw; - int i = 0; - int attribs[64]; - int screen; - Window root; - XVisualInfo* visual; - XSetWindowAttributes attr; - XSizeHints hints; - int interval = 0; - draw->display = XOpenDisplay(NULL); - if(draw->display == NULL) { - nb_function_log("Failed to open display", ""); - nb_draw_destroy(draw); - *pdraw = NULL; - return; - } - attribs[i++] = GLX_RGBA; - attribs[i++] = GLX_DOUBLEBUFFER; - - attribs[i++] = GLX_RED_SIZE; - attribs[i++] = 1; - attribs[i++] = GLX_GREEN_SIZE; - attribs[i++] = 1; - attribs[i++] = GLX_BLUE_SIZE; - attribs[i++] = 1; - attribs[i++] = GLX_DEPTH_SIZE; - attribs[i++] = 1; - - attribs[i++] = None; - - screen = DefaultScreen(draw->display); - root = RootWindow(draw->display, screen); - - visual = glXChooseVisual(draw->display, screen, attribs); - if(visual == NULL) { - nb_function_log("Failed to get visual", ""); - nb_draw_destroy(draw); - *pdraw = NULL; - return; - } - - attr.colormap = XCreateColormap(draw->display, root, visual->visual, AllocNone); - attr.event_mask = StructureNotifyMask | ExposureMask; - draw->window = XCreateWindow(draw->display, root, draw->width, draw->height, draw->width, draw->height, 0, visual->depth, InputOutput, visual->visual, CWColormap | CWEventMask, &attr); - - hints.x = draw->x; - hints.y = draw->y; - hints.width = draw->width; - hints.height = draw->height; - hints.flags = USSize | USPosition; - XSetNormalHints(draw->display, draw->window, &hints); - XSetStandardProperties(draw->display, draw->window, "NishBox (GLX)", "NishBox", None, (char**)NULL, 0, &hints); - - draw->wm_delete_window = XInternAtom(draw->display, "WM_DELETE_WINDOW", False); - XSetWMProtocols(draw->display, draw->window, &draw->wm_delete_window, 1); - - draw->context = glXCreateContext(draw->display, visual, NULL, True); - if(draw->context == NULL) { - XFree(visual); - nb_function_log("Failed to get OpenGL context", ""); - nb_draw_destroy(draw); - *pdraw = NULL; - return; - } - - XFree(visual); - - XMapWindow(draw->display, draw->window); - glXMakeCurrent(draw->display, draw->window, draw->context); - -#if defined(GLX_EXT_swap_control) - if(_nb_draw_has_extension(draw, "GLX_EXT_swap_control")) { - unsigned int tmp = -1; - PFNGLXSWAPINTERVALEXTPROC proc = (PFNGLXSWAPINTERVALEXTPROC)glXGetProcAddressARB("glXSwapIntervalEXT"); - if(proc != NULL) { - proc(draw->display, draw->window, 1); - } - glXQueryDrawable(draw->display, draw->window, GLX_SWAP_INTERVAL_EXT, &tmp); - interval = tmp; - } else -#endif - if(_nb_draw_has_extension(draw, "GLX_MESA_swap_control")) { - PFNGLXGETSWAPINTERVALMESAPROC proc = (PFNGLXGETSWAPINTERVALMESAPROC)glXGetProcAddressARB("glXGetSwapIntervalMESA"); - PFNGLXSWAPINTERVALMESAPROC proc2 = (PFNGLXSWAPINTERVALMESAPROC)glXGetProcAddressARB("glXSwapIntervalMESA"); - if(proc2 != NULL) { - proc2(1); - } - interval = proc(); - } else if(_nb_draw_has_extension(draw, "GLX_SGI_swap_control")) { - PFNGLXSWAPINTERVALSGIPROC proc = (PFNGLXSWAPINTERVALSGIPROC)glXGetProcAddressARB("glXSwapIntervalSGI"); - proc(1); - interval = 1; - } - if(interval > 0) { - nb_function_log("Enabled VSync", ""); - } -} - -int _nb_draw_step(nb_draw_t* draw) { - int ret = 0; - glXMakeCurrent(draw->display, draw->window, draw->context); - while(XPending(draw->display) > 0) { - XEvent event; - XNextEvent(draw->display, &event); - if(event.type == Expose) { - break; - } else if(event.type == ConfigureNotify) { - draw->x = event.xconfigure.x; - draw->y = event.xconfigure.y; - draw->width = event.xconfigure.width; - draw->height = event.xconfigure.height; - glXMakeCurrent(draw->display, draw->window, draw->context); - nb_draw_reshape(draw); - } else if(event.type == ClientMessage) { - if(event.xclient.data.l[0] == draw->wm_delete_window) { - draw->close = 1; - break; - } - } - } - if(ret == 0) { - nb_draw_frame(draw); - - glFlush(); - glXSwapBuffers(draw->display, draw->window); - } - return ret; -} - -void _nb_draw_destroy(nb_draw_t* draw) { - if(draw->context != NULL) { - glXMakeCurrent(draw->display, None, NULL); - glXDestroyContext(draw->display, draw->context); - } - if(draw->display != NULL) { - XDestroyWindow(draw->display, draw->window); - XCloseDisplay(draw->display); - } -} diff --git a/engine/Makefile b/engine/Makefile index f88b85d..1ee2c35 100644 --- a/engine/Makefile +++ b/engine/Makefile @@ -1,14 +1,16 @@ TARGET = libnishbox.a -OBJS = version.o core.o draw.o log.o $(BACKEND)_draw.o font.o stb_image.o math.o +OBJS = nb_version.o nb_core.o nb_draw.o nb_log.o nb_font.o nb_math.o nb_physics.o nb_mesh.o nb_model.o +OBJS += nb_$(BACKEND)_draw.o +OBJS += nb_stb_image.o include ../common.mk -include ext_lua.mk +-include ext_lua.mk $(TARGET): $(OBJS) $(AR) rcs $@ $(OBJS) -stb_image.c draw.c: ext_stb_image.h +nb_stb_image.c nb_draw.c: ext_stb_image.h ext_stb_image.h: wget https://github.com/nothings/stb/raw/refs/heads/master/stb_image.h -O $@ diff --git a/engine/nb_GLFW_draw.c b/engine/nb_GLFW_draw.c new file mode 100644 index 0000000..9017dd1 --- /dev/null +++ b/engine/nb_GLFW_draw.c @@ -0,0 +1,78 @@ +#define NB_EXPOSE_DRAW_PLATFORM +#define NB_EXPOSE_DRAW + +#include "nb_pre.h" + +/* External library */ +#include +#include +#include + +/* Interface */ +#include "nb_draw_platform.h" + +/* NishBox */ +#include "nb_log.h" +#include "nb_draw.h" + +/* Standard */ +#include +#include + +void nb_draw_platform_begin(void) { + glfwInit(); + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 1); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); + glfwWindowHint(GLFW_DOUBLEBUFFER, GLFW_TRUE); + glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_ANY_PROFILE); +} + +void nb_draw_platform_end(void) {} + +int nb_draw_platform_has_extension(nb_draw_t* draw, const char* query) { + const char* ext = NULL; + const char* ptr; + const int len = strlen(query); + + glfwMakeContextCurrent(draw->platform->window); + + return glfwExtensionSupported(query); +} + +int nb_draw_platform_step(nb_draw_t* draw) { + int ret = 0; + glfwMakeContextCurrent(draw->platform->window); + draw->close = glfwWindowShouldClose(draw->platform->window); + if(draw->close) glfwSetWindowShouldClose(draw->platform->window, GLFW_FALSE); + glfwPollEvents(); + if(ret == 0) { + nb_draw_frame(draw); + + glFlush(); + glfwSwapBuffers(draw->platform->window); + } + return ret; +} + +void nb_draw_platform_create(nb_draw_t* draw) { + draw->platform = malloc(sizeof(*draw->platform)); + memset(draw->platform, 0, sizeof(*draw->platform)); + + draw->platform->window = glfwCreateWindow(draw->width, draw->height, "NishBox (GLFW)", NULL, NULL); + if(draw->platform->window == NULL) { + nb_function_log("Failed to create window", ""); + nb_draw_destroy(draw); + *pdraw = NULL; + return; + } + + glfwMakeContextCurrent(draw->platform->window); + glfwSwapInterval(1); +} + +void nb_draw_platform_destroy(nb_draw_t* draw) { + if(draw->platform->window != NULL) { + glfwDestroyWindow(draw->platform->window); + } + free(draw->platform); +} diff --git a/engine/nb_GLX_draw.c b/engine/nb_GLX_draw.c new file mode 100644 index 0000000..74e5410 --- /dev/null +++ b/engine/nb_GLX_draw.c @@ -0,0 +1,194 @@ +#define NB_EXPOSE_DRAW_PLATFORM +#define NB_EXPOSE_DRAW + +#include "nb_pre.h" + +/* External library */ +#include +#include +#include +#include +#include + +/* Interface */ +#include "nb_draw_platform.h" + +/* NishBox */ +#include "nb_log.h" +#include "nb_draw.h" + +/* Standard */ +#include +#include + +#ifndef GLX_MESA_swap_control +#define GLX_MESA_swap_control 1 +typedef int (*PFNGLXGETSWAPINTERVALMESAPROC)(void); +typedef void (*PFNGLXSWAPINTERVALMESAPROC)(int); +#endif + +#ifndef GLX_EXT_swap_control +#define GLX_EXT_swap_control 1 +typedef void (*PFNGLXSWAPINTERVALEXTPROC)(Display*, GLXDrawable, int); +#endif + +#ifndef GLX_SGI_swap_control +#define GLX_SGI_swap_control 1 +typedef void (*PFNGLXSWAPINTERVALSGIPROC)(int); +#endif + +void nb_draw_platform_begin(void) {} +void nb_draw_platform_end(void) {} + +int nb_draw_platform_has_extension(nb_draw_t* draw, const char* query) { + const char* ext = NULL; + const char* ptr; + const int len = strlen(query); + + glXMakeCurrent(draw->platform->display, draw->platform->window, draw->platform->context); + + ext = glXQueryExtensionsString(draw->platform->display, DefaultScreen(draw->platform->display)); + ptr = strstr(ext, query); + return ((ptr != NULL) && ((ptr[len] == ' ') || (ptr[len] == '\0'))); +} + +void nb_draw_platform_create(nb_draw_t* draw) { + int i = 0; + int attribs[64]; + int screen; + Window root; + XVisualInfo* visual; + XSetWindowAttributes attr; + XSizeHints hints; + int interval = 0; + + draw->platform = malloc(sizeof(*draw->platform)); + memset(draw->platform, 0, sizeof(*draw->platform)); + + draw->platform->display = XOpenDisplay(NULL); + if(draw->platform->display == NULL) { + nb_function_log("Failed to open display", ""); + nb_draw_destroy(draw); + return; + } + attribs[i++] = GLX_RGBA; + attribs[i++] = GLX_DOUBLEBUFFER; + + attribs[i++] = GLX_RED_SIZE; + attribs[i++] = 1; + attribs[i++] = GLX_GREEN_SIZE; + attribs[i++] = 1; + attribs[i++] = GLX_BLUE_SIZE; + attribs[i++] = 1; + attribs[i++] = GLX_DEPTH_SIZE; + attribs[i++] = 1; + + attribs[i++] = None; + + screen = DefaultScreen(draw->platform->display); + root = RootWindow(draw->platform->display, screen); + + visual = glXChooseVisual(draw->platform->display, screen, attribs); + if(visual == NULL) { + nb_function_log("Failed to get visual", ""); + nb_draw_destroy(draw); + return; + } + + attr.colormap = XCreateColormap(draw->platform->display, root, visual->visual, AllocNone); + attr.event_mask = StructureNotifyMask | ExposureMask; + draw->platform->window = XCreateWindow(draw->platform->display, root, draw->width, draw->height, draw->width, draw->height, 0, visual->depth, InputOutput, visual->visual, CWColormap | CWEventMask, &attr); + + hints.x = draw->x; + hints.y = draw->y; + hints.width = draw->width; + hints.height = draw->height; + hints.flags = USSize | USPosition; + XSetNormalHints(draw->platform->display, draw->platform->window, &hints); + XSetStandardProperties(draw->platform->display, draw->platform->window, "NishBox (GLX)", "NishBox", None, (char**)NULL, 0, &hints); + + draw->platform->wm_delete_window = XInternAtom(draw->platform->display, "WM_DELETE_WINDOW", False); + XSetWMProtocols(draw->platform->display, draw->platform->window, &draw->platform->wm_delete_window, 1); + + draw->platform->context = glXCreateContext(draw->platform->display, visual, NULL, True); + if(draw->platform->context == NULL) { + XFree(visual); + nb_function_log("Failed to get OpenGL context", ""); + nb_draw_destroy(draw); + return; + } + + XFree(visual); + + XMapWindow(draw->platform->display, draw->platform->window); + glXMakeCurrent(draw->platform->display, draw->platform->window, draw->platform->context); + +#if defined(GLX_EXT_swap_control) + if(nb_draw_platform_has_extension(draw, "GLX_EXT_swap_control")) { + unsigned int tmp = -1; + PFNGLXSWAPINTERVALEXTPROC proc = (PFNGLXSWAPINTERVALEXTPROC)glXGetProcAddressARB("glXSwapIntervalEXT"); + if(proc != NULL) { + proc(draw->platform->display, draw->platform->window, 1); + } + glXQueryDrawable(draw->platform->display, draw->platform->window, GLX_SWAP_INTERVAL_EXT, &tmp); + interval = tmp; + } else +#endif + if(nb_draw_platform_has_extension(draw, "GLX_MESA_swap_control")) { + PFNGLXGETSWAPINTERVALMESAPROC proc = (PFNGLXGETSWAPINTERVALMESAPROC)glXGetProcAddressARB("glXGetSwapIntervalMESA"); + PFNGLXSWAPINTERVALMESAPROC proc2 = (PFNGLXSWAPINTERVALMESAPROC)glXGetProcAddressARB("glXSwapIntervalMESA"); + if(proc2 != NULL) { + proc2(1); + } + interval = proc(); + } else if(nb_draw_platform_has_extension(draw, "GLX_SGI_swap_control")) { + PFNGLXSWAPINTERVALSGIPROC proc = (PFNGLXSWAPINTERVALSGIPROC)glXGetProcAddressARB("glXSwapIntervalSGI"); + proc(1); + interval = 1; + } + if(interval > 0) { + nb_function_log("Enabled VSync", ""); + } +} + +int nb_draw_platform_step(nb_draw_t* draw) { + int ret = 0; + glXMakeCurrent(draw->platform->display, draw->platform->window, draw->platform->context); + while(XPending(draw->platform->display) > 0) { + XEvent event; + XNextEvent(draw->platform->display, &event); + if(event.type == Expose) { + break; + } else if(event.type == ConfigureNotify) { + draw->x = event.xconfigure.x; + draw->y = event.xconfigure.y; + draw->width = event.xconfigure.width; + draw->height = event.xconfigure.height; + glXMakeCurrent(draw->platform->display, draw->platform->window, draw->platform->context); + nb_draw_reshape(draw); + } else if(event.type == ClientMessage) { + if(event.xclient.data.l[0] == draw->platform->wm_delete_window) { + draw->close = 1; + break; + } + } + } + if(ret == 0) { + nb_draw_frame(draw); + + glFlush(); + glXSwapBuffers(draw->platform->display, draw->platform->window); + } + return ret; +} + +void nb_draw_platform_destroy(nb_draw_t* draw) { + if(draw->platform->context != NULL) { + glXMakeCurrent(draw->platform->display, None, NULL); + glXDestroyContext(draw->platform->display, draw->platform->context); + } + if(draw->platform->display != NULL) { + XDestroyWindow(draw->platform->display, draw->platform->window); + XCloseDisplay(draw->platform->display); + } +} diff --git a/engine/WGL_draw.c b/engine/nb_WGL_draw.c similarity index 60% rename from engine/WGL_draw.c rename to engine/nb_WGL_draw.c index 0a79fa3..bae9c2e 100644 --- a/engine/WGL_draw.c +++ b/engine/nb_WGL_draw.c @@ -4,7 +4,7 @@ /* External library */ #include -#include +#include /* Interface */ #include "nb_draw_platform.h" @@ -15,13 +15,15 @@ /* Standard */ #include +#include typedef const char*(APIENTRY* PFNWGLGETEXTENSIONSSTRINGARB)(HDC); typedef BOOL(APIENTRY* PFNWGLSWAPINTERVALPROC)(int); -void _nb_draw_init(void) {} +void nb_draw_platform_begin(void) {} +void nb_draw_platform_end(void) {} -LRESULT CALLBACK _nb_draw_proc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) { +LRESULT CALLBACK nb_draw_platform_proc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) { PAINTSTRUCT ps; RECT rect; nb_draw_t* draw = (nb_draw_t*)GetWindowLongPtr(hWnd, GWLP_USERDATA); @@ -36,7 +38,7 @@ LRESULT CALLBACK _nb_draw_proc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) { draw->y = rect.top; draw->width = rect.right - rect.left; draw->height = rect.bottom - rect.top; - wglMakeCurrent(draw->dc, draw->glrc); + wglMakeCurrent(draw->platform->dc, draw->platform->glrc); nb_draw_reshape(draw); break; case WM_CLOSE: @@ -51,30 +53,30 @@ LRESULT CALLBACK _nb_draw_proc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) { return 0; } -int _nb_draw_has_extension(nb_draw_t* draw, const char* query) { +int nb_draw_platform_has_extension(nb_draw_t* draw, const char* query) { const char* ext = NULL; const char* ptr; const int len = strlen(query); PFNWGLGETEXTENSIONSSTRINGARB proc; - wglMakeCurrent(draw->dc, draw->glrc); + wglMakeCurrent(draw->platform->dc, draw->platform->glrc); proc = (PFNWGLGETEXTENSIONSSTRINGARB)wglGetProcAddress("wglGetExtensionsStringARB"); if(proc != NULL) { - ext = proc(draw->dc); + ext = proc(draw->platform->dc); ptr = strstr(ext, query); return ((ptr != NULL) && ((ptr[len] == ' ') || (ptr[len] == '\0'))); } return 0; } -int _nb_draw_step(nb_draw_t* draw) { +int nb_draw_platform_step(nb_draw_t* draw) { MSG msg; int ret = 0; - wglMakeCurrent(draw->dc, draw->glrc); - while(PeekMessage(&msg, draw->window, 0, 0, PM_NOREMOVE)) { - if(GetMessage(&msg, draw->window, 0, 0)) { + wglMakeCurrent(draw->platform->dc, draw->platform->glrc); + while(PeekMessage(&msg, draw->platform->window, 0, 0, PM_NOREMOVE)) { + if(GetMessage(&msg, draw->platform->window, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } else { @@ -86,21 +88,24 @@ int _nb_draw_step(nb_draw_t* draw) { nb_draw_frame(draw); glFlush(); - SwapBuffers(draw->dc); + SwapBuffers(draw->platform->dc); } return ret; } -void _nb_draw_create(nb_draw_t** pdraw) { - nb_draw_t* draw = *pdraw; +void nb_draw_platform_create(nb_draw_t* draw) { WNDCLASSEX wc; PIXELFORMATDESCRIPTOR desc; PFNWGLSWAPINTERVALPROC wglSwapIntervalEXT; RECT rect; int fmt; DWORD style; - draw->instance = (HINSTANCE)GetModuleHandle(NULL); - if(draw->instance == NULL) { + + draw->platform = malloc(sizeof(*draw->platform)); + memset(draw->platform, 0, sizeof(*draw->platform)); + + draw->platform->instance = (HINSTANCE)GetModuleHandle(NULL); + if(draw->platform->instance == NULL) { nb_function_log("Failed to get instance", ""); nb_draw_destroy(draw); *pdraw = NULL; @@ -111,7 +116,7 @@ void _nb_draw_create(nb_draw_t** pdraw) { wc.cbSize = sizeof(wc); wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; - wc.lpfnWndProc = _nb_draw_proc; + wc.lpfnWndProc = nb_draw_platform_proc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = draw->instance; @@ -124,23 +129,21 @@ void _nb_draw_create(nb_draw_t** pdraw) { if(!RegisterClassEx(&wc)) { nb_function_log("Failed to register class", ""); nb_draw_destroy(draw); - *pdraw = NULL; return; } else { nb_function_log("Registered class", ""); } - draw->window = CreateWindow("nishbox", "NishBox (WGL)", (WS_OVERLAPPEDWINDOW), draw->x, draw->y, draw->width, draw->height, NULL, 0, draw->instance, NULL); - if(draw->window == NULL) { + draw->platform->window = CreateWindow("nishbox", "NishBox (WGL)", (WS_OVERLAPPEDWINDOW), draw->x, draw->y, draw->width, draw->height, NULL, 0, draw->platform->instance, NULL); + if(draw->platform->window == NULL) { nb_function_log("Failed to create window", ""); nb_draw_destroy(draw); - *pdraw = NULL; return; } else { nb_function_log("Created window", ""); } - SetWindowLongPtr(draw->window, GWLP_USERDATA, (LONG_PTR)draw); + SetWindowLongPtr(draw->platform->window, GWLP_USERDATA, (LONG_PTR)draw); memset(&desc, 0, sizeof(desc)); desc.nSize = sizeof(desc); @@ -151,21 +154,20 @@ void _nb_draw_create(nb_draw_t** pdraw) { desc.cAlphaBits = 8; desc.cDepthBits = 32; - draw->dc = GetDC(draw->window); + draw->dc = GetDC(draw->platform->window); - fmt = ChoosePixelFormat(draw->dc, &desc); - SetPixelFormat(draw->dc, fmt, &desc); + fmt = ChoosePixelFormat(draw->platform->dc, &desc); + SetPixelFormat(draw->platform->dc, fmt, &desc); - draw->glrc = wglCreateContext(draw->dc); + draw->platform->glrc = wglCreateContext(draw->platform->dc); if(draw->glrc == NULL) { nb_function_log("Failed to create OpenGL context", ""); nb_draw_destroy(draw); - *pdraw = NULL; return; } else { nb_function_log("Created OpenGL context", ""); } - wglMakeCurrent(draw->dc, draw->glrc); + wglMakeCurrent(draw->platform->dc, draw->platform->glrc); wglSwapIntervalEXT = (PFNWGLSWAPINTERVALPROC)wglGetProcAddress("wglSwapIntervalEXT"); if(wglSwapIntervalEXT != NULL) { @@ -174,21 +176,21 @@ void _nb_draw_create(nb_draw_t** pdraw) { } SetRect(&rect, 0, 0, draw->width, draw->height); - style = (DWORD)GetWindowLongPtr(draw->window, GWL_STYLE); + style = (DWORD)GetWindowLongPtr(draw->platform->window, GWL_STYLE); AdjustWindowRect(&rect, style, FALSE); - SetWindowPos(draw->window, NULL, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOMOVE); + SetWindowPos(draw->platform->window, NULL, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOMOVE); - ShowWindow(draw->window, SW_NORMAL); - UpdateWindow(draw->window); + ShowWindow(draw->platform->window, SW_NORMAL); + UpdateWindow(draw->platform->window); } -void _nb_draw_destroy(nb_draw_t* draw) { - if(draw->glrc != NULL) { +void nb_draw_platform_destroy(nb_draw_t* draw) { + if(draw->platform->glrc != NULL) { wglMakeCurrent(NULL, NULL); - ReleaseDC(draw->window, draw->dc); - wglDeleteContext(draw->glrc); + ReleaseDC(draw->platform->window, draw->platform->dc); + wglDeleteContext(draw->platform->glrc); } - if(draw->window != NULL) { - DestroyWindow(draw->window); + if(draw->platform->window != NULL) { + DestroyWindow(draw->platform->window); } } diff --git a/engine/core.c b/engine/nb_core.c similarity index 88% rename from engine/core.c rename to engine/nb_core.c index f9d56c7..dea678b 100644 --- a/engine/core.c +++ b/engine/nb_core.c @@ -15,7 +15,7 @@ /* NishBox */ #include "nb_draw.h" -#include "nb_draw_platform.h" +#include "nb_physics.h" #include "nb_log.h" #include "nb_version.h" @@ -36,11 +36,14 @@ void nb_engine_begin(void) { WSAStartup(MAKEWORD(1, 1), &wsa); nb_function_log("Winsock ready", ""); #endif - _nb_draw_init(); - dInitODE(); + nb_draw_begin(); + nb_physics_begin(); } -void nb_engine_end(void) { dCloseODE(); } +void nb_engine_end(void) { + nb_physics_end(); + nb_draw_end(); +} nb_engine_t* nb_engine_create(int nogui) { nb_engine_t* engine = malloc(sizeof(*engine)); @@ -57,8 +60,7 @@ nb_engine_t* nb_engine_create(int nogui) { return NULL; } } - engine->world = dWorldCreate(); - dWorldSetGravity(engine->world, 0, 0, -9.81); + engine->physics = nb_physics_create(); return engine; } @@ -82,7 +84,7 @@ void nb_engine_loop(nb_engine_t* engine) { } void nb_engine_destroy(nb_engine_t* engine) { - dWorldDestroy(engine->world); + if(engine->physics != NULL) nb_physics_destroy(engine->physics); if(engine->draw != NULL) nb_draw_destroy(engine->draw); free(engine); nb_function_log("Destroyed engine", ""); diff --git a/engine/nb_core.h b/engine/nb_core.h index 83165f5..98734c1 100644 --- a/engine/nb_core.h +++ b/engine/nb_core.h @@ -4,25 +4,13 @@ #include #include -/* External library */ -#ifdef NB_EXPOSE_CORE -#include -#endif +/* Type */ +#include /* NishBox */ -#include /* Standard */ -#ifdef NB_EXPOSE_CORE -typedef struct nb_engine { - dWorldID world; - nb_draw_t* draw; -} nb_engine_t; -#else -typedef void nb_engine_t; -#endif - void nb_engine_begin(void); void nb_engine_end(void); nb_engine_t* nb_engine_create(int nogui); diff --git a/engine/draw.c b/engine/nb_draw.c similarity index 94% rename from engine/draw.c rename to engine/nb_draw.c index ff2e642..e66e043 100644 --- a/engine/draw.c +++ b/engine/nb_draw.c @@ -26,6 +26,10 @@ GLfloat lightwht[] = {1.0, 1.0, 1.0, 1.0}; GLfloat lightdim[] = {0.2, 0.2, 0.2, 1.0}; GLfloat lightblk[] = {0.0, 0.0, 0.0, 1.0}; +void nb_draw_begin(void) { nb_draw_platform_begin(); } + +void nb_draw_end(void) { nb_draw_platform_end(); } + nb_draw_t* nb_draw_create(void) { nb_draw_t* draw = malloc(sizeof(*draw)); memset(draw, 0, sizeof(*draw)); @@ -34,8 +38,8 @@ nb_draw_t* nb_draw_create(void) { draw->width = 640; draw->height = 480; draw->running = 0; - _nb_draw_create(&draw); - if(draw != NULL) { + nb_draw_platform_create(draw); + if(draw->platform != NULL) { nb_function_log("Created drawing interface successfully", ""); nb_draw_init_opengl(draw); nb_draw_reshape(draw); @@ -46,8 +50,6 @@ nb_draw_t* nb_draw_create(void) { GLuint nb_test_texture; -void nb_draw_body(nb_draw_t* draw); - void nb_draw_init_opengl(nb_draw_t* draw) { int i; int w, h, ch; @@ -118,7 +120,7 @@ void nb_draw_init_opengl(nb_draw_t* draw) { } int nb_draw_has_extension(nb_draw_t* draw, const char* query) { - int ret = _nb_draw_has_extension(draw, query); + int ret = nb_draw_platform_has_extension(draw, query); const char* ext = NULL; const char* ptr; const int len = strlen(query); @@ -185,7 +187,7 @@ void nb_draw_frame(nb_draw_t* draw) { } int nb_draw_step(nb_draw_t* draw) { - int ret = _nb_draw_step(draw); + int ret = nb_draw_platform_step(draw); if(ret != 0) return ret; draw->close = 0; @@ -209,7 +211,6 @@ void nb_draw_destroy(nb_draw_t* draw) { glDeleteTextures(1, &draw->font[i]); } } - _nb_draw_destroy(draw); - free(draw); + nb_draw_platform_destroy(draw); nb_function_log("Destroyed drawing interface", ""); } diff --git a/engine/nb_draw.h b/engine/nb_draw.h index 88c1571..f3e2a13 100644 --- a/engine/nb_draw.h +++ b/engine/nb_draw.h @@ -4,31 +4,13 @@ #include #include -/* External library */ -#ifdef NB_EXPORT_DRAW -#include -#endif +/* Type */ +#include /* NishBox */ -#include /* Standard */ -#ifdef NB_EXPORT_DRAW -typedef struct nb_shape { - GLfloat points[3][3]; - GLfloat color[3]; - GLuint texture; -} nb_shape_t; -typedef struct nb_mesh { - nb_shape_t* shapes; - int shape_count; -} nb_mesh_t; -#else -typedef void nb_mesh_t; -typedef void nb_shape_t; -#endif - nb_draw_t* nb_draw_create(void); void nb_draw_destroy(nb_draw_t* draw); void nb_draw_frame(nb_draw_t* draw); @@ -36,5 +18,7 @@ int nb_draw_step(nb_draw_t* draw); void nb_draw_reshape(nb_draw_t* draw); void nb_draw_init_opengl(nb_draw_t* draw); int nb_draw_has_extension(nb_draw_t* draw, const char* query); +void nb_draw_begin(void); +void nb_draw_end(void); #endif diff --git a/engine/nb_draw_platform.h b/engine/nb_draw_platform.h index 0db9eab..d1a3c6e 100644 --- a/engine/nb_draw_platform.h +++ b/engine/nb_draw_platform.h @@ -4,60 +4,19 @@ #include #include -/* External library */ -#ifdef NB_EXPOSE_DRAW_PLATFORM -#include -#include -#if defined(USE_GLX) -#include -#include -#include -#elif defined(USE_WGL) -#include -#elif defined(USE_GLFW) -#include -#endif -#endif +/* Type */ +#include /* NishBox */ +#include /* Standard */ -#ifdef NB_EXPOSE_DRAW_PLATFORM -typedef struct nb_draw { -#if defined(USE_GLX) - Display* display; - Window window; - GLXContext context; - Atom wm_delete_window; -#elif defined(USE_WGL) - HINSTANCE instance; - HWND window; - HDC dc; - HGLRC glrc; -#elif defined(USE_GLFW) - GLFWwindow* window; -#endif - int close; - int x; - int y; - int width; - int height; - int running; - GLuint font[128]; - GLfloat light[4]; - GLfloat lookat[3]; - GLfloat camera[3]; - GLUquadric* quadric; -} nb_draw_t; -#else -typedef void nb_draw_t; -#endif - -void _nb_draw_create(nb_draw_t** pdraw); -void _nb_draw_destroy(nb_draw_t* draw); -int _nb_draw_step(nb_draw_t* draw); -int _nb_draw_has_extension(nb_draw_t* draw, const char* query); -void _nb_draw_init(void); +void nb_draw_platform_create(nb_draw_t* draw); +void nb_draw_platform_destroy(nb_draw_t* draw); +int nb_draw_platform_step(nb_draw_t* draw); +int nb_draw_platform_has_extension(nb_draw_t* draw, const char* query); +void nb_draw_platform_begin(void); +void nb_draw_platform_end(void); #endif diff --git a/engine/font.c b/engine/nb_font.c similarity index 100% rename from engine/font.c rename to engine/nb_font.c diff --git a/engine/nb_font.h b/engine/nb_font.h index 57c6351..a80dcee 100644 --- a/engine/nb_font.h +++ b/engine/nb_font.h @@ -4,7 +4,7 @@ #include #include -/* External library */ +/* Type */ /* NishBox */ diff --git a/engine/log.c b/engine/nb_log.c similarity index 100% rename from engine/log.c rename to engine/nb_log.c diff --git a/engine/nb_log.h b/engine/nb_log.h index 2972d2e..e69507c 100644 --- a/engine/nb_log.h +++ b/engine/nb_log.h @@ -4,14 +4,14 @@ #include #include -/* External library */ +/* Type */ /* NishBox */ /* Standard */ -void nb_log(const char* fmt, ...); - #define nb_function_log(fmt, arg...) nb_log("%6d %24s: " fmt "\n", __LINE__, __FUNCTION_NAME__, arg) +void nb_log(const char* fmt, ...); + #endif diff --git a/engine/nb_macro.h b/engine/nb_macro.h index 7d8b413..394ffaa 100644 --- a/engine/nb_macro.h +++ b/engine/nb_macro.h @@ -15,6 +15,30 @@ #define NB_EXPOSE_DRAW_PLATFORM #endif +#ifndef NB_EXPOSE_MESH +#define NB_EXPOSE_MESH +#endif + +#ifndef NB_EXPOSE_MODEL +#define NB_EXPOSE_MODEL +#endif + +#ifndef NB_EXPOSE_TEXTURE +#define NB_EXPOSE_TEXTURE +#endif + +#ifndef NB_EXPOSE_PHYSICS +#define NB_EXPOSE_PHYSICS +#endif + +#ifndef NB_EXPOSE_MATH +#define NB_EXPOSE_MATH +#endif + +#ifndef NB_EXPOSE_VERSION +#define NB_EXPOSE_VERSION +#endif + #endif #ifndef __FUNCTION_NAME__ @@ -25,4 +49,15 @@ #endif #endif +#define NB_DECLARE_TYPE(n, b) typedef struct nb_##n b nb_##n##_t; + +/* Expose them by default */ +#ifndef NB_EXPOSE_MATH +#define NB_EXPOSE_MATH +#endif + +#ifndef NB_EXPOSE_VERSION +#define NB_EXPOSE_VERSION +#endif + #endif diff --git a/engine/math.c b/engine/nb_math.c similarity index 97% rename from engine/math.c rename to engine/nb_math.c index fc22861..ac1c9f4 100644 --- a/engine/math.c +++ b/engine/nb_math.c @@ -1,5 +1,3 @@ -#define NB_EXPOSE_MATH - #include "nb_pre.h" /* External library */ diff --git a/engine/nb_math.h b/engine/nb_math.h index fec4f15..8d5ab05 100644 --- a/engine/nb_math.h +++ b/engine/nb_math.h @@ -4,25 +4,17 @@ #include #include -/* External library */ -#ifdef NB_EXPOSE_MATH -#include -#endif +/* Type */ +#include /* NishBox */ /* Standard */ -#ifdef NB_EXPOSE_MATH -typedef GLfloat* nb_vector_t; - #define NB_VECTOR_COPY(from, to) \ to[0] = from[0]; \ to[1] = from[1]; \ to[2] = from[2] -#else -typedef void* nb_vector_t; -#endif float nb_log2(float x); nb_vector_t nb_calculate_normal(nb_vector_t v0, nb_vector_t v1, nb_vector_t v2); diff --git a/engine/nb_mesh.c b/engine/nb_mesh.c new file mode 100644 index 0000000..0370a93 --- /dev/null +++ b/engine/nb_mesh.c @@ -0,0 +1,13 @@ +#define NB_EXPOSE_MESH + +#include "nb_pre.h" + +/* External library */ + +/* Interface */ +#include "nb_mesh.h" + +/* NishBox */ +#include "nb_math.h" + +/* Standard */ diff --git a/engine/nb_mesh.h b/engine/nb_mesh.h new file mode 100644 index 0000000..5841b42 --- /dev/null +++ b/engine/nb_mesh.h @@ -0,0 +1,14 @@ +#ifndef __NB_MESH_H__ +#define __NB_MESH_H__ + +#include +#include + +/* Type */ +#include + +/* NishBox */ + +/* Standard */ + +#endif diff --git a/engine/nb_model.c b/engine/nb_model.c new file mode 100644 index 0000000..0d5669c --- /dev/null +++ b/engine/nb_model.c @@ -0,0 +1,13 @@ +#define NB_EXPOSE_MODEL + +#include "nb_pre.h" + +/* External library */ + +/* Interface */ +#include "nb_model.h" + +/* NishBox */ +#include "nb_math.h" + +/* Standard */ diff --git a/engine/nb_model.h b/engine/nb_model.h new file mode 100644 index 0000000..6780b16 --- /dev/null +++ b/engine/nb_model.h @@ -0,0 +1,14 @@ +#ifndef __NB_MODEL_H__ +#define __NB_MODEL_H__ + +#include +#include + +/* Type */ +#include + +/* NishBox */ + +/* Standard */ + +#endif diff --git a/engine/nb_physics.c b/engine/nb_physics.c new file mode 100644 index 0000000..d57d0f7 --- /dev/null +++ b/engine/nb_physics.c @@ -0,0 +1,32 @@ +#define NB_EXPOSE_PHYSICS + +#include "nb_pre.h" + +/* External library */ +#include + +/* Interface */ +#include "nb_physics.h" + +/* NishBox */ +#include "nb_log.h" + +/* Standard */ +#include + +void nb_physics_begin(void) { dInitODE(); } + +void nb_physics_end(void) { dCloseODE(); } + +nb_physics_t* nb_physics_create(void) { + nb_physics_t* physics = malloc(sizeof(*physics)); + physics->id = dWorldCreate(); + dWorldSetGravity(physics->id, 0, 0, -9.81); + return physics; +} + +void nb_physics_destroy(nb_physics_t* physics) { + dWorldDestroy(physics->id); + free(physics); + nb_function_log("Destroyed physics", ""); +} diff --git a/engine/nb_physics.h b/engine/nb_physics.h new file mode 100644 index 0000000..20de323 --- /dev/null +++ b/engine/nb_physics.h @@ -0,0 +1,19 @@ +#ifndef __NB_PHYSICS_H__ +#define __NB_PHYSICS_H__ + +#include +#include + +/* Type */ +#include + +/* NishBox */ + +/* Standard */ + +void nb_physics_begin(void); +void nb_physics_end(void); +nb_physics_t* nb_physics_create(void); +void nb_physics_destroy(nb_physics_t* physics); + +#endif diff --git a/engine/stb_image.c b/engine/nb_stb_image.c similarity index 100% rename from engine/stb_image.c rename to engine/nb_stb_image.c diff --git a/engine/nb_texture.h b/engine/nb_texture.h new file mode 100644 index 0000000..dc53ba2 --- /dev/null +++ b/engine/nb_texture.h @@ -0,0 +1,14 @@ +#ifndef __NB_TEXTURE_H__ +#define __NB_TEXTURE_H__ + +#include +#include + +/* Type */ +#include + +/* NishBox */ + +/* Standard */ + +#endif diff --git a/engine/nb_type/core.h b/engine/nb_type/core.h new file mode 100644 index 0000000..d06e3e5 --- /dev/null +++ b/engine/nb_type/core.h @@ -0,0 +1,24 @@ +#ifndef __NB_TYPE_CORE_H__ +#define __NB_TYPE_CORE_H__ + +#include +#include + +#ifdef NB_EXPOSE_CORE +/* External library */ + +/* NishBox */ +#include +#include + +/* Standard */ + +NB_DECLARE_TYPE(engine, { + nb_physics_t* physics; + nb_draw_t* draw; +}); +#else +typedef void nb_engine_t; +#endif + +#endif diff --git a/engine/nb_type/draw.h b/engine/nb_type/draw.h new file mode 100644 index 0000000..903fc1e --- /dev/null +++ b/engine/nb_type/draw.h @@ -0,0 +1,33 @@ +#ifndef __NB_TYPE_DRAW_H__ +#define __NB_TYPE_DRAW_H__ + +#include +#include + +#ifdef NB_EXPOSE_DRAW +/* External library */ + +/* NishBox */ +#include + +/* Standard */ + +NB_DECLARE_TYPE(draw, { + nb_draw_platform_t* platform; + int close; + int x; + int y; + int width; + int height; + int running; + GLuint font[128]; + GLfloat light[4]; + GLfloat lookat[3]; + GLfloat camera[3]; + GLUquadric* quadric; +}); +#else +typedef void nb_draw_t; +#endif + +#endif diff --git a/engine/nb_type/draw_platform.h b/engine/nb_type/draw_platform.h new file mode 100644 index 0000000..6beb40b --- /dev/null +++ b/engine/nb_type/draw_platform.h @@ -0,0 +1,44 @@ +#ifndef __NB_TYPE_DRAW_PLATFORM_H__ +#define __NB_TYPE_DRAW_PLATFORM_H__ + +#include +#include + +#ifdef NB_EXPOSE_DRAW_PLATFORM +/* External library */ +#include +#include +#if defined(USE_GLX) +#include +#include +#include +#elif defined(USE_WGL) +#include +#elif defined(USE_GLFW) +#include +#endif + +/* NishBox */ + +/* Standard */ + +NB_DECLARE_TYPE(draw_platform, { +#if defined(USE_GLX) + Display* display; + Window window; + GLXContext context; + Atom wm_delete_window; +#elif defined(USE_WGL) + HINSTANCE instance; + HWND window; + HDC dc; + HGLRC glrc; +#elif defined(USE_GLFW) + GLFWwindow* window; +#endif +}); +#else +typedef void nb_draw_platform_t; +#endif + +#endif diff --git a/engine/nb_type/math.h b/engine/nb_type/math.h new file mode 100644 index 0000000..54d3c1e --- /dev/null +++ b/engine/nb_type/math.h @@ -0,0 +1,19 @@ +#ifndef __NB_TYPE_MATH_H__ +#define __NB_TYPE_MATH_H__ + +#include +#include + +#ifdef NB_EXPOSE_MATH +/* External library */ + +/* NishBox */ + +/* Standard */ + +typedef double* nb_vector_t; +#else +typedef void* nb_vector_t; +#endif + +#endif diff --git a/engine/nb_type/mesh.h b/engine/nb_type/mesh.h new file mode 100644 index 0000000..074c524 --- /dev/null +++ b/engine/nb_type/mesh.h @@ -0,0 +1,29 @@ +#ifndef __NB_TYPE_MESH_H__ +#define __NB_TYPE_MESH_H__ + +#include +#include + +#ifdef NB_EXPOSE_MESH +/* External library */ + +/* NishBox */ +#include + +/* Standard */ + +NB_DECLARE_TYPE(shape, { + nb_vector_t points[3]; + nb_vector_t color; +}); + +NB_DECLARE_TYPE(mesh, { + nb_shape_t* shapes; + int shape_count; +}); +#else +typedef void nb_mesh_t; +typedef void nb_shape_t; +#endif + +#endif diff --git a/engine/nb_type/model.h b/engine/nb_type/model.h new file mode 100644 index 0000000..f991322 --- /dev/null +++ b/engine/nb_type/model.h @@ -0,0 +1,24 @@ +#ifndef __NB_TYPE_MODEL_H__ +#define __NB_TYPE_MODEL_H__ + +#include +#include + +#ifdef NB_EXPOSE_MODEL +/* External library */ + +/* NishBox */ +#include +#include + +/* Standard */ + +NB_DECLARE_TYPE(model, { + nb_mesh_t* mesh; + nb_texture_t* texture; +}); +#else +typedef void nb_model_t; +#endif + +#endif diff --git a/engine/nb_type/physics.h b/engine/nb_type/physics.h new file mode 100644 index 0000000..d71580b --- /dev/null +++ b/engine/nb_type/physics.h @@ -0,0 +1,20 @@ +#ifndef __NB_TYPE_PHYSICS_H__ +#define __NB_TYPE_PHYSICS_H__ + +#include +#include + +#ifdef NB_EXPOSE_PHYSICS +/* External library */ +#include + +/* NishBox */ + +/* Standard */ + +NB_DECLARE_TYPE(physics, { dWorldID id; }); +#else +typedef void nb_physics_t; +#endif + +#endif diff --git a/engine/nb_type/texture.h b/engine/nb_type/texture.h new file mode 100644 index 0000000..4892c59 --- /dev/null +++ b/engine/nb_type/texture.h @@ -0,0 +1,20 @@ +#ifndef __NB_TYPE_TEXTURE_H__ +#define __NB_TYPE_TEXTURE_H__ + +#include +#include + +#ifdef NB_EXPOSE_TEXTURE +/* External library */ +#include + +/* NishBox */ + +/* Standard */ + +NB_DECLARE_TYPE(texture, { GLuint id; }); +#else +typedef void nb_texture_t; +#endif + +#endif diff --git a/engine/nb_type/version.h b/engine/nb_type/version.h new file mode 100644 index 0000000..8a0c4cf --- /dev/null +++ b/engine/nb_type/version.h @@ -0,0 +1,25 @@ +#ifndef __NB_TYPE_VERSION_H__ +#define __NB_TYPE_VERSION_H__ + +#include +#include + +#ifdef NB_EXPOSE_VERSION +/* External library */ + +/* NishBox */ + +/* Standard */ + +typedef struct nb_version { + int major; + int minor; + int patch; + char full[64]; + char opengl[32]; +} nb_version_t; +#else +typedef void nb_version_t; +#endif + +#endif diff --git a/engine/version.c b/engine/nb_version.c similarity index 100% rename from engine/version.c rename to engine/nb_version.c diff --git a/engine/nb_version.h b/engine/nb_version.h index 996d0ab..3438a2a 100644 --- a/engine/nb_version.h +++ b/engine/nb_version.h @@ -4,20 +4,13 @@ #include #include -/* External library */ +/* Type */ +#include /* NishBox */ /* Standard */ -typedef struct nb_version { - int major; - int minor; - int patch; - char full[64]; - char opengl[32]; -} nb_version_t; - void nb_get_version(nb_version_t* version); #endif