[OT] Texturing an indexed triangle mesh in OpenGL
TheDustbustr
thedustbustr at aol.com
Sun May 11 19:16:43 EDT 2003
My renderer is written in python, and thats about all this has to do with this
newsgroup, hence the [OT]
This one has been bugging me forever, and nobody seems to know the answer (not
even google!) Once I have created a triangle mesh, what is the best way to
texture it (with potentially different textures for each triangle)? My current
method, when used with a medium sized mesh (8000 triangles), yeilds me 40
frames per second (I have a Geforce 4)- I should be getting about 200.
glVertexPointerf(VertexArray)
prevtexture=""
for ind_i in range(0, len(IndiceArray), 3):
if (VertexArray[int(IndiceArray[ind_i])][1] <= 0) and (prevtexture
!= "data/water-0.bmp"):
glBindTexture(GL_TEXTURE_2D,
ResourceMgr().get("data/water-0.bmp"))
prevtexture="data/water-0.bmp"
elif (VertexArray[int(IndiceArray[ind_i])][1] > 3 and
VertexArray[int(IndiceArray[ind_i])][1] <= 10) and (prevtexture !=
"data/grass-0.bmp"):
glBindTexture(GL_TEXTURE_2D,
ResourceMgr().get("data/grass-0.bmp"))
prevtexture="data/grass-0.bmp"
elif (VertexArray[int(IndiceArray[ind_i])][1] > 0 and
VertexArray[int(IndiceArray[ind_i])][1] <= 3) and (prevtexture !=
"data/dirt-0.bmp"):
glBindTexture(GL_TEXTURE_2D,
ResourceMgr().get("data/dirt-0.bmp"))
prevtexture="data/dirt-0.bmp"
glBegin(GL_TRIANGLES)
glArrayElement(IndiceArray[ind_i])
glArrayElement(IndiceArray[ind_i+1])
glArrayElement(IndiceArray[ind_i+2])
glEnd()
IndiceArray is sorted by texture, so glBindTexture should only be called once
per texture per frame (in this case, 3 times per frame). Is there a better way
to do this?
If I render the terrain with just one tiled texture, I get roughly 120 frames
per second.
More information about the Python-list
mailing list