PDA

View Full Version : Polygon fill problem

razorsese
04-27-2011, 10:30 AM
I need some help whit the following code:

glBegin(GL_TRIANGLE_STRIP);

for(i=0;i<16;i++)
{

for(j=0;j<16;j++)
{
glVertex3f(i,i,0);
glVertex3f(i,j,0);
glVertex3f(j,i,0);

}

}
glEnd();

It's fill the polygon correctly but when I switch from FILL mode to Lines the following problem occur:

http://img824.imageshack.us/i/38963428.jpg/

dorbie
04-27-2011, 04:11 PM
You'r drawing a lot of crap.

(i,i) (i,j) (j,i) in a nested loop?

Really?

You need to break out the graph paper. The lines have shown you what a mess your'e drawing, it's also very inefficient w.r.t wasted fill. You're hitting a LOT of pixels a LOT of times. and have random winding and other things going on due to the tristrip, it's not just triangles you're drawing, it really is a mess. You can't possibly intend to draw what this code actually produces.

The Little Body
04-27-2011, 04:19 PM
Razorsese,

You want to draw one checkerboard ?

if yes

glBegin(GL_LINES);
for(i=0;i<16;i++)
{
for(j=0;j<16;j++)
{
glVertex3f(i,j,0);
glVertex3f(i+1,j,0);

glVertex3f(i+1,j,0);
glVertex3f(i+1,j+1,0);

glVertex3f(i+1,j+1),0);
glVertex3f(i,j+1,0);

glVertex3f(i,j+1,0);
glVertex3f(i,j,0);
}
}
glEnd();

MaxH
04-27-2011, 06:47 PM
You'r drawing a lot of crap.
Hee hee :)

That's what I felt like saying, but didn't dare.

The Little Body
04-27-2011, 06:58 PM
Or if you want filled quads :

for(i=0;i<16;i++)

{

for(j=0;j<16;j++)

{

glVertex3f(i/8,j/8,0);

// glVertex3f((i+1)/8,j/8,0);

glVertex3f((i+1)/8,j/8,0);

// glVertex3f((i+1)/8,(j+1)/8,0);

glVertex3f((i+1)/8,(j+1)/8,0);

// glVertex3f(i/8,(j+1)/8,0);

glVertex3f(i/8,(j+1)/8,0);

// glVertex3f(i/8,j/8,0);

}

}

glEnd();

(the /8 is here because I use a old framework that doesn't have the good view transformation matrix so it can be deleted)

razorsese
04-28-2011, 07:14 AM
I want to draw something like this:
(Whit triangle_strip)
http://img90.imageshack.us/i/flatjpg.jpg/

dorbie
04-28-2011, 12:05 PM
I want to draw something like this:
(Whit triangle_strip)
http://img90.imageshack.us/i/flatjpg.jpg/

Then the post immediately above yours is the answer.

I do encourage you to look at vertex issue order and the primitives you are rendering until you gain some insight into the correct vertex issue order. I wasn't joking when I said break out the graph paper, it will help.

This is a key thing to understand when drawing meshes.

dorbie
04-28-2011, 12:09 PM
P.S. that post draws quads, but I also encourage you to get tristrip rendering working. Your vertex issue order for triangle strips in a 16x16 grid of vertices is:

0, 17, 1, 18, 2, 19,......... 15, 31, 31, 17, 17, 33, 18, 34.... etc.

I have shown the two degenerate triangles for the row change to issue all these as a single strip, (the 31,31,17,17).

Remember if you have 16x16 quads you have 17x17 vertices and so you'll have to alter all the numbers....

Also to reverse the face winding you can issue 17, 0, 18, 1 etc.

Good luck.

dorbie
04-28-2011, 12:25 PM
Screw it, here it is (no guarantees, this is untested):

// width and height are vertex count
#define MESH_WIDTH 16
#define MESH_HEIGHT 16

glBegin(GL_TRIANGLE_STRIP);

for(i=0;i<MESH_HEIGHT;i++)
{

for(j=0;j<MESH_WIDTH;j++)
{
// using your promotion of int to float
glVertex3f(j,i*MESH_WIDTH,0);
glVertex3f(j,(i+1)*MESH_WIDTH,0);
}
// degenerate stitching of rows
glVertex3f(j,(i+1)*MESH_WIDTH,0);
glVertex3f(0,(i+1)*MESH_WIDTH,0);

}

glEnd();

It wastes a couple of degenerates at the end but that's negligible and optimizing it would actually be slower.