Skip to main content
gamedev.net
🔒 Locked 🎲 GameMaker

Using two projections

Started by Solano Apr 6, 2011 at 2:11 PM 0 replies 800+ views
Original Post
Solano
Solano
When i init opengl i use the following code:


glViewport(0, 0, 640, 480);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, (float)640/(float)480, 1, 1000);//set default values for projection


In the rendering function i have

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//update camera vectors
if keyboard_check(vk_left){
dir -= 1
lx = sin(degtorad(dir))
lz = -cos(degtorad(dir));
}
if keyboard_check(vk_right){
dir += 1
lx = sin(degtorad(dir))
lz = -cos(degtorad(dir));
}

glMatrixMode(GL_PROJECTION);// Select Projection
glPushMatrix();// Push The Matrix
glLoadIdentity();// Reset The Matrix
gluOrtho2D(0, 640, 480, 0);// Select Ortho Mode
glMatrixMode(GL_MODELVIEW);// Select Modelview Matrix
glPushMatrix();// Push The Matrix
glLoadIdentity();// Reset The Matrix

glColor3f(1.0,0.0,0.0);
glBegin(GL_QUADS);
glVertex2f(125, 125);
glVertex2f(125, 375);
glVertex2f(375, 375);
glVertex2f(375, 125);
glEnd();

glMatrixMode( GL_PROJECTION );// Select Projection
glPopMatrix();// Pop The Matrix
glMatrixMode( GL_MODELVIEW );// Select Modelview
glPopMatrix();// Pop The Matrix
glLoadIdentity();

gluLookAt(0,0, 10, lx, 10, ly, 0, 1, 0);
SwapBuffers(ehDC);


[s]But as soon as I press one of the the left or right key the red rectangle that im drawing disappears. Does anybody have any idea why that happens. [/s]

Nevermind fixed it.Edited code. Now the above is the working code. If some1 finds this thread through google i hope he can manage to use it.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.