I try to render a sprite on the screen. I used the example of the sprite in the SDK. I use the same .raw picture but for some reason mine won't render. Am i forgetting something? The app doesn't crash since my buttons still work and i change the clear code into another color and that worked also only the sprite won't render.
what is wrong?
Code: Select all
/*
Generated by Sony PSP Application AppWizard
Version : 2.0.0
File : main.c
Description : main file for psp projet
*/
// INCLUDES
#include <psptypes.h>
#include <pspmoduleinfo.h>
#include <pspthreadman.h>
#include <pspaudio.h>
#include <pspaudiolib.h>
#include <pspctrl.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspge.h>
#include <pspgu.h>
#include <pspkernel.h>
#include <math.h>
// MODULE INITIALISATION
PSP_MODULE_INFO("Sample", 0x0000, 1, 1);
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER);
static unsigned int __attribute__((aligned(16))) list[262144];
extern unsigned char ball_start[];
/* Define printf, just to make typing easier */
#define printf pspDebugScreenPrintf
#define SCR_WIDTH (480)
#define SCR_HEIGHT (272)
#define SIN_ITERATOR 20
struct Vertex
{
float u, v;
unsigned int color;
float x,y,z;
};
struct Vertex vertices[1];
int done = 0;
int love = 0;
int pressed = 0;
ScePspFMatrix4 projection;
ScePspFMatrix4 view;
ScePspFMatrix4 world;
void matrix_identity(float* matrix);
void matrix_projection(float* matrix, float fovy, float aspect, float near, float far);
/* Exit callback */
int exit_callback(void)
{
sceKernelExitGame();
return 0;
}
/* Callback thread */
void CallbackThread(void *arg)
{
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
}
/* 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;
}
int InitApp(void){
// init the Graphical Unit
sceGuInit();
sceGuStart(GU_DIRECT,list);
sceGuDrawBuffer(GU_PSM_8888,(void*)0,512);
sceGuDispBuffer(SCR_WIDTH,SCR_HEIGHT,(void*)0x88000,512);
sceGuDepthBuffer((void*)0x110000,512);
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);
sceGuAlphaFunc(GU_GREATER,0,0xff);
sceGuEnable(GU_ALPHA_TEST);
sceGuDepthFunc(GU_GEQUAL);
sceGuEnable(GU_DEPTH_TEST);
sceGuFrontFace(GU_CW);
sceGuShadeModel(GU_SMOOTH);
sceGuEnable(GU_CULL_FACE);
sceGuEnable(GU_TEXTURE_2D);
sceGuFinish();
sceGuSync(0,0);
sceDisplayWaitVblankStart();
sceGuDisplay(GU_TRUE);
vertices[0].x = 0;
vertices[0].y = 0;
vertices[0].z = 0;
vertices[1].x = 100;
vertices[1].y = 100;
vertices[1].z = 100;
return 0;
}
int Controls(void){
SceCtrlData pad;
sceCtrlReadBufferPositive(&pad, 1);
if (pad.Buttons != 0){
if (pad.Buttons & PSP_CTRL_CROSS){
sceGuTerm();
sceKernelExitGame();
}
}
return 0;
}
int SetupWorld(void){
matrix_identity((float*)&projection);
matrix_projection((float*)&projection,75.0f,16.0/9.0f,0.5f,1000.0f);
sceGuSetMatrix(GU_PROJECTION,&projection);
matrix_identity((float*)&view);
sceGuSetMatrix(GU_VIEW,&view);
matrix_identity((float*)&world);
sceGuSetMatrix(GU_MODEL,&world);
sceGuAmbientColor(0xffffffff);
return 0;
}
int Draw(void){
sceGuStart(GU_DIRECT,list);
SetupWorld();
sceGuTexMode(GU_PSM_5551,0,0,0);
sceGuTexImage(0,32,32,32,ball_start); // width, height, buffer width, tbp
sceGuTexFunc(GU_TFX_MODULATE,GU_TCC_RGBA); // NOTE: this enables reads of the alpha-component from the texture, otherwise blend/test won't work
sceGuTexFilter(GU_NEAREST,GU_NEAREST);
sceGuTexWrap(GU_CLAMP,GU_CLAMP);
sceGuTexScale(1,1);
sceGuTexOffset(0,0);
sceGuAmbientColor(0xffffffff);
sceGuClearColor(0xff000000);
sceGuClearDepth(0);
sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);
sceGuDrawArray(GU_SPRITES,GU_TEXTURE_32BITF|GU_VERTEX_32BITF,2,0,vertices);
sceGuFinish();
sceGuSync(0,0);
sceDisplayWaitVblankStart();
sceGuSwapBuffers();
return 0;
}
int main(void)
{
SetupCallbacks();
pspDebugScreenInit();
InitApp();
//SetupWorld();
/*print some text on the screen
printf("\nHey mooie schoonheid ik houd van jou!!!\n");
printf("En hou jij ook van mij?\n");
printf("\nAls je van me houd moet je op X drukken!\n");*/
sceCtrlSetSamplingCycle(0);
sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
while(!done){
// Get control input
Controls();
// Draw the scene
Draw();
}
sceGuTerm();
//sceKernelSleepThread();
sceKernelExitGame();
return 0;
}
void matrix_identity(float* matrix)
{
matrix[(0<<2)+0] = 1.0f;
matrix[(0<<2)+1] = 0.0f;
matrix[(0<<2)+2] = 0.0f;
matrix[(0<<2)+3] = 0.0f;
matrix[(1<<2)+0] = 0.0f;
matrix[(1<<2)+1] = 1.0f;
matrix[(1<<2)+2] = 0.0f;
matrix[(1<<2)+3] = 0.0f;
matrix[(2<<2)+0] = 0.0f;
matrix[(2<<2)+1] = 0.0f;
matrix[(2<<2)+2] = 1.0f;
matrix[(2<<2)+3] = 0.0f;
matrix[(3<<2)+0] = 0.0f;
matrix[(3<<2)+1] = 0.0f;
matrix[(3<<2)+2] = 0.0f;
matrix[(3<<2)+3] = 1.0f;
}
void matrix_projection(float* matrix, float fovy, float aspect, float near, float far)
{
matrix_identity(matrix);
float angle = (fovy / 2.0f) * (M_PI/180.0f);
float cotangent = cosf(angle) / sinf(angle);
matrix[(0<<2)+0] = cotangent / aspect;
matrix[(1<<2)+1] = cotangent;
matrix[(2<<2)+2] = (far + near) / (near - far);
matrix[(3<<2)+2] = 2.0f * (far * near) / (near - far);
matrix[(2<<2)+3] = -1;
matrix[(3<<2)+3] = 0.0f;
}
float sinf(float v)
{
float res,w;
int t;
float fac;
int i=(int)((v)/(2.0f*M_PI));
v-=i*2.0f*M_PI;
fac=1.0f;
res=0.0f;
w=v;
for(t=1;t<SIN_ITERATOR;)
{
res+=fac*w;
w*=v*v;
t++;
fac/=t;
t++;
fac/=t;
res-=fac*w;
w*=v*v;
t++;
fac/=t;
t++;
fac/=t;
}
return res;
}
float cosf(float v)
{
float res,w;
int t;
float fac;
int i=(int)((v)/(2.0f*M_PI));
v-=i*2.0f*M_PI;
fac=1.0f;
res=0.0f;
w=1.0f;
for(t=0;t<SIN_ITERATOR;)
{
res+=fac*w;
w*=v*v;
t++;
fac/=t;
t++;
fac/=t;
res-=fac*w;
w*=v*v;
t++;
fac/=t;
t++;
fac/=t;
}
return res;
}