coloring a texture
hi everybody! this time i'm becoming mad for a weird problem with textures. i got a nice surface with her nice texture and i would like to change its colors..like if i've placed a coloured light on it. i'm using this code but doesn't work... where's the error?
glActiveTextureARB(GL_TEXTURE2_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, m_textures[pFace->textureID]);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_ADD) ;
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_CONSTANT) ;
float mycolor[] = { 0.7,0,0,0};
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, mycolor);
as u can see, this is not the first texture, but GL_TEXTURE2_ARB.. using this code i have a scene without textures but all quite red ^__^
The behaviour you describe looks like the bound texture is black.
Few things to test :
- have you tried replacing all those calls to glTexEnv with : glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)
This will show your texture only. If the texture appears black, everything is normal. You just have to call glTexImage2D with non-black data :)
- have you tried setting up the same thing on another texture unit ? If it works with another texture unit, it either means that there is a driver bug (I've seen many like that on the ATi chipset you're runnning) or that you're having side effects (see below),
- do you ever happen to setup texture environment combine in other places in your program ? If it ever happens, you should try setting all the texture environment combine parameters, at least for testing purposes :
[edit] huh oh while I was posting code I found you've done a mistake : you use GL_TEXTURE and GL_CONSTANT for OPERANDS while it should be setup for SOURCES. The OPERAND parameters should be something like GL_SRC_COLOR. Just copy/paste the above code and it should work.
Few things to test :
- have you tried replacing all those calls to glTexEnv with : glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)
This will show your texture only. If the texture appears black, everything is normal. You just have to call glTexImage2D with non-black data :)
- have you tried setting up the same thing on another texture unit ? If it works with another texture unit, it either means that there is a driver bug (I've seen many like that on the ATi chipset you're runnning) or that you're having side effects (see below),
- do you ever happen to setup texture environment combine in other places in your program ? If it ever happens, you should try setting all the texture environment combine parameters, at least for testing purposes :
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_ADD);glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_CONSTANT);glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
[edit] huh oh while I was posting code I found you've done a mistake : you use GL_TEXTURE and GL_CONSTANT for OPERANDS while it should be setup for SOURCES. The OPERAND parameters should be something like GL_SRC_COLOR. Just copy/paste the above code and it should work.
@vincoof:
1) i get the same result as before, but now the texture is white ^__^
2) yes, and does the same thing
3) yes, for dot3 bump mapping
1) i get the same result as before, but now the texture is white ^__^
2) yes, and does the same thing
3) yes, for dot3 bump mapping
[edit]
1- weird. are you sure you uploaded the texture correctly ? I'm
especially thinking about mipmap issues (don't forget to call glTexParameteri(GL_S/T, GL_TEXTURE_MIN_FILTER, GL_LINEAR) if you don't fill mipmap levels)
2- fine, that's normal
3- do you happen to call glTexEnv with all types of combining parameters ? I mean, what kind of *second* arguments do you use apart from GL_GOMBINE_RGB and GL_OPERANDi_RGB ? Do you setup GL_SOURCEi_RGB ? Do you setup GL_*_ALPHA ?
[/edit]
have you tried correcting the calls to OPERAND like I mentioned ? Did it ever got better ?
From time to tile it's a good thing to call glGetError (we all tend to forget this one but it's pretty useful sometimes). With glGetError you could have tracked down yourself that the calls to glTexEnv with GL_OPERANDi_RGB where not correct ^^
[edit2]glad you replied while I was doing so. It's great news that it's working now :)
1- weird. are you sure you uploaded the texture correctly ? I'm
especially thinking about mipmap issues (don't forget to call glTexParameteri(GL_S/T, GL_TEXTURE_MIN_FILTER, GL_LINEAR) if you don't fill mipmap levels)
2- fine, that's normal
3- do you happen to call glTexEnv with all types of combining parameters ? I mean, what kind of *second* arguments do you use apart from GL_GOMBINE_RGB and GL_OPERANDi_RGB ? Do you setup GL_SOURCEi_RGB ? Do you setup GL_*_ALPHA ?
[/edit]
have you tried correcting the calls to OPERAND like I mentioned ? Did it ever got better ?
From time to tile it's a good thing to call glGetError (we all tend to forget this one but it's pretty useful sometimes). With glGetError you could have tracked down yourself that the calls to glTexEnv with GL_OPERANDi_RGB where not correct ^^
[edit2]glad you replied while I was doing so. It's great news that it's working now :)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement