Sign in to follow this  
renuser

Half of an image

Recommended Posts

I created a 2D martian character and decided to revolve him because it seemed fun at the time. I created him in 3 separate parts: head, torso, legs. I then lined him up correctly and used the glRotatef(angle1,0.0f,1.0f,0.0f); command to have all the portions rotate on the y axis. When I ran the program however, all of the body parts revolved together at the same speed, but only half of the head is there. The left side is present, but as he turns it flips over and shows the right, and as it continues to rotate its back on the left again. I wondered if I had accidentally deleted a portion of my code, but when I remove the Rotate, the whole head is there. Any suggestions are appreciated.

Share this post


Link to post
Share on other sites
Sounds like a backface culling problem, but it seems a bit odd that the whole thing appears when you remove the Rotate call.

How did you create this model? Are you using immediate mode calls (glBegin, glEnd, glColor and glVertex)? If so, could you post the code please?

John B

Share this post


Link to post
Share on other sites
Yes, they are. It is primitive, but this is the code:


glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,7.0f,-100.0f);

glRotatef(rquad,0.0f,1.0f,0.0f);

glBegin(GL_QUADS);
glColor3f(0.9f,0.4f,0.4f);
glVertex3f(-2.0f,5.0f,0.0f);
glVertex3f(2.0f,5.0f,0.0f);
glVertex3f(2.0f,-3.0f,0.0f);
glVertex3f(-2.0f,-3.0f,0.0f);
/////
glVertex3f(-6.0f,5.0f,0.0f);
glVertex3f(6.0f,5.0f,0.0f);
glVertex3f(6.0f,2.0f,0.0f);
glVertex3f(-6.0f,2.0f,0.0f);
/////
glVertex3f(-4.0f,6.0f,0.0f);
glVertex3f(4.0f,6.0f,0.0f);
glVertex3f(4.0f,5.0f,0.0f);
glVertex3f(-4.0f,5.0f,0.0f);
/////
glVertex3f(4.0f,2.0f,0.0f);
glVertex3f(6.0f,2.0f,0.0f);
glVertex3f(6.0f,0.0f,0.0f);
glVertex3f(4.0f,0.0f,0.0f);
/////
glVertex3f(-4.0f,2.0f,0.0f);
glVertex3f(-6.0f,2.0f,0.0f);
glVertex3f(-6.0f,0.0f,0.0f);
glVertex3f(-4.0f,0.0f,0.0f);
/////
glVertex3f(-6.0f,0.0f,0.0f);
glVertex3f(6.0f,0.0f,0.0f);
glVertex3f(6.0f,-3.0f,0.0f);
glVertex3f(-6.0f,-3.0f,0.0f);
/////
glVertex3f(-4.0f,-3.0f,0.0f);
glVertex3f(-2.0f,-3.0f,0.0f);
glVertex3f(-2.0f,-5.0f,0.0f);
glVertex3f(-4.0f,-5.0f,0.0f);
/////
glVertex3f(4.0f,-3.0f,0.0f);
glVertex3f(2.0f,-3.0f,0.0f);
glVertex3f(2.0f,-5.0f,0.0f);
glVertex3f(4.0f,-5.0f,0.0f);
//////
glVertex3f(-2.0f,-4.0f,0.0f);
glVertex3f(2.0f,-4.0f,0.0f);
glColor3f(0.7f,0.4f,0.4f);
glVertex3f(2.0f,-7.0f,0.0f);
glVertex3f(-2.0f,-7.0f,0.0f);
/////
glColor3f(0.9f,0.4f,0.4f);
glVertex3f(-7.0f,2.5f,0.0f);
glVertex3f(-6.0f,2.5f,0.0f);
glVertex3f(-6.0f,-0.5f,0.0f);
glVertex3f(-7.0f,-0.5f,0.0f);
//////
glVertex3f(7.0f,2.5f,0.0f);
glVertex3f(6.0f,2.5f,0.0f);
glVertex3f(6.0f,-0.5f,0.0f);
glVertex3f(7.0f,-0.5f,0.0f);
glEnd();
glLoadIdentity();
glTranslatef(0.0f,-1.0f,-75.0f);
glRotatef(rquad,0.0f,1.0f,0.0f);
glBegin(GL_QUADS);
glColor3f(0.0f,0.0f,0.4f);
glVertex3f(-4.0f,1.0f,0.0f);
glVertex3f(4.0f,1.0f,0.0f);
glColor3f(0.0f,0.0f,0.6f);
glVertex3f(4.0f,-2.0f,0.0f);
glVertex3f(-4.0f,-2.0f,0.0f);
//////
glVertex3f(-3.0f,-2.0f,0.0f);
glVertex3f(3.0f,-2.0f,0.0f);
glVertex3f(3.0f,-5.0f,0.0f);
glVertex3f(-3.0f,-5.0f,0.0f);
//////
glVertex3f(-2.0f,-5.0f,0.0f);
glVertex3f(2.0f,-5.0f,0.0f);
glVertex3f(2.0f,-6.0f,0.0f);
glVertex3f(-2.0f,-6.0f,0.0f);
//////
glVertex3f(-5.0f,2.0f,0.0f);
glColor3f(0.0f,0.0f,0.4f);
glVertex3f(-3.0f,2.0f,0.0f);
glVertex3f(-3.0f,0.0f,0.0f);
glColor3f(0.0f,0.0f,0.6f);
glVertex3f(-5.0f,0.0f,0.0f);
//////
glVertex3f(5.0f,2.0f,0.0f);
glVertex3f(3.0f,2.0f,0.0f);
glColor3f(0.0f,0.0f,0.4f);
glVertex3f(3.0f,0.0f,0.0f);
glVertex3f(5.0f,0.0f,0.0f);
glColor3f(0.0f,0.0f,0.6f);
//////
glVertex3f(-6.0f,1.0f,0.0f);
glVertex3f(-4.0f,1.0f,0.0f);
glVertex3f(-4.0f,-1.0f,0.0f);
glVertex3f(-6.0f,-1.0f,0.0f);
//////
glVertex3f(6.0f,1.0f,0.0f);
glVertex3f(4.0f,1.0f,0.0f);
glVertex3f(4.0f,-1.0f,0.0f);
glVertex3f(6.0f,-1.0f,0.0f);
//////
glVertex3f(-7.0f,0.0f,0.0f);
glVertex3f(-5.0f,0.0f,0.0f);
glVertex3f(-5.0f,-2.0f,0.0f);
glVertex3f(-7.0f,-2.0f,0.0f);
//////
glVertex3f(7.0f,0.0f,0.0f);
glVertex3f(5.0f,0.0f,0.0f);
glVertex3f(5.0f,-2.0f,0.0f);
glVertex3f(7.0f,-2.0f,0.0f);
//////
glVertex3f(-8.0f,-1.0f,0.0f);
glVertex3f(-6.0f,-1.0f,0.0f);
glVertex3f(-6.0f,-7.0f,0.0f);
glVertex3f(-8.0f,-7.0f,0.0f);
//////
glVertex3f(8.0f,-1.0f,0.0f);
glVertex3f(6.0f,-1.0f,0.0f);
glVertex3f(6.0f,-7.0f,0.0f);
glVertex3f(8.0f,-7.0f,0.0f);
//////
glColor3f(0.9f,0.4f,0.4f);
glVertex3f(-8.0f,-8.0f,0.0f);
glColor3f(0.7f,0.4f,0.4f);
glVertex3f(-7.0f,-7.0f,0.0f);
glColor3f(0.9f,0.4f,0.4f);
glVertex3f(-6.0f,-8.0f,0.0f);
glVertex3f(-7.0f,-9.0f,0.0f);
//////

