I'm experimenting with GU. Now I have a simple code, that get my some strange result. First triangle is drawn nice, but a second one, which is dynamically allocated, isn't drawn. If I change an array from dynamically allocatable to a statically allocatable one, then all triangles are drawn well.
Code: Select all
#include <malloc.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <SDL/SDL.h>
#include <SDL/SDL_ttf.h>
/*
#include <GL/gl.h>
#include <GL/glu.h>
*/
#include <math.h>
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspthreadman.h>
#include <pspdisplay.h>
#include <pspnet_inet.h>
#include <pspnet.h>
#include <psputility.h>
#include <pspgu.h>
#include <pspgum.h>
#include <psputils.h>
PSP_MODULE_INFO("ogl", 0, 3, 5);
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER | PSP_THREAD_ATTR_VFPU);
PSP_HEAP_SIZE_KB(-1024);
PSP_MAIN_THREAD_STACK_SIZE_KB(1024);
#define printf pspDebugScreenPrintf
#define BUF_WIDTH (512)
#define SCR_WIDTH (480)
#define SCR_HEIGHT (272)
void *dList;// display List, used by sceGUStart
void *fbp0;// frame buffer
typedef struct {
float x, y, z;
} Vertex_t;
Vertex_t __attribute__((aligned(16))) triangle[3] =
{
{ 100, 100, 0 }, { 200, 200, 0}, { 100, 200, 0}
} ;
Vertex_t *vv;
/*************************************************************
* EXIT CALLBACK STUFF
*************************************************************/
/* 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;
}
void initGU( void )
{
// Init GU
sceGuInit();
sceGuStart( GU_DIRECT, dList );
// Set Buffers
sceGuDrawBuffer( GU_PSM_8888, fbp0, 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( 65535, 0);
// Set Render States
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_CLIP_PLANES );
sceGuFinish();
sceGuSync(0,0);
sceDisplayWaitVblankStart();
sceGuDisplay(GU_TRUE);
// finish
}
void setupProjection( void )
{
// setup matrices for the triangle
sceGumMatrixMode(GU_PROJECTION);
sceGumLoadIdentity();
sceGumPerspective( 75.0f, 16.0f/9.0f, 0.5f, 1000.0f);
sceGumMatrixMode(GU_VIEW);
sceGumLoadIdentity();
sceGuClearColor( GU_COLOR( 0.0f, 0.0f, 0.0f, 1.0f ) );
sceGuClearDepth(0);
sceGumMatrixMode(GU_MODEL);
sceGumLoadIdentity();
}
int main(void)
{
SetupCallbacks();
pspDebugScreenInit();
if ( TTF_Init() ) {
fprintf(stderr, "TTF Error: %s\n", TTF_GetError());
exit(1);
}
atexit(TTF_Quit);
dList = memalign(16, 524288);
initGU();
setupProjection();
vv = (Vertex_t*)memalign(16, 3 * sizeof(Vertex_t));
vv[0].x = 100;
vv[0].y = 100;
vv[0].z = 0;
vv[1].x = 200;
vv[1].y = 100;
vv[1].z = 0;
vv[2].x = 200;
vv[2].y = 200;
vv[2].z = 0;
sceGuStart(GU_DIRECT, dList);
sceGuClear(GU_COLOR_BUFFER_BIT | GU_DEPTH_BUFFER_BIT);
sceGuColor(GU_COLOR(1, 1, 1, 0));
sceGumDrawArray(GU_TRIANGLES, GU_VERTEX_32BITF | GU_TRANSFORM_2D,
3, 0, triangle);
sceGuColor(GU_COLOR(0, 0, 1, 0));
sceGumDrawArray(GU_TRIANGLES, GU_VERTEX_32BITF | GU_TRANSFORM_2D,
3, 0, tr);
sceGuFinish();
sceGuSync(0, 0);
sceDisplayWaitVblankStart();
sceGuSwapBuffers();
sceKernelSleepThreadCB();
return 0;
}