problem making my own raw files

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

Moderators: cheriff, TyRaNiD

Post Reply
nicoli_s
Posts: 12
Joined: Mon Jan 02, 2006 7:23 am
Contact:

problem making my own raw files

Post by nicoli_s »

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.
nicoli_s
Posts: 12
Joined: Mon Jan 02, 2006 7:23 am
Contact:

Post by nicoli_s »

ok I actually fixed my own problem, figured out how to make .raw files with photo shop. now I got my model texturing right, but when i spin it, it randomly makes weird out of place triangles, anyone have any idea why? if i dont texture it or dont rotate it, it works fine
User avatar
nullp01nter
Posts: 26
Joined: Wed Jan 04, 2006 7:40 am
Location: Saxony/Germany

Post by nullp01nter »

Seems like you have a problem with the cache. Read http://www.goop.org/psp/cache-howto.html
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.
Maybe this helps.

Thoralt
nicoli_s
Posts: 12
Joined: Mon Jan 02, 2006 7:23 am
Contact:

Post by nicoli_s »

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&#40;"Cube Sample", 0, 1, 1&#41;;
PSP_MAIN_THREAD_ATTR&#40;THREAD_ATTR_USER&#41;;

#define printf	pspDebugScreenPrintf

static unsigned int __attribute__&#40;&#40;aligned&#40;16&#41;&#41;&#41; list&#91;262144&#93;;

extern unsigned char logo_start&#91;&#93;;

struct Vertex
&#123;
	float u,v;
	float color;
	float x,y,z;
&#125;;

int SetupCallbacks&#40;&#41;;

#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? */

int main&#40;int argc, char* argv&#91;&#93;&#41;
&#123;
	SetupCallbacks&#40;&#41;;
	SceCtrlData pad;
	int myFile;
	char* filename = "Chicken.m2";
	myFile = sceIoOpen&#40;filename,PSP_O_RDONLY,0777&#41;;
		//printf&#40;"Loading Model"&#41;;
		int vertoffset = 0;
		int numverts = 0;
		int faceoffset = 0;
		sceIoLseek&#40;myFile,0x44,SEEK_SET&#41;;
		sceIoRead&#40;myFile,&numverts,sizeof&#40;int&#41;&#41;;
		sceIoRead&#40;myFile,&vertoffset,sizeof&#40;int&#41;&#41;;
		sceIoLseek&#40;myFile,4,SEEK_CUR&#41;;
		sceIoRead&#40;myFile,&faceoffset,sizeof&#40;int&#41;&#41;;
		//printf&#40;"vertoffset is %i \n",vertoffset&#41;;
		struct Vertex __attribute__&#40;&#40;aligned&#40;16&#41;&#41;&#41; verts&#91;numverts&#93;;
		int n;
		sceIoLseek&#40;myFile,vertoffset,SEEK_SET&#41;;
		for &#40;n = 0;n < numverts;n++&#41;
		&#123;
			sceIoRead&#40;myFile,&verts&#91;n&#93;.x,4&#41;;
			sceIoRead&#40;myFile,&verts&#91;n&#93;.y,4&#41;;
			sceIoRead&#40;myFile,&verts&#91;n&#93;.z,4&#41;;
			//sceIoLseek&#40;myFile,36,SEEK_CUR&#41;;
			sceIoLseek&#40;myFile,20,SEEK_CUR&#41;;
			sceIoRead&#40;myFile,&verts&#91;n&#93;.u,4&#41;;
			sceIoRead&#40;myFile,&verts&#91;n&#93;.v,4&#41;;
			sceIoLseek&#40;myFile,8,SEEK_CUR&#41;;			
			//printf&#40;"x&#40;%i&#41; is %f y is %f z is %f\n",n,verts&#91;n&#93;.x,verts&#91;n&#93;.y,verts&#91;n&#93;.z&#41;;
		&#125;
		int numfaces;
		int nfaceoffset;
		printf&#40;"faceoffsetis %i\n",faceoffset&#41;;
		sceIoLseek&#40;myFile,faceoffset+8,SEEK_SET&#41;;
		sceIoRead&#40;myFile,&numfaces,sizeof&#40;int&#41;&#41;;
		sceIoRead&#40;myFile,&nfaceoffset,sizeof&#40;int&#41;&#41;;
		printf&#40;"newfaceoffsetis %i\n",nfaceoffset&#41;;
		printf&#40;"numverts %i \n",numverts&#41;;
		printf&#40;"numfaces %i \n",numfaces&#41;;
		//struct Vertex* faces;
		//faces = &#40;struct Vertex*&#41;sceGuGetMemory&#40;numfaces*sizeof&#40;struct Vertex&#41;&#41;;
		struct Vertex __attribute__&#40;&#40;aligned&#40;16&#41;&#41;&#41; faces&#91;numfaces&#93;;
		short x,y,z;
		sceIoLseek&#40;myFile,nfaceoffset,SEEK_SET&#41;;
		for &#40;n = 0; n < numfaces;n++&#41;
		&#123;
			sceIoRead&#40;myFile,&x,2&#41;;
			faces&#91;n&#93;.x = verts&#91;x&#93;.x;
			faces&#91;n&#93;.y = verts&#91;x&#93;.y;
			faces&#91;n&#93;.z = verts&#91;x&#93;.z;
			faces&#91;n&#93;.u = verts&#91;x&#93;.u;			
			faces&#91;n&#93;.v = verts&#91;x&#93;.v;
			faces&#91;n&#93;.color = 0;
			printf&#40;"face is %i %i %i \n",x,y,z&#41;;
		&#125;

	// 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_CW&#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

	int val = 0;
	int val2 = 0;
	int val3 = 0;

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

		// clear screen

		sceGuClearColor&#40;0xff554433&#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;;
                &#123;
                        ScePspFVector3 pos = &#123; 0, 0, -2.5f &#125;;
                        //ScePspFVector3 rot = &#123; val * 0.79f * &#40;GU_PI/180.0f&#41;, val * 0.98f * &#40;GU_PI/180.0f&#41;, val * 1.32f * &#40;GU_PI/180.0f&#41; &#125;;
			ScePspFVector3 rot = &#123; val * 0.79f * &#40;GU_PI/180.0f&#41;, val2 * 0.79f * &#40;GU_PI/180.0f&#41;, val3 * 0.79f * &#40;GU_PI/180.0f&#41; &#125;;
                        sceGumTranslate&#40;&pos&#41;;
                        sceGumRotateXYZ&#40;&rot&#41;;
                &#125;

		// setup texture

		sceGuTexMode&#40;GU_PSM_8888,0,0,0&#41;;
		sceGuTexImage&#40;0,64,64,64,logo_start&#41;;
		sceKernelDcacheWritebackAll&#40;&#41;;
		sceGuTexFunc&#40;GU_TFX_ADD,GU_TCC_RGB&#41;;
		sceGuTexEnvColor&#40;0xffff00&#41;;
		sceGuTexFilter&#40;GU_LINEAR,GU_LINEAR&#41;;
		sceGuTexScale&#40;1.0f,1.0f&#41;;
		sceGuTexOffset&#40;0.0f,0.0f&#41;;
		sceGuAmbientColor&#40;0xffffffff&#41;;

		// draw cube

		//sceGumDrawArray&#40;GU_TRIANGLES,GU_TEXTURE_32BITF|GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D,12*3,0,vertices&#41;;
		sceGumDrawArray&#40;GU_TRIANGLES,GU_TEXTURE_32BITF|GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D,numfaces*3,0,faces&#41;;

		sceGuFinish&#40;&#41;;
		sceGuSync&#40;0,0&#41;;

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

		sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
          	if&#40;pad.Buttons & PSP_CTRL_CROSS&#41; &#123;
                    val++;
          	&#125;
          	if&#40;pad.Buttons & PSP_CTRL_TRIANGLE&#41; &#123;
                    val--;
          	&#125;
          	if&#40;pad.Buttons & PSP_CTRL_SQUARE&#41; &#123;
                    val2--;
          	&#125;
          	if&#40;pad.Buttons & PSP_CTRL_CIRCLE&#41; &#123;
                    val2++;
          	&#125;
          	if&#40;pad.Buttons & PSP_CTRL_LTRIGGER&#41; &#123;
                    val3++;
          	&#125;
          	if&#40;pad.Buttons & PSP_CTRL_RTRIGGER&#41; &#123;
                    val3--;
          	&#125;
	&#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;
User avatar
nullp01nter
Posts: 26
Joined: Wed Jan 04, 2006 7:40 am
Location: Saxony/Germany

Post by nullp01nter »

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
User avatar
Thanhda
Posts: 331
Joined: Sat Apr 09, 2005 2:08 am
Location: Canada
Contact:

Post by Thanhda »

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
There are 10 types of people in the world: Those who understand binary, and those who don't...
nicoli_s
Posts: 12
Joined: Mon Jan 02, 2006 7:23 am
Contact:

Post by nicoli_s »

ok I'm still getting the freaking stray triangles that appear/dissappear as i rotate the model and ive tried puting the cache call in multiple places and still nothing, can anyone tell me exactlyt where I should put the cache call?
nicoli_s
Posts: 12
Joined: Mon Jan 02, 2006 7:23 am
Contact:

Post by nicoli_s »

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
ufoz
Posts: 86
Joined: Thu Nov 10, 2005 2:36 am
Location: Tokyo
Contact:

Post by ufoz »

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.
nicoli_s
Posts: 12
Joined: Mon Jan 02, 2006 7:23 am
Contact:

Post by nicoli_s »

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.
nicoli_s
Posts: 12
Joined: Mon Jan 02, 2006 7:23 am
Contact:

Post by nicoli_s »

found my problem, i was culling in the wrong direction :P
ufoz
Posts: 86
Joined: Thu Nov 10, 2005 2:36 am
Location: Tokyo
Contact:

Post by ufoz »

nicoli_s wrote:ufoz, are you from gotwow or bh? that name sounds familiar.
Neither, I wrote wowmapview and some of the documentation for the wow file formats :)

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...
nicoli_s
Posts: 12
Joined: Mon Jan 02, 2006 7:23 am
Contact:

Post by nicoli_s »

i knew that name was familiar. I had the wow model formats cracked back in alpha back when they used modified mdx files. I think next up is making a blp2 loader. only 8 bones, are you serious? or is it only 8 bones per mesh? oh well, itll be a fun challenge :P
Post Reply