Vertex array/indices problem?

Started by
2 comments, last by Sirveaux 20 years, 9 months ago
I am having trouble generating a vertex array and the indices for it. From what I can tell, my algorithm works right, though. I am trying to create a vert array for a 10x10 grid and then use the indices to point to them and get them to make a grid of 9x9 quads. Is there a mistake in my calculates or am I doing the wrong format? Maybe it's something with my calls to glVertexPointer or glDrawElements that is the problem?

	
        i=0;
	for (vy=0;vy<10;vy++)
	{
		for (vx=0;vx<10;vx++)
		{
			vertices[i] = (float)vx;
			vertices[i+1] = (float)vy;
			vertices[i+2] = 0.0;
			i+=3;
		}
	}

	for (i=0;i<(9*9*4);i+=4);
	{
		indices[i] = (i/4);
		indices[i+1] = (i/4)+1;
		indices[i+2] = (i/4) + 1 + 10;
		indices[i+3] = (i/4) + 10;
	}

...snip...

//These are how my calls to actually display the data look:

      	glVertexPointer ( 3, GL_FLOAT, 0, &vertices );
	glDrawElements  ( GL_QUADS, (9*9*4), GL_UNSIGNED_INT, indices );

Advertisement
Em, what EXACTLY is your problem?

However, this might help (it worked for me):

glDrawElements ( GL_QUADS, (9*9*4), GL_UNSIGNED_BYTE, indices );



[edited by - Wingman on July 8, 2003 11:07:49 AM]
I can''t get it to display at all. So using my algorithm it works fine for you? Maybe I''m just not doing something right with my transformations to get it into view then. Hmm... I''ll try it as a byte instead of an int and see if that helps any.
Okay. I see the problem with my indices loop. When it gets to the end of the grid (point #10 since it is a 10x10 grid), it tries to link the end points with the points at the beginning. It ends up trying to make a quad out of (9,0), (0,1), (0,2), and (9,1). Not what I''m going for at all. I''m not sure how to make it skip that end attempt at forming a quad, though.

I hope this makes a tiny bit of sense. It''s hard to demonstrate what is happening without a diagram or something. Heheh.

This topic is closed to new replies.

Advertisement