Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

OpenGL - using C (Textures and lighting)

Cpp NewbieCpp Newbie Member Posts: 16
Im trying to load in a couple of textures (wood for a table and plaster for a wall) I can load the textures in and get them onto the rectangles no problem but it knocks out the lighting.

Ive tried moving the calls to glPopMatrix and glPushMatrix but im not too sure where they should be.

If i disable the textures the lighting comes back to how it was.

How do I get textures and lighting?

Comments

  • SephirothSephiroth Fayetteville, NC, USAMember Posts: 1,035
    It's fairly simple using "glLightfv()". Say we want a light at 1.0, 1.0, 1.0 in the world. You'd set it up as follows.
    [code]
    float fLightAmbient[] = {0.5f, 0.5f, 0.5f, 1.0f};
    float fLightDiffuse[] = {1.0f, 1.0f, 1.0f, 1.0f};
    float fLightPosition[] = {1.0f, 1.0f, 1.0f, 1.0f};

    //This goes in your initialization function/class
    glLightfv(GL_LIGHT1, GL_AMBIENT, fLightAmbient);
    glLightfv(GL_LIGHT1, GL_DIFFUSE, fLightDiffuse);
    glLightfv(GL_LIGHT1, GL_POSITION, fLightPosition);
    glEnable(GL_LIGHT1);
    glEnable(GL_LIGHTING);
    [/code]
    That sets up a static light at 1.000, 1.000, 1.000 in the game world. Simple as that!

    -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]

  • gautamgautam Member Posts: 642
    : It's fairly simple using "glLightfv()". Say we want a light at 1.0, 1.0, 1.0 in the world. You'd set it up as follows.
    : [code]
    : float fLightAmbient[] = {0.5f, 0.5f, 0.5f, 1.0f};
    : float fLightDiffuse[] = {1.0f, 1.0f, 1.0f, 1.0f};
    : float fLightPosition[] = {1.0f, 1.0f, 1.0f, 1.0f};
    :
    : //This goes in your initialization function/class
    : glLightfv(GL_LIGHT1, GL_AMBIENT, fLightAmbient);
    : glLightfv(GL_LIGHT1, GL_DIFFUSE, fLightDiffuse);
    : glLightfv(GL_LIGHT1, GL_POSITION, fLightPosition);
    : glEnable(GL_LIGHT1);
    : glEnable(GL_LIGHTING);
    : [/code]
    : That sets up a static light at 1.000, 1.000, 1.000 in the game world. Simple as that!
    :
    : -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]
    :
    :

    Hi,

    Lighting in OpenGl works on goraud shading so basically its like vertex colors. Is your texture mode setup to modulate or decal.

    This is what it should be if you want lighting to affect the
    texture.
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

    If you change GL_MODULATE to GL_DECAL the texture won't get affected by lighting.



Sign In or Register to comment.