Skip to content

Commit

Permalink
Fix black window upon resizing.
Browse files Browse the repository at this point in the history
I don't know why, but removing the glOrtho call makes the window stop
going black when resizing.
  • Loading branch information
Quipyowert2 committed Dec 25, 2022
1 parent 2550f61 commit a2ede94
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
1 change: 1 addition & 0 deletions libgag/include/SDLGraphicContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ namespace GAGCore
// modifiers
virtual bool setRes(int w, int h, Uint32 flags);
virtual void setRes(int w, int h) { setRes(w, h, optionFlags); }
virtual SDL_Surface *getOrCreateSurface(int w, int h, Uint32 flags);
virtual SDL_Rect getRes();
virtual bool resChanged();
virtual void createGLContext();
Expand Down
41 changes: 27 additions & 14 deletions libgag/src/GraphicContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2055,11 +2055,25 @@ namespace GAGCore
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, w, 0, h, -1.0, -1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

SDL_Surface* GraphicContext::getOrCreateSurface(int w, int h, Uint32 flags) {
if (flags & USEGPU)
{
if (sdlsurface)
SDL_FreeSurface(sdlsurface);
// Can't use SDL_GetWindowSurface with OpenGL; the documentation forbids it.
sdlsurface = SDL_CreateRGBSurface(0, w, h, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
}
else
{
sdlsurface = SDL_GetWindowSurface(window);
}
return sdlsurface;
}

bool GraphicContext::setRes(int w, int h, Uint32 flags)
{
// check dimension
Expand Down Expand Up @@ -2101,27 +2115,31 @@ namespace GAGCore
// if window exists, resize it
if (window) {
SDL_SetWindowSize(window, w, h);
sdlsurface = SDL_GetWindowSurface(window);
getOrCreateSurface(w, h, flags);
#ifdef HAVE_OPENGL
if (flags & USEGPU)
{
resetMatrices();
}
#endif
setClipRect(0, 0, w, h);
nextFrame();
//nextFrame();
}
else {
// create the new window and the surface
window = SDL_CreateWindow(windowTitle.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, w, h, sdlFlags);
}
sdlsurface = window != nullptr ? SDL_GetWindowSurface(window) : nullptr;
sdlsurface = window != nullptr ? getOrCreateSurface(w, h, flags) : nullptr;
#ifdef HAVE_OPENGL
if (flags & USEGPU)
{
resetMatrices();
}
// enable GL context
if (flags & USEGPU)
{
if (!context)
createGLContext();
resetMatrices();
}
#endif
}

// check surface
if (!sdlsurface)
{
Expand All @@ -2132,11 +2150,6 @@ namespace GAGCore
else
{
_gc = this;
// enable GL context
if (flags & USEGPU && !context)
{
createGLContext();
}
// set _glFormat
if ((optionFlags & USEGPU) && (_gc->sdlsurface->format->BitsPerPixel != 32))
{
Expand Down

0 comments on commit a2ede94

Please sign in to comment.