Resizable window when using OpenGL interface

This commit is contained in:
Simon Robertshaw 2012-06-25 16:10:40 +01:00
parent ab8f382acc
commit dacb774ae0
4 changed files with 51 additions and 21 deletions

View File

@ -107,6 +107,7 @@ public:
#ifdef OGLI
//OpenGL specific instance variables
GLuint vidBuf, textTexture;
void Reset();
#endif
//Common graphics methods in Graphics.cpp

View File

@ -6,19 +6,7 @@
Graphics::Graphics():
sdl_scale(1)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//glOrtho(0, (XRES+BARSIZE)*sdl_scale, 0, (YRES+MENUSIZE)*sdl_scale, -1, 1);
glOrtho(0, (XRES+BARSIZE)*sdl_scale, (YRES+MENUSIZE)*sdl_scale, 0, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//glRasterPos2i(0, (YRES+MENUSIZE));
glRasterPos2i(0, 0);
glPixelZoom(1, 1);
Reset();
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@ -51,6 +39,22 @@ Graphics::~Graphics()
{
}
void Graphics::Reset()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//glOrtho(0, (XRES+BARSIZE)*sdl_scale, 0, (YRES+MENUSIZE)*sdl_scale, -1, 1);
glOrtho(0, (XRES+BARSIZE)*sdl_scale, (YRES+MENUSIZE)*sdl_scale, 0, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//glRasterPos2i(0, (YRES+MENUSIZE));
glRasterPos2i(0, 0);
glPixelZoom(1, 1);
}
void Graphics::Clear()
{
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

View File

@ -113,7 +113,7 @@ SDL_Surface * SDLOpen()
#ifndef OGLI
surface = SDL_SetVideoMode(XRES + BARSIZE, YRES + MENUSIZE, 32, SDL_SWSURFACE);
#else
surface = SDL_SetVideoMode(XRES + BARSIZE, YRES + MENUSIZE, 32, SDL_OPENGL);
surface = SDL_SetVideoMode((XRES + BARSIZE), (YRES + MENUSIZE), 32, SDL_OPENGL | SDL_RESIZABLE);
#endif
#if defined(OGLI)
@ -132,11 +132,14 @@ int main(int argc, char * argv[])
{
int elapsedTime = 0, currentTime = 0, lastTime = 0, currentFrame = 0;
unsigned int lastTick = 0;
float fps = 0, delta = 1.0f;
float fps = 0, delta = 1.0f, inputScale = 1.0f;
float currentWidth = XRES+BARSIZE, currentHeight = YRES+MENUSIZE;
sdl_scrn = SDLOpen();
#ifdef OGLI
SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
//glScaled(2.0f, 2.0f, 1.0f);
#endif
ui::Engine::Ref().g = new Graphics();
@ -168,26 +171,47 @@ int main(int argc, char * argv[])
engine->onKeyRelease(event.key.keysym.sym, event.key.keysym.unicode, event.key.keysym.mod&KEY_MOD_SHIFT, event.key.keysym.mod&KEY_MOD_CONTROL, event.key.keysym.mod&KEY_MOD_ALT);
break;
case SDL_MOUSEMOTION:
engine->onMouseMove(event.motion.x, event.motion.y);
engine->onMouseMove(event.motion.x*inputScale, event.motion.y*inputScale);
break;
case SDL_MOUSEBUTTONDOWN:
if(event.button.button == SDL_BUTTON_WHEELUP)
{
engine->onMouseWheel(event.motion.x, event.motion.y, 1);
engine->onMouseWheel(event.motion.x*inputScale, event.motion.y*inputScale, 1);
}
else if (event.button.button == SDL_BUTTON_WHEELDOWN)
{
engine->onMouseWheel(event.motion.x, event.motion.y, -1);
engine->onMouseWheel(event.motion.x*inputScale, event.motion.y*inputScale, -1);
}
else
{
engine->onMouseClick(event.motion.x, event.motion.y, event.button.button);
engine->onMouseClick(event.motion.x*inputScale, event.motion.y*inputScale, event.button.button);
}
break;
case SDL_MOUSEBUTTONUP:
if(event.button.button != SDL_BUTTON_WHEELUP && event.button.button != SDL_BUTTON_WHEELDOWN)
engine->onMouseUnclick(event.motion.x, event.motion.y, event.button.button);
engine->onMouseUnclick(event.motion.x*inputScale, event.motion.y*inputScale, event.button.button);
break;
#ifdef OGLI
case SDL_VIDEORESIZE:
float ratio = float(XRES+BARSIZE) / float(YRES+MENUSIZE);
float width = event.resize.w;
float height = width/ratio;
sdl_scrn = SDL_SetVideoMode(event.resize.w, height, 32, SDL_OPENGL | SDL_RESIZABLE);
glViewport(0, 0, width, height);
engine->g->Reset();
//glScaled(width/currentWidth, height/currentHeight, 1.0f);
currentWidth = width;
currentHeight = height;
inputScale = float(XRES+BARSIZE)/currentWidth;
if(sdl_scrn == NULL)
{
std::cerr << "Oh bugger" << std::endl;
}
break;
#endif
}
event.type = 0; //Clear last event
}

View File

@ -12,13 +12,14 @@
SaveRenderer::SaveRenderer(){
g = new Graphics();
//g = new Graphics();
sim = new Simulation();
ren = new Renderer(g, sim);
}
Thumbnail * SaveRenderer::Render(GameSave * save)
{
return NULL;
int width, height;
Thumbnail * tempThumb;
#ifdef OGLR