I have a "little" problem with gu. I'm trying to render something (a trinangle and some axis) but I canno't get anything rendered. Here is my code (baed on the samples of the sdk)
Code: Select all
struct Vertex
{
//float u,v;
unsigned int color;
float x,y,z;
};
#include "triangle.h"
PSP_MODULE_INFO("Triangle Sample", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER);
static unsigned int __attribute__((aligned(16))) list[262144];
int initGU()
{
// setup GU
void* fbp0 = (void *)getStaticVramBuffer(BUF_WIDTH,SCR_HEIGHT,GU_PSM_8888);
void* fbp1 = (void *)getStaticVramBuffer(BUF_WIDTH,SCR_HEIGHT,GU_PSM_8888);
void* zbp = (void *)getStaticVramBuffer(BUF_WIDTH,SCR_HEIGHT,GU_PSM_4444);
sceGuInit();
sceGuStart(GU_DIRECT,list);
sceGuDrawBuffer(GU_PSM_8888,fbp0,BUF_WIDTH);
sceGuDispBuffer(SCR_WIDTH,SCR_HEIGHT,fbp1,BUF_WIDTH);
sceGuDepthBuffer(zbp,BUF_WIDTH);
sceGuOffset(2048 - (SCR_WIDTH/2),2048 - (SCR_HEIGHT/2));
sceGuViewport(2048,2048,SCR_WIDTH,SCR_HEIGHT);
sceGuDepthRange(65535,0);
sceGuScissor(0,0,SCR_WIDTH,SCR_HEIGHT);
sceGuEnable(GU_SCISSOR_TEST);
sceGuFrontFace(GU_CW);
sceGuDisable(GU_CULL_FACE);
sceGuShadeModel(GU_SMOOTH);
sceGuEnable(GU_DEPTH_TEST);
sceGuDepthFunc(GU_GEQUAL);
/*sceGuDrawBuffer(GU_PSM_8888,fbp0,BUF_WIDTH);
sceGuDispBuffer(SCR_WIDTH,SCR_HEIGHT,fbp1,BUF_WIDTH);
sceGuDepthBuffer(zbp,BUF_WIDTH);
sceGuOffset(2048 - (SCR_WIDTH/2),2048 - (SCR_HEIGHT/2));
sceGuViewport(2048,2048,SCR_WIDTH,SCR_HEIGHT);
sceGuDepthRange(65535,0);
sceGuScissor(0,0,SCR_WIDTH,SCR_HEIGHT);
sceGuEnable(GU_SCISSOR_TEST);
sceGuDepthFunc(GU_GEQUAL);
sceGuEnable(GU_DEPTH_TEST);
sceGuFrontFace(GU_CW);
sceGuShadeModel(GU_SMOOTH);*/
sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);
sceGuFinish();
sceGuSync(0,0);
sceDisplayWaitVblankStart();
sceGuDisplay(GU_TRUE);
return 1;
}
int main(int argc, char* argv[])
{
setupCallbacks();
sceKernelDcacheWritebackAll();
pspDebugScreenInit();
initGU();
struct Vertex* triangle = (struct Vertex*)sceGuGetMemory(3 * sizeof(struct Vertex));
struct Vertex* axes = (struct Vertex*)sceGuGetMemory(6 * sizeof(struct Vertex));
triangle[0].x = 0; triangle[0].y = 272; triangle[0].z = 0;
triangle[0].color = GU_RGBA(255,0,0,255);
triangle[1].x = 240; triangle[1].y = 0; triangle[1].z = 0;
triangle[1].color = GU_RGBA(0,255,0,255);
triangle[2].x = 480; triangle[2].y = 272; triangle[2].z = 0;
triangle[2].color = GU_RGBA(0,0,255,255);
axes[0].x = 0; axes[0].y = 0; axes[0].z = 0;
axes[0].color = GU_RGBA(255,0,0,255);
axes[1].x = 100000; axes[1].y = 0; axes[1].z = 0;
axes[1].color = GU_RGBA(255,0,0,255);
axes[2].x = 0; axes[2].y = 0; axes[2].z = 0;
axes[2].color = GU_RGBA(0,255,0,255);
axes[3].x = 0; axes[3].y = 100000; axes[3].z = 0;
axes[3].color = GU_RGBA(0,255,0,255);
axes[4].x = 0; axes[4].y = 0; axes[4].z = 0;
axes[4].color = GU_RGBA(0,0,255,255);
axes[5].x = 0; axes[5].y = 0; axes[5].z = 100000;
axes[5].color = GU_RGBA(0,0,255,255);
while(running())
{
sceGuStart(GU_DIRECT,list);
Render(triangle, axes);
sceGuFinish();
sceGuSync(0,0);
sceDisplayWaitVblankStart();
sceGuSwapBuffers();
pspDebugScreenSetXY(0,0);
}
sceGuTerm();
sceKernelExitGame();
return 0;
}
void Render(struct Vertex *triangle, struct Vertex *axes)
{
sceGuClearColor(0xff00ff);
sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);
sceGumMatrixMode(GU_PROJECTION);
sceGumLoadIdentity();
sceGumPerspective(45,480.0f/272.0f, 10, 1000);
sceGumMatrixMode(GU_VIEW);
sceGumLoadIdentity();
sceGumDrawArray(GU_LINES,GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D,6,0,axes);
sceGumMatrixMode(GU_MODEL);
sceGumLoadIdentity();
ScePspFVector3 pos = {0,0,500};
ScePspFVector3 view = {0,0,0};
ScePspFVector3 up = {0,1,0};
sceGumLookAt(&pos,&view,&up);
sceGumDrawArray(GU_LINES,GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D,6,0,axes);
static float angle = 0;
sceGumRotateY(angle);
angle += 1.0f;
sceGumDrawArray(GU_TRIANGLES,GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D,3,0,triangle);
}
Thanks in advance,
Jacobo.