3d-objects on psp ... what did i miss?

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

Moderators: cheriff, TyRaNiD

Post Reply
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

3d-objects on psp ... what did i miss?

Post by LuMo »

hi there!
i tried to bring some models from pc to psp;
my first try was an rotating triangle, which worked really nice...
furter i try to load an model in my own format to psp...
the loading works fine (tested on pc and put out to screen[coordinates etc...])
when i put my code on psp it turns off.

here is my code; no clue whats wrong [noob]

Code: Select all

#include <pspkernel.h>
#include <pspiofilemgr.h> //new
#include <malloc.h>
#include <pspdisplay.h>
#include <pspdebug.h>
#include <pspctrl.h>

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>

#include <pspgu.h>
#include <pspgum.h>

PSP_MODULE_INFO&#40;"3D Mesh Test", 0, 1, 1&#41;;
PSP_MAIN_THREAD_ATTR&#40;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;
#define PIXEL_SIZE &#40;4&#41; /* change this if you change to another screenmode */
#define FRAME_SIZE &#40;BUF_WIDTH * SCR_HEIGHT * PIXEL_SIZE&#41;
#define ZBUF_SIZE &#40;BUF_WIDTH SCR_HEIGHT * 2&#41; /* zbuffer seems to be 16-bit? */


struct Vertex
&#123;
	float u, v; //static UV-texture
	unsigned int color;// = 0xff7f0000; // AABBGGRR
	float x,y,z;
&#125;;

struct Point
&#123;
	float x,y,z;
&#125;;


static unsigned int __attribute__&#40;&#40;aligned&#40;16&#41;&#41;&#41; list&#91;262144&#93;;
unsigned short __attribute__&#40;&#40;aligned&#40;16&#41;&#41;&#41; *faces;
struct Point __attribute__&#40;&#40;aligned&#40;16&#41;&#41;&#41; *points;
struct Vertex __attribute__&#40;&#40;aligned&#40;16&#41;&#41;&#41; *vertices;
// add coloredpoints at v2
int SetupCallbacks&#40;&#41;;


int main&#40;int argc, char* argv&#91;&#93;&#41;
&#123;
	SceCtrlData pad;
	SetupCallbacks&#40;&#41;;


	/*
	 load model code is here...
	 which works fine
	*/
	
	
	sceKernelDcacheWritebackAll&#40;&#41;;
	fclose&#40;fd&#41;;


	// setup ctrl
	sceCtrlSetSamplingCycle&#40;0&#41;;
	sceCtrlSetSamplingMode&#40;PSP_CTRL_MODE_ANALOG&#41;;

	float rx = 0;
	float ry = 0;
	float rz = 0;
	float pz = -20;
	float px = 0;

	// setup GU
	sceGuInit&#40;&#41;;
	sceGuStart&#40;GU_DIRECT,list&#41;;
	sceGuDrawBuffer&#40;GU_PSM_8888,&#40;void*&#41;0,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;0xc350,0x2710&#41;;
	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_CCW&#41;;
	sceGuShadeModel&#40;GU_SMOOTH&#41;;
	sceGuEnable&#40;GU_CULL_FACE&#41;;
	sceGuEnable&#40;GU_TEXTURE_2D&#41;;
	sceGuEnable&#40;GU_CLIP_PLANES&#41;;
	sceGuFinish&#40;&#41;;
	sceGuSync&#40;0,0&#41;;

	sceDisplayWaitVblankStart&#40;&#41;;
	sceGuDisplay&#40;GU_TRUE&#41;;

	// run sample

	for&#40;;;&#41;
	&#123;
		sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
		if&#40;pad.Buttons & PSP_CTRL_CIRCLE&#41; break;

		sceGuStart&#40;GU_DIRECT,list&#41;;

		// clear screen
		sceGuClearColor&#40;0xff000000&#41;;
		sceGuClearDepth&#40;0&#41;;
		sceGuClear&#40;GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT&#41;;

		// setup matrices for cube
		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;;
		sceGumMatrixMode&#40;GU_MODEL&#41;;
		sceGumLoadIdentity&#40;&#41;;

		/* some pad movement here */
		ScePspFVector3 pos = &#123; px, 0, pz &#125;;
		ScePspFVector3 rot = &#123; rx * 1.00f * &#40;M_PI/180.0f&#41;, ry * 1.00f * &#40;M_PI/180.0f&#41;, rz * &#40;M_PI/180.0f&#41;&#125;;
		sceGumRotateXYZ&#40;&rot&#41;;
		sceGumTranslate&#40;&pos&#41;;

		// draw cube
		sceGumDrawArray&#40;GU_TRIANGLES,GU_INDEX_16BIT|GU_NORMAL_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_3D,number_of_faces*3,faces,vertices&#41;;

		sceGuFinish&#40;&#41;;

		sceGuSync&#40;0,0&#41;;
		sceDisplayWaitVblankStart&#40;&#41;;
		sceGuSwapBuffers&#40;&#41;;
	&#125;

	sceGuTerm&#40;&#41;;

	sceKernelExitGame&#40;&#41;;
	return 0;
