PDA

View Full Version : Lights hav no effect when texture is on



uwi2k2
11-27-2012, 08:48 AM
Hi all,

sorry i have a really stupid problem here that is killing me today.

ich have e simple system with lights on and a lot of cubes with normals and texture coordinates
taking data from a texture atlas.

when i turn of 'GL_TEXTURE_2D' the lights are shown correctly according to the normals.
912

but as soon as i turn on the texture all the lighteffect is gone:
913


so the only bad guy could be my texture and the 'Modulate / Replace' setting .. but i tryed so mutch ..
here it is ..



GLuint LoadTexture( const char * filename, int width, int height )
{
GLuint texture;
unsigned char * data;
FILE * file;

//The following code will read in our RAW file
file = fopen( filename, "rb" );
if ( file == NULL ) return 0;
data = (unsigned char *)malloc( width * height * 3 );
fread( data, width * height * 3, 1, file );
fclose( file );

glGenTextures( 1, &texture ); //generate the texture with the loaded data
glBindTexture( GL_TEXTURE_2D, texture ); //bind the texture to itís array
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); //set texture environment parameters
//glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
//glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

// glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); // GL_LINEAR
// glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );

// glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
// glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST );

//Here we are setting the parameter to repeat the texture instead of clamping the texture
//to the edge of our shape.
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

//Generate the texture
//glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
gluBuild2DMipmaps( GL_TEXTURE_2D, 3, width, height, GL_RGB, GL_UNSIGNED_BYTE, data );

free( data ); //free the texture
return texture; //return whether it was successfull
}


you see, i tryed so many setting, mipmap on/off texture_env, min mag filter .. but nothing changes ...

can someone pls give me the hint ... it must be so simple that i just dont see it ...

THANX !!!
uwi

Dark Photon
11-27-2012, 09:49 AM
Check for GL errors:

* glGetError (or "How do I check for GL errors?) (http://www.opengl.org/wiki/FAQ#glGetError_.28or_.22How_do_I_check_for_GL_erro rs.3F.29)

And verify that lighting is still enabled, and that you're setting your vertex material properties properly. Failing that, post a short test program that demonstrates the problem.