I am a little unsure as to what exactly is going on with this, but basically I have the following code:
#include "SDL/SDL.h"
#include "Button.h"
#include "SDL/SDL_opengl.h"
#include <iostream>
using namespace std;
const int SCREENWIDTH = 800;
const int SCREENHEIGHT = 600;
void buttonAction()
{
cout<<"Button Pressed"<<endl;
}
void init_GL(int width, int height)
{
glClearColor( 0, 0, 0, 0 );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho( 0, width, height, 0, -1, 1 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
}
int main( int argc, char* args[] )
{
//The images
SDL_Surface* hello = NULL;
SDL_Surface* screen = NULL;
bool quit = false;
SDL_Event event;
int screenWidth = SCREENWIDTH;
int screenHeight = SCREENHEIGHT;
//Start SDL
SDL_Init( SDL_INIT_EVERYTHING );
//Set up screen
screen = SDL_SetVideoMode( screenWidth, screenHeight, 32, SDL_OPENGL | SDL_RESIZABLE );
//Start OpenGL
init_GL(screenWidth, screenHeight);
SDL_WM_SetCaption( "Button Test", NULL );
Button button(30, 30, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", *&buttonAction);
//While the user hasn't quit
while( quit == false )
{
//If there's events to handle
if( SDL_PollEvent( &event ) )
{
if(event.type == SDL_VIDEORESIZE)
{
screenWidth = event.resize.w;
screenHeight = event.resize.h;
glViewport(0, 0, screenWidth, screenHeight);
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho( 0, screenWidth, screenHeight, 0, -1, 1 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
}
//Handle button events
button.handleEvents(event);
//If the user has Xed out the window
if( event.type == SDL_QUIT )
{
//Quit the program
quit = true;
}
}
glPushMatrix();
//Fill the screen black
glBegin( GL_QUADS );
glColor4f( 0.0, 0.0, 0.0, 1.0 );
glVertex3f( 0, 0, 0 );
glVertex3f( screenWidth, 0, 0 );
glVertex3f( screenWidth, screenHeight, 0 );
glVertex3f( 0, screenHeight, 0 );
glEnd();
//Show the button
button.draw();
glPopMatrix();
//Update the screen
SDL_GL_SwapBuffers();
}
//Quit SDL
SDL_Quit();
return 0;
}
and when i first draw everything seems to be working fine, and looks like this:
[ATTACH=CONFIG]219[/ATTACH]
but when i resize i see the following:
[ATTACH=CONFIG]220[/ATTACH]
any idea as to what is causing my problem?
Thank you for your time!
Brandon Murphy