Page 1 of 1

New Member - hi everyone! :D / help drawing a primitive

Posted: May 9th, 2018, 2:49 pm
by ViLXDRYAD
Hi! i'm glad to see an active ps1 development community nowadays, also with so nice members! = D

been coding on psy-q for the past two weeks and it's very fun so far!

i got lost at how to draw a primitive by using an order table, can't really understand how the process is like; i've coded some stuff in C & OpenGL as well as a demo prod for pc, and so far i can tell the concept is way more abstract lol i'd really appreciate a hint on how to draw a primitive if possible :D

aside that, i can't wait to get involved in this community, seems like a really warm family, i look forward to have fun together! x3

Re: New Member - hi everyone! :D / help drawing a primitive

Posted: May 10th, 2018, 12:04 am
by Shadow

Code: Select all

POLY_F4 pf4;

void DrawSolidTri(short x1, short y1, short x2, short y2, short x3, short y3, int r, int g, int b, int ot)
{
	// draw a solid triangle and fill it with rgb colour
	// EG: DrawSolidTri(200,0, 170,30, 230,30, 255,0,255, 0);
	// check the Psy-Q documentation for the coordinates!

	SetPolyF3(&pf3);							// initialise the primitive
	setRGB0(&pf3, r, g, b);						// set the fill colour (RGB)
	setXY3(&pf3, x1,y1, x2,y2, x3,y3);			// draw 3 lines (3 sets of x/y co-ords)
	DrawPrim(&pf3);								// copy shape to frame buffer
	//DrawPrim(&pf3);							// copy shape to frame buffer
	GsSortPoly(&pf3, &WorldOrderingTable1[CurrentBuffer], ot); // put the polygon into the order table
}


void DrawTransTri(short x1, short y1, short x2, short y2, short x3, short y3, int r, int g, int b, int ot)
{
	// draw a transparent triangle
	// the transparency 'colour' is calculated from the fgnd & bgns pixels.
	// EG: DrawTransTri(50,0, 70,60, 130,60, 255,0,255, 0);

	SetPolyF3(&pf3);							// initialize primitive
	setRGB0(&pf3, r, g, b);						// set the foreground fill colour
	setSemiTrans(&pf3, 1);						// semi-transparency; 0=off; 1=on
	setXY3(&pf3, x1,y1, x2,y2, x3,y3);			// draw 4 lines (4 sets of x/y co-ords)
	//DrawPrim(&pf3);							// copy shape to frame buffer
	GsSortPoly(&pf3, &WorldOrderingTable1[CurrentBuffer], ot); // put the polygon into the order table
}

Re: New Member - hi everyone! :D / help drawing a primitive

Posted: May 10th, 2018, 2:19 am
by ViLXDRYAD
Hii, Shadow! = D first of all thanks for your help! x3

i modified a bit the code for it to work with the order table name i had (i'm using the hello world tutorial from here: http://www.psxdev.net/help/psyq_hello_world.html as a base for this so it is easier to read)

Code: Select all

GsSortPoly(&pf3, &myOT[CurrentBuffer], ot); // put the polygon into the order table
also modified POLY_F4 pf4; to POLY_F3 pf3; and compiled just fine :D

BUT when i try to draw the triangle on the main function, the triangle gets displayed for one frame and i get a Bad Opcode error on NO$PSX, i tried to draw it using this:

Code: Select all

DrawSolidTri(0, 0, 200, 200, 0, 300, 4, 255, 4, 0);
and this is how it looks like:
Image

this is the full code:


may i ask what i am doing wrong? :C thaanks a lot, beforehand! x3

Re: New Member - hi everyone! :D / help drawing a primitive

Posted: May 10th, 2018, 2:26 am
by Shadow
Are you compiling with code optimisation enabled? If so, disable it.
Otherwise, it could be a bug in NO$PSX, so maybe just disable warnings.

Re: New Member - hi everyone! :D / help drawing a primitive

Posted: May 10th, 2018, 4:12 am
by ViLXDRYAD
thanks for your reply! :D

@code optimization enabled: i didn't knew about that; may i ask where i can disable it? = 3 i use Windows 98 SE for deving so working on NO$PSX is way more efficient than moving the exe to a newer OS to test in PCSXR :C

@a bug in NO$PSX: i went and wrote a test to see if it ran correctly on PCSXR and turns out the same exe that pops that error in NO$PSX (also tried disabling the warnings and the screen just freezes) runs as intended there:
Image

(here's the source code: also has comments)

hopefully it is that code optimization option, otherwise it is odd since NO$PSX runs the other psy-q examples using primitives D:

Re: New Member - hi everyone! :D / help drawing a primitive

Posted: May 11th, 2018, 3:28 am
by Shadow
The code optimisation is in the makefile. It's the "-O" parameter followed by level 1, 2 or 3. EG: "-O3" for level 3 optimisation.

Re: New Member - hi everyone! :D / help drawing a primitive

Posted: May 11th, 2018, 11:23 am
by Greg
Change #define PACKETMAX 50 to #define PACKETMAX 500

Re: New Member - hi everyone! :D / help drawing a primitive

Posted: May 11th, 2018, 12:08 pm
by ViLXDRYAD
thaanks for your replies! :D

@ code optimisation option in makefile: i tried erasing the -O3 in it, and still the same error :c also tried with -O1 and -O2, though thanks for this hint! i didn't knew code optimisation was a thing before! x3

@ changing #define PACKETMAX 50 to #define PACKETMAX 500: YES! this did it! +O+ it ran beautifully on NO$PSX after that! :D

thaanks you so much, Greg and Shadow for all your great help! i really appreciate it! x3 gonna make sure i put you into the greets of what i'm working into = p, it wouldn't be possible without you! = D

Re: New Member - hi everyone! :D / help drawing a primitive

Posted: May 11th, 2018, 4:28 pm
by Shadow
Greg wrote: May 11th, 2018, 11:23 am Change #define PACKETMAX 50 to #define PACKETMAX 500
Ah, that would also help a bit. I forgot that the 'Hello World' code was optimised for the absolute minimum ;)
Nice thinking Greg :)