forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[GU] psp funny bug

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
lego



Joined: 17 Oct 2008
Posts: 43

PostPosted: Fri Oct 02, 2009 12:11 am    Post subject: [GU] psp funny bug Reply with quote

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 :-)?
Back to top
View user's profile Send private message
iceman755



Joined: 21 Jul 2008
Posts: 34

PostPosted: Fri Oct 02, 2009 3:39 am    Post subject: Reply with quote

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"
Back to top
View user's profile Send private message
a_noob



Joined: 17 Sep 2006
Posts: 97
Location: _start: jr 0xDEADBEEF

PostPosted: Fri Oct 02, 2009 4:15 am    Post subject: Reply with quote

Post your code and I will sort it out.
_________________
Code:
.øOº'ºOø.
'ºOo.oOº'
Back to top
View user's profile Send private message AIM Address MSN Messenger
lego



Joined: 17 Oct 2008
Posts: 43

PostPosted: Sat Oct 03, 2009 12:14 am    Post subject: Reply with quote

gl_test.c:

Code:


/* 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;
}


Makefile:
Code:

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
Back to top
View user's profile Send private message
willow :--)



Joined: 13 Jan 2007
Posts: 126

PostPosted: Sat Oct 03, 2009 1:06 am    Post subject: Reply with quote

shouldn't you initialize fbp0 at some point?
_________________
Wagic. Play that card game against an AI on your PSP
Back to top
View user's profile Send private message
a_noob



Joined: 17 Sep 2006
Posts: 97
Location: _start: jr 0xDEADBEEF

PostPosted: Sat Oct 03, 2009 1:18 am    Post subject: Reply with quote

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:
.øOº'ºOø.
'ºOo.oOº'
Back to top
View user's profile Send private message AIM Address MSN Messenger
lego



Joined: 17 Oct 2008
Posts: 43

PostPosted: Sat Oct 03, 2009 3:41 am    Post subject: Reply with quote

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 :-)!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
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