From 7bbc0321cd8680ff911b0bd9346516585b505f2f Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 24 Jul 2019 20:00:23 +0100 Subject: [PATCH] Backport OpenGL2 fixes from the enhanced branch --- src/Backends/Rendering/OpenGL2.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Backends/Rendering/OpenGL2.cpp b/src/Backends/Rendering/OpenGL2.cpp index 9aa66909..4fbd3f69 100644 --- a/src/Backends/Rendering/OpenGL2.cpp +++ b/src/Backends/Rendering/OpenGL2.cpp @@ -113,6 +113,7 @@ BOOL Backend_Init(SDL_Window *p_window) // Set up framebuffer (used for surface-to-surface blitting) glGenFramebuffersEXT(1, &framebuffer_id); + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer_id); // Set up framebuffer screen texture (used for screen-to-surface blitting) glGenTextures(1, &framebuffer_surface.texture_id); @@ -214,6 +215,9 @@ void Backend_Unlock(Backend_Surface *surface) static void BlitCommon(Backend_Surface *source_surface, const RECT *rect, long x, long y, BOOL colour_key) { + if (rect->right - rect->left < 0 || rect->bottom - rect->top < 0) + return; + // Switch to colour-key shader if we have to glUseProgram(colour_key ? colour_key_program_id : 0); @@ -250,6 +254,9 @@ void Backend_BlitToScreen(Backend_Surface *source_surface, const RECT *rect, lon static void ColourFillCommon(const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) { + if (rect->right - rect->left < 0 || rect->bottom - rect->top < 0) + return; + // Disable colour-keying glUseProgram(0); @@ -303,6 +310,12 @@ Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width unsigned char *buffer = (unsigned char*)malloc(width * height * 4); + if (buffer == NULL) + { + free(glyph); + return NULL; + } + switch (pixel_mode) { // FONT_PIXEL_MODE_LCD is unsupported