PDA

View Full Version : How reshape function should look like for 2D game?



Neomex01
12-14-2010, 05:18 AM
How reshape function should look like for 2D game?


void SystemClass::Reshape( int w, int h ) // ignore system class
{
glViewport ( 0, 0, w, h );
glMatrixMode ( GL_PROJECTION );
glLoadIdentity ( );
PrepareScene();

if ( h==0 ) // Calculate The Aspect Ratio Of The Window
gluOrtho2D ( 0 , float(w) , 0 , float(h) );
else
gluOrtho2D ( 0 , float(w) , 0 , float(h) );

glMatrixMode ( GL_MODELVIEW ); // Select The Model View Matrix
glLoadIdentity ( ); // Reset The Model View Matrix
PrepareScene();
}

PrepareScene


void PrepareScene()
{
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) ;
glLoadIdentity ();
gluOrtho2D ( 0 , 800 , 0 , 600 ) ;
glColor3f ( 1.0 , 1.0 , 1.0 ) ;
}

ZbuffeR
12-14-2010, 05:54 AM
Several questions :
- do you prefer that a bigger window will cover more game surface ? Then the code you posted is perfect.
- do you want to constrain the visible in-game width ? try this :
gluOrtho2D ( 0 , ingameWidth , 0 , float(h)/float(w)*ingameWidth );
- do you want to constrain the visible in-game height ? try this :
gluOrtho2D ( 0 , float(w)/float(h)*ingameHeight , 0 , ingameHeight);
- somethig else ? Please explain.

Neomex01
12-14-2010, 06:04 AM
Thanks for reply!
When I compile mine code, I can see only black screen instead of quad plane.
What I want to do, is scaling game surface, which always will be 800x600 no matter of window size.

Neomex01
12-14-2010, 12:47 PM
Anyone?