glVertex3f(8.0f,-8.0f,0.0f);
glColor3f(0.7f,0.4f,0.4f);
glVertex3f(7.0f,-7.0f,0.0f);
glColor3f(0.9f,0.4f,0.4f);
glVertex3f(6.0f,-8.0f,0.0f);
glVertex3f(7.0f,-9.0f,0.0f);
glEnd();
glBegin(GL_TRIANGLES);
glColor3f(0.7f,0.4f,0.4f);
glVertex3f(-8.0f,-7.0f,0.0f);
glVertex3f(-7.0f,-7.0f,0.0f);
glColor3f(0.9f,0.4f,0.4f);
glVertex3f(-8.0f,-8.0f,0.0f);
//////
glColor3f(0.7f,0.4f,0.4f);
glVertex3f(8.0f,-7.0f,0.0f);
glVertex3f(7.0f,-7.0f,0.0f);
glColor3f(0.9f,0.4f,0.4f);
glVertex3f(8.0f,-8.0f,0.0f);
glEnd();

glLoadIdentity();
glTranslatef(0.0f,-12.0f,-75.0f);
glRotatef(rquad,0.0f,1.0f,0.0f);
glBegin(GL_QUADS);
//////
glColor3f(0.0f,0.4f,0.0f);
glVertex3f(-4.0f,5.0f,0.0f);
glVertex3f(4.0f,5.0f,0.0f);
glColor3f(0.5f,0.0f,0.0f);
glVertex3f(4.0f,4.0f,0.0f);
glVertex3f(-4.0f,4.0f,0.0f);
//////
glColor3f(0.0f,0.0f,0.6f);
glVertex3f(-4.0f,4.0f,0.0f);
glVertex3f(4.0f,4.0f,0.0f);
glVertex3f(4.0f,0.0f,0.0f);
glVertex3f(-4.0f,0.0f,0.0f);
//////
glVertex3f(-5.0f,3.0f,0.0f);
glVertex3f(-1.0f,3.0f,0.0f);
glVertex3f(-1.0f,-3.0f,0.0f);
glVertex3f(-5.0f,0.-3.0f,0.0f);
//////
glVertex3f(5.0f,3.0f,0.0f);
glVertex3f(1.0f,3.0f,0.0f);
glVertex3f(1.0f,-3.0f,0.0f);
glVertex3f(5.0f,-3.0f,0.0f);
//////
glVertex3f(-4.0f,-3.0f,0.0f);
glVertex3f(-2.0f,-3.0f,0.0f);
glVertex3f(-2.0f,-5.0f,0.0f);
glVertex3f(-4.0f,-5.0f,0.0f);
//////
glVertex3f(4.0f,-3.0f,0.0f);
glVertex3f(2.0f,-3.0f,0.0f);
glVertex3f(2.0f,-5.0f,0.0f);
glVertex3f(4.0f,-5.0f,0.0f);
//////
glVertex3f(-4.5f,-5.0f,0.0f);
glVertex3f(-1.5f,-5.0f,0.0f);
glVertex3f(-1.5f,-9.0f,0.0f);
glVertex3f(-4.5f,-9.0f,0.0f);
//////
glVertex3f(4.5f,-5.0f,0.0f);
glVertex3f(1.5f,-5.0f,0.0f);
glVertex3f(1.5f,-9.0f,0.0f);
glVertex3f(4.5f,-9.0f,0.0f);
//////
glVertex3f(-5.0f,-9.0f,0.0f);
glVertex3f(-1.0f,-9.0f,0.0f);
glVertex3f(-1.0f,-10.0f,0.0f);
glVertex3f(-5.0f,-10.0f,0.0f);
//////
glVertex3f(5.0f,-9.0f,0.0f);
glVertex3f(1.0f,-9.0f,0.0f);
glVertex3f(1.0f,-10.0f,0.0f);
glVertex3f(5.0f,-10.0f,0.0f);
glEnd();
rquad+=0.25f;

