Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 10 of 10

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

  1. #1
    Intern Newbie
    Join Date
    Apr 2001
    Posts
    36

    Texure map works now, but it causes my lighting to get all messed up

    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

  2. #2
    Intern Contributor
    Join Date
    May 2001
    Location
    Cheltenham,Gloucestershire,England
    Posts
    86

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

    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.

  3. #3
    Intern Newbie
    Join Date
    Apr 2001
    Posts
    36

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

    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.

  4. #4
    Intern Contributor
    Join Date
    May 2001
    Location
    Cheltenham,Gloucestershire,England
    Posts
    86

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

    Hi there,

    check your normal calculations!!

    Cheers

    Mark.

  5. #5
    Intern Contributor
    Join Date
    May 2001
    Location
    Cheltenham,Gloucestershire,England
    Posts
    86

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

    Also - i dont think glRotate etc transform light
    positions. so you may want to manually
    roate your light position.

  6. #6
    Intern Newbie
    Join Date
    Apr 2001
    Posts
    36

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

    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();
    }

  7. #7
    Advanced Member Frequent Contributor
    Join Date
    Sep 2000
    Location
    SWEDEN
    Posts
    718

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

    Make sure you aren't supplying the light vector in eye-space.

  8. #8
    Intern Newbie
    Join Date
    Apr 2001
    Posts
    36

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

    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 !

    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

  9. #9
    Member Regular Contributor
    Join Date
    Nov 2000
    Location
    Huntsville, AL. USA
    Posts
    319

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

    Try this ...


    glEnable(GL_TEXTURE_2D);
    glDisable(GL_LIGHTING);

    renderTheQuadAsAbove();

    glDisable(GL_TEXTURE_2D);
    glEnable(GL_LIGHTING);

    renderTheSnowmanAsAbove();
    ...
    Obsessive - A word used by the lazy to describe the motivated.

  10. #10
    Intern Newbie
    Join Date
    Apr 2001
    Posts
    36

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

    THANK YOU!...duh...I can't belive it was that simple. Finally I can move on now.

    Thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •