PDA

View Full Version : Problems with glGenTextures



dew
03-12-2001, 01:44 AM
When i try to generate a texture object with glGenTextures i do not get any identifier back.
What am i doing wrong and how can i solve this problem?

Bob
03-12-2001, 01:49 AM
Well, you don't give much information, except that something is wrong. Please tell us more, how do you use it for example?

dew
03-12-2001, 03:59 AM
Additional info:
This is an extraction from my source code:

void World::addtexture(String id)
{
int n;
bool loaded=false;
Texture *tex;
GLuint index;

for(n=0;n<num_textures;n++)
if(id==texturestore[n]->ID) loaded=true;
if(!loaded)
{
BMPFile handle;
tex=handle.load(id.text);
texturestore[num_textures]=tex;
tex->idnum=num_textures;
glGenTextures(1,&index);
glBindTexture(GL_TEXTURE_2D,index);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

glTexImage2D(GL_TEXTURE_2D,0,3,tex->width,tex >height,0,GL_RGB,GL_UNSIGNED_BYTE,tex->data);
num_textures++;
}

}

In this source I do not get any identifier (index) for the texture object I wanted, therefore I believe that it was not created.
I have looked at an example that uses glGenTextures and it worked, therefore I started to remove code from it to see if the same problem occurred there as in my code.
And indeed it did.
But when the glutCreateWindow() function was executed it started to work again. Iím confused.
I havenít found any good documentation on glGenTextures and if there should be any premises and constraints to make it work.
I have also thought about if errors reported by OpenGL affects the functionality of certain functions, and if this is the case with my problem?

Bob
03-12-2001, 05:40 AM
glutCreateWindow does not only creates a window on the screen. It also creates an OpenGL rendering context, which is a requirement for OpenGL to work at all. If you remove that function, a context will not be created, and no calls to OpenGL will work as expected.

As long as you create a context before doing anything else, there should be no problem with your code. You can do some error checking after glGenTexture. If index is zero, no texture was allocated, otherwise a texture was properly allocated.

dew
03-12-2001, 06:05 AM
Thanks for the help, could been lost out there for ages without your help http://www.opengl.org/discussion_boards/ubb/smile.gif

Now it works as it should.