forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

sceGuDrawArray - Different behavior when using LINE_STRIP...

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
lagwagon666



Joined: 20 Aug 2006
Posts: 4

PostPosted: Sun Aug 20, 2006 5:51 am    Post subject: sceGuDrawArray - Different behavior when using LINE_STRIP... Reply with quote

...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:
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(i=0;i<5;i++) square[i].color=0xFF00FF00;

sceGuDrawArray(GU_LINE_STRIP,GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_2D,5,NULL,square);
      
for(i=0;i<5;i++) square[i].color=0xFFFFFFFF;

sceGuDrawArray(GU_TRIANGLE_FAN,GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_2D,5,NULL,square);


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
Back to top
View user's profile Send private message
Aion



Joined: 24 Jul 2006
Posts: 40
Location: Montreal

PostPosted: Sun Aug 20, 2006 7:26 am    Post subject: Reply with quote

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.
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.
Back to top
View user's profile Send private message
Raphael



Joined: 17 Jan 2006
Posts: 646
Location: Germany

PostPosted: Sun Aug 20, 2006 6:41 pm    Post subject: Re: sceGuDrawArray - Different behavior when using LINE_STRI Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
lagwagon666



Joined: 20 Aug 2006
Posts: 4

PostPosted: Tue Aug 22, 2006 6:38 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Aion



Joined: 24 Jul 2006
Posts: 40
Location: Montreal

PostPosted: Tue Aug 22, 2006 7:16 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group