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 

Can't get gouraud shaded triangles to work

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



Joined: 05 Jun 2008
Posts: 7

PostPosted: Thu Apr 01, 2010 6:27 pm    Post subject: Can't get gouraud shaded triangles to work Reply with quote

Hey guys,
I recently began to play around with the ps2, which is really fun...but I've run in some troubles.
How the hell can I draw gouraud shaded triangles? I thought it would be a simple matter of setting the right bit in the PRIM register and giving each vertex a different color...turns out it seems to be much harder than I thought.
My code is roughly based on the tutorial by dreamtime, to which I put a link at the end because the one on the main page is dead.
It looks like this:
Code:

GIF_BEGIN_PACKET(gs_dma_buf);
GIF_TAG(gs_dma_buf, 1, 1, 0, 0, 1, 8,   
    (PRIM<<0)  |
    (RGBAQ<<4) |
    (XYZ2<<8)  |
    (RGBAQ<<12)|
    (XYZ2<<16) |
    (RGBAQ<<20)|
    (XYZ2<<24) |
    (GIF_NOP<<28));
gs_dma_buf[gs_dma_buf_cur++] = GS_PRIM(PRIM_TRI, 1, 0, 0, 0, 0, 0, 0, 0);
gs_dma_buf[gs_dma_buf_cur++] = GS_RGBAQ(255, 0, 0, 0, 0);
gs_dma_buf[gs_dma_buf_cur++] = GS_XYZ(x1<<4, y1<<4, 0);
gs_dma_buf[gs_dma_buf_cur++] = GS_RGBAQ(0, 255, 0, 0, 0);
gs_dma_buf[gs_dma_buf_cur++] = GS_XYZ(x2<<4, y2<<4, 0);
gs_dma_buf[gs_dma_buf_cur++] = GS_RGBAQ(0, 0, 255, 0, 0);
gs_dma_buf[gs_dma_buf_cur++] = GS_XYZ(x3<<4, y3<<4, 0);
gs_dma_buf[gs_dma_buf_cur++] = 0;
gs_dma_buf_size = 5;
GIF_SEND_PACKET(gs_dma_buf);

I also tried using A+D Packets and even used working "magic numbers" from gsKit, alas with no success. The triangle is always blue (i.e. the last color I specified).
I really have no idea what could be the problem, the macros are correct, the information is also correct...could it be anything in the initialization routine? Do I have to set up another register properly?
Please give me a hint what could be wrong...

http://aap.papnet.eu/ps2tut_01.zip

Edit: fixed code


Last edited by aap on Thu Apr 01, 2010 6:48 pm; edited 1 time in total
Back to top
View user's profile Send private message
ragnarok2040



Joined: 09 Aug 2006
Posts: 230

PostPosted: Thu Apr 01, 2010 6:40 pm    Post subject: Reply with quote

It looks like you don't have the GS_PRIM register setting prior to the vertex data in your packet which might be setting your first RGBAQ data into the PRIM register. You should also set the NOP register data to 0 and advance your gs_dma_buf_cur index, just so you make sure you don't use up that data slot in the packet accidentally in case you change it in the future.
Back to top
View user's profile Send private message
aap



Joined: 05 Jun 2008
Posts: 7

PostPosted: Thu Apr 01, 2010 6:52 pm    Post subject: Reply with quote

Oh, sorry, I forgot to copy that (my code is a mess with huge blocks in comments).
Fixed it, should be correct now...but still doesn't work.
Back to top
View user's profile Send private message
ragnarok2040



Joined: 09 Aug 2006
Posts: 230

PostPosted: Thu Apr 01, 2010 6:59 pm    Post subject: Reply with quote

Maybe the primitive override is enabled. Try setting PRMODECONT to 1 to turn it off. Or add a PRMODE setting after the PRIM setting, it uses the same GS_PRIM() macro, except it doesn't set the type. You'll need to set it whenever you want to change a primitive's attributes, though.
Back to top
View user's profile Send private message
aap



Joined: 05 Jun 2008
Posts: 7

PostPosted: Thu Apr 01, 2010 7:07 pm    Post subject: Reply with quote

Woah, thank you. That's the solution :)
I knew it was a simple matter of setting some bits in some register, I just didn't know which one :P
Cool, thanks, that was a quick answer :)
Back to top
View user's profile Send private message
ragnarok2040



Joined: 09 Aug 2006
Posts: 230

PostPosted: Thu Apr 01, 2010 7:21 pm    Post subject: Reply with quote

No problem, :D.

It's still fresh in my mind because of the new libdraw implementation.
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 -> PS2 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