 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
ffelagund
Joined: 16 Mar 2006 Posts: 14
|
Posted: Sun Jul 02, 2006 9:49 pm Post subject: Nothing rendered with GU |
|
|
Hello,
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: |
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);
}
|
Could anybody help me?
Thanks in advance,
Jacobo. _________________ I dont know... flight casual! |
|
| Back to top |
|
 |
ffelagund
Joined: 16 Mar 2006 Posts: 14
|
Posted: Mon Jul 03, 2006 2:50 am Post subject: |
|
|
I've dumped the content of the matrix generated by sceGumLookAt and it's all zeroes. Anybody could realize what I am doing wrong?
Edit: after called gumInit() at the begining I do not get more 0'matrices (they seem correct now), but things are still out of screen :( _________________ I dont know... flight casual! |
|
| Back to top |
|
 |
hardhat

Joined: 02 Mar 2006 Posts: 17
|
Posted: Mon Jul 03, 2006 3:31 pm Post subject: |
|
|
sceGetGuMemory doesn't do what you think it does. Try replacing:
| Code: |
struct Vertex* triangle = (struct Vertex*)sceGuGetMemory(3 * sizeof(struct Vertex));
struct Vertex* axes = (struct Vertex*)sceGuGetMemory(6 * sizeof(struct Vertex));
|
with
| Code: |
struct Vertex* triangle = (struct Vertex*)memalign(16,3 * sizeof(struct Vertex));
struct Vertex* axes = (struct Vertex*)memalign(16,6 * sizeof(struct Vertex));
|
That wasted lots of my time, since there are no samples in the SDK that do dynamic memory allocation of sceGumDrawArray buffers. _________________ HardHat
Try my homebrew: Open Gladiator, Fur Trader, Skater Maze, Jafe's Hike, Jumping Jack |
|
| Back to top |
|
 |
ffelagund
Joined: 16 Mar 2006 Posts: 14
|
Posted: Tue Jul 04, 2006 8:49 pm Post subject: |
|
|
Thanks!
That's exactly what was happening, once changed that lines, the triangle gets renderered perfectly :) _________________ I dont know... flight casual! |
|
| 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
|