My Triangle Dissapears

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

Moderators: cheriff, TyRaNiD

Post Reply
BlackDragon777
Posts: 32
Joined: Thu Sep 15, 2005 8:26 am

My Triangle Dissapears

Post by BlackDragon777 »

Well, I managed to draw a triangle to the screen however it only stays on the screen for half a second and then is cleared. I am swapping buffers so maybe I need to draw my triangle to some other place in emmory as well however the sample graphics demos didn't seem to be doing that. Here is my main loop.

Code: Select all

while(1)
	{

		sceGuStart(GU_DIRECT, list);

		sceGuClearColor(0);
		sceGuClearDepth(0);
		sceGuClear(GU_COLOR_BUFFER_BIT | GU_DEPTH_BUFFER_BIT);

		sceGuColor(0xFFFFFFFF);

		vertex = (Vertex *)sceGuGetMemory(sizeof(Vertex)*3);
		vertex[0].x = 100;
		vertex[0].y = 100;
		vertex[0].z = 0;

		vertex[1].x = 150;
		vertex[1].y = 50;
		vertex[1].z = 0;

		vertex[2].x = 200;
		vertex[2].y = 100;
		vertex[2].z = 0;
		sceGuDrawArray(GU_TRIANGLES, GU_VERTEX_32BITF | GU_TRANSFORM_2D, 3, 0, vertex);

		sceGuFinish();
		sceGuSync(0,0);

		sceDisplayWaitVblankStart();
		sceGuSwapBuffers();

	}
Any ideas?
BlackDragon777
Posts: 32
Joined: Thu Sep 15, 2005 8:26 am

Post by BlackDragon777 »

I guess if I said sceGuInit(), I wouldn't have had to post this. Sorry about this one. It was a careless overlook.

However I do have one other question.

How could I do a goraud shaded triangle based on the code I have provided? It seems that if I use sceGuColor 3 times before drawing the points, the last color I chose is tectured for the whole triangle. How can I send seperate colors for seperate verticies?


Thanks in advance!
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

BlackDragon777 wrote:How could I do a goraud shaded triangle based on the code I have provided? It seems that if I use sceGuColor 3 times before drawing the points, the last color I chose is tectured for the whole triangle. How can I send seperate colors for seperate verticies?
You could use a vertex struct like this:

Code: Select all

struct Vertex 
{ 
   unsigned int color; 
   float x, y, z; 
};
and then sceGuDrawArray(GU_TRIANGLES, GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D, 3, 0, vertices) and sceGuShadeModel(GU_SMOOTH). See http://forums.ps2dev.org/viewtopic.php?p=24801#24801 for a full example and just add the ShadeModel call.
BlackDragon777
Posts: 32
Joined: Thu Sep 15, 2005 8:26 am

Post by BlackDragon777 »

Oh ok Cool thanks a lot Shine!
Post Reply