OpenGL Dark Orb of Doom ....

This topic is 4610 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

int DrawGLScene(GLvoid) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glBindTexture(GL_TEXTURE_2D, texture[STARS]);

glTexCoord2f(0.0f + starscroll, 1.0f); glVertex3f(-3.2f, 2.4f, -50.0f);
glTexCoord2f(1.0f + starscroll, 1.0f); glVertex3f( 3.2f, 2.4f, -50.0f);
glTexCoord2f(1.0f + starscroll, 0.0f); glVertex3f( 3.2f,-2.4f, -50.0f);
glTexCoord2f(0.0f + starscroll, 0.0f); glVertex3f(-3.2f,-2.4f, -50.0f);
glEnd();

glPushMatrix();

glTranslatef(0.0f, 0.0f, -20.0f);

glRotatef(-90.0f,1.0f,0.0f,0.0f);
glRotatef(yrot,0.0f,0.0f,1.0f);

glBindTexture(GL_TEXTURE_2D, texture[EARTH]);

glPopMatrix();

glEnable(GL_BLEND);
glDisable(GL_DEPTH_TEST);

glBlendFunc(GL_DST_COLOR,GL_ZERO);

glTexCoord2f(0.0f, 0.0f); glVertex3f(-3.2f, -2.4f,  -1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 3.2f, -2.4f,  -1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 3.2f,  2.4f,  -1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-3.2f,  2.4f,  -1.0f);
glEnd();

glBlendFunc(GL_ONE, GL_ONE);
glBindTexture(GL_TEXTURE_2D, texture[OVERLAY]);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-3.2f, -2.4f,  -1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 3.2f, -2.4f,  -1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 3.2f,  2.4f,  -1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-3.2f,  2.4f,  -1.0f);
glEnd();

glEnable(GL_DEPTH_TEST);
glDisable(GL_BLEND);

starscroll+=0.0005;
xrot+=xspeed;
yrot+=yspeed;
return TRUE;
}



Share on other sites
You aren't specifying normals for the quads you are rendering, so OpenGL uses whatever the last used normal is (or whatever your implementation sets as the default, I don't remember if OpenGL specifies a default normal or not - you can check in the OpenGL Spec to find out). Rendering the quadric will change the current normal, so it will affect the lighting calculations on the quads. Just specify a normal for each of those quads and that should fix it. It looks like (0,0,1) is the normal you want to be using for those quads.

EDIT: You can read more about lighting and the math behind it in the Lighting Chapter of the Red Book.

EDIT2: Okay, the default normal is specified to be (0,0,1) so that explains why the quads looked fine without the quadric. I'm not sure why even the quadric is rendered differently when you render everything though. It could be how you are blending your masked quad. And yeah, like Waffler says in the next post, if you don't want lighting to effect something (no lighting on the starfield makes sense [grin]) then you should disable lighting before you render that.

[Edited by - Kalidor on April 6, 2006 4:57:08 PM]

Share on other sites
For some of your 2D overlays, you may want to turn lighting off with glDisable(GL_LIGHTING). That way it is always bright and un-shaded. Of course, you may also want to make sure the color is currently glColor4f(1.0f, 1.0f, 1.0f, 1.0f), so it's white and fully opaque.

Share on other sites
Quote:

This looks like it's the correct explanation to me. I think when you call the function to draw the sphere, the normals are getting generated for it, and the last one stays there(OpenGL is a state machine), so everything that gets drawn afterwards uses whatever the last normal of the sphere, unless you specify the normal of the other objects. That would explain the darkness of your objects. Also, when you specify your quadric object, you are determining whether normals are generated inside or outside, so yes, they should be getting generated upon rendering of the sphere.

Share on other sites
Yeah, I had tried disabling lighting for everything but the quad and that did it. I had forgotten about normals. [embarrass] Although that still doesn't seem to explain why the quadratric is dark when I draw the masked texture, but it's working now so I'll blame solar flares and call it good. Thanks.

1. 1
Rutin
45
2. 2
3. 3
4. 4
5. 5

• 10
• 28
• 20
• 9
• 20
• Forum Statistics

• Total Topics
633409
• Total Posts
3011702
• Who's Online (See full list)

There are no registered users currently online

×