PDA

View Full Version : Ambient does not affect textured meshes



devdept
09-27-2010, 01:06 AM
Hi All,

Why when I draw a mesh with the following settings the ambient value is not used? I can even set full white without altering the mesh color.


glMaterialfv(GL_FRONT_AND_BACK, gl_AMBIENT, [0.2, 0.2, 0.2, 1]);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, [0, 0, 0, 1]);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 0);

glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, [1, 1, 1, 1 ]);

glEnable(GL_TEXTURE_1D);
glBindTexture(GL_TEXTURE_1D, textureName);

glBegin(GL_TRIANGLES);

...

Thanks,

Alberto

ZbuffeR
09-27-2010, 07:09 AM
Is the typo gl_AMBIENT instead of GL_AMBIENT also in your code ?
Otherwise, check value for glLightModelfv GL_LIGHT_MODEL_AMBIENT (if you did not touch it, default should be good).
http://www.opengl.org/sdk/docs/man/xhtml/glLightModel.xml
Some advice about deprecated GL lighting model and what to set as material ambient and light ambient values :
http://www.sjbaker.org/steve/omniv/opengl_lighting.html

devdept
09-27-2010, 07:49 AM
Hi ZbuffeR,

We only have one call to:


glLightModelfv(GL_LIGHT_MODEL_AMBIENT, [ .15f, .15f, .15f, 1]);
Do you confirm that a triangle with a solid blue texture shall look like a triangle with the three vertices color as 0,0,255 for the same material parameters?

Can the material 1,1,1,1 DIFFUSE value totally override the material AMBIENT component?

Thanks.

Alberto

ZbuffeR
09-27-2010, 07:58 AM
You did not say a word about the typo I noted : is it on your code too ?

To have 0,0,255 when only using ambient, you should have set :
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, [ 1.0f, 1.0f, 1.0f, 1.0f]);
Otherwise you will have 0,0,38 (255*0.18f).

Diffuse and Ambient are separate.

EDIT : just saw you mentionned texturing. Try without any texture, until you have the expected result.

devdept
09-27-2010, 08:26 AM
Yes, the typo is ok in my code, sorry.

The point is that I can't see the ambient effect when I draw the model using 1D textures like in my first post.

I supposed that setting material ambient as 1,1,1,1 will result in a almost white model (as it happens when I don't use the 1D texture), what do you think?

What parameter can make the 1D texture drawing immune from material AMBIENT ?

Thanks,

Alberto

carsten neumann
09-27-2010, 11:30 AM
Have you set glTexEnv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE) or something along those lines?

devdept
09-28-2010, 12:39 AM
Yes carsten,

We did also this test:


glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, [0.2, 0.2, 0.2, 1]);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, [0, 0, 0, 1]);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 0);

glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, [1, 1, 1, 1 ]);

glEnable(GL_TEXTURE_1D);
glBindTexture(GL_TEXTURE_1D, textureName);
glTexEnv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); // <- HERE
glBegin(GL_TRIANGLES);

...

without success...

Is it in the correct position?

Thanks,

Alberto