2D image failing to display

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

Moderators: cheriff, TyRaNiD

Post Reply
snow
Posts: 31
Joined: Sat Dec 15, 2007 12:34 pm

2D image failing to display

Post by snow »

I've been toying around with the snes emulator and this is simply me attempting to display a rendered frame. I've borrowed the rendering code from snes9xtyl. The native resolution of the snes is 256x224 (normally). I tried just writing to the VRAM directly which ended up at least showing me pixels but they were the wrong color and pretty much a mess :-P

I'm using the following initialization,

Code: Select all

#define VRAM_ADDR 0x04000000
#define MAX_DRAW_BUFFER_SIZE (0x077800)
#define BUF_WIDTH (512)
#define SCR_WIDTH (480)
#define SCR_HEIGHT (272)

void* drawBufferAddress = 0;

{
	sceGuInit();
	sceGuStart(GU_DIRECT,list);
	sceGuDrawBuffer(GU_PSM_5551,(void*)0,BUF_WIDTH);
	sceGuDispBuffer(SCR_WIDTH,SCR_HEIGHT,(void*)MAX_DRAW_BUFFER_SIZE,BUF_WIDTH);
	sceGuOffset(2048 - (SCR_WIDTH/2),2048 - (SCR_HEIGHT/2));
	sceGuViewport(2048,2048,SCR_WIDTH,SCR_HEIGHT);
	sceGuScissor(0,0,SCR_WIDTH,SCR_HEIGHT);
	sceGuEnable(GU_SCISSOR_TEST);
	sceGuClear(GU_COLOR_BUFFER_BIT);
	sceGuFinish();
	sceGuSync(0,0);

	sceDisplayWaitVblankStart();
	sceGuDisplay(1);
}
And my rendering loop,

Code: Select all

{
sceKernelDcacheWritebackAll();

	sceGuStart(GU_DIRECT,list);
	sceGuDrawBufferList(GU_PSM_5551,(void*)drawBufferAddress,512);
	sceGuTexFunc(GU_TFX_REPLACE,GU_TCC_RGB);
	sceGuEnable(GU_SCISSOR_TEST);
	  
	sceGuScissor(0,0,SCR_WIDTH,SCR_HEIGHT);
	sceGuDisable(GU_DEPTH_TEST);
	sceGuDisable(GU_ALPHA_TEST);

	sceGuTexMode(GU_PSM_5551,0,0,0);
	sceGuTexImage(0,Width,Height,512,(void*)GFX.Screen);
	sceGuTexFunc(GU_TFX_REPLACE,0);
	sceGuTexFilter(GU_NEAREST,GU_NEAREST);
	sceGuTexScale(1.0f/Width,1.0f/Height);
	sceGuTexOffset(0,0);
	sceGuTexWrap(GU_CLAMP,GU_CLAMP);
	
	struct Vertex* vertices = (struct Vertex*)sceGuGetMemory(4 * sizeof(struct Vertex));    	
	vertices[0].u = -128;
	vertices[0].v = -112;
	vertices[0].x = 0;
	vertices[0].y = 0;
	vertices[1].u = 128;
	vertices[1].v = -112;
	vertices[1].x = 480;
	vertices[1].y = 0;
	vertices[2].u = -128;
	vertices[2].v = 112;
	vertices[2].x = 0;
	vertices[2].y = 272;
	vertices[3].u = 128;
	vertices[3].v = 112;
	vertices[3].x = 480;
	vertices[3].y = 272;

	sceGuDrawArray(GU_SPRITES,GU_TEXTURE_16BIT|GU_VERTEX_16BIT|GU_TRANSFORM_2D,4,0,vertices);
	
	sceGuFinish();
	sceGuSync(0,0);
	drawBufferAddress = sceGuSwapBuffers();
}
Any help is appreciated.
quadrizo
Posts: 21
Joined: Thu Aug 23, 2007 10:21 pm

Post by quadrizo »

well ...
when you use GU_SPRITES you have to define only two vertices : the top left and the bottom right corner

so here you draw two sprites with no height
try:

Code: Select all

   struct Vertex* vertices = (struct Vertex*)sceGuGetMemory(2 * sizeof(struct Vertex));       
   vertices[0].u = -128;
   vertices[0].v = -112;
   vertices[0].x = 0;
   vertices[0].y = 0;

   vertices[1].u = 128;
   vertices[1].v = 112;
   vertices[1].x = 480;
   vertices[1].y = 272;

   sceGuDrawArray(GU_SPRITES,GU_TEXTURE_16BIT|GU_VERTEX_16BIT|GU_TRANSFORM_2D,2,0,vertices);
[/code]
Post Reply