From: slack Date: Thu, 2 Oct 2008 23:53:59 +0000 (+0200) Subject: WIP: I can has on-screen triangles :) X-Git-Url: http://slack.codemaniacs.com/git/?a=commitdiff_plain;h=58f29661095c79d17364214ff3120ea8d33d2a5f;p=laz0r.git WIP: I can has on-screen triangles :) --- diff --git a/Makefile b/Makefile index 83c83f2..3c3c8fb 100644 --- a/Makefile +++ b/Makefile @@ -5,10 +5,11 @@ PSP_FW_VERSION=401 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 = diff --git a/game.cc b/game.cc index a631946..fad9d39 100644 --- a/game.cc +++ b/game.cc @@ -1,10 +1,47 @@ #include "game.h" +#include "gfx.h" + +#include +#include +#include +#include + +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(); } diff --git a/gfx.cc b/gfx.cc index 6d7cf1c..af05fa7 100644 --- a/gfx.cc +++ b/gfx.cc @@ -1,14 +1,23 @@ #include "gfx.h" +#include +#include + #include #include -#include +#include +#include +#include +#include +#include // 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); @@ -30,8 +39,8 @@ void GFX::init() 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 ) ); @@ -45,26 +54,24 @@ void GFX::init() // 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 ); @@ -72,8 +79,13 @@ void update_fps( void ) 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); @@ -81,7 +93,7 @@ void GFX::perspective(float fov, float aspect, float znear, float zfar) 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(); diff --git a/gfx.h b/gfx.h index 97081fc..83eb2d4 100644 --- a/gfx.h +++ b/gfx.h @@ -2,29 +2,34 @@ #define GFX_H #include "singleton.h" +#include -class GFX: public Singleton +class Gfx: public Singleton { - 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