0

When working with glut, i used glutsolidsphere to draw my spheres, but having moved to glfw, i had to use glusphere. I basically copied the entire function "glutsolidsphere" to my own code, but am getting a strange lighting problem where before i wasn't. Heres the code for the sphere :

Sphere

void drawSolidSphere(GLdouble radius, GLint slices, GLint stacks)
{
    GLUquadric *shape = gluNewQuadric();
    gluQuadricDrawStyle(shape, GLU_FILL);
    gluQuadricNormals(shape, GLU_SMOOTH);
    gluSphere(shape, radius, slices, stacks);
}

Whats the problem here?

Edit : For some reason, i cant upload images from college, so i'll try describe it : The sphere outline looks fine, however you can see the segments on the inside, like the outside of the sphere is transparent, and it causes there to be clear divides in the sphere.

DuskFall
  • 422
  • 2
  • 14

1 Answers1

1

Looks like there's a problem with depth testing.

Assuming you have a depth buffer from glfw, does this fix it?

glEnable(GL_DEPTH_TEST);

I haven't used glfw, but to request a depth buffer it looks like you just need to pass 24 for example to the depthbits argument of glfwOpenWindow.

You will also need to add GL_DEPTH_BUFFER_BIT to your glClear call if you haven't already.

I've experienced inconsistencies with the default GL state, specifically GL_DEPTH_TEST, across windows and linux using glut/freeglut before.

Also, see gluNewQuadric leaking memory

Community
  • 1
  • 1
jozxyqk
  • 16,424
  • 12
  • 91
  • 180
  • 1
    I had all that enabled, but that wasnt the problem, it was how GLFW handled the enables and such. If they were outside the windowShouldClose loop, they had no effect, but if the enables were inside, it works. – DuskFall Sep 27 '13 at 15:12
  • @DuskFall: This makes sense, you have to realize that OpenGL commands are only valid when you have a render context bound. Most of the window system frameworks will switch bound contexts for each window event, some even unbind the context after the callback returns. The best place to do state changes when you use these frameworks is from within a callback function. – Andon M. Coleman Sep 29 '13 at 04:44