Lighting and Textures

Started by bittramp, March 30, 2011, 16:41:16

Previous topic - Next topic

bittramp

Hello,
I have been trying out a few examples to understand this stuff and find myself perplexed.  I started with drawing some quads.  Then drawing some quads with textures.  Then drawing some with lighting.  But when I tried to combine lighting and texture I had some problems.  I found this page http://www.opengl.org/resources/faq/technical/texture.htm which was a great help, but obviously there are still some things I don't understand going on.

http://breadmilkbeercigarettes.com/bmbc/shelves/users/bbb/src/java/QuadLightingTexture.php This is my code.

It creates 5 rotating quads.  One of which it draws with a texture I create.  When the normal side rotates to the front I see the specular reflection on the texture and other quads.  But I cannot get the quads the color I want.  They all get colored the color of the last pixel in the first column of my texture. (??)
I tried a few variations on the quads, but they stay fully painted (ie no shading from lighting) and yet they do have specular lighting on them.

The important methods are initGL() and renderGL().  Perhaps it's mixing in the GL1.2 constants but without that call I get same results minus specular.  And naturally if I comment out the enabling of texture_2d I get all the shading I expect.

Anyone have some advice?  I know my code is probably whacked.  And I may have some things inside a push/pop matrix that don't belong there.  But I am trying to learn.

Thanks,
BBB

Fool Running

For any polygons you don't want to have a texture, you need to disable texturing (GL11.glDisable(GL11.GL_TEXTURE_2D)). Otherwise, the polygons will all use the last texture coordinate (last call to GL11.glTextureCoord2f() or whatever). OpenGL is a gigantic state machine, so it will always use whatever value for whatever state was last set, even for the next rendered frame.

Hope that helps. ;D
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

bittramp

Yes, thanks.  That did it.  I hadn't seen examples where disable and enable were used inside of the render portion around elements that needed specific functionality, so it never dawned on me that I should do that.  In fact, I kind of thought of it as some global enablement for textures and not specific to the next modeling calls.  And I guess I was wrong.  So much to learn.

Thanks again.

I supposed if I had models I didn't want lighting applied to, like quads with text textures, I should just disable lighting during their rendering?  Is that how most people work?  Disabling and enabling functionality on the fly?

Fool Running

Yes, that is the correct way of doing it (Enabling and disabling stuff). However, there is sometimes a cost to enabling, disabling, or changing certain things (like the current texture or shader). Sometimes (not always) you can get a performance boost by drawing groups of stuff based on which attributes they have (texturing, lighting, shaders, etc.) before changing to other attributes.
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D