PDA

View Full Version : transparent teapots w/lights



simmosn
12-16-2002, 11:14 AM
i am trying to make 2 partly transparent tepots with a light source. i can't see what is wrong with the code below:




#include <GL/glut.h>
#include <stdio.h>
void init(void)
{
glShadeModel (GL_SMOOTH);
GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat mat_shininess[] = { 50.0 };
GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };
// glClearColor (0.0, 0.0, 0.0, 0.0);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
}

void display(void)
{

glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable (GL_DEPTH_TEST);

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glColor4f(0.5, 0.5, 0.5, 0.5);
glutSolidTeapot (1.5);
glColor4f(0.5, 0.5, 0.5, 0.5);
glutSolidTeapot (1.0);
glFlush ();
}

void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
glOrtho (-1.5*(GLfloat)w/(GLfloat)h, 1.5*(GLfloat)w/(GLfloat)h, -1.5, 1.5, -10.0, 10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

int main(int argc, char** argv)
{
glutInit(&amp;argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize (800, 600);
glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]);
init ();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}

147-2
12-16-2002, 11:25 AM
Well, I see you setting your callbacks a little late. Im not at home, so my refrence materials are not very useful to me http://www.opengl.org/discussion_boards/ubb/smile.gif but methinks that you otta call your glutDisplayFunc(display) and glutReshapeFunc(reshape) right after glutInit. Who knows, mebbe you should call it before glutInit. Plz check the documentation on this, but I think that the glutInitWindowPosition() needs your glutDisplayFunc() and glutReshapeFunc() to already be set.

Bob
12-16-2002, 11:47 AM
His callbacks are fine. Callbacks in GLUT are set per window (not all, but display and reshape are), and therefore a window must be created before setting callbacks.

To the problem. You're using lighting, and the primary color is calculated from lights and materials instead of taken from glColor. In short, your calls to glColor4f isn't doing anything.

simmosn
12-16-2002, 12:14 PM
thanks. any ideas how to solve?

yakuza
12-16-2002, 12:35 PM
You can either specify material properties glMaterial*() , or:




glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
glEnable(GL_COLOR_MATERIAL);