Sign in to follow this  
Steve00000

Theres texture distortion on my cube : (

Recommended Posts

Steve00000    122
Hi, I'm trying to draw a texture on a large cube. The cube is loaded from a .vtx model file which is made with anim8or.

When the cube is drawn only two faces on the cube are displayed correctly. The sides of the cube that are not drawn correctly are distorted and look as though they have been stretched from the correctly drawn sides edge to other. This is the code that is meant to draw the cube:

          // 1 based array
glBindTexture(GL_TEXTURE_2D, texture(1));
glBegin(GL_TRIANGLES);//);GL_TRIANGLES
for(int iter = 0; iter < cubesy.index().size(); iter++) // 36 indices, 24 vertices
{
int index = cubesy.index()[iter];
const cvertex& vertref = cubesy.vertex()[index];
const point3<short>& normref = cubesy.normal()[index];

glNormal3s(normref.x, normref.y, normref.z);
glTexCoord2s(vertref.u, vertref.v);
glVertex3f(vertref.x, vertref.y, vertref.z);
}
glEnd();





here is the data from the vtx file


// mesh01
// 24 vertices
// NOTE: first 3 are a vertex, second 3 are a normal, last 2 are a tex coord
.Vertex
-4.13221 -4.71958 -4.71959 0 0 -1 0 0
5.30695 -4.71958 -4.71959 0 0 -1 1 0
5.30695 4.71957 -4.71959 0 0 -1 1 1
-4.13221 4.71957 -4.71959 0 0 -1 0 1
5.30695 -4.71958 4.71957 0 0 1 1 0
-4.13221 -4.71958 4.71957 0 0 1 0 0
-4.13221 4.71957 4.71957 0 0 1 0 1
5.30695 4.71957 4.71957 0 0 1 1 1
5.30695 -4.71958 -4.71959 1 0 0 1 0
5.30695 -4.71958 4.71957 1 0 0 1 0
5.30695 4.71957 4.71957 1 0 0 1 1
5.30695 4.71957 -4.71959 1 0 0 1 1
-4.13221 4.71957 -4.71959 0 1 0 0 1
5.30695 4.71957 -4.71959 0 1 0 1 1
5.30695 4.71957 4.71957 0 1 0 1 1
-4.13221 4.71957 4.71957 0 1 0 0 1
-4.13221 -4.71958 -4.71959 -1 0 0 0 0
-4.13221 4.71957 -4.71959 -1 0 0 0 1
-4.13221 4.71957 4.71957 -1 0 0 0 1
-4.13221 -4.71958 4.71957 -1 0 0 0 0
-4.13221 -4.71958 -4.71959 0 -1 0 0 0
-4.13221 -4.71958 4.71957 0 -1 0 0 0
5.30695 -4.71958 4.71957 0 -1 0 1 0
5.30695 -4.71958 -4.71959 0 -1 0 1 0
// end of .Vertex

// 12 faces
.Index
0 1 2 -1
0 2 3 -1
4 5 6 -1
4 6 7 -1
8 9 10 -1
8 10 11 -1
12 13 14 -1
12 14 15 -1
16 17 18 -1
16 18 19 -1
20 21 22 -1
20 22 23 -1
// end if .Index





The source that I read about how to read from this file format said to draw as triangles, which is being done of course. However maybe I'm doing something wrong, even tho I did check that the data is being read in properly, and the drawing routine has the right stuff at the right time. Anyways for anyone who helps me, Thx : )

Share this post


Link to post
Share on other sites
karwosts    840
Your source data looks like garbage to me. If you look at the indices it is making a square out of every 4 vertices. If you break them out and look at the UV's for the individual faces, they look wrong.


Face 1:
0 1 2 -1
0 2 3 -1

0: -4.13221 -4.71958 -4.71959 0 0 -1 0 0
1: 5.30695 -4.71958 -4.71959 0 0 -1 1 0
2: 5.30695 4.71957 -4.71959 0 0 -1 1 1
3: -4.13221 4.71957 -4.71959 0 0 -1 0 1
// ok so far....

Face 2:
4 5 6 -1
4 6 7 -1
4: 5.30695 -4.71958 4.71957 0 0 1 1 0
5: -4.13221 -4.71958 4.71957 0 0 1 0 0
6: -4.13221 4.71957 4.71957 0 0 1 0 1
7: 5.30695 4.71957 4.71957 0 0 1 1 1
//still looking fine....

Face 3:
8 9 10 -1
8 10 11 -1

8: 5.30695 -4.71958 -4.71959 1 0 0 1 0
9: 5.30695 -4.71958 4.71957 1 0 0 1 0
10: 5.30695 4.71957 4.71957 1 0 0 1 1
11: 5.30695 4.71957 -4.71959 1 0 0 1 1
//incorrect!

If you look at the texcoords for this face, they are (1,0) (1,0) (1,1) (1,1). This is wrong for a square. I haven't gone through the rest of the faces but I'd bet they are the same.

Share this post


Link to post
Share on other sites
Steve00000    122
I found that blender does not come ready with .vtx output. I did try to change some of the source data in my first post, and got *more correct results. Because of this odd situation, if ppl wouldn't mind suggesting a file format that blender comes ready with output for and providing a link to the format specs I'd be really greatful. I had a look at a few of the formats but couldn't find much info on em. I was being kinda picky I guess cause I wanted tex coords and vertex data together, but I thought the 3ds format looked interesting, but I didn't find a resource for its specs.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this