Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


glBindTexture() not needed?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
10 replies to this topic

#1 Paprica   Members   -  Reputation: 126

Like
0Likes
Like

Posted 10 August 2012 - 08:53 AM

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?

Sponsor:

#2 dpadam450   Members   -  Reputation: 949

Like
0Likes
Like

Posted 10 August 2012 - 08:57 AM

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.

#3 Paprica   Members   -  Reputation: 126

Like
0Likes
Like

Posted 10 August 2012 - 09:50 AM

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

Edited by Paprica, 10 August 2012 - 09:51 AM.


#4 dpadam450   Members   -  Reputation: 949

Like
0Likes
Like

Posted 10 August 2012 - 10:27 AM

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.

#5 Aldacron   GDNet+   -  Reputation: 3278

Like
1Likes
Like

Posted 10 August 2012 - 10:29 AM

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.

#6 darookie   Members   -  Reputation: 1437

Like
2Likes
Like

Posted 10 August 2012 - 10:30 AM

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.

#7 darookie   Members   -  Reputation: 1437

Like
1Likes
Like

Posted 10 August 2012 - 10:38 AM

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.

#8 Paprica   Members   -  Reputation: 126

Like
0Likes
Like

Posted 10 August 2012 - 10:48 AM

DAMN!
So I've been reading an outdated version the whole time!? Posted Image
Gonna get the last version now. Do you guys know any other changes that were made to the book over the years?

#9 dpadam450   Members   -  Reputation: 949

Like
0Likes
Like

Posted 10 August 2012 - 06:58 PM

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.

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!?

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.

#10 mhagain   Crossbones+   -  Reputation: 8284

Like
1Likes
Like

Posted 11 August 2012 - 06:41 AM

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.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#11 darookie   Members   -  Reputation: 1437

Like
0Likes
Like

Posted 11 August 2012 - 12:23 PM

DAMN!
So I've been reading an outdated version the whole time!? Posted Image
Gonna get the last version now. Do you guys know any other changes that were made to the book over the years?

Here's a fairly decent tutorial (a free eBook rather) that uses the current state of the OpenGL API: Learning Modern 3D Graphics Programming




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS