WIP: I can has on-screen triangles :)
authorslack <slack@Blackbird.(none)>
Thu, 2 Oct 2008 23:53:59 +0000 (01:53 +0200)
committerslack <slack@Blackbird.(none)>
Thu, 2 Oct 2008 23:53:59 +0000 (01:53 +0200)
Makefile
game.cc
gfx.cc
gfx.h

index 83c83f26065070308b59d40ce877a910667caf7c..3c3c8fbb7347414160c085d5a8d33d088e5140b1 100644 (file)
--- 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 a6319468e1fdc95120e597055c655cec4e20006b..fad9d39c0b0ce150cbd68138c7a0c84413db3d44 100644 (file)
--- a/game.cc
+++ b/game.cc
@@ -1,10 +1,47 @@
 #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, &center, &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 6d7cf1c28ba0eeaf636edbc9b42df9ae5b620ea1..af05fa73bcd075434f7ed798c794ff4ef79c3aab 100644 (file)
--- a/gfx.cc
+++ b/gfx.cc
@@ -1,14 +1,23 @@
 #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);
@@ -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 97081fca86b2e31a23cb953b4ab1e426cb533a36..83eb2d4f9ca1911b9ef99795af076bad1c3525ba 100644 (file)
--- a/gfx.h
+++ b/gfx.h
@@ -2,29 +2,34 @@
 #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