Advertisement

tirangle strips question

Started by May 08, 2001 01:36 PM
0 comments, last by omegasyphon 23 years, 9 months ago
when i try to create an square grid using triangle strips it doesnt come out right. when i loop it like this for x=0 x<100 x+=20 for y=0y<100 y+=20 draw strips end y end x this pseudo code draws a bunch of squares with diagonals at each corner in the middle, and it draws it straight down. when i swap the for loops starting with y , it just draws the strips horizontally as if there was no y value. heres my code
  
for (y;y<100.0;y+=20.0f)
	{
		for (x;x<100.0;x+=20.0f)
		{
			glBegin(GL_TRIANGLE_STRIP);
				glVertex3f(x,y+20.0f,0.0f);
				glVertex3f(x,y,0.0f);			
				glVertex3f(x+20.0f,y+20.0f,0.0f);
			glEnd();
		}

	}
  
First off, since you only specify an X and Y to define a point, you can use glVertex2f instead of glVertex3f .

You''re only drawing the upper left triangle of each grid square rather than the whole square. Now I can''t really make out your description of what''s happening, but the code says the above.

Its almost right. What you need to do is change the order in which you draw the vertices, and add one more command. Heres the total conversion:

  ...glVertex2f(x+20.0f, y+20.0f);glVertex2f(x, y+20.0f);glVertex2f(x, y);glVertex2f(x+20.0f, y);...  


Hope that does work; it''s off the top of my head.

This topic is closed to new replies.

Advertisement