Vertex Arrays problem with rendering correctly

Started by
14 comments, last by MARS_999 20 years, 8 months ago
the tex coords need to be in exactly the same order as your vertices. it might be easier/safer to handle them in the same loop as your vertices.

and the way you increase z i would really use a while loop instead. changing your counter variable all over the place will just result in confusion.
f@dzhttp://festini.device-zero.de
Advertisement
Do you mean my indices array or the vertex array? I am assuming you mean indicies beings that is the order in which the vertex data is going to be called correct?
hehe, that depends on how to look at it.
if you have vertices in your vertex array like this
0 1 2 3 4 5

then the tex coords for them should also be
0 1 2 3 4 5

if they already are in the same order try to write a few lines down. are you still line by line left to right? because then for the first line you should NOT change the "y" of your texcoords, as the first line obviously is supposed to be the top edge of the texture. only your x should alternate every single step, y should only change with each line.
f@dzhttp://festini.device-zero.de
quote:Original post by Trienco
hehe, that depends on how to look at it.
if you have vertices in your vertex array like this
0 1 2 3 4 5

then the tex coords for them should also be
0 1 2 3 4 5

if they already are in the same order try to write a few lines down. are you still line by line left to right? because then for the first line you should NOT change the "y" of your texcoords, as the first line obviously is supposed to be the top edge of the texture. only your x should alternate every single step, y should only change with each line.


Ok here is what I got. I have texturing going on now but for some reason it looks wrong?

//fill indices array with alignment for processing vertex array datafor(z = 0; z < MAP_Z - 1; z++)	{		for(x = 0; x < MAP_X; x++)		{			current_vertex = z * MAP_X + x;			indices[index++] = current_vertex;			indices[index++] = current_vertex + MAP_X;		}	}//fill texture vertex array	for(z = 0; z < MAP_Z; z++)	{		for(x = 0; x < MAP_X; x++)		{			tex_coord[z][x].x = float(x % 2);			tex_coord[z][x].y = float(z % 2);		}	}	CalNormal();	glVertexPointer(3, GL_FLOAT, 0, terrain);	glTexCoordPointer(2, GL_FLOAT, 0, tex_coord);	glEnableClientState(GL_VERTEX_ARRAY);	glEnableClientState(GL_TEXTURE_COORD_ARRAY);


Is that correct? In the texture array each element

tex_coord[0][0].x = 0.0f
tex_coord[0][0].y = 0.0f
tex_coord[0][1].x = 1.0f
tex_coord[0][1].y = 0.0f
tex_coord[0][2].x = 0.0f
tex_coord[0][2].y = 0.0f
tex_coord[0][3].x = 1.0f
tex_coord[0][3].y = 0.0f

then when I goto 2nd row
tex_coord[1][0].x = 0.0f
tex_coord[1][0].y = 1.0f
tex_coord[1][1].x = 1.0f
tex_coord[1][1].y = 1.0f
tex_coord[1][2].x = 0.0f
tex_coord[1][2].y = 1.0f
tex_coord[1][3].x = 1.0f
tex_coord[1][3].y = 1.0f

is that a correct algorithm?

Ok, now I got it to work. Trienco is right about 0,1,2,3 ect.. But I didn''t understand it at first and still don''t? Why would I give texture coordinates of 0,1,2,3,4 instead of the texture coordinates that you give glTexCoord2f(0.0f, 0.0f); glTexCoord2f(0.0f, 1.0f); ect... I don''t understand how OpenGL can take texture coordnate 0,255 and use it like 0.0f, 1.0f? Thanks for the help so far and now I got the texturing up and running but still am confused.
if you set the mode to repeat, then 21 is the same as 0 (and 1), 21.5 is the same as 0.5

the difference is simple: you have every vertex only once, while in immediate mode you could give the same vertex with different texcoords. but obviously one vertex cant have two values and opengl doesnt have a crystal ball telling it that you want it to be 1 for the quad you just did and 0 for the next quad youre doing.
f@dzhttp://festini.device-zero.de

This topic is closed to new replies.

Advertisement