Texture problems with vertex arrays - OpenGL

Started by
4 comments, last by McGrane 11 years ago

Hey people,

Im having trouble getting my textures to display right.

5jf4JEa.png

The square in the top left is the image i am using, and as you can see, the images are coming out wrong.

The output of my program as far as i can see is in the correct format..


	Index: 1	tX: 0	tY: 0
	Index: 2	tX: 1	tY: 0
	Index: 11	tX: 1	tY: 1
	Index: 1	tX: 0	tY: 0
	Index: 11	tX: 1	tY: 1
	Index: 10	tX: 0	tY: 1
	Index: 3	tX: 0	tY: 0
	Index: 4	tX: 1	tY: 0
	Index: 13	tX: 1	tY: 1
	Index: 3	tX: 0	tY: 0
	Index: 13	tX: 1	tY: 1
	Index: 12	tX: 0	tY: 1
	Index: 5	tX: 0	tY: 0
	Index: 6	tX: 1	tY: 0
	Index: 15	tX: 1	tY: 1
	Index: 5	tX: 0	tY: 0
	Index: 15	tX: 1	tY: 1
	Index: 14	tX: 0	tY: 1
	Index: 7	tX: 0	tY: 0
	Index: 8	tX: 1	tY: 0
	Index: 17	tX: 1	tY: 1

This is my code for displaying the images.


glEnableClientState( GL_VERTEX_ARRAY );
glEnableClientState( GL_TEXTURE_COORD_ARRAY );

glVertexPointer( 3, GL_FLOAT, 0, m_vertices );
glTexCoordPointer( 2, GL_FLOAT, 0, texCoords );

glBindTexture(GL_TEXTURE_2D, m_textureOne );
glDrawElements( GL_TRIANGLES, m_ammountPoints, GL_UNSIGNED_INT, m_squareLight );
	
glDisableClientState( GL_VERTEX_ARRAY );	
glDisableClientState( GL_TEXTURE_COORD_ARRAY );

Any ideas what could be going wrong ? - as far as i can tell, the indices seem to line up with the texcoords.. But everysqure seems to be different ?

Advertisement

This is certainly not my area of expertise, but if I had to hazard a guess, I'd say that the problem lies in the vertex/texcoord ordering. If you get those things goofed up somehow it tends to make it look strange, like your example.

What have you got in those two arrays (m_vertices, texCoords)?

My Games -- My Music 

Come join us for some friendly game dev discussions over in XNA Chat!

Does OpenGL do tex coords by the order of the vertex or the order of the indices? The m_vertices is just the x and z coords of the board..


int counter = 0;
for( float z = 0.0f; z < 90.0f; z+= 10 ) {
    for( float x = 0.0f; x < 90.0f; x+= 10 ) {
	m_vertices[counter]   =    x;	
	m_vertices[counter+1] = 0.0f;	
	m_vertices[counter+2] =   -z;
	counter+=3;
    }	
}

and the tex coords are worked out as..


	for( int i = 0; i < m_ammountPoints; i += 12 ) {
		m_texCoords   = 0.0f; m_texCoords[i+1] = 0.0f; 
		m_texCoords[i+2] = 1.0f; m_texCoords[i+3] = 0.0f;
		m_texCoords[i+4] = 1.0f; m_texCoords[i+5] = 1.0f;

		m_texCoords[i+6]  = 0.0f; m_texCoords[i+7]  = 0.0f;
		m_texCoords[i+8]  = 1.0f; m_texCoords[i+9]  = 1.0f;
		m_texCoords[i+10] = 0.0f; m_texCoords[i+11] = 1.0f;
	}

I understand that the order messes this up.. but from the output i was reading above - where index is the index of the point drawn, and tX being the texture X and ty being the texture Y, and it being drawn in the order..

----3

/

1...2

then

3...2

/

1...

I think the ordering makes sence, unless i miss understand what way its ordered :S

Do things like this... http://www.opengl.org/wiki/VBO_-_just_examples

I could be mistaken but I think Vertex and TexCoords are linked together such that index n will reference the vertex at n and the texCoord at n.

However you seem to be trying to reference the vertex at n but reference the texCoord at count.

Yea, perfect, it is done like that smile.png Thanks for the help !

VeFjeif.png

This topic is closed to new replies.

Advertisement