Sign in to follow this  
Daft_ Panzer

[*Solved*] gluSphere is ruining my space battle game :(

Recommended Posts

Daft_ Panzer    144
My space battle fun is being ruined by some kind of random wierdness :( Here is my experimental game without a call to gluSphere: (everything is flat textured rectangles, including the background) Photo Sharing and Video Hosting at Photobucket Here is the exact same code, only with an added call to gluSphere: Photo Sharing and Video Hosting at Photobucket I’d really like to have that pretty spinning 3D planet in the background. I don’t understand why its messing things up. Its not just the functions that use blending/alpha masking, as you can see the original background is also darker, and that’s a plain square with no blending. I have no idea why the spaceships are OK, other than they are PNG textures (the PNG loader sets black areas to zero alpha as the textures are loaded, that’s the only difference I can think of – the other textures are a mix of jpg and bmp). I’ve tried compensating for the darkness of the blended things. by making the lighting really, really bright. But even values above 1 for the r/g/b are still dark. I have to go to 11 or more to get max brightness. Which seems very odd, and also it didn’t solve the masking problem. I went as high as 111 for r/g/b, and I still had visible boxes around the projectiles. It seems to me that the white and black in the masks aren’t cancelling each other out properly, as opposed to problems with depth/z axis. Probably the weirdest thing is that these bad effects stay, even if gluSphere is only called on one frame and then never called again! Here is my code for getting a sphere. Ive narrowed down the problem to the actual call to gluSphere. void DSphere(int tex, float rad) { glEnable(GL_LIGHT3); //positioned light with no ambient, to get nicer shading on 3D objects GLUquadricObj *pObj = gluNewQuadric(); gluQuadricTexture(pObj, true); glBindTexture(GL_TEXTURE_2D, texture[tex]); gluSphere(pObj, rad, 30, 30); glDisable(GL_LIGHT3); } I’ve used quadratic spheres before with no problems. I have no idea what is messing up here :( Well, thanks for reading this, and thanks for any help :) [Edited by - Daft_ Panzer on May 9, 2007 8:44:41 PM]

Share this post


Link to post
Share on other sites
Thaumaturge    3826
Hmm... Could it be that the last normal value produced for the sphere is being carried over to the rest of your drawing code?

I take it from your use of light 3 that lighting is on and that you're using at least the first two OpenGL lights in your standard drawing somewhere; in that case it might be that the final normal being generated in the call to gluSphere() is being used for your subsequent geometries, and thus producing lighting that differs from your intent.

Perhaps try specifying a normal appropriate to your setup after you've called your sphere.

Share this post


Link to post
Share on other sites
Daft_ Panzer    144
Yes, i have 3 different lights, the idea is that they are activated and deactivated as needed by different draw functions.

Normals are something i was hoping to ignore, i dont know much about using them to be honest :( I dont think there would be any manually specificed normals in the code anywhere.

So maybe it's taking the normal of the last face of the sphere, which would be at some odd angle, and applying that to all my flat-on square objects. In which case, specifying a normal straight into the screen after calling gluSphere could fix things?

thanks a lot, i will have a fiddle with this :D

Share this post


Link to post
Share on other sites
Daft_ Panzer    144
Thaumaturge, you were absolutely right, thanks so much!

The simple addition of "glNormal3f(0,0,1);" removes all problems. Now here is a 3D planet, with a second blended 3D sphere for the planet atmosphere, and all particles and projectiles looking fine.

Photo Sharing and Video Hosting at Photobucket

I’d never have thought of normals. I could have been fiddling with this for a week, and still have gotten nowhere.

May heaven shower you with eternal blessings :)

Share this post


Link to post
Share on other sites
zedz    291
heres an alternative to gluSphere ( does the same thing though )
note - its not optimized, ideally youll stick the whole thing into a single list of tris or quads

void SPHERE::render_sphere_DEBUG( void )
{
float off_H = ( M_PI ) / float(stacks);
float off_R = ( M_PI * 2.0 ) / float(slices);
VEC3 v;
float a,b;
int st,sl;

// draw the tips as tri_fans
glBegin( GL_TRIANGLE_FAN );
v.x = sin( 0.0 ) * sin( 0.0 );
v.z = cos( 0.0 ) * sin( 0.0 );
v.y = cos( 0.0 );
glNormal3fv( v );
glVertex3fv( center + v*radius );
for ( sl=0; sl<slices+1; sl++ )
{
a = float(sl)*off_R;
v.x = sin( a ) * sin( off_H );
v.z = cos( a ) * sin( off_H );
v.y = cos( off_H );
glNormal3fv( v );
glVertex3fv( center + v*radius );
}
glEnd();
glBegin( GL_TRIANGLE_FAN );
v.x = sin( 0.0 ) * sin( M_PI );
v.z = cos( 0.0 ) * sin( M_PI );
v.y = cos( M_PI );
glNormal3fv( v );
glVertex3fv( center + v*radius );
for ( sl=slices; sl>=0; sl-- )
{
a = float(sl)*off_R;
v.x = sin( a ) * sin( M_PI-off_H );
v.z = cos( a ) * sin( M_PI-off_H );
v.y = cos( M_PI-off_H );
glNormal3fv( v );
glVertex3fv( center + v*radius );
}
glEnd();

for ( st=1; st<stacks-1; st++ )
{
b = float(st)*off_H;
glBegin( GL_QUAD_STRIP );
for ( sl=0; sl<slices+1; sl++ )
{
a = float(sl)*off_R;
v.x = sin( a ) * sin( b );
v.z = cos( a ) * sin( b );
v.y = cos( b );
glNormal3fv( v );
glVertex3fv( center + v*radius );
v.x = sin( a ) * sin( b+off_H );
v.z = cos( a ) * sin( b+off_H );
v.y = cos( b+off_H );
glNormal3fv( v );
glVertex3fv( center + v*radius );
}
glEnd();
}
}

Share this post


Link to post
Share on other sites
Daft_ Panzer    144
@Thaumaturge, thanks for the compliment! Im planning a simple 'risk' style strategy game, played out on a galactic map, with star systems instead of provinces, and real-time battles. I ended up with the space battle engine kinda by accident, i was aiming to make a scrolling shoot-em-up to begin with :)

@zedz, that code will be very useful, thankyou!

[Edited by - Daft_ Panzer on May 9, 2007 9:11:48 PM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this