Skip to main content
GameDev.net gamedev.net
🔒 Locked

Problem with rendering using GLUT

Started by qhash Dec 1, 2004 at 2:37 PM 1 replies 550+ views
Original Post
qhash
qhash
I am writing a simple side-scroller game , similiar to Bounce for Nokia cell phones. Now the problem is that i cant render two things at the same time - the level and the player object. void render_level() { for(int j=0;j<=32;j++) for (int i=0;i<=10;i++) { if (Level_map[j] == 49) draw_block(i,j,-80,15,2,9); } draw_player(CurrentPosX,CurrentPosY,-16); } void draw_player(float xpos,float ypos ,float zpos) { glPushMatrix(); glTranslatef(CurrentPosX,CurrentPosY,-36); glBegin(GL_QUADS); glVertex3f(-0.5,0.5,0.0); glVertex3f(0.5,0.5,0.0); glVertex3f(0.5,-0.5,0.0); glVertex3f(-0.5,-0.5,0.0); glEnd(); glPopMatrix(); } void render_Scene(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); render_level(); glutSwapBuffers(); } draw block function is the same as draw player but with darkening one of corners for shading effect. When I put draw_player function not inside draw_level function but in function registered for drawing , i get the same result -only those blocks for level are rendered , i cant see the square representing the player.
alnite
alnite
Not really a solution, but make sure you reset the model view matrix after you clear the screen and depth buffer.
void render_Scene(void){   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);   glMatrixMode( GL_MODELVIEW );   glLoadIdentity();   render_level();   glutSwapBuffers();}

Some things are still unclear to me. Why is that in draw_player() function, you take x, y, and z, but used global variables instead? Why is the z when calling draw_player() is -16, but inside draw_player() it's -36?
zedzeek
zedzeek
>>for(int j=0;j<=32;j++)
for (int i=0;i<=10;i++)
{
if (Level_map[j] == 49) draw_block(i,j,-80,15,2,9);
}
draw_player(CurrentPosX,CurrentPosY,-16);
}
<<

this is only gonna draw one block once
and draw the player 32x in the same position!

work through your code with your finger

Topic Locked

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

Sign in to reply to this topic.