🔒 Locked
Texturing triangle fans problem
Advertisement
Original Post
hello, after a long fight with texturing my terrain made out of triangle fans, I surrender. Anyone knows the reason for such buggy texture mapping (look at picture)? http://i13.tinypic.com/543ss54.jpg
My terrain is a 289x289 heightmap, divided into 289 17x17 patches. Here's the temporary terrain rendering code... (mesh is rendered correctly, only texturing isn't working)
texture size is 289x289, I want it to be stretched across the whole terrain
EDIT: Lod is integer value equal to 3/5/9 depending on my level of detail needs
texture size is 289x289, I want it to be stretched across the whole terrain
for (int pZ=0;pZ<289;pZ+=16) { for (int pX=0;pX<289;pX+=16) { for (int fZ=pZ+(lod-1)/2;fZ<pZ+17;fZ+=(lod-1)) { for (int fX=pX+(lod-1)/2;fX<pX+17;fX+=(lod-1)) { glBegin(GL_TRIANGLE_FAN); RenderVertex(fX, fZ); RenderVertex((fX-(lod-1)/2), (fZ-(lod-1)/2)); RenderVertex(fX, (fZ-(lod-1)/2)); RenderVertex((fX+(lod-1)/2), (fZ-(lod-1)/2)); RenderVertex((fX+(lod-1)/2), fZ); RenderVertex((fX+(lod-1)/2), (fZ+(lod-1)/2)); RenderVertex(fX, (fZ+(lod-1)/2)); RenderVertex((fX-(lod-1)/2), (fZ+(lod-1)/2)); RenderVertex((fX-(lod-1)/2), fZ); RenderVertex((fX-(lod-1)/2), (fZ-(lod-1)/2)); glEnd(); } } } }void CTerrain::RenderVertex(int x, int z){ float tX, tZ; tX = (x/289); tZ = (z/289); glTexCoords2f(tX, tZ); glVertex3f(x*TileSize, GetTrueHeightAtPoint(x, z), z*TileSize);};EDIT: Lod is integer value equal to 3/5/9 depending on my level of detail needs
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);and it was doing fine when my terrain was based off triangle strips :|
But what address mode are you using? Do you make the following calls:
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
somewhere in your code? If you're not then add them, and try setting the last parameter to GL_REPEAT.
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
somewhere in your code? If you're not then add them, and try setting the last parameter to GL_REPEAT.
Setting it to REPEAT didn't change anything, but when I set it to CLAMP, everything that was solid green on the screenshot, became black, while the rest remained same
hmm after some changes, I made it work, problem solved but...
interesting
is there some rule, that you can't bind/change rendering modes AFTER glBegin but BEFORE any glVertex calls? because this:
doesn't show the texture, yet if I move the Enable and BindTexture before glBegin() it works flawlessly?
interesting
is there some rule, that you can't bind/change rendering modes AFTER glBegin but BEFORE any glVertex calls? because this:
{ glDisable(GL_TEXTURE_2D); glBegin(GL_TRIANGLE_FAN); RenderVertex()}void CTerrain::RenderVertex(int x, int z){ float tX, tZ; tX = (1.0*x/289.0); tZ = (1.0*z/289.0); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, grass.ID); glTexCoord2f(tX, tZ); glVertex3f(x*TileSize, GetTrueHeightAtPoint(x, z)*0.01, z*TileSize); verts++;};doesn't show the texture, yet if I move the Enable and BindTexture before glBegin() it works flawlessly?
Quote:
Original post by AndyEsser
You can't have glEnable() or glBindTexture between glBegin or glEnd. In fact I believe the only calls you can have are for vertex,texture and normal functions.
From the manpages:
Quote:
Only a subset of GL commands can be used between glBegin and glEnd. The commands are glVertex, glColor, glIndex, glNormal, glTexCoord, glEvalCoord, glEvalPoint, glArrayElement, glMaterial, and glEdgeFlag. Also, it is acceptable to use glCallList or glCallLists to execute display lists that include only the preceding commands. If any other GL command is executed between glBegin and glEnd, the error flag is set and the command is ignored.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement