 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
LuMo
Joined: 21 Aug 2005 Posts: 410 Location: Austria
|
Posted: Mon Jan 02, 2006 12:50 am Post subject: 3d-objects on psp ... what did i miss? |
|
|
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: |
#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("3D Mesh Test", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER);
#define printf pspDebugScreenPrintf
#define BUF_WIDTH (512)
#define SCR_WIDTH (480)
#define SCR_HEIGHT (272)
#define PIXEL_SIZE (4) /* change this if you change to another screenmode */
#define FRAME_SIZE (BUF_WIDTH * SCR_HEIGHT * PIXEL_SIZE)
#define ZBUF_SIZE (BUF_WIDTH SCR_HEIGHT * 2) /* zbuffer seems to be 16-bit? */
struct Vertex
{
float u, v; //static UV-texture
unsigned int color;// = 0xff7f0000; // AABBGGRR
float x,y,z;
};
struct Point
{
float x,y,z;
};
static unsigned int __attribute__((aligned(16))) list[262144];
unsigned short __attribute__((aligned(16))) *faces;
struct Point __attribute__((aligned(16))) *points;
struct Vertex __attribute__((aligned(16))) *vertices;
// add coloredpoints at v2
int SetupCallbacks();
int main(int argc, char* argv[])
{
SceCtrlData pad;
SetupCallbacks();
/*
load model code is here...
which works fine
*/
sceKernelDcacheWritebackAll();
fclose(fd);
// setup ctrl
sceCtrlSetSamplingCycle(0);
sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
float rx = 0;
float ry = 0;
float rz = 0;
float pz = -20;
float px = 0;
// setup GU
sceGuInit();
sceGuStart(GU_DIRECT,list);
sceGuDrawBuffer(GU_PSM_8888,(void*)0,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(0xc350,0x2710);
sceGuScissor(0,0,SCR_WIDTH,SCR_HEIGHT);
sceGuEnable(GU_SCISSOR_TEST);
sceGuDepthFunc(GU_GEQUAL);
sceGuEnable(GU_DEPTH_TEST);
sceGuFrontFace(GU_CCW);
sceGuShadeModel(GU_SMOOTH);
sceGuEnable(GU_CULL_FACE);
sceGuEnable(GU_TEXTURE_2D);
sceGuEnable(GU_CLIP_PLANES);
sceGuFinish();
sceGuSync(0,0);
sceDisplayWaitVblankStart();
sceGuDisplay(GU_TRUE);
// run sample
for(;;)
{
sceCtrlReadBufferPositive(&pad, 1);
if(pad.Buttons & PSP_CTRL_CIRCLE) break;
sceGuStart(GU_DIRECT,list);
// clear screen
sceGuClearColor(0xff000000);
sceGuClearDepth(0);
sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);
// setup matrices for cube
sceGumMatrixMode(GU_PROJECTION);
sceGumLoadIdentity();
sceGumPerspective(75.0f,16.0f/9.0f,0.5f,1000.0f);
sceGumMatrixMode(GU_VIEW);
sceGumLoadIdentity();
sceGumMatrixMode(GU_MODEL);
sceGumLoadIdentity();
/* some pad movement here */
ScePspFVector3 pos = { px, 0, pz };
ScePspFVector3 rot = { rx * 1.00f * (M_PI/180.0f), ry * 1.00f * (M_PI/180.0f), rz * (M_PI/180.0f)};
sceGumRotateXYZ(&rot);
sceGumTranslate(&pos);
// draw cube
sceGumDrawArray(GU_TRIANGLES,GU_INDEX_16BIT|GU_NORMAL_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_3D,number_of_faces*3,faces,vertices);
sceGuFinish();
sceGuSync(0,0);
sceDisplayWaitVblankStart();
sceGuSwapBuffers();
}
sceGuTerm();
sceKernelExitGame();
return 0;
}
/* 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;
}
|
further THIS is my makefile:
| Code: |
TARGET = mymeshtest
OBJS = mymeshtest.o
INCDIR =
CFLAGS = -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBDIR =
LDFLAGS =
LIBS= -lpspgum -lpspgu -lm
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = 3dloadtest
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
|
thanks in advance
lumo _________________ "Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com |
|
| Back to top |
|
 |
subbie
Joined: 05 May 2005 Posts: 122
|
Posted: Wed Jan 04, 2006 3:40 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
LuMo
Joined: 21 Aug 2005 Posts: 410 Location: Austria
|
Posted: Wed Jan 04, 2006 3:51 am Post subject: |
|
|
"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: | struct Vertex
{
unsigned int color;// = 0xff7f0000; //static AABBGGRR
float x,y,z;
}; |
does not compile...
brings me the following error:
| Quote: | /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 |
|
| Back to top |
|
 |
subbie
Joined: 05 May 2005 Posts: 122
|
Posted: Wed Jan 04, 2006 6:32 am Post subject: |
|
|
| 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: | struct Vertex
{
unsigned int color;// = 0xff7f0000; //static AABBGGRR
float x,y,z;
}; |
does not compile...
brings me the following error:
| Quote: | /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. |
|
| Back to top |
|
 |
nullp01nter

Joined: 04 Jan 2006 Posts: 26 Location: Saxony/Germany
|
Posted: Wed Jan 04, 2006 7:54 am Post subject: |
|
|
@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: | sceGumDrawArray(GU_TRIANGLES,
GU_INDEX_16BIT|GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D,
number_of_faces*3,
faces,
vertices); |
Hope this helps.
Thoralt |
|
| Back to top |
|
 |
LuMo
Joined: 21 Aug 2005 Posts: 410 Location: Austria
|
Posted: Wed Jan 04, 2006 11:02 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
|
|
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
|