[GU] psp funny bug

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

Moderators: cheriff, TyRaNiD

Post Reply
lego
Posts: 43
Joined: Fri Oct 17, 2008 1:09 am

[GU] psp funny bug

Post by lego »

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 :-)?
iceman755
Posts: 30
Joined: Mon Jul 21, 2008 1:12 am

Post by iceman755 »

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"
a_noob
Posts: 97
Joined: Sun Sep 17, 2006 8:33 am
Location: _start: jr 0xDEADBEEF

Post by a_noob »

Post your code and I will sort it out.

Code: Select all

.øOº'ºOø.
'ºOo.oOº'
lego
Posts: 43
Joined: Fri Oct 17, 2008 1:09 am

Post by lego »

gl_test.c:

Code: Select all


/* 68x34 480x272 */
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspgu.h>
#include <pspgum.h>

PSP_MODULE_INFO&#40;"test", 0, 1, 1&#41;;
PSP_MAIN_THREAD_ATTR&#40;PSP_THREAD_ATTR_USER&#41;;

#define printf pspDebugScreenPrintf

#define BUF_WIDTH &#40;512&#41;
#define SCR_WIDTH &#40;480&#41;
#define SCR_HEIGHT &#40;272&#41;

void *dList;// display List, used by sceGUStart
void *fbp0;// frame buffer

typedef struct &#123;
  float x, y, z;
&#125; Vertex;

Vertex __attribute__&#40;&#40;aligned&#40;16&#41;&#41;&#41; triangle&#91;3&#93; =
&#123;
  &#123; 100, 100, 0 &#125;, &#123; 200, 200, 0&#125;, &#123; 100, 200, 0&#125;
&#125;  ;

Vertex *dyn_tr;


/* Exit callback */
int exit_callback&#40;int arg1, int arg2, void *common&#41; &#123;
  sceKernelExitGame&#40;&#41;;
  return 0;
&#125;

/* Callback thread */
int CallbackThread&#40;SceSize args, void *argp&#41; &#123;
  int cbid;

  cbid = sceKernelCreateCallback&#40;"Exit Callback", exit_callback, NULL&#41;;
  sceKernelRegisterExitCallback&#40;cbid&#41;;

  sceKernelSleepThreadCB&#40;&#41;;

  return 0;

&#125;

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks&#40;void&#41; &#123;
  int thid = 0;

  thid = sceKernelCreateThread&#40;"update_thread", CallbackThread, 0x11, 0xFA0, 0, 0&#41;;
  if&#40;thid >= 0&#41; &#123;
    sceKernelStartThread&#40;thid, 0, 0&#41;;
  &#125;

  return thid;
&#125;

void InitGU&#40; void &#41;
&#123;
  // Init GU
  sceGuInit&#40;&#41;;
  sceGuStart&#40; GU_DIRECT, dList &#41;;

  // Set Buffers
  sceGuDrawBuffer&#40; GU_PSM_8888, fbp0, BUF_WIDTH &#41;;
  sceGuDispBuffer&#40; SCR_WIDTH, SCR_HEIGHT, &#40;void*&#41;0x88000, BUF_WIDTH&#41;;
  sceGuDepthBuffer&#40; &#40;void*&#41;0x110000, BUF_WIDTH&#41;;

  sceGuOffset&#40; 2048 - &#40;SCR_WIDTH/2&#41;, 2048 - &#40;SCR_HEIGHT/2&#41;&#41;;
  sceGuViewport&#40; 2048, 2048, SCR_WIDTH, SCR_HEIGHT&#41;;
  sceGuDepthRange&#40; 65535, 0&#41;;

  // Set Render States
  sceGuScissor&#40; 0, 0, SCR_WIDTH, SCR_HEIGHT&#41;;
  sceGuEnable&#40; GU_SCISSOR_TEST &#41;;
  sceGuDepthFunc&#40; GU_GEQUAL &#41;;
  sceGuEnable&#40; GU_DEPTH_TEST &#41;;
  sceGuFrontFace&#40; GU_CW &#41;;
  sceGuShadeModel&#40; GU_SMOOTH &#41;;
  sceGuEnable&#40; GU_CULL_FACE &#41;;
  sceGuEnable&#40; GU_CLIP_PLANES &#41;;
  sceGuFinish&#40;&#41;;
  sceGuSync&#40;0,0&#41;;

  sceDisplayWaitVblankStart&#40;&#41;;
  sceGuDisplay&#40;GU_TRUE&#41;;
  // finish
&#125;

void SetupProjection&#40; void &#41;
&#123;
  // setup matrices for the triangle
  sceGumMatrixMode&#40;GU_PROJECTION&#41;;
  sceGumLoadIdentity&#40;&#41;;
  sceGumPerspective&#40; 75.0f, 16.0f/9.0f, 0.5f, 1000.0f&#41;;

  sceGumMatrixMode&#40;GU_VIEW&#41;;
  sceGumLoadIdentity&#40;&#41;;

  sceGuClearColor&#40; GU_COLOR&#40; 0.0f, 0.0f, 0.0f, 1.0f &#41; &#41;;
  sceGuClearDepth&#40;0&#41;;
&#125;

int main&#40;int argc, char** argv&#41;
&#123;
  pspDebugScreenInit&#40;&#41;;
  SetupCallbacks&#40;&#41;;


  dList = memalign&#40;16, 640&#41;;

  InitGU&#40;&#41;;
  SetupProjection&#40;&#41;;

  sceGuClearColor&#40; GU_COLOR&#40; 0.0f, 1.0f, 0.0f, 0.0f &#41; &#41;;
  sceGuClear&#40;GU_COLOR_BUFFER_BIT | GU_DEPTH_BUFFER_BIT&#41;;

  sceGuStart&#40; GU_DIRECT, dList &#41;;
    sceGumMatrixMode&#40;GU_MODEL&#41;;
    sceGumLoadIdentity&#40;&#41;;

    sceGuColor&#40;GU_COLOR&#40;1, 1, 0, 0&#41;&#41;;
    sceGumDrawArray&#40;GU_TRIANGLES, GU_VERTEX_32BITF | GU_TRANSFORM_2D,
                 3, 0, triangle&#41;;

    dyn_tr = &#40;Vertex*&#41;sceGuGetMemory&#40;3 * sizeof&#40;Vertex&#41;&#41;;
    dyn_tr&#91;0&#93;.x = 100;
    dyn_tr&#91;0&#93;.y = 100;
    dyn_tr&#91;0&#93;.z = 0;
    dyn_tr&#91;1&#93;.x = 200;
    dyn_tr&#91;1&#93;.y = 100;
    dyn_tr&#91;1&#93;.z = 0;
    dyn_tr&#91;2&#93;.x = 200;
    dyn_tr&#91;2&#93;.y = 200;
    dyn_tr&#91;2&#93;.z = 0;


    sceKernelDcacheWritebackAll&#40;&#41;;
    sceGuColor&#40;GU_COLOR&#40;0, 0, 1, 0&#41;&#41;;
    sceGumDrawArray&#40;GU_TRIANGLES, GU_VERTEX_32BITF | GU_TRANSFORM_2D,
                 3, 0, dyn_tr&#41;;
  sceGuFinish&#40;&#41;;
  sceGuSync&#40;0, 0&#41;;

  sceDisplayWaitVblankStart&#40;&#41;;
  sceGuSwapBuffers&#40;&#41;;

  sceKernelSleepThreadCB&#40;&#41;;
  return 0;
&#125;
Makefile:

Code: Select all

TARGET = gl_test
OBJS = gl_test.o
PSP-PREF = $&#40;shell psp-config --psp-prefix&#41;

PSPSDK = $&#40;PSPDEV&#41;/psp/sdk
CFLAGS = -O2 -G0 -Wall -I$&#40;PSP-PREF&#41;/include
LDFLAGS = -L$&#40;PSP-PREF&#41;/lib
LIBS = -lpspgum -lpspgu -lpsprtc -lpspvfpu -lm
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;

BUILD_PRX = 1
PSP_FW_VERSION = 500

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = gl_test

PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build.mak

install&#58;
        mount /media/usbflash 
        mkdir /media/usbflash/psp/game5xx/gl_test || true
        cp EBOOT.PBP /media/usbflash/psp/game5xx/gl_test
        umount /media/usbflash
willow :--)
Posts: 107
Joined: Sat Jan 13, 2007 11:50 am

Post by willow :--) »

shouldn't you initialize fbp0 at some point?
a_noob
Posts: 97
Joined: Sun Sep 17, 2006 8:33 am
Location: _start: jr 0xDEADBEEF

Post by a_noob »

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º'
lego
Posts: 43
Joined: Fri Oct 17, 2008 1:09 am

Post by lego »

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.
Many thanks for the explanation :-)!
Post Reply