What's Here?
Members: 149,513
Replies: 506,619
Topics: 79,833
Snippets: 2,666
Tutorials: 706
Total Online: 1,353
Members: 68
Guests: 1,285
Loading. Please Wait...
Why am I getting alpha faces?
Why am I getting alpha faces?
RicardoDiaz
12 Aug, 2007 - 09:30 PM
New D.I.C Head
Joined: 12 Aug, 2007
Posts: 10
My Contributions
Hi, I followed a tutorial and modified it a bit to display a rotating 3D triangle. The first face comes perfect, but the other three appear to have some transparency. Why is this? Here's the code (only the part that draws the pyramid):
CODE
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glLoadIdentity(); glTranslatef(0.0, 0.0, -6.0); glRotatef(rtri, 0.0, 1.0, 0.0); glBegin(GL_TRIANGLES); glColor3f(1.0, 0.0, 0.0); glVertex3f(0.0, 1.0, 0.0); glColor3f(0.0, 1.0, 0.0); glVertex3f(-1.0, -1.0, 1.0); glColor3f(0.0, 0.0, 1.0); glVertex3f(1.0, -1.0, 1.0); /*------------------------*/ glColor3f(1.0, 0.0, 0.0); glVertex3f(0.0, 1.0, 0.0); glColor3f(0.0, 0.0, 1.0); glVertex3f( 1.0, -1.0, 1.0); glColor3f(0.0, 1.0, 0.0); glVertex3f(1.0, -1.0, -1.0); /*------------------------*/ glColor3f(1.0, 0.0, 0.0); glVertex3f(0.0, 1.0, 0.0); glColor3f(0.0, 1.0, 0.0); glVertex3f( 1.0, -1.0, -1.0); glColor3f(0.0, 0.0, 1.0); glVertex3f(-1.0, -1.0, -1.0); /*------------------------*/ glColor3f(1.0, 0.0, 0.0); glVertex3f(0.0, 1.0, 0.0); glColor3f(0.0, 0.0, 1.0); glVertex3f( -1.0, -1.0, -1.0); glColor3f(0.0, 1.0, 0.0); glVertex3f(-1.0, -1.0, 1.0); glEnd(); glutSwapBuffers();
RicardoDiaz
RE: Why Am I Getting Alpha Faces? 13 Aug, 2007 - 07:45 AM
New D.I.C Head
Joined: 12 Aug, 2007
Posts: 10
My Contributions
Here's the entire code:
CODE
#include <GLUT/glut.h> #define windowWidth 550 #define windowHeight 400 GLvoid initGL(GLvoid); GLvoid display(GLvoid); GLvoid reshape(int width, int height); GLvoid idle(GLvoid); GLfloat rtri; int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(windowWidth, windowHeight); glutInitWindowPosition (0, 44); glutCreateWindow ("GLUT Display"); initGL(); glutDisplayFunc(display); glutReshapeFunc(reshape); glutIdleFunc(idle); glutMainLoop(); rtri = 0; return 0; } GLvoid initGL(GLvoid) { glClearColor(1.0, 1.0, 1.0, 0.0); glClearDepth(1.0); glDepthFunc(GL_LESS); glEnable(GL_DEPTH | GL_DOUBLE | GLUT_RGB); glShadeModel(GL_SMOOTH); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0, (GLfloat)windowWidth/(GLfloat)windowHeight, 0.1, 100.0); glMatrixMode(GL_MODELVIEW); } GLvoid idle(GLvoid) { rtri += 0.1; glutPostRedisplay(); } GLvoid display(GLvoid) { glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glLoadIdentity(); glTranslatef(0.0, 0.0, -6.0); glRotatef(rtri, 0.0, 1.0, 0.0); glBegin(GL_TRIANGLES); glColor3f(1.0, 0.0, 0.0); glVertex3f(0.0, 1.0, 0.0); glColor3f(0.0, 1.0, 0.0); glVertex3f(-1.0, -1.0, 1.0); glColor3f(0.0, 0.0, 1.0); glVertex3f(1.0, -1.0, 1.0); /*------------------------*/ glColor3f(1.0, 0.0, 0.0); glVertex3f(0.0, 1.0, 0.0); glColor3f(0.0, 0.0, 1.0); glVertex3f( 1.0, -1.0, 1.0); glColor3f(0.0, 1.0, 0.0); glVertex3f(1.0, -1.0, -1.0); /*------------------------*/ glColor3f(1.0, 0.0, 0.0); glVertex3f(0.0, 1.0, 0.0); glColor3f(0.0, 1.0, 0.0); glVertex3f( 1.0, -1.0, -1.0); glColor3f(0.0, 0.0, 1.0); glVertex3f(-1.0, -1.0, -1.0); /*------------------------*/ glColor3f(1.0, 0.0, 0.0); glVertex3f(0.0, 1.0, 0.0); glColor3f(0.0, 0.0, 1.0); glVertex3f( -1.0, -1.0, -1.0); glColor3f(0.0, 1.0, 0.0); glVertex3f(-1.0, -1.0, 1.0); glEnd(); glutSwapBuffers(); } GLvoid reshape(int width, int height) { glViewport (0, 0, width, height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0, (GLfloat)width/(GLfloat)height, 0.1, 100.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); }
Be Social
Programming
Web Development
Reference Sheets
Bye Bye Ads
Monthly Drawing
Top Contributors
Top 10 Kudos This Month