Sign in to follow this  
qhash

Problem with rendering using GLUT

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][i] == 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 this post


Link to post
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 this post


Link to post
Share on other sites
>>for(int j=0;j<=32;j++)
for (int i=0;i<=10;i++)
{
if (Level_map[j][i] == 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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this