&#125;

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

further THIS is my makefile:

Code: Select all

TARGET = mymeshtest
OBJS = mymeshtest.o

INCDIR =
CFLAGS = -G0 -Wall
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;

LIBDIR =
LDFLAGS =
LIBS= -lpspgum -lpspgu -lm

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = 3dloadtest

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

thanks in advance
lumo
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
subbie
Posts: 122
Joined: Thu May 05, 2005 4:14 am

Post by subbie »

Not sure what is causing the crash but there is a bug in your draw.

struct Vertex
{
float u, v; //static UV-texture
unsigned int color;// = 0xff7f0000; // AABBGGRR
float x,y,z;
};


sceGumDrawArray(GU_TRIANGLES,GU_INDEX_16BIT|GU_NORMAL_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_3D,number_of_faces*3,faces,vertices);

Based on your Vertex format. Your flags should be "GU_INDEX_16BIT|GU_TEXTURE_32BITF|GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D". The flags help in telling it what to use and strides.

If say your vertex setup was like this.

struct Vertex
{
unsigned int color;// = 0xff7f0000; // AABBGGRR
float x,y,z;
};

your flags would be "GU_INDEX_16BIT|GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D".

There is a doc somewhere with the sdk to tell you the full order of the vertex setup if you want to add in normals or etc.
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

"doc somewhere" ... thats my problem i was not able to find it
i tried your:
"GU_INDEX_16BIT|GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D"-flag with my struct:

Code: Select all

struct Vertex
&#123;
	unsigned int color;// = 0xff7f0000; //static AABBGGRR
	float x,y,z;
&#125;;
does not compile...
brings me the following error:
/usr/local/pspdev/psp/sdk/include/pspgum.h:20: error: too few arguments to funct
ion 'void sceGumDrawArray(int, int, int, const void*, const void*)'
mymeshtest.cpp:218: error: at this point in file
make: *** [mymeshtest.o] Error 1
greets
lumo
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
subbie
Posts: 122
Joined: Thu May 05, 2005 4:14 am

Post by subbie »

LuMo wrote:"doc somewhere" ... thats my problem i was not able to find it
i tried your:
"GU_INDEX_16BIT|GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D"-flag with my struct:

Code: Select all

struct Vertex
&#123;
	unsigned int color;// = 0xff7f0000; //static AABBGGRR
	float x,y,z;
&#125;;
does not compile...
brings me the following error:
/usr/local/pspdev/psp/sdk/include/pspgum.h:20: error: too few arguments to funct
ion 'void sceGumDrawArray(int, int, int, const void*, const void*)'
mymeshtest.cpp:218: error: at this point in file
make: *** [mymeshtest.o] Error 1
greets
lumo
could you please copy and paste the exact source as there is probably a miss type.
User avatar
nullp01nter
Posts: 26
Joined: Wed Jan 04, 2006 7:40 am
Location: Saxony/Germany

Post by nullp01nter »

@LuMo:Sounds like you copied "GU_INDEX_16BIT|GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D" as the _only_ parameter to the function. You have to keep the other parameters.
Try this:

Code: Select all

sceGumDrawArray&#40;GU_TRIANGLES,
        GU_INDEX_16BIT|GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D,
        number_of_faces*3,
        faces,
        vertices&#41;;
Hope this helps.

Thoralt
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

still crashes...
possibly i have an error in the way i try to display it...
i do not want to publish the code right now, until its done (and working)
so if anyone is willed to help me bugfixing i will give code away to him;
(i really want to get the code working soon cause i already bugged around with this for days now)
thanks in advance
lumo
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
Post Reply