Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL Lightning

Tags:

c++

opengl

After enabling lighting in OpenGL, color in lines and polygons are no longer rendering. (Created color from glColor3f() )

This is code:

        glLightModelf(GL_LIGHT_MODEL_AMBIENT, GL_TRUE);
        GLfloat light1_position[] = { 5000, 2000, 1000,1 };
        glEnable(GL_LIGHT0);
        glLightfv(GL_LIGHT0, GL_POSITION, light1_position);
        GLfloat light_ambient[] = { 1,1,1,1 };
        glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
        glEnable(GL_LIGHTING);

What am I doing wrong?

like image 314
Леонтий Хачуев Avatar asked Feb 17 '26 02:02

Леонтий Хачуев


1 Answers

You must enable these things before using them :

glEnable ( GL_LIGHTING);
glEnable( GL_COLOR_MATERIAL); 
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
glShadeModel( GL_SMOOTH);
like image 140
Reznicencu Bogdan Avatar answered Feb 21 '26 14:02

Reznicencu Bogdan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!