Skip to content

Commit

Permalink
OpenGL UI fixes for on OS X/all platforms
Browse files Browse the repository at this point in the history
 - Reinitialise textures after SDL_SetVideoMode
 - Fix header includes and remove GLEW setup on OSX
  • Loading branch information
simtr committed Jul 12, 2016
1 parent b66ca77 commit 6cfaeb9
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/PowderToySDL.cpp
Expand Up @@ -1043,7 +1043,7 @@ int main(int argc, char * argv[])
SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
//glScaled(2.0f, 2.0f, 1.0f);
#endif
#if defined(OGLI)
#if defined(OGLI) && !defined(MACOSX)
int status = glewInit();
if(status != GLEW_OK)
{
Expand Down
3 changes: 3 additions & 0 deletions src/graphics/Graphics.h
Expand Up @@ -188,6 +188,9 @@ class Graphics
//OpenGL specific instance variables
GLuint vidBuf, textTexture;
void Reset();
void LoadDefaults();
void InitialiseTextures();
void DestroyTextures();
#endif

//Common graphics methods in Graphics.cpp
Expand Down
50 changes: 35 additions & 15 deletions src/graphics/OpenGLGraphics.cpp
Expand Up @@ -10,12 +10,36 @@ Graphics::Graphics():
{
// if(gMutex == TMPMUT)
// pthread_mutex_init (&gMutex, NULL);
Reset();
LoadDefaults();
InitialiseTextures();

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);


//Texture for main UI

}

void Graphics::LoadDefaults()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

//glOrtho(0, WINDOWW*sdl_scale, 0, WINDOWH*sdl_scale, -1, 1);
glOrtho(0, WINDOWW*sdl_scale, WINDOWH*sdl_scale, 0, -1, 1);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

//glRasterPos2i(0, WINDOWH);
glRasterPos2i(0, 0);
glPixelZoom(1, 1);

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}

void Graphics::InitialiseTextures()
{
glEnable(GL_TEXTURE_2D);

glGenTextures(1, &vidBuf);
Expand All @@ -39,6 +63,11 @@ Graphics::Graphics():
glDisable(GL_TEXTURE_2D);
}

void Graphics::DestroyTextures()
{
//Todo...
}

void Graphics::Acquire()
{
pthread_mutex_lock(&gMutex);
Expand All @@ -55,18 +84,9 @@ Graphics::~Graphics()

void Graphics::Reset()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

//glOrtho(0, WINDOWW*sdl_scale, 0, WINDOWH*sdl_scale, -1, 1);
glOrtho(0, WINDOWW*sdl_scale, WINDOWH*sdl_scale, 0, -1, 1);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

//glRasterPos2i(0, WINDOWH);
glRasterPos2i(0, 0);
glPixelZoom(1, 1);
LoadDefaults();
DestroyTextures();
InitialiseTextures();
}

void Graphics::Clear()
Expand Down
4 changes: 3 additions & 1 deletion src/graphics/OpenGLHeaders.h
@@ -1,6 +1,8 @@
#ifdef MACOSX

#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_OS_X_VERSION_10_9
#include <OpenGL/glu.h>
#elif __MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
#include <OpenGL/gl3.h>
#include <OpenGL/glu.h>
#else
Expand Down

0 comments on commit 6cfaeb9

Please sign in to comment.