#include "SDL/SDL.h"
#include "SDL/SDL_opengl.h"
#include <iostream>
using namespace std;
const int SCREENWIDTH = 800;
const int SCREENHEIGHT = 600;
void init_GL(int width, int height)
{
glClearColor( 0, 0, 0, 0 );
glViewport(0, 0, width, height);
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho( 0, width, height, 0, -1, 1 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
}
int main( int argc, char* args[] )
{
SDL_Surface* screen = NULL;
bool quit = false;
SDL_Event event;
int screenWidth = SCREENWIDTH;
int screenHeight = SCREENHEIGHT;
SDL_Init( SDL_INIT_EVERYTHING );
screen = SDL_SetVideoMode( screenWidth, screenHeight, 32, SDL_OPENGL | SDL_RESIZABLE | SDL_DOUBLEBUF);
init_GL(screenWidth, screenHeight);
SDL_WM_SetCaption( "Button Test", NULL );
while( quit == false )
{
if( SDL_PollEvent( &event ) )
{
if(event.type == SDL_VIDEORESIZE) // The window is resized
{
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();
}
if( event.type == SDL_QUIT )
{
quit = true;
}
}
glPushMatrix();
glClear(GL_COLOR_BUFFER_BIT);
glTranslatef( 50, 50, 0 );
glBegin(GL_LINE_STRIP);
glColor4f( 1.0, 1.0, 1.0, 1.0 );
glVertex3f( 0, 0, 0 );
glVertex3f( 50, 0, 0 );
glVertex3f( 50, 50, 0 );
glVertex3f( 0, 50, 0 );
glVertex3f( 0, 0, 0 );
glEnd();
glPopMatrix();
SDL_GL_SwapBuffers();
}
SDL_Quit();
return 0;
}