BUILD_PRX=1
INCDIR =
-CFLAGS = -O2 -G0 -Wall
+CFLAGS = -g -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
+LIBS = -lpspgum -lpspgu -lpsprtc -lstdc++ -lm
LIBDIR =
LDFLAGS =
#include "game.h"
+#include "gfx.h"
+
+#include <pspgu.h>
+#include <pspgum.h>
+#include <psptypes.h>
+#include <pspdisplay.h>
+
+float triangle[]={1,-1,0,-1,-1,0,0,1,0};
int game_main(int argc, char **argv)
{
+ GFX.init();
+
+ GFX.perspective(75.0f, 16.0f/9.0f, 0.5f, 1000.0f);
+
+ ScePspFVector3 eye={0,0,-10};
+ ScePspFVector3 center={0,0,0};
+ ScePspFVector3 up={0,1,0};
+ GFX.look_at(&eye, ¢er, &up);
+ sceGumMatrixMode(GU_MODEL);
while(1)
{
+ sceGuStart(GU_DIRECT, GFX.display_list);
+ sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);
+
+ sceGumLoadIdentity();
+ sceGuColor(GU_COLOR(1.0f,1.0f,1.0f,0.0f));
+ sceGumDrawArray(GU_TRIANGLES, GU_VERTEX_32BITF | GU_TRANSFORM_3D, 3, 0, triangle);
+
+ ScePspFVector3 move={2,0,0};
+ sceGumTranslate(&move);
+
+ sceGuColor(GU_COLOR(1.0f,0.0f,0.0f,0.0f));
+ sceGumDrawArray(GU_TRIANGLES, GU_VERTEX_32BITF | GU_TRANSFORM_3D, 3, 0, triangle);
+
+ sceGuFinish();
+ sceGuSync(0,0);
+
+ GFX.update_fps();
+ GFX.swap_buffers();
}
+
+ GFX.cleanup();
}
#include "gfx.h"
+#include <ctime>
+#include <cstdio>
+
#include <pspgu.h>
#include <pspgum.h>
-#include <psprtc.h>
+#include <psptypes.h>
+#include <pspdisplay.h>
+#include <pspdebug.h>
+#include <psprtc.h>
+#include <malloc.h> // for memalign
-void GFX::init()
+void Gfx::init()
{
- dList = memalign(16, 2048);
+ display_list = memalign(16, 2048);
fbp0 = 0;
+ pspDebugScreenInit();
+
// Init GU
sceGuInit();
sceGuStart(GU_DIRECT, display_list);
sceGuEnable( GU_DEPTH_TEST );
sceGuShadeModel( GU_SMOOTH );
sceGuFrontFace( GU_CW );
- sceGuEnable( GU_CULL_FACE );
- sceGuEnable( GU_CLIP_PLANES );
+ //sceGuEnable( GU_CULL_FACE );
+ //sceGuEnable( GU_CLIP_PLANES );
// set clear color/depth
sceGuClearColor( GU_COLOR( 0.0f, 0.0f, 0.0f, 1.0f ) );
// finish
// init fps counter
- sceRtcGetCurrentTick( &fpsTickLast );
- tickResolution = sceRtcGetTickResolution();
+ sceRtcGetCurrentTick( &fps_tick_last );
+ tick_resolution = sceRtcGetTickResolution();
}
-}
-
-void GFX::cleanup()
+void Gfx::cleanup()
{
sceGuTerm();
}
-void update_fps( void )
+void Gfx::update_fps( void )
{
frames_drawn++;
- sceRtcGetCurrentTick( &fpsTickNow );
+ sceRtcGetCurrentTick( &fps_tick_now );
if( ((fps_tick_now - fps_tick_last)/((float)tick_resolution)) >= 1.0f )
{
fps_tick_last = fps_tick_now;
- sprintf( fps_display, "FPS: %d", frames_drawn );
+ sprintf( fps_display, "ticks=%f, FPS: %d", ((double)fps_tick_now/(double)tick_resolution), frames_drawn );
frames_drawn = 0;
}
pspDebugScreenSetOffset( (int)fbp0 );
pspDebugScreenPrintf( fps_display );
}
-
-void GFX::perspective(float fov, float aspect, float znear, float zfar)
+
+void Gfx::swap_buffers()
+{
+ fbp0=sceGuSwapBuffers();
+}
+
+void Gfx::perspective(float fov, float aspect, float znear, float zfar)
{
// setup projection matrix
sceGumMatrixMode(GU_PROJECTION);
sceGumPerspective(fov, aspect, znear, zfar);
}
-void GFX::look_at(ScePspFVector3 *eye, ScePspFVector3 *center, ScePspFVector3 *up)
+void Gfx::look_at(ScePspFVector3 *eye, ScePspFVector3 *center, ScePspFVector3 *up)
{
sceGumMatrixMode(GU_VIEW);
sceGumLoadIdentity();
#define GFX_H
#include "singleton.h"
+#include <psptypes.h>
-class GFX: public Singleton<GFX>
+class Gfx: public Singleton<Gfx>
{
- void *display_list;
- void *fb0; //< frame buffer
+ void *fbp0; //< frame buffer
int frames_drawn;
- char fps_display[100];
+ char fps_display[200];
u32 tick_resolution;
u64 fps_tick_now, fps_tick_last;
public:
- const int SCR_WIDTH=480;
- const int SCR_HEIGHT=272;
- const int BUF_WIDTH=512;
+ void *display_list;
+ static const int SCR_WIDTH=480;
+ static const int SCR_HEIGHT=272;
+ static const int BUF_WIDTH=512;
void init();
void cleanup();
+
void update_fps();
+ void swap_buffers();
- void setup_perspective(float fov, float aspect, float znear, float zfar);
+ void perspective(float fov, float aspect, float znear, float zfar);
void look_at(ScePspFVector3 *eye, ScePspFVector3 *center, ScePspFVector3 *up);
};
+#define GFX Gfx::Instance()
+
#endif