glBindTexture() not needed?

Started by
9 comments, last by darookie 11 years, 9 months ago
Hello. I just noticed the the red book (http://fly.cc.fer.hr/~unreal/theredbook/chapter09.html) doesn't use glBindTexture() at all, but other texture guides like the one below do use it.
http://www.gamedev.net/page/resources/_/technical/opengl/opengl-texture-mapping-an-introduction-r947

Is it not needed?
Advertisement
That webpage is lying to you. You have to call glBindTexture. glTexImage2D has no parameter that specifies what texture you are loading your image into.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

Then how come the example code in that webpage works?
What are the cons in not using glBindTexture()?
Because that code doesn't work I can assure you that 100%. They never call glGenTextures either. They either left out code or never actually compiled it and just typed it up.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal


Then how come the example code in that webpage works?
What are the cons in not using glBindTexture()?


Have you actually tried the code? I don't believe it will work on a modern OpenGL card. If you look at the About page for that version of the book, you will see that the copyright date is 1994. That means it's the first edition of the book and was written against OpenGL 1.0. You'll notice there also are no calls to glGenTextures. Texture objects, which require the calls to gen/bind/texture were added to OpenGL in version 1.1. If you look at the same chapter from the Second Edition of the book (published in 1997), you'll see that the calls to glGenTextures and glBindTexture are there.
The samples work because they use only one single texture. OpenGL is a state machine and has some default values defined, like default texture object name. You will need to call glBindtexture as soon as you need more than one texture. Since the default case is to have more than one texture per scene, glBindTexture is the recommended way to go.
In short: no, the website is not lying, it's just not telling the whole story at this point.

You'll notice there also are no calls to glGenTextures. Texture objects, which require the calls to gen/bind/texture were added to OpenGL in version 1.1.

glGenTextures is actually not required. The function simply asks the implementation for available texture object names, not texture objects. If you manage your own texture object ids, glGenTextures is actually not necessary. Likewise glBindTexture will simply bind a name to a texture object - in effect it only provides an alias - not using the function will simply replace/use the default texture object for the selected target.
DAMN!
So I've been reading an outdated version the whole time!? wacko.png
Gonna get the last version now. Do you guys know any other changes that were made to the book over the years?
Likewise glBindTexture will simply bind a name to a texture object - in effect it only provides an alias - not using the function will simply replace/use the default texture object for the selected target.[/quote]
Sure as you stated it is probably just using the texture handle 1. But you are confusing this guy in saying that not calling glBindTexture will do something. You have to use glBindTexture if you want more than 1 texture.

So I've been reading an outdated version the whole time!?[/quote]
No and yes. Learning any openGL will help you and is not a waste. Just learn things. The reference you are looking at is not the newest openGL but there is a lot of stuff to learn not just regarding GL but 3D programming in general.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal


glGenTextures is actually not required. The function simply asks the implementation for available texture object names, not texture objects. If you manage your own texture object ids, glGenTextures is actually not necessary.

While this can be done, the OP should know that it's deprecated in recent GL_VERSIONs.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

This topic is closed to new replies.

Advertisement