Question

I'm using GLUT to work with OpenGL (would work with SDL if I could). And I need to draw sphere. I'm using gluSphere but it simply doesn't draw anything.

Here's my GLUT initialization:

// Initializes display
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(600, 600);

// Window settings
glutCreateWindow("Collision detect");
glClearColor(0.0, 0.0, 0.0, 1.0);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glEnable(GL_TEXTURE_2D);

Quadratic initialization:

quadratic = gluNewQuadric();
if( !quadratic){
    throw new PROGRAM_EXCEPTION( "Cannot initialize quadartic", NULL);
}
gluQuadricNormals(quadratic, GLU_SMOOTH);
//gluQuadricDrawStyle( quadratic, GLU_FILL);
gluQuadricTexture(quadratic, GL_TRUE); // Tried both GL_TRUE and GL_FALSE

And my draw function:

glPushMatrix();
glTranslatef( position.getX(), position.getY(), position.getZ());
// This commented piece of code draws dot where I want it to,
// so coordinates and camera position are just fine
//  glBegin(GL_POINTS);
//  glVertex3f( 0,0,0);
//  glEnd();
gluSphere( quadratic, 20.0f, 32, 32); // Tried r = 0.02f, 0.2f, 2.0f, 20.0f, none works
glPopMatrix();

Question: what am I missing? Is there some trick in glut to enable quadratics to draw? Is it incompatible with some of my settings?

I've spent several hours trying to sort this out, tried different things... If you need some other piece of code, just say which... I don't want to paste 2000 lines here. And one more thing, I've triple check, I'm not using it inside glBegin() and glEnd(). I have few triangles enclosing the space and they draw just fine.

Was it helpful?

Solution 2

The problem was that I have class that was taking care of drawing ball (called Sprit) it created quadratic in constructor (also copy constructor created it own quadratic) and deleted quadratic in destructor. Though I've written copy constructor carefully I forgot to write assign operator and I've used deleted quadratic. I was using glGetError() to check that everything's fine, no error was reported so I assumed it's problem of GLUT.

OTHER TIPS

Question: what am I missing?

How about setting up a viewport and projection?

Use this guide http://www.mediafire.com/?x6h3hz6hn1wqq73

Chapter 2 mainly covers everything you are looking for. It also deals with the language and technology stacks you are using.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top