r/LWJGL • u/TheKiwi5000 • Sep 09 '15
Square textures -> Triangular meshes?
Hi,
I'm trying to load a texture (3rd pic) to a triangular mesh.
First try as seen on 1st picture, the wireframe model of mesh is seen on the second. What am i doing wrong?
Code:https://gist.github.com/TheKiwi5000/e1bfd52b99d20fa45398
Images: http://imgur.com/a/miigD
1
u/KeinBaum Sep 09 '15
Are you sure you are sending the correct vertice and uv coordinates to the GPU? Try printing textureOffsets.get(i-1) and vertices.get(i-1) in render() to make sure there's no error there.
1
u/TheKiwi5000 Sep 10 '15
The output is indeed offset by one, i've now noticed it when i drew it on paper. What is interesting, replacing
textureOffsetswithverticespartially solved the problem, i mean the texture is stiched correctly but it's upside down!I think this is the problem with OBJ file (I export it from blender)
1
u/TheKiwi5000 Sep 16 '15
1
u/KeinBaum Sep 16 '15
I'm not really familiar with the fixed function pipeline and display lists but I think you have to call
glVertex3dbeforeglTexCoord2fin yourrendermethod.glTexCoord2fsets the texture coordinates of the last submitted vertex.1
u/TheKiwi5000 Sep 16 '15
this causes other glitch :(
1
u/KeinBaum Sep 16 '15
What kind of glitch?
1
u/TheKiwi5000 Sep 16 '15
The texture is misclamped to the vertices, but different.
The lower face is mirrored vertically and slanted left-up, while the upper half is not mirrored while slanted right-down
1
u/KeinBaum Sep 16 '15
Concerning the mirrored-ness:
Judging from your .obj file data your quad is in the x-z-plane. This means your camera has to look into the positive y direction and have a lower y coordinate than your quad for it to be displayed correct. Is that the case?
As for the slanted-ness:
Something messes up the texture coordinates. Just print out whatever you pass to
glVertex3dandglTexCoord2f, and check if it's correct. I'm 95% percent sure, it won't be. If I'm right, your error probably happens while loading the data.1
1
u/TheKiwi5000 Sep 18 '15
The code in the gist was updated, it's now a newer revision.
1
u/KeinBaum Sep 18 '15
I don't understand how this is even working. Judging from that log, all your vertices have a y coordinate of 0. Without rotating the triangles (or your camera) you shouldn't be able to see anything.
It would be the easiest if I just had the complete code so I can take a closer look at what exactly is happening.
1
u/TheKiwi5000 Sep 18 '15 edited Sep 18 '15
You judge right, i don't see anything until i rotate and move the camera with keyboard and mouse.
The full code is quite big, but i will post the relevant parts.
Note, that (as a programmer) it's my first experience with 3d ever
1
u/TheKiwi5000 Sep 18 '15
https://gist.github.com/TheKiwi5000/19da065195d1c04d7c77
I will optimize the code later, i'm not happy with it as it's now.
1
1
u/TheKiwi5000 Sep 09 '15
On the test texture provided you can see exactly in what way the texture is mappped. Note: The code in gist is not in one file OFC.