ref: d6888040a2db4065a2550c147f754258e8ac0a5c
parent: 9948fa8b074e16e382fae89e958b186602d5cd7b
author: Clownacy <Clownacy@users.noreply.github.com>
date: Wed Jul 24 18:08:37 EDT 2019
Backport some OpenGL 2.1 fixes
--- a/src/Backends/Rendering/OpenGL2.cpp
+++ b/src/Backends/Rendering/OpenGL2.cpp
@@ -71,6 +71,16 @@
return program_id;
}
+static void SetRenderTarget(Backend_Surface *surface)
+{
+ glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, surface->texture_id, 0);
+
+ glViewport(0, 0, surface->width, surface->height);
+
+ glLoadIdentity();
+ glOrtho(0.0, surface->width, 0.0, surface->height, 1.0, -1.0);
+}
+
SDL_Window* Backend_CreateWindow(const char *title, int width, int height)
{
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY);
@@ -84,8 +94,8 @@
{
window = p_window;
- int screen_width, screen_height;
- SDL_GetWindowSize(window, &screen_width, &screen_height);
+ int window_width, window_height;
+ SDL_GetWindowSize(window, &window_width, &window_height);
context = SDL_GL_CreateContext(window);
@@ -96,13 +106,7 @@
if (!GLEW_EXT_framebuffer_object)
return FALSE;
-// glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glOrtho(0.0, screen_width, 0.0, screen_height, 1.0, -1.0);
-// glMatrixMode(GL_PROJECTION);
-// glLoadIdentity();
-
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@@ -127,12 +131,12 @@
// Set up framebuffer screen texture (used for screen-to-surface blitting)
glGenTextures(1, &framebuffer_surface.texture_id);
glBindTexture(GL_TEXTURE_2D, framebuffer_surface.texture_id);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, screen_width, screen_height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, window_width, window_height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- framebuffer_surface.width = screen_width;
- framebuffer_surface.height = screen_height;
+ framebuffer_surface.width = window_width;
+ framebuffer_surface.height = window_height;
return TRUE;
}
@@ -153,6 +157,11 @@
// Target actual screen, and not our framebuffer
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
+ glViewport(0, 0, framebuffer_surface.width, framebuffer_surface.height);
+
+ glLoadIdentity();
+ glOrtho(0.0, framebuffer_surface.width, 0.0, framebuffer_surface.height, 1.0, -1.0);
+
// Draw framebuffer to screen
glPushMatrix();
glLoadIdentity();
@@ -248,7 +257,7 @@
void Backend_Blit(Backend_Surface *source_surface, const RECT *rect, Backend_Surface *destination_surface, long x, long y, BOOL colour_key)
{
// Point our framebuffer to the destination texture
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, destination_surface->texture_id, 0);
+ SetRenderTarget(destination_surface);
BlitCommon(source_surface, rect, x, y, colour_key);
}
@@ -256,7 +265,7 @@
void Backend_BlitToScreen(Backend_Surface *source_surface, const RECT *rect, long x, long y, BOOL colour_key)
{
// Point our framebuffer to the screen texture
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, framebuffer_surface.texture_id, 0);
+ SetRenderTarget(&framebuffer_surface);
BlitCommon(source_surface, rect, x, y, colour_key);
}
@@ -284,7 +293,7 @@
void Backend_ColourFill(Backend_Surface *surface, const RECT *rect, unsigned char red, unsigned char green, unsigned char blue)
{
// Point our framebuffer to the destination texture
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, surface->texture_id, 0);
+ SetRenderTarget(surface);
ColourFillCommon(rect, red, green, blue);
}
@@ -292,7 +301,7 @@
void Backend_ColourFillToScreen(const RECT *rect, unsigned char red, unsigned char green, unsigned char blue)
{
// Point our framebuffer to the screen texture
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, framebuffer_surface.texture_id, 0);
+ SetRenderTarget(&framebuffer_surface);
ColourFillCommon(rect, red, green, blue);
}
@@ -300,7 +309,7 @@
void Backend_ScreenToSurface(Backend_Surface *surface, const RECT *rect)
{
// Point our framebuffer to the destination texture
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, surface->texture_id, 0);
+ SetRenderTarget(surface);
BlitCommon(&framebuffer_surface, rect, rect->left, rect->top, FALSE);
}
@@ -407,7 +416,7 @@
void Backend_DrawGlyph(Backend_Surface *surface, Backend_Glyph *glyph, long x, long y, const unsigned char *colours)
{
// Point our framebuffer to the destination texture
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, surface->texture_id, 0);
+ SetRenderTarget(surface);
DrawGlyphCommon(glyph, x, y, colours);
}
@@ -415,7 +424,7 @@
void Backend_DrawGlyphToScreen(Backend_Glyph *glyph, long x, long y, const unsigned char *colours)
{
// Point our framebuffer to the screen texture
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, framebuffer_surface.texture_id, 0);
+ SetRenderTarget(&framebuffer_surface);
DrawGlyphCommon(glyph, x, y, colours);
}