Share this post


Link to post
Share on other sites
If you have Culling enabled, then you will need to provide normals for each vertex, or face using the glNormal3f function. Also, try using glPushMatrix and glPopMatrix rather than using glLoadIdenity. Here's an example


glTranslatef x,y,z
glRotatef angle,x,y,z

glPushMatrix
\\Draw Head
glPopMatrix

glTranslatef x,y,z

glPushMatrix
\\Draw Head
glPopMatrix

glTranslatef x,y,z

glPushMatrix
\\Draw Head
glPopMatrix


Share this post


Link to post
Share on other sites
No you don't need normals for culling. Culling depends on the order in which you define your vertices. However, visualizing the normals could help you to see if a polygon is facing the correct direction. Just pay attention to calculating to normals from the positions in the same way for all polygons.

Try glDisable(GL_CULL_FACE) to disable culling. If you now see all your polygons you have a backface culling problem.

Share this post


Link to post
Share on other sites
You will, however, want to reenable backface culling for performance and visual quality.

I tried your code with my engine and found that the left (or right) part's winding is different to the rest. Fix that and you can reenable backface culling.

Just another hint:
For debugging I use the following setup:

glDisable(GL_CULL_FACE);
glPolygonMode(GL_FRONT,GL_FILL);
glPolygonMode(GL_BACK,GL_LINE);

This way all primitives are drawn but those that would be culled away (backfacing polygons) are drawn in wireframe mode so I can check whether there is actually a backface culling problem. In Release mode just enable backface culling and you're fine.

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