The problem I need to solve is how to implement a zoom feature in my camera for the 2D game I am working on.
Here is my initGL function, which I call only once at startup:
bool initGL()
{
//Set clear color
glClearColor( 0, 0, 0, 0 );
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
//Set projection
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho( 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, -1500, 1500 );
//Initialize modelview matrix
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
//If there was any errors
if( glGetError() != GL_NO_ERROR )
{
return false;
}
//If everything initialized
return true;
}
Before I render, I do a
glTranslatef(-xCam, -yCam, 0 );
where xCam and yCam is the camera position, which lets me draw on screen where I intend to draw even though I move my camera around. So all is well there.
But how do I take this camera and ZOOM in on what's on screen? I've seen a few suggestions around involving glOrtho and glScalef, but I'm not sure how to implement them. Help!