|
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
View previous topic :: View next topic |
Author |
Message |
aap
Joined: 05 Jun 2008 Posts: 7
|
Posted: Thu Apr 01, 2010 6:27 pm Post subject: Can't get gouraud shaded triangles to work |
|
|
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 |
|
|
ragnarok2040
Joined: 09 Aug 2006 Posts: 230
|
Posted: Thu Apr 01, 2010 6:40 pm Post subject: |
|
|
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 |
|
|
aap
Joined: 05 Jun 2008 Posts: 7
|
Posted: Thu Apr 01, 2010 6:52 pm Post subject: |
|
|
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 |
|
|
ragnarok2040
Joined: 09 Aug 2006 Posts: 230
|
Posted: Thu Apr 01, 2010 6:59 pm Post subject: |
|
|
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 |
|
|
aap
Joined: 05 Jun 2008 Posts: 7
|
Posted: Thu Apr 01, 2010 7:07 pm Post subject: |
|
|
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 |
|
|
ragnarok2040
Joined: 09 Aug 2006 Posts: 230
|
Posted: Thu Apr 01, 2010 7:21 pm Post subject: |
|
|
No problem, :D.
It's still fresh in my mind because of the new libdraw implementation. |
|
Back to top |
|
|
|
|
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
|