Hi.
My program using pspgu draw simple 2 triangles. But instead of two big triangles, I have four little one :-) with changed colors.
Did anybody occur this :-)?
[GU] psp funny bug
I don't know a lot about GU (just very basic knowledge) but, You have to show some code, because, without code, it's hard to know that what you say is what you have coded, maybe there is no bug and just, You think you are doing one thing and coding another.
"Libera eas de ore leonis, ne absorbeat eas tartarus, ne cadant in obscurum"
gl_test.c:
Makefile:
Code: Select all
/* 68x34 480x272 */
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspgu.h>
#include <pspgum.h>
PSP_MODULE_INFO("test", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER);
#define printf pspDebugScreenPrintf
#define BUF_WIDTH (512)
#define SCR_WIDTH (480)
#define SCR_HEIGHT (272)
void *dList;// display List, used by sceGUStart
void *fbp0;// frame buffer
typedef struct {
float x, y, z;
} Vertex;
Vertex __attribute__((aligned(16))) triangle[3] =
{
{ 100, 100, 0 }, { 200, 200, 0}, { 100, 200, 0}
} ;
Vertex *dyn_tr;
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common) {
sceKernelExitGame();
return 0;
}
/* Callback thread */
int CallbackThread(SceSize args, void *argp) {
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void) {
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0) {
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
void InitGU( void )
{
// Init GU
sceGuInit();
sceGuStart( GU_DIRECT, dList );
// Set Buffers
sceGuDrawBuffer( GU_PSM_8888, fbp0, BUF_WIDTH );
sceGuDispBuffer( SCR_WIDTH, SCR_HEIGHT, (void*)0x88000, BUF_WIDTH);
sceGuDepthBuffer( (void*)0x110000, BUF_WIDTH);
sceGuOffset( 2048 - (SCR_WIDTH/2), 2048 - (SCR_HEIGHT/2));
sceGuViewport( 2048, 2048, SCR_WIDTH, SCR_HEIGHT);
sceGuDepthRange( 65535, 0);
// Set Render States
sceGuScissor( 0, 0, SCR_WIDTH, SCR_HEIGHT);
sceGuEnable( GU_SCISSOR_TEST );
sceGuDepthFunc( GU_GEQUAL );
sceGuEnable( GU_DEPTH_TEST );
sceGuFrontFace( GU_CW );
sceGuShadeModel( GU_SMOOTH );
sceGuEnable( GU_CULL_FACE );
sceGuEnable( GU_CLIP_PLANES );
sceGuFinish();
sceGuSync(0,0);
sceDisplayWaitVblankStart();
sceGuDisplay(GU_TRUE);
// finish
}
void SetupProjection( void )
{
// setup matrices for the triangle
sceGumMatrixMode(GU_PROJECTION);
sceGumLoadIdentity();
sceGumPerspective( 75.0f, 16.0f/9.0f, 0.5f, 1000.0f);
sceGumMatrixMode(GU_VIEW);
sceGumLoadIdentity();
sceGuClearColor( GU_COLOR( 0.0f, 0.0f, 0.0f, 1.0f ) );
sceGuClearDepth(0);
}
int main(int argc, char** argv)
{
pspDebugScreenInit();
SetupCallbacks();
dList = memalign(16, 640);
InitGU();
SetupProjection();
sceGuClearColor( GU_COLOR( 0.0f, 1.0f, 0.0f, 0.0f ) );
sceGuClear(GU_COLOR_BUFFER_BIT | GU_DEPTH_BUFFER_BIT);
sceGuStart( GU_DIRECT, dList );
sceGumMatrixMode(GU_MODEL);
sceGumLoadIdentity();
sceGuColor(GU_COLOR(1, 1, 0, 0));
sceGumDrawArray(GU_TRIANGLES, GU_VERTEX_32BITF | GU_TRANSFORM_2D,
3, 0, triangle);
dyn_tr = (Vertex*)sceGuGetMemory(3 * sizeof(Vertex));
dyn_tr[0].x = 100;
dyn_tr[0].y = 100;
dyn_tr[0].z = 0;
dyn_tr[1].x = 200;
dyn_tr[1].y = 100;
dyn_tr[1].z = 0;
dyn_tr[2].x = 200;
dyn_tr[2].y = 200;
dyn_tr[2].z = 0;
sceKernelDcacheWritebackAll();
sceGuColor(GU_COLOR(0, 0, 1, 0));
sceGumDrawArray(GU_TRIANGLES, GU_VERTEX_32BITF | GU_TRANSFORM_2D,
3, 0, dyn_tr);
sceGuFinish();
sceGuSync(0, 0);
sceDisplayWaitVblankStart();
sceGuSwapBuffers();
sceKernelSleepThreadCB();
return 0;
}
Code: Select all
TARGET = gl_test
OBJS = gl_test.o
PSP-PREF = $(shell psp-config --psp-prefix)
PSPSDK = $(PSPDEV)/psp/sdk
CFLAGS = -O2 -G0 -Wall -I$(PSP-PREF)/include
LDFLAGS = -L$(PSP-PREF)/lib
LIBS = -lpspgum -lpspgu -lpsprtc -lpspvfpu -lm
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
BUILD_PRX = 1
PSP_FW_VERSION = 500
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = gl_test
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
install:
mount /media/usbflash
mkdir /media/usbflash/psp/game5xx/gl_test || true
cp EBOOT.PBP /media/usbflash/psp/game5xx/gl_test
umount /media/usbflash
-
- Posts: 107
- Joined: Sat Jan 13, 2007 11:50 am
The reason they are big, is you are expecting thew draw co-ordinates to be per pixel, but you are using gum to create a projection matrix, (mainly for 3D) So, they are infact quite large. Because when you set a projection matrix, people tend to use the scale of 1unit = 1meter. So you infact are drawing quite large triangles. However if you want it perpixel ratio, A) either setup and orthographic projection. or B) remove all sceGum calls, change the sceGumDrawArray to sceGuDrawArray. With the later, you must do all the rotation and translation math yourself, per vertex. Which is faster in the case of simple 2D objects, but slower if you decide to process larger amounts of data.
Code: Select all
.øOº'ºOø.
'ºOo.oOº'
Many thanks for the explanation :-)!a_noob wrote:The reason they are big, is you are expecting thew draw co-ordinates to be per pixel, but you are using gum to create a projection matrix, (mainly for 3D) So, they are infact quite large. Because when you set a projection matrix, people tend to use the scale of 1unit = 1meter. So you infact are drawing quite large triangles. However if you want it perpixel ratio, A) either setup and orthographic projection. or B) remove all sceGum calls, change the sceGumDrawArray to sceGuDrawArray. With the later, you must do all the rotation and translation math yourself, per vertex. Which is faster in the case of simple 2D objects, but slower if you decide to process larger amounts of data.