View Full Version : glBindTexture problem
02-07-2000, 08:40 AM
How do I use glBindTexture? - all the source code I can find is hopelessly unreadable and the OpenGL help file I have skips over most of it conveniantly. Simple examples preferred with some doc. if poss
02-08-2000, 01:58 AM
I did have the same problem, months ago.
The fact is I was missing the meaning of the specs about binding texture objects.
In short, OGL drivers maintain several distinct objects (data structures), which hold texture data + parameters.
Binding works by associating a 'name'(actually an integer value) to each texture object; each time you have to make a particular object active, you simply set the binding to the name you had.
Ok, now I will come up with an example.
Here, for clarity, I use exclusively 2D textures, that is GL_TEXTURE_2D as the target.
unsigned texture_handle; // holds the name
//-- allocate a name
//-- bind the named object to the target
// this will make the object's data available // to all the operations on the associated target
//-- set parameters
// ... other params ...
0, // no mipmap LoD
4, // components
0, // no border
Rendering of scene
//-- bind the named object
// this recalls all stored states for the object
// now subsequent operations that need
// texturing data will fetch the previously
// stored info from the bound object
//... draw geometry, specifying TexCoords
// the binding remains current until you call
// glBindTexture with another name
// when you don't need anymore texturing, you
// simply disable it.
That's it. Have a try!
What does the "1" mean?
In the tutorials I've read the texture_handle was a kind of GLuint? What kind of data is it (I'd think just a kind of integer) But how can that store a texture?
Is it possible to generate a texture from something like an arry of byte in which I place the RGB values for each pixel, it seems a lot easier than all the other stuff I read to me. And when yes how?
04-26-2004, 01:26 PM
What about reading the docs ?
Choose your flavor :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/opengl/glfunc02_3p6b .asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/opengl/glfunc02_3p6b.asp)
glGenTextures( n, *textures);
n: The number of texture names to be generated.
textures: A pointer to the first element of an array in which the generated texture names are stored.
You can see an OpenGL 'name' as an ID, an SQL key, it is a number that identifies a unique object (texture, display list, etc).
To specify actual texels data, read the above post about glTexImage, and the reference docs as well.
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.