0
\$\begingroup\$

I have a simple school task, I need to draw an octahedron and a sphere with light in it. It works, but works weird I use this code 8 times with different coordinates to draw an octahedron

glColor3f(1.0, 0.0, 1.0);
    glVertex3f( 0.25 - position, -0.25 - position, -0.25);
    glVertex3f( 0.25 - position, -0.25 - position,  0.25);
    glVertex3f( 0.0  - position,  0.25 - position,  0.0);
    // position is just an additional thing to move edges

and this to draw a sphere

if (lightEnabled == true) {
        glEnable(GL_LIGHTING);
        glEnable(GL_LIGHT0);
        glEnable(GL_COLOR_MATERIAL);
        glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);

        GLfloat lights[] = {0.3, 0.3, 0.3, 1.0};
        glLightfv(GL_LIGHT0, GL_AMBIENT, lights);
        GLfloat lightsPosition[] = {0.0, 0.0, 0.5, 1.0};
        glLightfv(GL_LIGHT0, GL_POSITION, lightsPosition);
    } else {
        glDisable(GL_LIGHTING);
        glDisable(GL_LIGHT0);
        glDisable(GL_COLOR_MATERIAL);

    }
    glutWireSphere(0.1, 25, 25);

Here's the screen of the problem with edgesAs you can see, purple and yellow edges are bright, and that's not exactly correct

I was told that this is a problem with normal matrix or something, but I can't figure it out.

\$\endgroup\$

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.