Advertisement

NeHe Tutorial question

Started by February 14, 2006 12:23 AM
3 comments, last by levjs 18 years, 6 months ago
I've been going through the NeHe tutorials, and am quite pleased at the results, after i followed the tutorial through making the 3D pyramid, i did the full 3d quad myself and it worked fine, and i added a bottom to the pyramid, and that also worked fine, but here goes my question. When I got to the texturing tutorial, I didn't start fresh, I just modified one side of my box to show the bitmap. That worked fine, but all of the colors got messed up... It's like everywhere I use glColor3f(r,g,b); where r g and b are actually my specific settings for the color i wanted to appear, it doesn't show any colors unless they are near to what's in the NeHe bitmap. So, in effect, all my beautifully blended reds greens and blues became blacks and blues. I even had my cube in nice pretty pastel colors and it's all blue as well. Does anyone have any idea what might have caused this, and how I can fix it? I don't want to run into this issue when I actually go to create a game and decide that something I've made would work great by just using standard colors and not having to texture it.
Your are adding color to the texture. You want to blend the color somehow. Maybe be glColor4ub? Or just glColor4f.

What you are doing is creating a white pyramid and adding color.
Then you are either adding texture to the pyimid then color(which makes it darken) or adding color then texture(which gives about the same result)
.::WARNING!::. Axesor is a total newb or n00b! Beware his lack ofintellegence of OpenGL. Feel sorry for him and keep him in your thoughts.~Leader of the phsychoward
Advertisement
Textures and colour can both be applied at the same time. If they are then the resulting colour you see is (by default - it can be changed) the componentwise product of the colours, i.e. the amount of red you see is the amount of red you specified in your glColor call multiplied by the amount of red in the texel (texture pixel) at that location, where both colours are specified in the 0.0f-1.0f range.

In addition, OpenGL is a state machine. When you set a state it remains set and continues to apply to all relevant operations until you change it or disable it (if possible). In particular the currently bound texture, whether texturing is enabled and the current texture coordinate are all states. If you specify a texture coordinate then it applies to all subsequent vertices, not just the next one. The result is that not specifying a texture coordinate does not mean that that the vertex is untextured. It just means that it's textured with the same texel as the previous vertex. If all vertices of a polygon use the same texture coordinate then the polygon will be textured with a single texel of the texture map. This is what is happening to you. The colour you are setting is being multiplied by the colour of that single texel from your texture map. The solution is to explicitly glDisable(GL_TEXTURE_2D); when you do not want texturing (and remember so set the colour back to white when you do want texturing unless you want your texture tinted).

Σnigma
Yeah, I had discovered that not implicity telling the program to use glColor3f(1.0f,1.0f,1.0f) before using the texture, the texture would change colors. So basically if i'm understanding you, I should instead of enabling the texture at the beginning, i should just enable it when i need it and the rest of the colors should be fine?
Yes, Or else disable it where you don't need it. :) Whichever one is less trouble.

This topic is closed to new replies.

Advertisement