I enabled lighting and now everything is grey?
Almost everything. The only thing that is not grey is a sphere created with glutSolidSphere(). Everything else is grey. How may I fix this?
thanks in advance!
/* This is grey */ glLoadIdentity(); glTranslatef(x-0.5, y-0.4, -1); glColor3f(0, 1, 0); glBegin(GL_QUADS); glVertex2f(0, 0); glVertex2f(w, 0); glVertex2f(w, h); glVertex2f(0, h); glEnd();/*This is from the the init for OpenGL */ float lighting[] = {0.2, 0.2, 0.2, 1}; float lightdirection[] = {0, 0, 2, 1}; float lightstr[] = {0.7, 0.7, 0.7, 1}; glClearColor(0, 0, 0, 0); glClearDepth(1.0); glDepthFunc(GL_LESS); glEnable(GL_DEPTH_TEST); glShadeModel(GL_SMOOTH); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f, x/y, 0.1, 100.0f); glMatrixMode(GL_MODELVIEW); glEnable(GL_LIGHTING); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lighting); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_POSITION, lightdirection); glLightfv(GL_LIGHT0, GL_DIFFUSE, lightstr); glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT, GL_DIFFUSE);
If I remove lighting its ok except everything looks like there is no Z axis.
When lighting is enables OpenGl uses the material properties set with
glMaterial(...) calls rather than the color set through glColor calls
That said its often easiest to call
glEnable(GL_COLOR_MATERIAL);
which will often do exactly what you want - though there are some potential
problems
glMaterial(...) calls rather than the color set through glColor calls
That said its often easiest to call
glEnable(GL_COLOR_MATERIAL);
which will often do exactly what you want - though there are some potential
problems
I looked at NeHe's Lesson 7 It goes over lighting and such. I got the GLUT version and compared some stuff. When I plugged in your code, I got different results as expected, but nothing unexpected really.
This is what they did:
So it's not grey because of a mistake, it's just at the position of your object, it is not being lighted. I would have to see a screen shot to see what you are talking about exactly, so for now, take a look at that Lesson 7 and see if you can find anything different if this is not what you are expecting. Pay close attention to the order of functions as well, for they matter in OpenGL! Good luck!
This is what they did:
GLfloat LightAmbient[]= { 0.5f, 0.5f, 0.5f, 1.0f };GLfloat LightDiffuse[]= { 1.0f, 1.0f, 1.0f, 1.0f };GLfloat LightPosition[]= { 0.0f, 0.0f, 2.0f, 1.0f };glShadeModel(GL_SMOOTH); // Enable Smooth Shading glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background glEnable ( GL_COLOR_MATERIAL ); glColorMaterial ( GL_FRONT, GL_AMBIENT_AND_DIFFUSE ); glEnable ( GL_CULL_FACE ); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient); // Setup The Ambient Light glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse); // Setup The Diffuse Light glLightfv(GL_LIGHT1, GL_POSITION,LightPosition); // Position The Light glEnable(GL_LIGHT1); // Enable Light One*
So it's not grey because of a mistake, it's just at the position of your object, it is not being lighted. I would have to see a screen shot to see what you are talking about exactly, so for now, take a look at that Lesson 7 and see if you can find anything different if this is not what you are expecting. Pay close attention to the order of functions as well, for they matter in OpenGL! Good luck!
I found my mistake. I was reading NeHe's tutorials, and I didn't put in glNormal3f() anywhere. I read about it and it all makes sense now.
Quote:Original post by Four
I found my mistake. I was reading NeHe's tutorials, and I didn't put in glNormal3f() anywhere. I read about it and it all makes sense now.
Glad you found it! NeHe's tutorials are pretty good IMO.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement