sceGuDrawArray - Different behavior when using LINE_STRIP...

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
lagwagon666
Posts: 4
Joined: Sun Aug 20, 2006 5:34 am

sceGuDrawArray - Different behavior when using LINE_STRIP...

Post by lagwagon666 »

...instead of GU_TRIANGLE_FAN?

Hello, I use the sceGuDrawArray()-Function with GU_TRIANGLE_FAN from PSPSDK to draw filled rectangles on the screen. However, I found out that when I use the GU_LINE_STRIP primitive, the edges of my rectangle differ, for a better understanding here is some sample code:

Code: Select all

Vertex* square = (Vertex*)sceGuGetMemory(5 * sizeof(Vertex));	    
if(square==NULL) return -1;
		
square[0].x=10;
square[0].y=10;
			
square[1].x=59;
square[1].y=10;
		
square[2].x=59;
square[2].y=59;
		
square[3].x=10;
square[3].y=59;
		
square[4].x=10;
square[4].y=10;
		
int i;
		
for&#40;i=0;i<5;i++&#41; square&#91;i&#93;.color=0xFF00FF00;

sceGuDrawArray&#40;GU_LINE_STRIP,GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_2D,5,NULL,square&#41;;
		
for&#40;i=0;i<5;i++&#41; square&#91;i&#93;.color=0xFFFFFFFF;

sceGuDrawArray&#40;GU_TRIANGLE_FAN,GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_2D,5,NULL,square&#41;;
this code creates an array of 5 vertexes, which defines a square which has a side-length of exactly 50 pixels. However the first call of sceGuDrawArray does draws an empty square with a green border and an side length of exactly 50 pixels but the second call using the GU_TRIANGLE_FAN prim. is a little smaller so on the left, the right and the bottom there seems a single pixel row to be missing. This causes that you see a white solid square with a green border around. Is this correct behaviour caused by the TRIANGLE_FAN primitive or is this a bug? How do draw filled rectangles with a specified size?

Thanks for your help

Dave-O
Aion
Posts: 40
Joined: Mon Jul 24, 2006 10:58 pm
Location: Montreal

Post by Aion »

TRIANGLE_FAN and LINE_STRIP are very different.

LINE_STRIP creates a serie of dot all connected together.

TRIANGLE_FAN create a serie of filled triangles, all sharing 1 vertex, the 1st one. Look at picture (B) to get an idea. Image
So, you last triangle ends up being of width 0, because it has those coordinates (10,10) (10,59) (10,10). Also, because your drawing them counter-clock wise, they won't be rendered if backface culling is enabled.

In this instance, only draw 4 vertex and it should work fine. You should also try to do some research on the basic vertex drawing methods to fully understand them.
User avatar
Raphael
Posts: 646
Joined: Tue Jan 17, 2006 4:54 pm
Location: Germany
Contact:

Re: sceGuDrawArray - Different behavior when using LINE_STRI

Post by Raphael »

lagwagon666 wrote:using the GU_TRIANGLE_FAN prim. is a little smaller so on the left, the right and the bottom there seems a single pixel row to be missing. This causes that you see a white solid square with a green border around. Is this correct behaviour caused by the TRIANGLE_FAN primitive or is this a bug? How do draw filled rectangles with a specified size?

Thanks for your help

Dave-O
This is correct behaviour of every good rasterizer, due to filling conventions on the rasterization of triangles. It's to prevent drawing common pixels between connected triangles twice, because it would be visible with blending enabled (and also some performance gain).
So if you want to draw a filled rectangle with width x and height y, you'd need to place the rightmost and the bottommost vertex at x+1/y+1.

Regards
<Don't push the river, it flows.>
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki

Alexander Berl
lagwagon666
Posts: 4
Joined: Sun Aug 20, 2006 5:34 am

Post by lagwagon666 »

thx for your replies...
Aion wrote: TRIANGLE_FAN create a serie of filled triangles, all sharing 1 vertex, the 1st one [...] So, you last triangle ends up being of width 0
I understand what you mean, but this doesn't seem to be the behaviour of TRIANGLE_FAN because, in this case, my code wouldn't draw in fact an square, wouldn't it? If I got you right, my code should draw an triangle and an line with an width of 0 pixels what in fact ain't visible.
Raphael wrote:So if you want to draw a filled rectangle with width x and height y, you'd need to place the rightmost and the bottommost vertex at x+1/y+1.
That has been the workaround I used. Thanks for your explanations.

Dave-O.
Aion
Posts: 40
Joined: Mon Jul 24, 2006 10:58 pm
Location: Montreal

Post by Aion »

lagwagon666 wrote:thx for your replies...
Aion wrote: TRIANGLE_FAN create a serie of filled triangles, all sharing 1 vertex, the 1st one [...] So, you last triangle ends up being of width 0
I understand what you mean, but this doesn't seem to be the behaviour of TRIANGLE_FAN because, in this case, my code wouldn't draw in fact an square, wouldn't it? If I got you right, my code should draw an triangle and an line with an width of 0 pixels what in fact ain't visible.
Not at all.
Your Vertex 1-3 will create a right angle triangle.
Your Vertex 4 will then creates a second right angle triangle which form your rectangle
Your Vertex 5 creates a line on top that basicly erases 1 pixel of your rectangle because of what Raphael mentionned.
Post Reply