Skip to main content
gamedev.net
🔒 Locked

Texturing problems

Started by MatrixCubed 1 reply 400+ views
Original Post
MatrixCubed
MatrixCubed
Hello, I'm currently using the following code for allocating textures in my game. It is called once per texture (which is enumerated using ANSI _findfirst() and _findnext()):
    
AUX_RGBImageRec* lptex;
lptex = auxDIBImageLoad(szName);
glGenTextures(1, &(g_lpTextureList[i].iID));
glBindTexture(GL_TEXTURE_2D, g_lpTextureList[i].iID);
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, lptex->sizeX, lptex->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, lptex->data);
  

The list of textures (g_lpTextureList) is simply an array of structures which only holds filenames and OpenGL-generated texture IDs.

Then, per tile that I render, I call the following code:

      
glBindTexture(GL_TEXTURE_2D, gGetTextureID(szName));
glColor3f(1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(x,     g_dwHeight - y - h, z);
glTexCoord2f(1.0f, 0.0f); glVertex3f(x + w, g_dwHeight - y - h, z);
glTexCoord2f(1.0f, 1.0f); glVertex3f(x + w, g_dwHeight - y,     z);
glTexCoord2f(0.0f, 1.0f); glVertex3f(x,     g_dwHeight - y,     z);
    
This is done between calls for glBegin(GL_QUADS) and glEnd(). gGetTextureID() loops through the array of available textures, looking for the proper string, and returning the OpenGL texture ID (generated from glGenTextures()). The problem here is that, no matter how many textures are added to the list, the renderer ALWAYS chooses the last-loaded texture. I am confused; should each glGenTextures() call generate a unique texture, for which the data is dependent on the call to auxDIBImageLoad()? Maybe I should be using glGenTextures() only once, allocating an array of textures? I don't know if this is a limitation of my OpenGL implementation (in Windows 2000), my video card (Voodoo3 3000 AGP), or PEBKAC. Help? MatrixCubed
http://MatrixCubed.cjb.net [edited by - MatrixCubed on June 12, 2002 5:10:40 PM]
Antorian
Antorian
I''ve got the same problem with a similar way.
So I think that in your case it comes from: gGetTextureID(szName)

The glGenTextures() procedure is well (you can use it as many times you want;until you don''t have no more memory for texture).
So the problem come from the second call to glBindTexture.
That means that it can''t get the texture and select it for the next render.
So it''s why the last loaded texture is use (because the last Bind texture is OK)
You need only to do glBindTexture(ID) with ID equal to number that is return by glGenTextures.
You don''t need a texture array.
You should simply remember the ID of the texture loaded with glGenTextures.
The effect of glBindTexture is to retrieve the texture in memory and to select it as current texture for rendering.
So don''t focus on the name of the texture but only on its ID.
Hope that can help you.

I''''m 4 & I draw
I''m 4 & I draw
MatrixCubed
MatrixCubed
PROBLEM SOLVED

Apparently the only calls you can have between glBegin() and glEnd() are:


  
glVertex
glColor
glIndex
glNormal
glTexCoord
glEvalCoord
glEvalPoint
glMaterial
glEdgeFlag


I was using glBindTexture() between glBegin() and glEnd(). Moved this outside these calls, and problem solved.

What a nightmare!!!




MatrixCubed
http://MatrixCubed.cjb.net

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.