diff --git a/src/Backends/GLFW3/Window-Software.cpp b/src/Backends/GLFW3/Window-Software.cpp index 173fca73..4f2900a5 100644 --- a/src/Backends/GLFW3/Window-Software.cpp +++ b/src/Backends/GLFW3/Window-Software.cpp @@ -24,7 +24,7 @@ static float framebuffer_y_ratio; static GLuint screen_texture_id; -unsigned char* WindowBackend_Software_CreateWindow(const char *window_title, int screen_width, int screen_height, bool fullscreen, size_t *pitch) +bool WindowBackend_Software_CreateWindow(const char *window_title, int screen_width, int screen_height, bool fullscreen) { glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 1); @@ -81,18 +81,16 @@ unsigned char* WindowBackend_Software_CreateWindow(const char *window_title, int framebuffer = (unsigned char*)malloc(framebuffer_width * framebuffer_height * 3); - *pitch = framebuffer_width * 3; - Backend_PostWindowCreation(); - return framebuffer; + return true; } else { Backend_ShowMessageBox("Fatal error (OpenGL rendering backend)", "Could not create window"); } - return NULL; + return false; } void WindowBackend_Software_DestroyWindow(void) @@ -102,6 +100,13 @@ void WindowBackend_Software_DestroyWindow(void) glfwDestroyWindow(window); } +unsigned char* WindowBackend_Software_GetFramebuffer(size_t *pitch) +{ + *pitch = framebuffer_width * 3; + + return framebuffer; +} + void WindowBackend_Software_Display(void) { glClear(GL_COLOR_BUFFER_BIT); diff --git a/src/Backends/Rendering/Software.cpp b/src/Backends/Rendering/Software.cpp index 178c61ff..bb4880b3 100644 --- a/src/Backends/Rendering/Software.cpp +++ b/src/Backends/Rendering/Software.cpp @@ -33,19 +33,22 @@ static RenderBackend_Surface *glyph_destination_surface; RenderBackend_Surface* RenderBackend_Init(const char *window_title, int screen_width, int screen_height, bool fullscreen) { - size_t pitch; - framebuffer.pixels = WindowBackend_Software_CreateWindow(window_title, screen_width, screen_height, fullscreen, &pitch); - framebuffer.width = screen_width; - framebuffer.height = screen_height; - framebuffer.pitch = pitch; + if (WindowBackend_Software_CreateWindow(window_title, screen_width, screen_height, fullscreen)) + { + size_t pitch; + framebuffer.pixels = WindowBackend_Software_GetFramebuffer(&pitch); + framebuffer.width = screen_width; + framebuffer.height = screen_height; + framebuffer.pitch = pitch; - if (framebuffer.pixels == NULL) + return &framebuffer; + } + else { Backend_PrintError("Failed to create window"); - return NULL; } - return &framebuffer; + return NULL; } void RenderBackend_Deinit(void) @@ -56,6 +59,10 @@ void RenderBackend_Deinit(void) void RenderBackend_DrawScreen(void) { WindowBackend_Software_Display(); + + size_t pitch; + framebuffer.pixels = WindowBackend_Software_GetFramebuffer(&pitch); + framebuffer.pitch = pitch; } RenderBackend_Surface* RenderBackend_CreateSurface(unsigned int width, unsigned int height) diff --git a/src/Backends/Window-Software.h b/src/Backends/Window-Software.h index a7c7eb79..02c4bf85 100644 --- a/src/Backends/Window-Software.h +++ b/src/Backends/Window-Software.h @@ -2,7 +2,8 @@ #include -unsigned char* WindowBackend_Software_CreateWindow(const char *window_title, int screen_width, int screen_height, bool fullscreen, size_t *pitch); +bool WindowBackend_Software_CreateWindow(const char *window_title, int screen_width, int screen_height, bool fullscreen); void WindowBackend_Software_DestroyWindow(void); +unsigned char* WindowBackend_Software_GetFramebuffer(size_t *pitch); void WindowBackend_Software_Display(void); void WindowBackend_Software_HandleWindowResize(unsigned int width, unsigned int height);