Archived

This topic is now archived and is closed to further replies.

Vertex array/indices problem?

This topic is 5273 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 );

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites