PDA

View Full Version : Polygon edges



c0de
04-19-2007, 02:21 AM
Hello.
I'm quite new to opengl. Probably this is a noobish question for many of you, but I would really like to know how to draw a box or cube (one color, i.e. Red) with visible edges from any viewing angle. In many vewing positions, the edge between two faces cannot be distinguished. I'm currently using a basic way to draw the box, by setting a color and drawing with GL_POLYGON. (using Linux and Qt)
I'm using opengl to simulate a mechanical hand and all 3D objects should be like in real world. With or without shadows, the objects should have the same color and lighting properties in any viewing angle.

Thank you.

c0de
04-19-2007, 02:42 PM
I figured out how to make those edges visible. It's all about lighting. But still, i cant figure how to set the light fixed. I made a simple object (a box) and even when i push matrix, the light still rotates/translates with the object. here is the code

void GLScene::paintGL()
{
glClear (GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef( 0.0, 0.0, -10.0 );
glScalef( scale, scale, scale );
glRotatef( xRot, 1.0, 0.0, 0.0 );
glRotatef( yRot, 0.0, 1.0, 0.0 );
glRotatef( zRot, 0.0, 0.0, 1.0 );
glCallList(object);
glPopMatrix();
glFlush();
}

paintGL - executed everytime I change an angle

next: initialization (lights and stuff)

void GLScene::initializeGL()
{

GLfloat whiteDir[4] = {1.0, 0.0, 0.0, 1.0};
GLfloat whiteAmb[4] = {1.0, 0.0, 0.0, 1.0};
GLfloat lightPos[4] = {2.0, 2.0, 2.0, 0.0};
glEnable(GL_NORMALIZE);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
// glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, whiteAmb);
glMaterialfv(GL_FRONT, GL_DIFFUSE, whiteDir);
glMaterialfv(GL_FRONT, GL_SPECULAR, whiteDir);
glMaterialf(GL_FRONT, GL_SHININESS, 100.0);
glLightfv(GL_LIGHT0, GL_DIFFUSE, whiteDir);
glLightfv(GL_LIGHT0, GL_SPECULAR, whiteDir);

glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
glShadeModel( GL_SMOOTH );
glEnable(GL_DEPTH_TEST);
glClearColor( 0.0, 0.0, 0.0, 0.0 );
object = glGenLists( 1 );
glNewList( object, GL_COMPILE );
drawbox(1.0,1.0,1.0);
glEndList();
}

drawbox function, draws a cube 1x1x1.

What i need is to have the light fixed (like in real world, when illuminating an object that rotates around its own axis, with a fixed light source.)
Anyone has any idea of how can i do this?

Thanks in advance.