Welcome to Dream.In.Code
Become an Expert!

Join 149,513 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,353 people online right now. Registration is fast and FREE... Join Now!




Why am I getting alpha faces?

 
Reply to this topicStart new topic

Why am I getting alpha faces?

RicardoDiaz
12 Aug, 2007 - 09:30 PM
Post #1

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();

User is offlineProfile CardPM
+Quote Post

RicardoDiaz
RE: Why Am I Getting Alpha Faces?
13 Aug, 2007 - 04:15 AM
Post #2

New D.I.C Head
*

Joined: 12 Aug, 2007
Posts: 10


My Contributions
Oh, is it because of the depths? How can I fix this?

User is offlineProfile CardPM
+Quote Post

1lacca
RE: Why Am I Getting Alpha Faces?
13 Aug, 2007 - 05:33 AM
Post #3

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 12 times
My Contributions
Could you post the OGL initialization codes as well (just to see if blending is enabled, and things like that)?
User is offlineProfile CardPM
+Quote Post

RicardoDiaz
RE: Why Am I Getting Alpha Faces?
13 Aug, 2007 - 07:45 AM
Post #4

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();
}

User is offlineProfile CardPM
+Quote Post

Nova Dragoon
RE: Why Am I Getting Alpha Faces?
13 Aug, 2007 - 08:05 AM
Post #5

The Innocent Shall Suffer, Big Time
Group Icon

Joined: 16 Aug, 2001
Posts: 6,145



Thanked: 8 times
Dream Kudos: 515
Expert In: Python, Linux

My Contributions
I think you are drawing that transparent triangle in the wrong order, I think the correct way is drawing them clock wise, the visible face then points towards you.
User is offlineProfile CardPM
+Quote Post

RicardoDiaz
RE: Why Am I Getting Alpha Faces?
13 Aug, 2007 - 08:23 AM
Post #6

New D.I.C Head
*

Joined: 12 Aug, 2007
Posts: 10


My Contributions
Well, every face was drawn clockwise, I don't know if hthat's what you mean. But the triangle rotates, how can I change which face points twards me?

User is offlineProfile CardPM
+Quote Post

serializer
RE: Why Am I Getting Alpha Faces?
15 Aug, 2007 - 08:17 PM
Post #7

D.I.C Head
**

Joined: 25 Jun, 2007
Posts: 108


My Contributions
QUOTE(RicardoDiaz @ 13 Aug, 2007 - 09:23 AM) *

Well, every face was drawn clockwise, I don't know if hthat's what you mean. But the triangle rotates, how can I change which face points twards me?


Draw it twice; once clockwise, once anticlockwise; that way, you will always be able to see one of the faces...

--serializer
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 07:50PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month