PDA

View Full Version : Texure map works now, but it causes my lighting to get all messed up



DJKAOS
06-05-2001, 10:16 PM
I finally got my texture mapping to work.
I mapped the background of a mountain onto a GL_QUAD, that quad is farther back on the Z axis than my objects. But when I run it the background looks great but my objects have lost almost all of they color, they have a blusish tint to them, also when I rotate my objects the background goes away..or it gets very dark..its hard to tell. When I remove the lighting effects.. my objects have no color or shading or anything, but the background doesn't disapear when I rotate.


Could my light position be in the wrong place?

Thanks for any help

MButchers
06-05-2001, 10:38 PM
Hi there,

make sure you unbind the texture before rendering
your other objects by either using glBintTexture(GL_TEXTURE_2D,0) or
glDisable(GL_TEXTURE_2D) as the other
objects are most likly using this texture for
rendering with a t,u of 0,0

Hope it helps.

Mark.

DJKAOS
06-05-2001, 10:49 PM
Thanks!

That fixed my problem of the objects in front of the background not looking right, now they look right all the time..but the background still fades to super dark when I rotate or tranlate my objects.

I'm to tired to work on it now though, thanks for the help.

MButchers
06-05-2001, 11:07 PM
Hi there,

check your normal calculations!!

Cheers

Mark.

MButchers
06-06-2001, 01:41 AM
Also - i dont think glRotate etc transform light
positions. so you may want to manually
roate your light position.

DJKAOS
06-06-2001, 09:30 AM
I think my normal vector is correct..its
just directly in the z direction.. (0,0,1)
right?

I narrowed it down that the loaded bitmap dissapears from my GL_QUAD when the window is redrawn.

Here is my display function

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

//glColor3f(1.0, 1.0, 1.0); // Set the color to white
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glBindTexture(GL_TEXTURE_2D, texture[0]); // choose the texture to use.

glBegin(GL_QUADS);
glNormal3f(0.0, 0.0, 1.0);
glTexCoord2f(0.0, 0.0); glVertex3f(-1.5, -1.5, -1.0);
glTexCoord2f(1.0, 0.0); glVertex3f(1.5, -1.5, -1.0);
glTexCoord2f(1.0, 1.0); glVertex3f(1.5, 1.5, -1.0);
glTexCoord2f(0.0, 1.0); glVertex3f(-1.5, 1.5, -1.0);
glEnd();

glDisable(GL_TEXTURE_2D); // Unbindes the loaded texture

glTranslatef(xtrans, ytrans, ztrans);
glRotatef(yrot,0,1,0);

createSnowman();

glFlush();
glutSwapBuffers();
}

harsman
06-06-2001, 10:43 AM
Make sure you aren't supplying the light vector in eye-space.

DJKAOS
06-06-2001, 01:45 PM
Ok I figured out that my Lighting colors are getting applied to my bitmapped texture, which makes sence I guess but I still cant figure out why the bitmap dissapears when anything changes...like if I resize the window, or press a key, or anything. so anyway I tried changing the color to red..and it makes my bitmap tinted red..but when I do something the bitmap goes away and I'm left with a solid red background. I'm so confused ! http://www.opengl.org/discussion_boards/ubb/smile.gif

GLfloat diffuse2[] = { 0.9, 0.1, 0.1, 1.0 }; // redish color

glBindTexture(GL_TEXTURE_2D, texture[0]); // choose the texture to use.

glMaterialfv(GL_FRONT, GL_AMBIENT, diffuse2); // Does this have anything do do with it?
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse2); // "" "" ""
glBegin(GL_QUADS);
glNormal3f(0.0, 0.0, 1.0);
glTexCoord2f(0.0, 0.0); glVertex3f(-1.5, -1.5, -1.0);
glTexCoord2f(1.0, 0.0); glVertex3f(1.5,-1.5,-1.0);
glTexCoord2f(1.0, 1.0); glVertex3f(1.5, 1.5, -1.0);
glTexCoord2f(0.0, 1.0); glVertex3f(-1.5, 1.5, -1.0);
glEnd();

glDisable(GL_TEXTURE_2D); // Unbindes the loaded texture

pleopard
06-06-2001, 01:57 PM
Try this ...


glEnable(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);

renderTheQuadAsAbove();

glDisable(GL_TEXTURE_2D);
glEnable(GL_LIGHTING);

renderTheSnowmanAsAbove();
...

DJKAOS
06-06-2001, 02:40 PM
THANK YOU!...duh...I can't belive it was that simple. Finally I can move on now.

Thanks again.