-1

I'm trying to figure out how to write my own primitives like gluSolidCube()..

In the following code I'm drawing 2 quads. One with the help of this method (the red one) and another one - by my own with the help of glBegin()/glEnd() (the blue one).

glPushMatrix();
    glRotatef(-angleX, 0, 0, 1);
    glRotatef(angleY, 0, 1, 0);

    glColor3f(1, 0, 0);
    glTranslatef(0.6, 0, 0);
    glutSolidCube(1);

    glColor3f(0, 0, 1);
    glTranslatef(-1.2, 0, 0);
    glPolygonMode(GL_FRONT, GL_FILL);
    glShadeModel(GL_SMOOTH);
    glBegin(GL_QUADS);
        glVertex3f(0.5, 0.5, 0.5);
        glVertex3f(0.5, 0.5, -0.5);
        glVertex3f(-0.5, 0.5, -0.5);
        glVertex3f(-0.5, 0.5, 0.5);

        glVertex3f(0.5, 0.5, 0.5);
        glVertex3f(0.5, 0.5, -0.5);
        glVertex3f(0.5, -0.5, -0.5);
        glVertex3f(0.5, -0.5, 0.5);

        glVertex3f(-0.5, 0.5, -0.5);
        glVertex3f(-0.5, 0.5, 0.5);
        glVertex3f(-0.5, -0.5, 0.5);
        glVertex3f(-0.5, -0.5, -0.5);

        glVertex3f(0.5, 0.5, -0.5);
        glVertex3f(-0.5, 0.5, -0.5);
        glVertex3f(-0.5, -0.5, -0.5);
        glVertex3f(0.5, -0.5, -0.5);

        glVertex3f(0.5, 0.5, 0.5);
        glVertex3f(-0.5, 0.5, 0.5);
        glVertex3f(-0.5, -0.5, 0.5);
        glVertex3f(0.5, -0.5, 0.5);

        glVertex3f(0.5, -0.5, 0.5);
        glVertex3f(0.5, -0.5, -0.5);
        glVertex3f(-0.5, -0.5, -0.5);
        glVertex3f(-0.5, -0.5, 0.5);
    glEnd();
glPopMatrix();

So as you can see at the following screenshots the lightnings on the red quad is correct unlike the blue one. How to solve this?

screen 1

screen 2

genpfault
  • 51,148
  • 11
  • 85
  • 139
GV_FiQst
  • 1,487
  • 14
  • 30
  • 2
    For the minimum code that you have provided, you need normals: http://gamedev.stackexchange.com/questions/50653/opengl-why-do-i-have-to-set-a-normal-with-glnormal/50656 – Amadeus Sep 12 '16 at 16:31
  • @Amadeus this link didn't provide me with a solution. I tried to add before every glVertex() a glNormal(0, 0, 1) and it didn't help... – GV_FiQst Sep 12 '16 at 17:06

1 Answers1

1

OpenGL fixed-function lighting won't work correctly without sensible vertex/face normals.

You need to supply some, perhaps via glNormal().

Community
  • 1
  • 1
genpfault
  • 51,148
  • 11
  • 85
  • 139
  • Ok as I understood I need to do more maths. For every plane I need to get a normal vector? Is there some equation for this? Gone googling... – GV_FiQst Sep 12 '16 at 17:02