PDA

View Full Version : glutSolidSphere stops the light???



BennUK
02-24-2004, 09:05 AM
I am creating my first real game demo and am spending FAR too jmuch time on the lighting. The way it works is that when you fire in the game, one of the bullets in the array is activated and then every bullet in the array is moved forward and rendered at update.

The thing is I have mada a simple light model (ambient with a bit of specular) but when I press fire (and GlutSolidSphere is called) it turns off the lights. I have removed this line and it is fine, is this a known problem and is there a way around it?

Cheers for any help,

BennUK

Honk
02-24-2004, 09:46 AM
Thats unlikley, since all glutSolidSphere() does is this:




static GLUquadricObj *quadObj;
#define QUAD_OBJ_INIT() { if(!quadObj) initQuadObj(); }

static void
initQuadObj(void)
{
quadObj = gluNewQuadric();
if (!quadObj)
__glutFatalError("out of memory.");
}

void APIENTRY
glutSolidSphere(GLdouble radius, GLint slices, GLint stacks)
{
QUAD_OBJ_INIT();
gluQuadricDrawStyle(quadObj, GLU_FILL);
gluQuadricNormals(quadObj, GLU_SMOOTH);
/* If we ever changed/used the texture or orientation state
of quadObj, we'd need to change it to the defaults here
with gluQuadricTexture and/or gluQuadricOrientation. */
gluSphere(quadObj, radius, slices, stacks);
}


So it must be your code. Perhaps you want to show some of it?

BennUK
02-24-2004, 09:52 AM
With these parts commented out, it's fine, as soon as I put the glutSolidSphere back, it dies. Hmmmn.


void CworldModel::renderBullets(void)
{
for(int i = 0; i < BULLET_AMOUNT; i ++)
{
if (player.getBulletState(i))
{
//glLoadIdentity();
glPushMatrix();
glTranslatef(player.getBulletPosition(i, 0) + 0.5, 45, player.getBulletPosition(i, 2));
glEnable(GL_COLOR_MATERIAL);
//glutSolidSphere(0.1, 16, 16);
glDisable(GL_COLOR_MATERIAL);
glPopMatrix();


}
}
}

Thanks

BennUK

Honk
02-24-2004, 10:27 AM
Have you changed your matrixmode to



glMatrixMode(GL_MODELVIEW);


otherwise you are still doing everything in the projection matrix mode, which wont work (the projection matrix mode only has a depth of two stack entries).

zix99
02-24-2004, 12:04 PM
I remember something similiar to this hapenning to me... I recall it having to do something with GL_COLOR_MATERIAL but I don't exactly know... Try taking those glEnable and glDisable lines out and just draw the sphere and see what it does...

Hope it works, I don't exactly remember

BennUK
02-25-2004, 06:10 AM
Tried both the above and no joy http://www.opengl.org/discussion_boards/ubb/frown.gif Thanks for your help though guys, guess I will just have to pull my code to bits and see if i can get to the bottom of it that way.

BennUK

Relic
02-25-2004, 08:25 AM
The enable color material call will set the materials to the current color. The default is front_and_back, ambient_and_diffuse. The glutSolidSphere has no colors. If your color was black before, you're screwed.
It's one of OpenGL pitfalls described in the so-named doc on the main page: http://www.opengl.org/resources/features/KilgardTechniques/oglpitfall/ see #14.

This is one of the reasons why it's clever to set parameters first and call enable as last.

laprej
03-04-2004, 08:41 PM
I think if you do a glPushAttrib(GL_ALL_ATTRIB_BITS), draw your glut sphere, and then pop them off again it might work... I had a similar problem before.