Reinitialize GL after SDL_SetVideoMode

On some systems SDL_SetVideoMode resets OpenGL context,
dropping the screen texture and leading to glTexSubimage2D
failure when using the --opengl-2d switch.

Attached patch reinitialized OpenGL after window resize.

This is a forward port of Jakub Higersberger patch at
 #2839785. This fix the broken resize with cli frontend
reported in #3195218.
This commit is contained in:
riccardom 2011-03-16 21:42:53 +00:00
parent 8422f0ab7c
commit 80fd38374f
3 changed files with 33 additions and 8 deletions

View File

@ -318,11 +318,19 @@ initGL( GLuint *screen_texture) {
}
static void
resizeWindow( u16 width, u16 height) {
resizeWindow( u16 width, u16 height, GLuint *screen_texture) {
int comp_width = 3 * width;
int comp_height = 2 * height;
GLenum errCode;
surface = SDL_SetVideoMode(width, height, 32, sdl_videoFlags);
initGL(screen_texture);
#ifdef HAVE_LIBAGG
Hud.reset();
#endif
if ( comp_width > comp_height) {
width = 2*height/3;
}
@ -353,9 +361,6 @@ resizeWindow( u16 width, u16 height) {
errString = gluErrorString(errCode);
fprintf( stderr, "GL resize failed: %s\n", errString);
}
surface = SDL_SetVideoMode( width, height, 32,
sdl_videoFlags );
}
@ -422,9 +427,15 @@ opengl_Draw( GLuint *texture, int software_convert) {
#endif
/* this is a stub for resizeWindow_stub in the case of no gl headers or no opengl 2d */
#ifdef INCLUDE_OPENGL_2D
static void
resizeWindow_stub (u16 width, u16 height) {
resizeWindow_stub (u16 width, u16 height, GLuint *screen_texture) {
}
#else
static void
resizeWindow_stub (u16 width, u16 height, void *screen_texture) {
}
#endif
static void
Draw( void) {
@ -681,7 +692,7 @@ int main(int argc, char ** argv) {
/* set the initial window size */
if ( my_config.opengl_2d) {
resizeWindow( 256, 192*2);
resizeWindow( 256, 192*2, screen_texture);
}
#endif
@ -709,6 +720,11 @@ int main(int argc, char ** argv) {
ctrls_cfg.focused = 1;
ctrls_cfg.fake_mic = 0;
ctrls_cfg.keypad = 0;
#ifdef INCLUDE_OPENGL_2D
ctrls_cfg.screen_texture = screen_texture;
#else
ctrls_cfg.screen_texture = NULL;
#endif
ctrls_cfg.resize_cb = &resizeWindow_stub;
while(!ctrls_cfg.sdl_quit) {

View File

@ -428,7 +428,7 @@ process_ctrls_event( SDL_Event& event,
switch (event.type)
{
case SDL_VIDEORESIZE:
cfg->resize_cb( event.resize.w, event.resize.h);
cfg->resize_cb( event.resize.w, event.resize.h, cfg->screen_texture);
break;
case SDL_ACTIVEEVENT:

View File

@ -23,6 +23,10 @@
#ifndef CTRLSSDL_H
#define CTRLSSDL_H
#ifdef HAVE_GL_GL_H
#include <GL/gl.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@ -90,7 +94,12 @@ struct ctrls_event_config {
int sdl_quit;
int boost;
int fake_mic;
void (*resize_cb)(u16 width, u16 height);
GLuint *screen_texture;
#ifdef HAVE_GL_GL_H
void (*resize_cb)(u16 width, u16 height, GLuint *screen_texture);
#else
void (*resize_cb)(u16 width, u16 height, void *screen_texture);
#endif
};
void load_default_config(const u16 kbCfg[]);