Half of an image

Started by
6 comments, last by Lord_Evil 17 years, 1 month ago
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.
Advertisement
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
The best thing about the internet is the way people with no experience or qualifications can pretend to be completely superior to other people who have no experience or qualifications.
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;
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,zglRotatef angle,x,y,zglPushMatrix  \\Draw HeadglPopMatrixglTranslatef x,y,zglPushMatrix  \\Draw HeadglPopMatrixglTranslatef x,y,zglPushMatrix  \\Draw HeadglPopMatrix

How did you set up your projection matrix?
Particularly the znear and zfar params.
Hi.
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.
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
Ohh, okay thanks. Disabling the culling worked. Thanks Lord_Evil
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.
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!

This topic is closed to new replies.

Advertisement