Jump to content

  • Log In with Google      Sign In   
  • Create Account

Texture problems with vertex arrays - OpenGL


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 McGrane   Members   -  Reputation: 1090

Like
0Likes
Like

Posted 26 March 2013 - 08:42 AM

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 ?



Sponsor:

#2 Jutaris   Members   -  Reputation: 475

Like
0Likes
Like

Posted 26 March 2013 - 03:01 PM

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 Site -- My Music  -- My Ramblings -- My Game

 Basic Flying Rules:Try to stay in the middle of the air. Do not go near the edges of it. The edges of the air can be recognized by the appearance of ground, buildings, sea, trees and interstellar space. It is much more difficult to fly there.

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


#3 McGrane   Members   -  Reputation: 1090

Like
0Likes
Like

Posted 26 March 2013 - 05:21 PM

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[i]   = 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


Edited by McGrane, 26 March 2013 - 05:22 PM.


#4 jellyfishchris   Members   -  Reputation: 300

Like
0Likes
Like

Posted 26 March 2013 - 08:13 PM

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



#5 stannic   Members   -  Reputation: 173

Like
1Likes
Like

Posted 26 March 2013 - 10:11 PM

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.



#6 McGrane   Members   -  Reputation: 1090

Like
0Likes
Like

Posted 27 March 2013 - 11:34 AM

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

 

VeFjeif.png






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS