# Problem with rendering using GLUT

This topic is 4952 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.

##### Share on other sites
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?

##### Share on other sites
>>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!

1. 1
2. 2
3. 3
4. 4
Rutin
17
5. 5

• 12
• 9
• 12
• 37
• 12
• ### Forum Statistics

• Total Topics
631419
• Total Posts
2999984
×