problem making my own raw files
problem making my own raw files
ok I'm relatively new to PSP devlopment and I'm working on porting a World of Warcraft model viewer to the psp to get used to coding for the PSP. i got the actual model loading, but now I'm stuck at texturing. I just need to know what to use to create raw files. I've tried using a bmp2raw that i found on the forum here, but it makes my texture turn red. if anyone knows what I can do to use custom textures, I'd appreciate it, sorry if the answer is elsewhere, ive tried searching but found no real solution.
- nullp01nter
- Posts: 26
- Joined: Wed Jan 04, 2006 7:40 am
- Location: Saxony/Germany
Seems like you have a problem with the cache. Read http://www.goop.org/psp/cache-howto.html
Thoralt
Maybe this helps.You'll see some vertices looking fine, but others are way off in space. You'll see most of your texture, but chunks of it are missing or junk.
Thoralt
ok I still have no idea exactly how/where I'm supposed to use those functions, could you give me an example? here is my code:
Code: Select all
/*
* PSP Software Development Kit - http://www.pspdev.org
* -----------------------------------------------------------------------
* Licensed under the BSD license, see LICENSE in PSPSDK root for details.
*
* Copyright (c) 2005 Jesper Svennevid
*/
#include <pspkernel.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("Cube Sample", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER);
#define printf pspDebugScreenPrintf
static unsigned int __attribute__((aligned(16))) list[262144];
extern unsigned char logo_start[];
struct Vertex
{
float u,v;
float color;
float x,y,z;
};
int SetupCallbacks();
#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? */
int main(int argc, char* argv[])
{
SetupCallbacks();
SceCtrlData pad;
int myFile;
char* filename = "Chicken.m2";
myFile = sceIoOpen(filename,PSP_O_RDONLY,0777);
//printf("Loading Model");
int vertoffset = 0;
int numverts = 0;
int faceoffset = 0;
sceIoLseek(myFile,0x44,SEEK_SET);
sceIoRead(myFile,&numverts,sizeof(int));
sceIoRead(myFile,&vertoffset,sizeof(int));
sceIoLseek(myFile,4,SEEK_CUR);
sceIoRead(myFile,&faceoffset,sizeof(int));
//printf("vertoffset is %i \n",vertoffset);
struct Vertex __attribute__((aligned(16))) verts[numverts];
int n;
sceIoLseek(myFile,vertoffset,SEEK_SET);
for (n = 0;n < numverts;n++)
{
sceIoRead(myFile,&verts[n].x,4);
sceIoRead(myFile,&verts[n].y,4);
sceIoRead(myFile,&verts[n].z,4);
//sceIoLseek(myFile,36,SEEK_CUR);
sceIoLseek(myFile,20,SEEK_CUR);
sceIoRead(myFile,&verts[n].u,4);
sceIoRead(myFile,&verts[n].v,4);
sceIoLseek(myFile,8,SEEK_CUR);
//printf("x(%i) is %f y is %f z is %f\n",n,verts[n].x,verts[n].y,verts[n].z);
}
int numfaces;
int nfaceoffset;
printf("faceoffsetis %i\n",faceoffset);
sceIoLseek(myFile,faceoffset+8,SEEK_SET);
sceIoRead(myFile,&numfaces,sizeof(int));
sceIoRead(myFile,&nfaceoffset,sizeof(int));
printf("newfaceoffsetis %i\n",nfaceoffset);
printf("numverts %i \n",numverts);
printf("numfaces %i \n",numfaces);
//struct Vertex* faces;
//faces = (struct Vertex*)sceGuGetMemory(numfaces*sizeof(struct Vertex));
struct Vertex __attribute__((aligned(16))) faces[numfaces];
short x,y,z;
sceIoLseek(myFile,nfaceoffset,SEEK_SET);
for (n = 0; n < numfaces;n++)
{
sceIoRead(myFile,&x,2);
faces[n].x = verts[x].x;
faces[n].y = verts[x].y;
faces[n].z = verts[x].z;
faces[n].u = verts[x].u;
faces[n].v = verts[x].v;
faces[n].color = 0;
printf("face is %i %i %i \n",x,y,z);
}
// 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_CW);
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
int val = 0;
int val2 = 0;
int val3 = 0;
for(;;)
{
sceGuStart(GU_DIRECT,list);
// clear screen
sceGuClearColor(0xff554433);
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();
{
ScePspFVector3 pos = { 0, 0, -2.5f };
//ScePspFVector3 rot = { val * 0.79f * (GU_PI/180.0f), val * 0.98f * (GU_PI/180.0f), val * 1.32f * (GU_PI/180.0f) };
ScePspFVector3 rot = { val * 0.79f * (GU_PI/180.0f), val2 * 0.79f * (GU_PI/180.0f), val3 * 0.79f * (GU_PI/180.0f) };
sceGumTranslate(&pos);
sceGumRotateXYZ(&rot);
}
// setup texture
sceGuTexMode(GU_PSM_8888,0,0,0);
sceGuTexImage(0,64,64,64,logo_start);
sceKernelDcacheWritebackAll();
sceGuTexFunc(GU_TFX_ADD,GU_TCC_RGB);
sceGuTexEnvColor(0xffff00);
sceGuTexFilter(GU_LINEAR,GU_LINEAR);
sceGuTexScale(1.0f,1.0f);
sceGuTexOffset(0.0f,0.0f);
sceGuAmbientColor(0xffffffff);
// draw cube
//sceGumDrawArray(GU_TRIANGLES,GU_TEXTURE_32BITF|GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D,12*3,0,vertices);
sceGumDrawArray(GU_TRIANGLES,GU_TEXTURE_32BITF|GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D,numfaces*3,0,faces);
sceGuFinish();
sceGuSync(0,0);
sceDisplayWaitVblankStart();
sceGuSwapBuffers();
sceCtrlReadBufferPositive(&pad, 1);
if(pad.Buttons & PSP_CTRL_CROSS) {
val++;
}
if(pad.Buttons & PSP_CTRL_TRIANGLE) {
val--;
}
if(pad.Buttons & PSP_CTRL_SQUARE) {
val2--;
}
if(pad.Buttons & PSP_CTRL_CIRCLE) {
val2++;
}
if(pad.Buttons & PSP_CTRL_LTRIGGER) {
val3++;
}
if(pad.Buttons & PSP_CTRL_RTRIGGER) {
val3--;
}
}
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;
}
- nullp01nter
- Posts: 26
- Joined: Wed Jan 04, 2006 7:40 am
- Location: Saxony/Germany
Just a short summary explanation: The CPU of your PSP is executing your code and working on your data in normal RAM. Because this is slow, the CPU internally caches parts of that slow RAM. It can happen, that data is not instantly written back to RAM if you updated some variable (keyword "dirty"). If then another component of the PSP (here: the gfx engine) tries to use this data, it is still in the CPUs cache and the gfx engine does not know about it. Therefore it reads "old" data. To get around this problem, you write back the cache after you finished manipulating all data and before any other part of the PSP starts using this data. That would be right before you call sceGumDrawArray(). Insert a sceKernelDcacheWritebackAll(), and at least this problem is addressed.
But I do not know if it solves all issues, I did not review the rest of your code, but your description of the problem sounded like a cache problem.
Thoralt
But I do not know if it solves all issues, I did not review the rest of your code, but your description of the problem sounded like a cache problem.
Thoralt
why, not just use a bmp image rather then a raw file. i wrote it under pspgl, but the parsing code should work in anything.
http://forums.ps2dev.org/viewtopic.php?t=4487
http://forums.ps2dev.org/viewtopic.php?t=4487
There are 10 types of people in the world: Those who understand binary, and those who don't...
ok so my model loader finally works! I've got World of Warcraft models loading textured, I just have to figure out how to flip the normals. anyone know of an easy way to do this? also I switched to using a faces and a vert array in the sceGumDrawArray function and it got rid of my extra stuff, hope it helps anyone with the same problem as me
Yay WoW models! I was thinking of porting wowmodelview or at least part of it, but unfortunately I'm way too lazy for that :P
Are you transferring textures automatically somehow, or did you just export some from the mpq and convert it?
Anyway, theoretically the normals are usable the way they are stored in the m2 file, their coordinates are in the same order as the vertices (z axis up I think). But if you need to flip them, the way to do that would be to multiply every coordinate by -1.
Are you transferring textures automatically somehow, or did you just export some from the mpq and convert it?
Anyway, theoretically the normals are usable the way they are stored in the m2 file, their coordinates are in the same order as the vertices (z axis up I think). But if you need to flip them, the way to do that would be to multiply every coordinate by -1.
ufoz, are you from gotwow or bh? that name sounds familiar. I tried using the normals once and it was acting funky but ill try again. right now it loads fine (using a static model and texture) but you like see inside the model. I was actually thinking of using the models for some sort of turn based RTS game to learn using the psp better.
Neither, I wrote wowmapview and some of the documentation for the wow file formats :)nicoli_s wrote:ufoz, are you from gotwow or bh? that name sounds familiar.
So are you planning to animate the models too? The psp has hardware support for 8 bones but I think most models use much more than that so there's a good challenge, I guess you would have to chop up the model somehow to be able to do it in hardware...