Results 1 to 5 of 5

Thread: transparent teapots w/lights

  1. #1

    transparent teapots w/lights

    i am trying to make 2 partly transparent tepots with a light source. i can't see what is wrong with the code below:

    Code :
    #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;
    }

  2. #2
    Senior Member Regular Contributor
    Join Date
    Oct 2002
    Location
    San Diego, CA, USA
    Posts
    209

    Re: transparent teapots w/lights

    Well, I see you setting your callbacks a little late. Im not at home, so my refrence materials are not very useful to me 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.

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: transparent teapots w/lights

    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.

  4. #4

    Re: transparent teapots w/lights

    thanks. any ideas how to solve?

  5. #5
    Senior Member Regular Contributor
    Join Date
    Apr 2001
    Location
    Fort Collins, Colorado
    Posts
    446

    Re: transparent teapots w/lights

    You can either specify material properties glMaterial*() , or:

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

Similar Threads

  1. Speed of built in lights v.s. custom lights
    By STTrife in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 01-23-2013, 05:11 PM
  2. Two teapots!
    By GracefulEase in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 04-21-2009, 03:31 PM
  3. Bad lights - Why?
    By in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 05-01-2001, 11:57 AM
  4. Replies: 13
    Last Post: 11-29-2000, 02:19 PM
  5. overlaying transparent and non transparent bitmaps
    By dodgyposse in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-13-2000, 01:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean