├── Tutorial4a ├── Box.h ├── Box.cpp ├── texture.png ├── framebuffer.c ├── framebuffer.h ├── makefile ├── GameApp.h ├── GraphicsObject.h ├── Triangle.h ├── Triangle.cpp ├── GraphicsObject.cpp ├── GameApp.cpp ├── main.cpp └── graphics.h ├── .gitattributes ├── Tutorial11 ├── load1.png ├── load2.png ├── framebuffer.c ├── framebuffer.h ├── LoadingScreen.h ├── makefile ├── GameApp.h ├── GraphicsObject.h ├── GameApp.cpp ├── main.cpp ├── LoadingScreen.cpp ├── GraphicsObject.cpp └── graphics.h ├── Tutorial12 ├── stone03.png ├── brickmorter.png ├── UVtexturesCrate256.png ├── framebuffer.c ├── UVtexturesHousePlatDak1024type3.png ├── framebuffer.h ├── krat.mtl ├── Model.h ├── makefile ├── DesertHouse.mtl ├── GameApp.h ├── GraphicsObject.h ├── GraphicsObject.cpp ├── krat.obj ├── main.cpp ├── GameApp.cpp ├── Model.cpp └── graphics.h ├── Tutorial5 ├── texture.png ├── framebuffer.c ├── framebuffer.h ├── Triangle.h ├── GameApp.h ├── GraphicsObject.h ├── Triangle.cpp ├── main.cpp ├── GameApp.cpp ├── GraphicsObject.cpp └── graphics.h ├── TutorialFX2 ├── texture.png ├── framebuffer.c ├── framebuffer.h ├── makefile ├── GameApp.h ├── GraphicsObject.h ├── main.cpp ├── GameApp.cpp ├── GraphicsObject.cpp └── graphics.h ├── Tutorial17textures ├── land1.png ├── land2.png ├── land3.png └── land4.png ├── Tutorial17 ├── framebuffer.c ├── framebuffer.h ├── makefile ├── GameApp.h ├── GraphicsObject.h ├── SkyBox.h ├── GraphicsObject.cpp ├── main.cpp ├── GameApp.cpp ├── SkyBox.cpp └── graphics.h ├── Tutorialm1 ├── Timer.h ├── GameApp.h ├── GraphicsObject.h ├── Timer.cpp ├── GraphicsObject.cpp ├── GameApp.cpp └── main.cpp ├── Tutorial0 ├── makefile ├── GraphicsObject.h ├── make.bat ├── GraphicsObject.cpp └── main.cpp ├── Tutorial1 ├── GameApp.h ├── makefile ├── GraphicsObject.h ├── make.bat ├── GameApp.cpp ├── GraphicsObject.cpp └── main.cpp ├── Tutorial6a ├── GameApp.h ├── GraphicsObject.h ├── GameApp.cpp ├── main.cpp └── GraphicsObject.cpp ├── Tutorialm5 ├── GameApp.h ├── GraphicsObject.h ├── GraphicsObject.cpp ├── main.cpp └── GameApp.cpp ├── Tutorial6b ├── makefile ├── GameApp.h ├── GraphicsObject.h ├── main.cpp ├── GameApp.cpp └── GraphicsObject.cpp ├── Tutorialm2 ├── makefile ├── GraphicsObject.h ├── GameApp.h ├── UtilObject.h ├── UtilObject.cpp ├── GraphicsObject.cpp ├── main.cpp └── GameApp.cpp ├── Tutorialm9 ├── makefile ├── GraphicsObject.h ├── GameApp.h ├── GameApp.cpp ├── GraphicsObject.cpp └── main.cpp ├── Tutorial2 ├── Triangle.h ├── GraphicsObject.h ├── GameApp.h ├── Triangle.cpp ├── GraphicsObject.cpp ├── GameApp.cpp └── main.cpp └── README.md /Tutorial4a/Box.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Tutorial4a/Box.cpp: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /Tutorial11/load1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PSP-Archive/3D-PSP-Tutorials/HEAD/Tutorial11/load1.png -------------------------------------------------------------------------------- /Tutorial11/load2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PSP-Archive/3D-PSP-Tutorials/HEAD/Tutorial11/load2.png -------------------------------------------------------------------------------- /Tutorial12/stone03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PSP-Archive/3D-PSP-Tutorials/HEAD/Tutorial12/stone03.png -------------------------------------------------------------------------------- /Tutorial4a/texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PSP-Archive/3D-PSP-Tutorials/HEAD/Tutorial4a/texture.png -------------------------------------------------------------------------------- /Tutorial5/texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PSP-Archive/3D-PSP-Tutorials/HEAD/Tutorial5/texture.png -------------------------------------------------------------------------------- /TutorialFX2/texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PSP-Archive/3D-PSP-Tutorials/HEAD/TutorialFX2/texture.png -------------------------------------------------------------------------------- /Tutorial12/brickmorter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PSP-Archive/3D-PSP-Tutorials/HEAD/Tutorial12/brickmorter.png -------------------------------------------------------------------------------- /Tutorial17textures/land1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PSP-Archive/3D-PSP-Tutorials/HEAD/Tutorial17textures/land1.png -------------------------------------------------------------------------------- /Tutorial17textures/land2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PSP-Archive/3D-PSP-Tutorials/HEAD/Tutorial17textures/land2.png -------------------------------------------------------------------------------- /Tutorial17textures/land3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PSP-Archive/3D-PSP-Tutorials/HEAD/Tutorial17textures/land3.png -------------------------------------------------------------------------------- /Tutorial17textures/land4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PSP-Archive/3D-PSP-Tutorials/HEAD/Tutorial17textures/land4.png -------------------------------------------------------------------------------- /Tutorial12/UVtexturesCrate256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PSP-Archive/3D-PSP-Tutorials/HEAD/Tutorial12/UVtexturesCrate256.png -------------------------------------------------------------------------------- /Tutorial11/framebuffer.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "graphics.h" 3 | 4 | Color* g_vram_base = (Color*) (0x40000000 | 0x04000000); 5 | -------------------------------------------------------------------------------- /Tutorial12/framebuffer.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "graphics.h" 3 | 4 | Color* g_vram_base = (Color*) (0x40000000 | 0x04000000); 5 | -------------------------------------------------------------------------------- /Tutorial17/framebuffer.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "graphics.h" 3 | 4 | Color* g_vram_base = (Color*) (0x40000000 | 0x04000000); 5 | -------------------------------------------------------------------------------- /Tutorial4a/framebuffer.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "graphics.h" 3 | 4 | Color* g_vram_base = (Color*) (0x40000000 | 0x04000000); 5 | -------------------------------------------------------------------------------- /Tutorial5/framebuffer.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "graphics.h" 3 | 4 | Color* g_vram_base = (Color*) (0x40000000 | 0x04000000); 5 | -------------------------------------------------------------------------------- /TutorialFX2/framebuffer.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "graphics.h" 3 | 4 | Color* g_vram_base = (Color*) (0x40000000 | 0x04000000); 5 | -------------------------------------------------------------------------------- /Tutorial11/framebuffer.h: -------------------------------------------------------------------------------- 1 | #ifndef FRAMEBUFFER_H 2 | #define FRAMEBUFFER_H 3 | 4 | #include 5 | 6 | extern u32* g_vram_base; 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /Tutorial12/UVtexturesHousePlatDak1024type3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PSP-Archive/3D-PSP-Tutorials/HEAD/Tutorial12/UVtexturesHousePlatDak1024type3.png -------------------------------------------------------------------------------- /Tutorial12/framebuffer.h: -------------------------------------------------------------------------------- 1 | #ifndef FRAMEBUFFER_H 2 | #define FRAMEBUFFER_H 3 | 4 | #include 5 | 6 | extern u32* g_vram_base; 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /Tutorial17/framebuffer.h: -------------------------------------------------------------------------------- 1 | #ifndef FRAMEBUFFER_H 2 | #define FRAMEBUFFER_H 3 | 4 | #include 5 | 6 | extern u32* g_vram_base; 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /Tutorial4a/framebuffer.h: -------------------------------------------------------------------------------- 1 | #ifndef FRAMEBUFFER_H 2 | #define FRAMEBUFFER_H 3 | 4 | #include 5 | 6 | extern u32* g_vram_base; 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /Tutorial5/framebuffer.h: -------------------------------------------------------------------------------- 1 | #ifndef FRAMEBUFFER_H 2 | #define FRAMEBUFFER_H 3 | 4 | #include 5 | 6 | extern u32* g_vram_base; 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /TutorialFX2/framebuffer.h: -------------------------------------------------------------------------------- 1 | #ifndef FRAMEBUFFER_H 2 | #define FRAMEBUFFER_H 3 | 4 | #include 5 | 6 | extern u32* g_vram_base; 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /Tutorial12/krat.mtl: -------------------------------------------------------------------------------- 1 | newmtl initialShadingGroup 2 | illum 4 3 | Kd 0.00 0.00 0.00 4 | Ka 0.00 0.00 0.00 5 | Tf 1.00 1.00 1.00 6 | map_Kd UVtexturesCrate256.png# 7 | Ni 1.00 8 | -------------------------------------------------------------------------------- /Tutorialm1/Timer.h: -------------------------------------------------------------------------------- 1 | #ifndef TIMER_H_ 2 | #define TIMER_H_ 3 | 4 | #include "time.h" 5 | 6 | class Timer { 7 | 8 | protected: 9 | time_t TimeNow_; 10 | time_t TimeStart_; 11 | bool timerStarted_; 12 | 13 | public: 14 | void startTimer(); 15 | void resetTimer(); 16 | int getTimer(); 17 | 18 | }; 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /Tutorial11/LoadingScreen.h: -------------------------------------------------------------------------------- 1 | #ifndef LOADINGSCREEN_H_ 2 | #define LOADINGSCREEN_H_ 3 | 4 | #include 5 | 6 | class LoadingScreen { 7 | 8 | protected: 9 | static int RunLoadingScreen(SceSize args, void *argp); 10 | SceUID thid_; 11 | 12 | public: 13 | LoadingScreen(); 14 | void KillLoadingScreen(); 15 | 16 | }; 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /Tutorial12/Model.h: -------------------------------------------------------------------------------- 1 | #ifndef MODEL_H_ 2 | #define MODEL_H_ 3 | 4 | #include "GraphicsObject.h" 5 | 6 | class Model { 7 | 8 | protected: 9 | ObjMeshPart* parts; 10 | int partCount; 11 | bool Load(const char* file, const char* mtl); 12 | 13 | public: 14 | Model(const char* file, const char* mtl); 15 | void Render(); 16 | 17 | }; 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /Tutorial0/makefile: -------------------------------------------------------------------------------- 1 | TARGET = out 2 | OBJS = $(wildcard *.cpp) $(wildcard *.c) 3 | 4 | INCDIR = 5 | CFLAGS = -O2 -G0 -Wall -g 6 | CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti -g 7 | ASFLAGS = $(CFLAGS) 8 | 9 | LIBDIR = 10 | LDFLAGS = 11 | LIBS = -lstdc++ -lc -lpspgu 12 | 13 | PSPSDK=$(shell psp-config --pspsdk-path) 14 | include $(PSPSDK)/lib/build.mak 15 | -------------------------------------------------------------------------------- /Tutorial1/GameApp.h: -------------------------------------------------------------------------------- 1 | #ifndef GAMEAPP_H_ 2 | #define GAMEAPP_H_ 3 | 4 | #include "GraphicsObject.h" 5 | 6 | class GameApp { 7 | 8 | protected: 9 | int frameCount; 10 | GraphicsObject* gfx; 11 | 12 | int Controls(); 13 | void Render(); 14 | bool Load(); 15 | 16 | public: 17 | GameApp(); 18 | ~GameApp(); 19 | int Run(); 20 | 21 | }; 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /Tutorial1/makefile: -------------------------------------------------------------------------------- 1 | TARGET = out 2 | OBJS = $(wildcard *.cpp) $(wildcard *.c) 3 | 4 | INCDIR = 5 | CFLAGS = -O2 -G0 -Wall -g 6 | CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti -g 7 | ASFLAGS = $(CFLAGS) 8 | 9 | LIBDIR = 10 | LDFLAGS = 11 | LIBS = -lstdc++ -lc -lpspgu -lpsprtc 12 | 13 | PSPSDK=$(shell psp-config --pspsdk-path) 14 | include $(PSPSDK)/lib/build.mak 15 | -------------------------------------------------------------------------------- /Tutorial6a/GameApp.h: -------------------------------------------------------------------------------- 1 | #ifndef GAMEAPP_H_ 2 | #define GAMEAPP_H_ 3 | 4 | #include "GraphicsObject.h" 5 | 6 | class GameApp { 7 | 8 | protected: 9 | int frameCount; 10 | GraphicsObject* gfx; 11 | 12 | int Controls(); 13 | void Render(); 14 | bool Load(); 15 | 16 | public: 17 | GameApp(); 18 | ~GameApp(); 19 | int Run(); 20 | 21 | }; 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /Tutorialm5/GameApp.h: -------------------------------------------------------------------------------- 1 | #ifndef GAMEAPP_H_ 2 | #define GAMEAPP_H_ 3 | 4 | #include "GraphicsObject.h" 5 | 6 | class GameApp { 7 | 8 | protected: 9 | int frameCount; 10 | GraphicsObject* gfx; 11 | 12 | int Controls(); 13 | void Render(); 14 | bool Load(); 15 | 16 | public: 17 | GameApp(); 18 | ~GameApp(); 19 | int Run(); 20 | 21 | }; 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /Tutorial6b/makefile: -------------------------------------------------------------------------------- 1 | TARGET = out 2 | OBJS = $(wildcard *.cpp) $(wildcard *.c) 3 | 4 | INCDIR = 5 | CFLAGS = -O2 -G0 -Wall -g 6 | CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti -g 7 | ASFLAGS = $(CFLAGS) 8 | 9 | LIBDIR = 10 | LDFLAGS = 11 | LIBS = -lc -g -lpspgum -lpspgu -lstdc++ -lm -lpsppower 12 | 13 | PSPSDK=$(shell psp-config --pspsdk-path) 14 | include $(PSPSDK)/lib/build.mak 15 | -------------------------------------------------------------------------------- /TutorialFX2/makefile: -------------------------------------------------------------------------------- 1 | TARGET = out 2 | OBJS = $(wildcard *.cpp) $(wildcard *.c) 3 | 4 | INCDIR = 5 | CFLAGS = -O2 -G0 -Wall 6 | CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti 7 | ASFLAGS = $(CFLAGS) 8 | 9 | LIBDIR = 10 | LDFLAGS = 11 | LIBS = -lc -g -lpng -lz -lpspgum -lpspgu -lstdc++ -lm 12 | 13 | PSPSDK=$(shell psp-config --pspsdk-path) 14 | include $(PSPSDK)/lib/build.mak 15 | 16 | -------------------------------------------------------------------------------- /Tutorialm2/makefile: -------------------------------------------------------------------------------- 1 | TARGET = out 2 | OBJS = $(wildcard *.cpp) $(wildcard *.c) 3 | 4 | INCDIR = 5 | CFLAGS = -O2 -G0 -Wall -g 6 | CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti -g 7 | ASFLAGS = $(CFLAGS) 8 | 9 | LIBDIR = 10 | LDFLAGS = 11 | LIBS = -lc -g -lpspgum -lpspgu -lstdc++ -lm -lpsppower 12 | 13 | PSPSDK=$(shell psp-config --pspsdk-path) 14 | include $(PSPSDK)/lib/build.mak 15 | -------------------------------------------------------------------------------- /Tutorial11/makefile: -------------------------------------------------------------------------------- 1 | TARGET = out 2 | OBJS = $(wildcard *.cpp) $(wildcard *.c) 3 | 4 | INCDIR = 5 | CFLAGS = -O2 -G0 -Wall -g 6 | CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti -g 7 | ASFLAGS = $(CFLAGS) 8 | 9 | LIBDIR = 10 | LDFLAGS = 11 | LIBS = -lstdc++ -lc -lpspgu -lpspgum -lpng -lz -lpsprtc -lm 12 | 13 | PSPSDK=$(shell psp-config --pspsdk-path) 14 | include $(PSPSDK)/lib/build.mak 15 | -------------------------------------------------------------------------------- /Tutorial12/makefile: -------------------------------------------------------------------------------- 1 | TARGET = out 2 | OBJS = $(wildcard *.cpp) $(wildcard *.c) 3 | 4 | INCDIR = 5 | CFLAGS = -O2 -G0 -Wall -g 6 | CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti -g 7 | ASFLAGS = $(CFLAGS) 8 | 9 | LIBDIR = 10 | LDFLAGS = 11 | LIBS = -lc -g -lpspgum -lpspgu -lpng -lz -lstdc++ -lm -lpsppower 12 | 13 | PSPSDK=$(shell psp-config --pspsdk-path) 14 | include $(PSPSDK)/lib/build.mak 15 | -------------------------------------------------------------------------------- /Tutorial17/makefile: -------------------------------------------------------------------------------- 1 | TARGET = out 2 | OBJS = $(wildcard *.cpp) $(wildcard *.c) 3 | 4 | INCDIR = 5 | CFLAGS = -O2 -G0 -Wall -g 6 | CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti -g 7 | ASFLAGS = $(CFLAGS) 8 | 9 | LIBDIR = 10 | LDFLAGS = 11 | LIBS = -lc -g -lpspgum -lpspgu -lpng -lz -lstdc++ -lm -lpsppower 12 | 13 | PSPSDK=$(shell psp-config --pspsdk-path) 14 | include $(PSPSDK)/lib/build.mak 15 | -------------------------------------------------------------------------------- /Tutorial4a/makefile: -------------------------------------------------------------------------------- 1 | TARGET = out 2 | OBJS = $(wildcard *.cpp) $(wildcard *.c) 3 | 4 | INCDIR = 5 | CFLAGS = -O2 -G0 -Wall -g 6 | CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti -g 7 | ASFLAGS = $(CFLAGS) 8 | 9 | LIBDIR = 10 | LDFLAGS = 11 | LIBS = -lc -g -lpspgum -lpspgu -lpng -lz -lstdc++ -lm -lpsppower 12 | 13 | PSPSDK=$(shell psp-config --pspsdk-path) 14 | include $(PSPSDK)/lib/build.mak 15 | -------------------------------------------------------------------------------- /Tutorialm9/makefile: -------------------------------------------------------------------------------- 1 | TARGET = out 2 | OBJS = $(wildcard *.cpp) $(wildcard *.c) 3 | 4 | INCDIR = 5 | CFLAGS = -O2 -G0 -Wall -g 6 | CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti -g 7 | ASFLAGS = $(CFLAGS) 8 | 9 | LIBDIR = 10 | LDFLAGS = 11 | LIBS = -lc -g -lpspgum -lpspgu -lstdc++ -lm -lpsppower -lpsprtc 12 | 13 | PSPSDK=$(shell psp-config --pspsdk-path) 14 | include $(PSPSDK)/lib/build.mak 15 | -------------------------------------------------------------------------------- /Tutorial11/GameApp.h: -------------------------------------------------------------------------------- 1 | #ifndef GAMEAPP_H_ 2 | #define GAMEAPP_H_ 3 | 4 | #include "GraphicsObject.h" 5 | #include "LoadingScreen.h" 6 | 7 | class GameApp { 8 | 9 | protected: 10 | int frameCount; 11 | GraphicsObject* gfx; 12 | LoadingScreen* loadscr; 13 | 14 | int Controls(); 15 | void Render(); 16 | bool Load(); 17 | 18 | public: 19 | GameApp(); 20 | ~GameApp(); 21 | int Run(); 22 | 23 | }; 24 | 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /Tutorial2/Triangle.h: -------------------------------------------------------------------------------- 1 | #ifndef TRIANGLE_H_ 2 | #define TRIANGLE_H_ 3 | 4 | #include 5 | 6 | typedef struct { unsigned int color; 7 | float x, y, z; } vertex; // vertex to render 8 | 9 | class Triangle { 10 | 11 | protected: 12 | vertex* triangle; 13 | float rot; 14 | ScePspFMatrix4 world; 15 | 16 | public: 17 | Triangle(); 18 | ~Triangle(); 19 | 20 | void Render(); 21 | 22 | }; 23 | 24 | #endif 25 | 26 | -------------------------------------------------------------------------------- /Tutorial5/Triangle.h: -------------------------------------------------------------------------------- 1 | #ifndef TRIANGLE_H_ 2 | #define TRIANGLE_H_ 3 | 4 | #include 5 | 6 | typedef struct { unsigned int color; 7 | float x, y, z; } vertex; // vertex to render 8 | 9 | class Triangle { 10 | 11 | protected: 12 | vertex* triangle; 13 | float rot; 14 | ScePspFMatrix4 world; 15 | 16 | public: 17 | Triangle(); 18 | ~Triangle(); 19 | 20 | void Render(); 21 | 22 | }; 23 | 24 | #endif 25 | 26 | -------------------------------------------------------------------------------- /Tutorialm1/GameApp.h: -------------------------------------------------------------------------------- 1 | #ifndef GAMEAPP_H_ 2 | #define GAMEAPP_H_ 3 | 4 | #include "GraphicsObject.h" 5 | #include "Timer.h" 6 | 7 | class GameApp { 8 | 9 | protected: 10 | GraphicsObject* gfx; 11 | Timer* timer; 12 | 13 | int buttonCross; 14 | int buttonSquare; 15 | 16 | int Controls(); 17 | void Render(); 18 | bool Load(); 19 | 20 | public: 21 | GameApp(); 22 | ~GameApp(); 23 | int Run(); 24 | 25 | }; 26 | 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /Tutorial6b/GameApp.h: -------------------------------------------------------------------------------- 1 | #ifndef GAMEAPP_H_ 2 | #define GAMEAPP_H_ 3 | 4 | #include "GraphicsObject.h" 5 | #include 6 | 7 | class GameApp { 8 | 9 | protected: 10 | int frameCount; 11 | GraphicsObject* gfx; 12 | 13 | ScePspFMatrix4 projection; 14 | ScePspFMatrix4 view; 15 | 16 | int Controls(); 17 | void Render(); 18 | bool Load(); 19 | 20 | public: 21 | GameApp(); 22 | ~GameApp(); 23 | int Run(); 24 | 25 | }; 26 | 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /Tutorial12/DesertHouse.mtl: -------------------------------------------------------------------------------- 1 | newmtl lambert2SG 2 | illum 4 3 | Kd 0.00 0.00 0.00 4 | Ka 0.00 0.00 0.00 5 | Tf 1.00 1.00 1.00 6 | map_Kd UVtexturesHousePlatDak1024type3.png# 7 | Ni 1.00 8 | newmtl lambert3SG 9 | illum 4 10 | Kd 0.00 0.00 0.00 11 | Ka 0.00 0.00 0.00 12 | Tf 1.00 1.00 1.00 13 | map_Kd brickmorter.png# 14 | Ni 1.00 15 | newmtl lambert4SG 16 | illum 4 17 | Kd 0.00 0.00 0.00 18 | Ka 0.00 0.00 0.00 19 | Tf 1.00 1.00 1.00 20 | map_Kd stone03.png# 21 | Ni 1.00 22 | -------------------------------------------------------------------------------- /Tutorial0/GraphicsObject.h: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHICSOBJECT_H_ 2 | #define GRAPHICSOBJECT_H_ 3 | 4 | class GraphicsObject { 5 | 6 | private: 7 | static GraphicsObject* _instance; 8 | 9 | protected: 10 | GraphicsObject(void); 11 | GraphicsObject(const GraphicsObject&); 12 | GraphicsObject& operator= (const GraphicsObject&); 13 | 14 | public: 15 | static GraphicsObject* Instance(void); 16 | ~GraphicsObject(void); 17 | 18 | bool Init3DGraphics(void); 19 | }; 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /Tutorial1/GraphicsObject.h: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHICSOBJECT_H_ 2 | #define GRAPHICSOBJECT_H_ 3 | 4 | class GraphicsObject { 5 | 6 | private: 7 | static GraphicsObject* _instance; 8 | 9 | protected: 10 | GraphicsObject(void); 11 | GraphicsObject(const GraphicsObject&); 12 | GraphicsObject& operator= (const GraphicsObject&); 13 | 14 | public: 15 | static GraphicsObject* Instance(void); 16 | ~GraphicsObject(void); 17 | 18 | bool Init3DGraphics(void); 19 | }; 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /Tutorialm1/GraphicsObject.h: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHICSOBJECT_H_ 2 | #define GRAPHICSOBJECT_H_ 3 | 4 | class GraphicsObject { 5 | 6 | private: 7 | static GraphicsObject* _instance; 8 | 9 | protected: 10 | GraphicsObject(void); 11 | GraphicsObject(const GraphicsObject&); 12 | GraphicsObject& operator= (const GraphicsObject&); 13 | 14 | public: 15 | static GraphicsObject* Instance(void); 16 | ~GraphicsObject(void); 17 | 18 | bool Init3DGraphics(void); 19 | }; 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /Tutorialm2/GraphicsObject.h: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHICSOBJECT_H_ 2 | #define GRAPHICSOBJECT_H_ 3 | 4 | class GraphicsObject { 5 | 6 | private: 7 | static GraphicsObject* _instance; 8 | 9 | protected: 10 | GraphicsObject(void); 11 | GraphicsObject(const GraphicsObject&); 12 | GraphicsObject& operator= (const GraphicsObject&); 13 | 14 | public: 15 | static GraphicsObject* Instance(void); 16 | ~GraphicsObject(void); 17 | 18 | bool Init3DGraphics(void); 19 | }; 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /Tutorialm5/GraphicsObject.h: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHICSOBJECT_H_ 2 | #define GRAPHICSOBJECT_H_ 3 | 4 | class GraphicsObject { 5 | 6 | private: 7 | static GraphicsObject* _instance; 8 | 9 | protected: 10 | GraphicsObject(void); 11 | GraphicsObject(const GraphicsObject&); 12 | GraphicsObject& operator= (const GraphicsObject&); 13 | 14 | public: 15 | static GraphicsObject* Instance(void); 16 | ~GraphicsObject(void); 17 | 18 | bool Init3DGraphics(void); 19 | }; 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /Tutorialm9/GraphicsObject.h: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHICSOBJECT_H_ 2 | #define GRAPHICSOBJECT_H_ 3 | 4 | class GraphicsObject { 5 | 6 | private: 7 | static GraphicsObject* _instance; 8 | 9 | protected: 10 | GraphicsObject(void); 11 | GraphicsObject(const GraphicsObject&); 12 | GraphicsObject& operator= (const GraphicsObject&); 13 | 14 | public: 15 | static GraphicsObject* Instance(void); 16 | ~GraphicsObject(void); 17 | 18 | bool Init3DGraphics(void); 19 | }; 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /Tutorial2/GraphicsObject.h: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHICSOBJECT_H_ 2 | #define GRAPHICSOBJECT_H_ 3 | 4 | class GraphicsObject { 5 | 6 | private: 7 | static GraphicsObject* _instance; 8 | 9 | protected: 10 | GraphicsObject(void); 11 | GraphicsObject(const GraphicsObject&); 12 | GraphicsObject& operator= (const GraphicsObject&); 13 | 14 | public: 15 | static GraphicsObject* Instance(void); 16 | ~GraphicsObject(void); 17 | 18 | bool Init3DGraphics(void); 19 | 20 | }; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /Tutorial2/GameApp.h: -------------------------------------------------------------------------------- 1 | #ifndef GAMEAPP_H_ 2 | #define GAMEAPP_H_ 3 | 4 | #include "GraphicsObject.h" 5 | #include "Triangle.h" 6 | #include 7 | 8 | class GameApp { 9 | 10 | protected: 11 | GraphicsObject* gfx; 12 | Triangle* triangle; 13 | 14 | ScePspFMatrix4 projection; 15 | ScePspFMatrix4 view; 16 | 17 | int Controls(); 18 | void Render(); 19 | bool Load(); 20 | 21 | public: 22 | GameApp(); 23 | ~GameApp(); 24 | int Run(); 25 | 26 | }; 27 | 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /Tutorial4a/GameApp.h: -------------------------------------------------------------------------------- 1 | #ifndef GAMEAPP_H_ 2 | #define GAMEAPP_H_ 3 | 4 | #include "GraphicsObject.h" 5 | #include "Triangle.h" 6 | #include 7 | 8 | class GameApp { 9 | 10 | protected: 11 | GraphicsObject* gfx; 12 | Triangle* triangle; 13 | 14 | ScePspFMatrix4 projection; 15 | ScePspFMatrix4 view; 16 | 17 | int Controls(); 18 | void Render(); 19 | bool Load(); 20 | 21 | public: 22 | GameApp(); 23 | ~GameApp(); 24 | int Run(); 25 | 26 | }; 27 | 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /Tutorial4a/GraphicsObject.h: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHICSOBJECT_H_ 2 | #define GRAPHICSOBJECT_H_ 3 | 4 | 5 | class GraphicsObject { 6 | 7 | private: 8 | static GraphicsObject* _instance; 9 | 10 | protected: 11 | GraphicsObject(void); 12 | GraphicsObject(const GraphicsObject&); 13 | GraphicsObject& operator= (const GraphicsObject&); 14 | 15 | public: 16 | static GraphicsObject* Instance(void); 17 | ~GraphicsObject(void); 18 | 19 | bool Init3DGraphics(void); 20 | 21 | }; 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /Tutorial12/GameApp.h: -------------------------------------------------------------------------------- 1 | #ifndef GAMEAPP_H_ 2 | #define GAMEAPP_H_ 3 | 4 | #include "GraphicsObject.h" 5 | #include 6 | #include "Model.h" 7 | 8 | class GameApp { 9 | 10 | protected: 11 | GraphicsObject* gfx; 12 | Model* model; 13 | ScePspFMatrix4 projection; 14 | ScePspFMatrix4 view; 15 | 16 | float rot; 17 | 18 | int Controls(); 19 | void Render(); 20 | bool Load(); 21 | 22 | public: 23 | GameApp(); 24 | ~GameApp(); 25 | int Run(); 26 | 27 | }; 28 | 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /Tutorialm2/GameApp.h: -------------------------------------------------------------------------------- 1 | #ifndef GAMEAPP_H_ 2 | #define GAMEAPP_H_ 3 | 4 | #include "GraphicsObject.h" 5 | #include "UtilObject.h" 6 | 7 | class GameApp { 8 | 9 | protected: 10 | GraphicsObject* gfx; 11 | UtilObject* utils; 12 | 13 | int goodRandom; 14 | int badRandom; 15 | 16 | int buttonCross; 17 | int buttonSquare; 18 | 19 | int Controls(); 20 | void Render(); 21 | bool Load(); 22 | 23 | public: 24 | GameApp(); 25 | ~GameApp(); 26 | int Run(); 27 | 28 | }; 29 | 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /Tutorial17/GameApp.h: -------------------------------------------------------------------------------- 1 | #ifndef GAMEAPP_H_ 2 | #define GAMEAPP_H_ 3 | 4 | #include "GraphicsObject.h" 5 | #include 6 | #include "SkyBox.h" 7 | 8 | class GameApp { 9 | 10 | protected: 11 | GraphicsObject* gfx; 12 | SkyBox* sky; 13 | 14 | ScePspFMatrix4 projection; 15 | ScePspFMatrix4 view; 16 | 17 | float rot; 18 | 19 | int Controls(); 20 | void Render(); 21 | bool Load(); 22 | 23 | public: 24 | GameApp(); 25 | ~GameApp(); 26 | int Run(); 27 | 28 | }; 29 | 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /Tutorial0/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | ECHO COmpiling project... 4 | 5 | SET path=%path%;C:\cygwin\bin;C:\cygwin\usr/local/pspdev/bin 6 | SET PSPSDK=C:\cygwin\usr/local/pspdev 7 | 8 | make.exe 9 | 10 | ECHO Delete objects not needed... 11 | DEL *.o 12 | 13 | SET DRIVE=.\ 14 | 15 | ECHO Creating the PBP 16 | MD %DRIVE%TUTORIAL0%% 17 | Elf2pbpm -FILEOUT=%DRIVE%TUTORIAL0%%\EBOOT.PBP -TITLE="Tutorial 0" 18 | 19 | ECHO Rename to EBOOT.PBP 20 | MD %DRIVE%TUTORIAL0 21 | MOVE out.elf %DRIVE%TUTORIAL0\EBOOT.PBP 22 | 23 | -------------------------------------------------------------------------------- /Tutorial1/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | ECHO Compiling project... 4 | 5 | SET path=%path%;C:\cygwin\bin;C:\cygwin\usr/local/pspdev/bin 6 | SET PSPSDK=C:\cygwin\usr/local/pspdev 7 | 8 | make.exe 9 | 10 | ECHO Delete objects not needed... 11 | DEL *.o 12 | 13 | SET DRIVE=.\ 14 | 15 | ECHO Creating the PBP 16 | MD %DRIVE%TUTORIAL0%% 17 | Elf2pbpm -FILEOUT=%DRIVE%TUTORIAL1%%\EBOOT.PBP -TITLE="Tutorial 1" 18 | 19 | ECHO Rename to EBOOT.PBP 20 | MD %DRIVE%TUTORIAL1 21 | MOVE out.elf %DRIVE%TUTORIAL1\EBOOT.PBP 22 | 23 | -------------------------------------------------------------------------------- /TutorialFX2/GameApp.h: -------------------------------------------------------------------------------- 1 | #ifndef GAMEAPP_H_ 2 | #define GAMEAPP_H_ 3 | 4 | #include "GraphicsObject.h" 5 | extern "C" { 6 | #include "graphics.h" 7 | } 8 | 9 | class GameApp { 10 | 11 | protected: 12 | GraphicsObject* gfx; 13 | Image* pic; 14 | 15 | ScePspFMatrix4 projection; 16 | ScePspFMatrix4 view; 17 | 18 | bool fadeout; 19 | int fade; 20 | 21 | int Controls(); 22 | void Render(); 23 | bool Load(); 24 | 25 | public: 26 | GameApp(); 27 | ~GameApp(); 28 | int Run(); 29 | 30 | }; 31 | 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /Tutorial4a/Triangle.h: -------------------------------------------------------------------------------- 1 | #ifndef TRIANGLE_H_ 2 | #define TRIANGLE_H_ 3 | 4 | #include 5 | extern "C" { 6 | #include "graphics.h" 7 | } 8 | 9 | typedef struct { float u,v; 10 | unsigned int color; 11 | float x, y, z; } vertex; // vertex to render 12 | 13 | class Triangle { 14 | 15 | protected: 16 | vertex* triangle; 17 | float rot; 18 | ScePspFMatrix4 world; 19 | Image* texture; 20 | 21 | public: 22 | Triangle(); 23 | ~Triangle(); 24 | 25 | void Render(); 26 | 27 | }; 28 | 29 | #endif 30 | 31 | -------------------------------------------------------------------------------- /Tutorial5/GameApp.h: -------------------------------------------------------------------------------- 1 | #ifndef GAMEAPP_H_ 2 | #define GAMEAPP_H_ 3 | 4 | #include "GraphicsObject.h" 5 | #include "Triangle.h" 6 | extern "C" { 7 | #include "graphics.h" 8 | } 9 | 10 | class GameApp { 11 | 12 | protected: 13 | GraphicsObject* gfx; 14 | Triangle* triangle; 15 | Image* pic; 16 | 17 | ScePspFMatrix4 projection; 18 | ScePspFMatrix4 view; 19 | 20 | int Controls(); 21 | void Render(); 22 | bool Load(); 23 | 24 | public: 25 | GameApp(); 26 | ~GameApp(); 27 | int Run(); 28 | 29 | }; 30 | 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /Tutorial17/GraphicsObject.h: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHICSOBJECT_H_ 2 | #define GRAPHICSOBJECT_H_ 3 | 4 | 5 | typedef struct { float u, v; 6 | float x, y, z; } vertex2d; // vertex to render 7 | 8 | class GraphicsObject { 9 | 10 | private: 11 | static GraphicsObject* _instance; 12 | 13 | protected: 14 | GraphicsObject(void); 15 | GraphicsObject(const GraphicsObject&); 16 | GraphicsObject& operator= (const GraphicsObject&); 17 | 18 | public: 19 | static GraphicsObject* Instance(void); 20 | ~GraphicsObject(void); 21 | 22 | bool Init3DGraphics(void); 23 | 24 | }; 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /Tutorialm2/UtilObject.h: -------------------------------------------------------------------------------- 1 | #ifndef UTILOBJECT_H_ 2 | #define UTILOBJECT_H_ 3 | 4 | #include 5 | 6 | class UtilObject { 7 | 8 | private: 9 | static UtilObject* _instance; 10 | protected: 11 | UtilObject(void); 12 | UtilObject(const UtilObject&); 13 | UtilObject& operator= (const UtilObject&); 14 | 15 | SceKernelUtilsMt19937Context ctx; 16 | 17 | public: 18 | static UtilObject* Instance(void); 19 | ~UtilObject(void); 20 | void InitRandomizer(); 21 | int getRandomIntBad(int low, int high); 22 | int getRandomIntGood(int low, int high); 23 | 24 | }; 25 | 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /Tutorialm9/GameApp.h: -------------------------------------------------------------------------------- 1 | #ifndef GAMEAPP_H_ 2 | #define GAMEAPP_H_ 3 | 4 | #include "GraphicsObject.h" 5 | #include 6 | 7 | class GameApp { 8 | 9 | protected: 10 | GraphicsObject* gfx; 11 | 12 | int frames; // for calculating the frames per second 13 | u32 res; // resolution 14 | u64 now; // the ticks at current point 15 | u64 previous; // the ticks at the previous point 16 | char fps[100]; // the text buffer 17 | 18 | int Controls(); 19 | void Render(); 20 | bool Load(); 21 | 22 | public: 23 | GameApp(); 24 | ~GameApp(); 25 | int Run(); 26 | 27 | }; 28 | 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /Tutorial17/SkyBox.h: -------------------------------------------------------------------------------- 1 | #ifndef SKYBOX_H 2 | #define SKYBOX_H 3 | 4 | #include "GraphicsObject.h" 5 | #include 6 | 7 | extern "C" { 8 | #include "graphics.h" 9 | } 10 | 11 | class SkyBox { 12 | 13 | protected: 14 | 15 | ScePspFMatrix4 world; 16 | 17 | vertex2d* boxside1; 18 | vertex2d* boxside2; 19 | vertex2d* boxside3; 20 | vertex2d* boxside4; 21 | Image* texture1; 22 | Image* texture2; 23 | Image* texture3; 24 | Image* texture4; 25 | void CreateBox(); 26 | 27 | public: 28 | SkyBox(); 29 | ~SkyBox(); 30 | void Render(ScePspFVector3 pos); 31 | 32 | 33 | 34 | }; 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /Tutorialm1/Timer.cpp: -------------------------------------------------------------------------------- 1 | #include "Timer.h" 2 | #include 3 | 4 | void Timer::startTimer() { 5 | 6 | // getting current time 7 | sceKernelLibcTime(&this->TimeStart_); 8 | 9 | // set bool timer is started 10 | this->timerStarted_ = true; 11 | } 12 | 13 | 14 | int Timer::getTimer() { 15 | if(!this->timerStarted_) 16 | return 0; 17 | 18 | // getting current time 19 | sceKernelLibcTime(&this->TimeNow_); 20 | 21 | // return the time now minus the start time, resulting in difference time. 22 | return ((int)this->TimeNow_ - (int)this->TimeStart_); 23 | 24 | } 25 | 26 | void Timer::resetTimer() { 27 | this->timerStarted_ = false; 28 | 29 | } 30 | 31 | -------------------------------------------------------------------------------- /Tutorial6a/GraphicsObject.h: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHICSOBJECT_H_ 2 | #define GRAPHICSOBJECT_H_ 3 | 4 | typedef struct { unsigned int color; 5 | float x, y, z; } lineVertex; 6 | 7 | class GraphicsObject { 8 | 9 | private: 10 | static GraphicsObject* _instance; 11 | 12 | protected: 13 | GraphicsObject(void); 14 | GraphicsObject(const GraphicsObject&); 15 | GraphicsObject& operator= (const GraphicsObject&); 16 | 17 | public: 18 | static GraphicsObject* Instance(void); 19 | ~GraphicsObject(void); 20 | 21 | bool Init3DGraphics(void); 22 | int Render2DLineOn3D(const float x1, const float y1, const float x2, const float y2, const unsigned int color); 23 | }; 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /Tutorial5/GraphicsObject.h: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHICSOBJECT_H_ 2 | #define GRAPHICSOBJECT_H_ 3 | 4 | extern "C" { 5 | #include "graphics.h" 6 | } 7 | 8 | typedef struct { float u, v; 9 | float x, y, z; } vertex2d; // vertex to render 10 | 11 | class GraphicsObject { 12 | 13 | private: 14 | static GraphicsObject* _instance; 15 | 16 | protected: 17 | GraphicsObject(void); 18 | GraphicsObject(const GraphicsObject&); 19 | GraphicsObject& operator= (const GraphicsObject&); 20 | 21 | public: 22 | static GraphicsObject* Instance(void); 23 | ~GraphicsObject(void); 24 | 25 | bool Init3DGraphics(void); 26 | 27 | int Render2DImageOn3D(float left, float top, const Image* texture); 28 | }; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /Tutorial11/GraphicsObject.h: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHICSOBJECT_H_ 2 | #define GRAPHICSOBJECT_H_ 3 | 4 | extern "C" { 5 | #include "graphics.h" 6 | } 7 | 8 | typedef struct { float u, v; 9 | float x, y, z; } vertex2d; // vertex to render 10 | 11 | 12 | class GraphicsObject { 13 | 14 | private: 15 | static GraphicsObject* _instance; 16 | 17 | protected: 18 | GraphicsObject(void); 19 | GraphicsObject(const GraphicsObject&); 20 | GraphicsObject& operator= (const GraphicsObject&); 21 | 22 | public: 23 | static GraphicsObject* Instance(void); 24 | ~GraphicsObject(void); 25 | 26 | bool Init3DGraphics(void); 27 | 28 | int Render2DImageOn3D(float left, float top, const Image* texture); 29 | }; 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /Tutorial6b/GraphicsObject.h: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHICSOBJECT_H_ 2 | #define GRAPHICSOBJECT_H_ 3 | 4 | typedef struct { unsigned int color; 5 | float x, y, z; } lineVertex; 6 | 7 | class GraphicsObject { 8 | 9 | private: 10 | static GraphicsObject* _instance; 11 | 12 | protected: 13 | GraphicsObject(void); 14 | GraphicsObject(const GraphicsObject&); 15 | GraphicsObject& operator= (const GraphicsObject&); 16 | 17 | public: 18 | static GraphicsObject* Instance(void); 19 | ~GraphicsObject(void); 20 | 21 | bool Init3DGraphics(void); 22 | int Render2DLineOn3D(const float x1, const float y1, const float x2, const float y2, const unsigned int color); 23 | int Render3DLine(const float x1, const float y1, const float z1, const float x2, const float y2, const float z2, const unsigned int color); 24 | }; 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /TutorialFX2/GraphicsObject.h: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHICSOBJECT_H_ 2 | #define GRAPHICSOBJECT_H_ 3 | 4 | extern "C" { 5 | #include "graphics.h" 6 | } 7 | 8 | typedef struct { float u, v; 9 | float x, y, z; } vertex2d; // vertex to render 10 | 11 | typedef struct { unsigned int color; 12 | float x, y, z; } vertexc2d; // vertex to render 13 | 14 | class GraphicsObject { 15 | 16 | private: 17 | static GraphicsObject* _instance; 18 | 19 | protected: 20 | GraphicsObject(void); 21 | GraphicsObject(const GraphicsObject&); 22 | GraphicsObject& operator= (const GraphicsObject&); 23 | 24 | public: 25 | static GraphicsObject* Instance(void); 26 | ~GraphicsObject(void); 27 | 28 | bool Init3DGraphics(void); 29 | 30 | int Render2DImageOn3D(float left, float top, const Image* texture); 31 | int RenderScreenFade(const unsigned int r, const unsigned int g,const unsigned int b,const int alphaPercentage); 32 | }; 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /Tutorial2/Triangle.cpp: -------------------------------------------------------------------------------- 1 | #include "Triangle.h" 2 | #include 3 | #include 4 | #include "malloc.h" 5 | 6 | 7 | Triangle::Triangle() { 8 | 9 | triangle = (vertex*)memalign(16,3 * sizeof(vertex)); 10 | triangle[0].color = 0xffffffff; 11 | triangle[0].x = -4.0f; 12 | triangle[0].y = 2.0f; 13 | triangle[0].z = 10.0f; 14 | 15 | triangle[1].color = 0xffffffff; 16 | triangle[1].x = 0.0f; 17 | triangle[1].y = -2.0f; 18 | triangle[1].z = 10.0f; 19 | 20 | triangle[2].color = 0xffffffff; 21 | triangle[2].x = 4.0f; 22 | triangle[2].y = 2.0f; 23 | triangle[2].z = 10.0f; 24 | 25 | rot = 0.0f; 26 | } 27 | 28 | Triangle::~Triangle() { 29 | delete(triangle); 30 | } 31 | 32 | void Triangle::Render() { 33 | 34 | rot += 0.05f; 35 | 36 | sceGumMatrixMode(GU_MODEL); 37 | sceGumLoadIdentity(); 38 | sceGumRotateY(rot); 39 | 40 | sceGumDrawArray(GU_TRIANGLES, GU_COLOR_8888 | GU_VERTEX_32BITF | GU_TRANSFORM_3D, 3, 0, triangle); 41 | } 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /Tutorial5/Triangle.cpp: -------------------------------------------------------------------------------- 1 | #include "Triangle.h" 2 | #include 3 | #include 4 | #include "malloc.h" 5 | 6 | 7 | Triangle::Triangle() { 8 | 9 | triangle = (vertex*)memalign(16,3 * sizeof(vertex)); 10 | triangle[0].color = 0xffffffff; 11 | triangle[0].x = -4.0f; 12 | triangle[0].y = 2.0f; 13 | triangle[0].z = 10.0f; 14 | 15 | triangle[1].color = 0xffffffff; 16 | triangle[1].x = 0.0f; 17 | triangle[1].y = -2.0f; 18 | triangle[1].z = 10.0f; 19 | 20 | triangle[2].color = 0xffffffff; 21 | triangle[2].x = 4.0f; 22 | triangle[2].y = 2.0f; 23 | triangle[2].z = 10.0f; 24 | 25 | rot = 0.0f; 26 | } 27 | 28 | Triangle::~Triangle() { 29 | delete(triangle); 30 | } 31 | 32 | void Triangle::Render() { 33 | 34 | rot += 0.05f; 35 | 36 | sceGumMatrixMode(GU_MODEL); 37 | sceGumLoadIdentity(); 38 | sceGumRotateY(rot); 39 | 40 | sceGumDrawArray(GU_TRIANGLES, GU_COLOR_8888 | GU_VERTEX_32BITF | GU_TRANSFORM_3D, 3, 0, triangle); 41 | } 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /Tutorial12/GraphicsObject.h: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHICSOBJECT_H_ 2 | #define GRAPHICSOBJECT_H_ 3 | 4 | extern "C" { 5 | #include "graphics.h" 6 | } 7 | 8 | typedef struct { float u, v; 9 | unsigned int color; 10 | float nx, ny, nz; 11 | float x, y, z; } vertexfull; // vertex to render 12 | 13 | typedef struct { float u, v; } ScePspFTVector2; 14 | 15 | typedef struct { unsigned int vertices[3]; 16 | unsigned int textc[3]; 17 | unsigned int normals[3]; } FaceObj; 18 | 19 | typedef struct { unsigned int faceCount; 20 | vertexfull *Vertices; 21 | Image* texture; } ObjMeshPart; 22 | 23 | class GraphicsObject { 24 | 25 | private: 26 | static GraphicsObject* _instance; 27 | 28 | protected: 29 | GraphicsObject(void); 30 | GraphicsObject(const GraphicsObject&); 31 | GraphicsObject& operator= (const GraphicsObject&); 32 | 33 | public: 34 | static GraphicsObject* Instance(void); 35 | ~GraphicsObject(void); 36 | 37 | bool Init3DGraphics(void); 38 | 39 | }; 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /Tutorialm2/UtilObject.cpp: -------------------------------------------------------------------------------- 1 | #include "UtilObject.h" 2 | #include 3 | #include 4 | 5 | UtilObject* UtilObject::_instance = 0;// initialize pointer 6 | 7 | UtilObject* UtilObject::Instance (void) { 8 | 9 | if (_instance == 0){ 10 | _instance = new UtilObject; // create sole instance 11 | } 12 | return _instance; // address of sole instance 13 | } 14 | 15 | UtilObject::UtilObject(void) { 16 | // creation of object 17 | } 18 | 19 | UtilObject::~UtilObject(void) { 20 | // clean up 21 | } 22 | 23 | void UtilObject::InitRandomizer() { 24 | srand(time(NULL)); 25 | sceKernelUtilsMt19937Init(&ctx, time(NULL)); 26 | } 27 | 28 | int UtilObject::getRandomIntBad(int low, int high) { 29 | // return a random number between low and high 30 | return (rand() % (high-low+1)) + low ; 31 | } 32 | 33 | int UtilObject::getRandomIntGood(int low, int high) { 34 | // return a random number between low and high using a twister. 35 | u32 rand_val = sceKernelUtilsMt19937UInt(&ctx); 36 | rand_val = low + rand_val % (high-low); 37 | return (int)rand_val; 38 | } 39 | 40 | -------------------------------------------------------------------------------- /Tutorial1/GameApp.cpp: -------------------------------------------------------------------------------- 1 | #include "GameApp.h" 2 | #include "GraphicsObject.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | GameApp::GameApp() { 10 | 11 | } 12 | 13 | GameApp::~GameApp() { 14 | 15 | } 16 | 17 | int GameApp::Run() { 18 | 19 | if(!Load()) 20 | return 1; 21 | 22 | // game loop 23 | while(1) { 24 | if (Controls() == 9) 25 | break; 26 | Render(); 27 | } 28 | return 0; 29 | } 30 | 31 | bool GameApp::Load() { 32 | // get pointer to Graphics object. 33 | gfx = GraphicsObject::Instance(); 34 | // set up the environment. 35 | gfx->Init3DGraphics(); 36 | 37 | // set frameCount 38 | frameCount = 0; 39 | 40 | return true; 41 | } 42 | 43 | int GameApp::Controls() { 44 | // reading controls 45 | SceCtrlData pad; 46 | sceCtrlReadBufferPositive(&pad, 1); 47 | 48 | // check for input 49 | if (pad.Buttons != 0){ 50 | if (pad.Buttons & PSP_CTRL_CROSS){ 51 | return 9; 52 | } 53 | } 54 | 55 | return 0; 56 | 57 | } 58 | 59 | void GameApp::Render() { 60 | // render information. 61 | frameCount++; 62 | pspDebugScreenPrintf("Rendering frame %d\n", frameCount); 63 | sceDisplayWaitVblankStart(); 64 | sceGuSwapBuffers(); 65 | } 66 | -------------------------------------------------------------------------------- /Tutorialm9/GameApp.cpp: -------------------------------------------------------------------------------- 1 | #include "GameApp.h" 2 | #include "GraphicsObject.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "stdio.h" 10 | 11 | 12 | GameApp::GameApp() { 13 | 14 | } 15 | 16 | GameApp::~GameApp() { 17 | 18 | } 19 | 20 | int GameApp::Run() { 21 | 22 | if(!Load()) 23 | return 1; 24 | 25 | // game loop 26 | while(1) { 27 | if (Controls() == 9) 28 | break; 29 | Render(); 30 | } 31 | return 0; 32 | } 33 | 34 | bool GameApp::Load() { 35 | // get pointer to Graphics object. 36 | gfx = GraphicsObject::Instance(); 37 | // set up the environment. 38 | gfx->Init3DGraphics(); 39 | 40 | sceRtcGetCurrentTick(&previous); 41 | res = sceRtcGetTickResolution(); 42 | 43 | 44 | return true; 45 | } 46 | 47 | int GameApp::Controls() { 48 | // reading controls 49 | SceCtrlData pad; 50 | sceCtrlReadBufferPositive(&pad, 1); 51 | 52 | // check for input 53 | if (pad.Buttons != 0){ 54 | if (pad.Buttons & PSP_CTRL_CROSS){ 55 | return 9; 56 | } 57 | } 58 | 59 | return 0; 60 | 61 | } 62 | 63 | void GameApp::Render() { 64 | // render information. 65 | frames++; 66 | sceRtcGetCurrentTick( &now ); 67 | 68 | if( ((now - previous)/((float)res)) >= 1.0f ) 69 | { 70 | previous = now; 71 | sprintf(fps, "FPS: %d", frames); 72 | frames = 0; 73 | } 74 | 75 | pspDebugScreenSetXY(0, 0); 76 | pspDebugScreenPrintf("Frames per second: %s\n", fps); 77 | sceDisplayWaitVblankStart(); 78 | sceGuSwapBuffers(); 79 | } 80 | -------------------------------------------------------------------------------- /Tutorial4a/Triangle.cpp: -------------------------------------------------------------------------------- 1 | #include "Triangle.h" 2 | #include 3 | #include 4 | #include "malloc.h" 5 | #include "stdio.h" 6 | 7 | 8 | Triangle::Triangle() { 9 | 10 | triangle = (vertex*)memalign(16,3 * sizeof(vertex)); 11 | triangle[0].u = 0.0f; 12 | triangle[0].v = 0.0f; 13 | triangle[0].color = 0xffffffff; 14 | triangle[0].x = -4.0f; 15 | triangle[0].y = 2.0f; 16 | triangle[0].z = 10.0f; 17 | 18 | triangle[1].u = 0.5f; 19 | triangle[1].v = 1.0f; 20 | triangle[1].color = 0xffffffff; 21 | triangle[1].x = -4.0f; 22 | triangle[1].y = -2.0f; 23 | triangle[1].z = 10.0f; 24 | 25 | triangle[2].u = 1.0f; 26 | triangle[2].v = 0.0f; 27 | triangle[2].color = 0xffffffff; 28 | triangle[2].x = 4.0f; 29 | triangle[2].y = 2.0f; 30 | triangle[2].z = 10.0f; 31 | 32 | rot = 1.5f; 33 | 34 | //char buffer[256]; 35 | //sprintf(buffer, "texture.png"); 36 | texture = loadImage("texture.png"); 37 | } 38 | 39 | Triangle::~Triangle() { 40 | delete(triangle); 41 | } 42 | 43 | void Triangle::Render() { 44 | 45 | rot += 0.01f; 46 | 47 | sceGumMatrixMode(GU_MODEL); 48 | sceGumLoadIdentity(); 49 | sceGumRotateY(rot); 50 | 51 | sceGuTexMode(GU_PSM_8888, 0 ,0 ,0); 52 | sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGB); 53 | sceGuTexFilter(GU_LINEAR, GU_LINEAR); 54 | sceGuTexScale(1.0f, 1.0f); 55 | sceGuTexImage(0, texture->textureWidth, texture->textureHeight, texture->textureWidth, (void*)texture->data); 56 | sceGumDrawArray(GU_TRIANGLES, GU_TEXTURE_32BITF | GU_COLOR_8888 | GU_VERTEX_32BITF | GU_TRANSFORM_3D, 3, 0, triangle); 57 | } 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /Tutorial2/GraphicsObject.cpp: -------------------------------------------------------------------------------- 1 | #include "GraphicsObject.h" 2 | #include 3 | #include 4 | 5 | static unsigned int __attribute__((aligned(16))) list[262144]; 6 | 7 | GraphicsObject* GraphicsObject::_instance = 0;// initialize pointer 8 | 9 | GraphicsObject* GraphicsObject::Instance (void) { 10 | 11 | if (_instance == 0){ 12 | _instance = new GraphicsObject; // create sole instance 13 | } 14 | return _instance; // address of sole instance 15 | } 16 | 17 | GraphicsObject::GraphicsObject(void) { 18 | // creation of object 19 | } 20 | 21 | GraphicsObject::~GraphicsObject(void) { 22 | // clean up 23 | } 24 | 25 | bool GraphicsObject::Init3DGraphics(void) { 26 | 27 | // Initialize the GraphicalSystem 28 | sceGuInit(); 29 | gumInit(); 30 | sceGuStart(GU_DIRECT,list); 31 | sceGuDrawBuffer(GU_PSM_8888,(void*)0,512); 32 | sceGuDispBuffer(480,272,(void*)0x88000,512); 33 | sceGuDepthBuffer((void*)0x110000,512); 34 | sceGuOffset(2048 - (480/2),2048 - (272/2)); 35 | 36 | // create a viewport centered at 2048,2048 width 480 and height 272 37 | sceGuViewport(2048,2048,480,272); 38 | sceGuDepthRange(0xc350,0x2710); 39 | 40 | sceGuScissor(0,0,480,272); 41 | sceGuEnable(GU_SCISSOR_TEST); 42 | sceGuDepthFunc(GU_GEQUAL); 43 | sceGuEnable(GU_DEPTH_TEST); 44 | sceGuFrontFace(GU_CW); 45 | sceGuShadeModel(GU_SMOOTH); 46 | sceGuEnable(GU_CULL_FACE); 47 | sceGuEnable(GU_CLIP_PLANES); 48 | sceGuEnable(GU_LIGHTING); 49 | 50 | sceGuFinish(); 51 | // wait untill the list has finished. 52 | sceGuSync(0,0); 53 | // turn on the display 54 | sceGuDisplay(GU_TRUE); 55 | 56 | return true; 57 | } 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /Tutorial12/GraphicsObject.cpp: -------------------------------------------------------------------------------- 1 | #include "GraphicsObject.h" 2 | #include 3 | #include 4 | 5 | static unsigned int __attribute__((aligned(16))) list[262144]; 6 | 7 | GraphicsObject* GraphicsObject::_instance = 0;// initialize pointer 8 | 9 | GraphicsObject* GraphicsObject::Instance (void) { 10 | 11 | if (_instance == 0){ 12 | _instance = new GraphicsObject; // create sole instance 13 | } 14 | return _instance; // address of sole instance 15 | } 16 | 17 | GraphicsObject::GraphicsObject(void) { 18 | // creation of object 19 | } 20 | 21 | GraphicsObject::~GraphicsObject(void) { 22 | // clean up 23 | } 24 | 25 | bool GraphicsObject::Init3DGraphics(void) { 26 | 27 | // Initialize the GraphicalSystem 28 | sceGuInit(); 29 | gumInit(); 30 | sceGuStart(GU_DIRECT,list); 31 | sceGuDrawBuffer(GU_PSM_8888,(void*)0,512); 32 | sceGuDispBuffer(480,272,(void*)0x88000,512); 33 | sceGuDepthBuffer((void*)0x110000,512); 34 | sceGuOffset(2048 - (480/2),2048 - (272/2)); 35 | 36 | // create a viewport centered at 2048,2048 width 480 and height 272 37 | sceGuViewport(2048,2048,480,272); 38 | sceGuDepthRange(0xc350,0x2710); 39 | 40 | sceGuScissor(0,0,480,272); 41 | sceGuEnable(GU_SCISSOR_TEST); 42 | sceGuDepthFunc(GU_GEQUAL); 43 | sceGuEnable(GU_DEPTH_TEST); 44 | sceGuFrontFace(GU_CW); 45 | sceGuShadeModel(GU_SMOOTH); 46 | sceGuEnable(GU_CULL_FACE); 47 | sceGuEnable(GU_TEXTURE_2D); 48 | sceGuEnable(GU_CLIP_PLANES); 49 | sceGuEnable(GU_LIGHTING); 50 | 51 | sceGuFinish(); 52 | // wait untill the list has finished. 53 | sceGuSync(0,0); 54 | // turn on the display 55 | sceGuDisplay(GU_TRUE); 56 | 57 | return true; 58 | } 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /Tutorial17/GraphicsObject.cpp: -------------------------------------------------------------------------------- 1 | #include "GraphicsObject.h" 2 | #include 3 | #include 4 | 5 | static unsigned int __attribute__((aligned(16))) list[262144]; 6 | 7 | GraphicsObject* GraphicsObject::_instance = 0;// initialize pointer 8 | 9 | GraphicsObject* GraphicsObject::Instance (void) { 10 | 11 | if (_instance == 0){ 12 | _instance = new GraphicsObject; // create sole instance 13 | } 14 | return _instance; // address of sole instance 15 | } 16 | 17 | GraphicsObject::GraphicsObject(void) { 18 | // creation of object 19 | } 20 | 21 | GraphicsObject::~GraphicsObject(void) { 22 | // clean up 23 | } 24 | 25 | bool GraphicsObject::Init3DGraphics(void) { 26 | 27 | // Initialize the GraphicalSystem 28 | sceGuInit(); 29 | gumInit(); 30 | sceGuStart(GU_DIRECT,list); 31 | sceGuDrawBuffer(GU_PSM_8888,(void*)0,512); 32 | sceGuDispBuffer(480,272,(void*)0x88000,512); 33 | sceGuDepthBuffer((void*)0x110000,512); 34 | sceGuOffset(2048 - (480/2),2048 - (272/2)); 35 | 36 | // create a viewport centered at 2048,2048 width 480 and height 272 37 | sceGuViewport(2048,2048,480,272); 38 | sceGuDepthRange(0xc350,0x2710); 39 | 40 | sceGuScissor(0,0,480,272); 41 | sceGuEnable(GU_SCISSOR_TEST); 42 | sceGuDepthFunc(GU_GEQUAL); 43 | sceGuEnable(GU_DEPTH_TEST); 44 | sceGuFrontFace(GU_CW); 45 | sceGuShadeModel(GU_SMOOTH); 46 | sceGuEnable(GU_CULL_FACE); 47 | sceGuEnable(GU_TEXTURE_2D); 48 | sceGuEnable(GU_CLIP_PLANES); 49 | sceGuEnable(GU_LIGHTING); 50 | 51 | sceGuFinish(); 52 | // wait untill the list has finished. 53 | sceGuSync(0,0); 54 | // turn on the display 55 | sceGuDisplay(GU_TRUE); 56 | 57 | return true; 58 | } 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /Tutorial4a/GraphicsObject.cpp: -------------------------------------------------------------------------------- 1 | #include "GraphicsObject.h" 2 | #include 3 | #include 4 | 5 | static unsigned int __attribute__((aligned(16))) list[262144]; 6 | 7 | GraphicsObject* GraphicsObject::_instance = 0;// initialize pointer 8 | 9 | GraphicsObject* GraphicsObject::Instance (void) { 10 | 11 | if (_instance == 0){ 12 | _instance = new GraphicsObject; // create sole instance 13 | } 14 | return _instance; // address of sole instance 15 | } 16 | 17 | GraphicsObject::GraphicsObject(void) { 18 | // creation of object 19 | } 20 | 21 | GraphicsObject::~GraphicsObject(void) { 22 | // clean up 23 | } 24 | 25 | bool GraphicsObject::Init3DGraphics(void) { 26 | 27 | // Initialize the GraphicalSystem 28 | sceGuInit(); 29 | gumInit(); 30 | sceGuStart(GU_DIRECT,list); 31 | sceGuDrawBuffer(GU_PSM_8888,(void*)0,512); 32 | sceGuDispBuffer(480,272,(void*)0x88000,512); 33 | sceGuDepthBuffer((void*)0x110000,512); 34 | sceGuOffset(2048 - (480/2),2048 - (272/2)); 35 | 36 | // create a viewport centered at 2048,2048 width 480 and height 272 37 | sceGuViewport(2048,2048,480,272); 38 | sceGuDepthRange(0xc350,0x2710); 39 | 40 | sceGuScissor(0,0,480,272); 41 | sceGuEnable(GU_SCISSOR_TEST); 42 | sceGuDepthFunc(GU_GEQUAL); 43 | sceGuEnable(GU_DEPTH_TEST); 44 | sceGuFrontFace(GU_CW); 45 | sceGuShadeModel(GU_SMOOTH); 46 | sceGuEnable(GU_CULL_FACE); 47 | sceGuEnable(GU_CLIP_PLANES); 48 | sceGuEnable(GU_LIGHTING); 49 | sceGuEnable(GU_TEXTURE_2D); 50 | 51 | sceGuFinish(); 52 | // wait untill the list has finished. 53 | sceGuSync(0,0); 54 | // turn on the display 55 | sceGuDisplay(GU_TRUE); 56 | 57 | return true; 58 | } 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /Tutorial0/GraphicsObject.cpp: -------------------------------------------------------------------------------- 1 | #include "GraphicsObject.h" 2 | #include 3 | 4 | static unsigned int __attribute__((aligned(16))) list[262144]; 5 | 6 | GraphicsObject* GraphicsObject::_instance = 0;// initialize pointer 7 | 8 | GraphicsObject* GraphicsObject::Instance (void) { 9 | 10 | if (_instance == 0){ 11 | _instance = new GraphicsObject; // create sole instance 12 | } 13 | return _instance; // address of sole instance 14 | } 15 | 16 | GraphicsObject::GraphicsObject(void) { 17 | // creation of object 18 | } 19 | 20 | GraphicsObject::~GraphicsObject(void) { 21 | // clean up 22 | } 23 | 24 | bool GraphicsObject::Init3DGraphics(void) { 25 | 26 | // Initialize the GraphicalSystem 27 | sceGuInit(); 28 | sceGuStart(GU_DIRECT,list); 29 | sceGuDrawBuffer(GU_PSM_8888,(void*)0,512); 30 | sceGuDispBuffer(480,272,(void*)0x88000,512); 31 | sceGuDepthBuffer((void*)0x110000,512); 32 | sceGuOffset(2048 - (480/2),2048 - (272/2)); 33 | 34 | // create a viewport centered at 2048,2048 width 480 and height 272 35 | sceGuViewport(2048,2048,480,272); 36 | sceGuDepthRange(0xc350,0x2710); 37 | 38 | sceGuScissor(0,0,480,272); 39 | sceGuEnable(GU_SCISSOR_TEST); 40 | sceGuDepthFunc(GU_GEQUAL); 41 | sceGuEnable(GU_DEPTH_TEST); 42 | sceGuFrontFace(GU_CW); 43 | sceGuShadeModel(GU_SMOOTH); 44 | sceGuEnable(GU_CULL_FACE); 45 | sceGuEnable(GU_TEXTURE_2D); 46 | sceGuEnable(GU_CLIP_PLANES); 47 | sceGuEnable(GU_LIGHTING); 48 | sceGuEnable(GU_BLEND); 49 | sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0); 50 | sceGuFinish(); 51 | // wait untill the list has finished. 52 | sceGuSync(0,0); 53 | // turn on the display 54 | sceGuDisplay(GU_TRUE); 55 | 56 | return true; 57 | } 58 | 59 | -------------------------------------------------------------------------------- /Tutorial1/GraphicsObject.cpp: -------------------------------------------------------------------------------- 1 | #include "GraphicsObject.h" 2 | #include 3 | 4 | static unsigned int __attribute__((aligned(16))) list[262144]; 5 | 6 | GraphicsObject* GraphicsObject::_instance = 0;// initialize pointer 7 | 8 | GraphicsObject* GraphicsObject::Instance (void) { 9 | 10 | if (_instance == 0){ 11 | _instance = new GraphicsObject; // create sole instance 12 | } 13 | return _instance; // address of sole instance 14 | } 15 | 16 | GraphicsObject::GraphicsObject(void) { 17 | // creation of object 18 | } 19 | 20 | GraphicsObject::~GraphicsObject(void) { 21 | // clean up 22 | } 23 | 24 | bool GraphicsObject::Init3DGraphics(void) { 25 | 26 | // Initialize the GraphicalSystem 27 | sceGuInit(); 28 | sceGuStart(GU_DIRECT,list); 29 | sceGuDrawBuffer(GU_PSM_8888,(void*)0,512); 30 | sceGuDispBuffer(480,272,(void*)0x88000,512); 31 | sceGuDepthBuffer((void*)0x110000,512); 32 | sceGuOffset(2048 - (480/2),2048 - (272/2)); 33 | 34 | // create a viewport centered at 2048,2048 width 480 and height 272 35 | sceGuViewport(2048,2048,480,272); 36 | sceGuDepthRange(0xc350,0x2710); 37 | 38 | sceGuScissor(0,0,480,272); 39 | sceGuEnable(GU_SCISSOR_TEST); 40 | sceGuDepthFunc(GU_GEQUAL); 41 | sceGuEnable(GU_DEPTH_TEST); 42 | sceGuFrontFace(GU_CW); 43 | sceGuShadeModel(GU_SMOOTH); 44 | sceGuEnable(GU_CULL_FACE); 45 | sceGuEnable(GU_TEXTURE_2D); 46 | sceGuEnable(GU_CLIP_PLANES); 47 | sceGuEnable(GU_LIGHTING); 48 | sceGuEnable(GU_BLEND); 49 | sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0); 50 | sceGuFinish(); 51 | // wait untill the list has finished. 52 | sceGuSync(0,0); 53 | // turn on the display 54 | sceGuDisplay(GU_TRUE); 55 | 56 | return true; 57 | } 58 | 59 | -------------------------------------------------------------------------------- /Tutorial6a/GameApp.cpp: -------------------------------------------------------------------------------- 1 | #include "GameApp.h" 2 | #include "GraphicsObject.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | static unsigned int __attribute__((aligned(16))) list[262144]; 10 | 11 | 12 | GameApp::GameApp() { 13 | 14 | } 15 | 16 | GameApp::~GameApp() { 17 | 18 | } 19 | 20 | int GameApp::Run() { 21 | 22 | if(!Load()) 23 | return 1; 24 | 25 | // game loop 26 | while(1) { 27 | if (Controls() == 9) 28 | break; 29 | Render(); 30 | } 31 | return 0; 32 | } 33 | 34 | bool GameApp::Load() { 35 | // get pointer to Graphics object. 36 | gfx = GraphicsObject::Instance(); 37 | // set up the environment. 38 | gfx->Init3DGraphics(); 39 | 40 | // set frameCount 41 | frameCount = 0; 42 | 43 | return true; 44 | } 45 | 46 | int GameApp::Controls() { 47 | // reading controls 48 | SceCtrlData pad; 49 | sceCtrlReadBufferPositive(&pad, 1); 50 | 51 | // check for input 52 | if (pad.Buttons != 0){ 53 | if (pad.Buttons & PSP_CTRL_CROSS){ 54 | return 9; 55 | } 56 | } 57 | 58 | return 0; 59 | 60 | } 61 | 62 | void GameApp::Render() { 63 | // render information. 64 | sceGuStart(GU_DIRECT,list); 65 | 66 | // clear screen 67 | sceGuClearColor(0xff000000); 68 | sceGuClearDepth(0); 69 | sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT); 70 | 71 | // set the ambient light 72 | sceGuAmbient(0xffffffff); 73 | 74 | // setting the view 75 | sceGumMatrixMode(GU_VIEW); 76 | sceGumLoadIdentity(); 77 | 78 | gfx->Render2DLineOn3D(5,5, 475, 268, 0xffff6b38); 79 | 80 | // ending rendering 81 | sceGuFinish(); 82 | sceGuSync(0,0); 83 | sceDisplayWaitVblankStart(); 84 | sceGuSwapBuffers(); 85 | } 86 | -------------------------------------------------------------------------------- /Tutorialm1/GraphicsObject.cpp: -------------------------------------------------------------------------------- 1 | #include "GraphicsObject.h" 2 | #include 3 | 4 | static unsigned int __attribute__((aligned(16))) list[262144]; 5 | 6 | GraphicsObject* GraphicsObject::_instance = 0;// initialize pointer 7 | 8 | GraphicsObject* GraphicsObject::Instance (void) { 9 | 10 | if (_instance == 0){ 11 | _instance = new GraphicsObject; // create sole instance 12 | } 13 | return _instance; // address of sole instance 14 | } 15 | 16 | GraphicsObject::GraphicsObject(void) { 17 | // creation of object 18 | } 19 | 20 | GraphicsObject::~GraphicsObject(void) { 21 | // clean up 22 | } 23 | 24 | bool GraphicsObject::Init3DGraphics(void) { 25 | 26 | // Initialize the GraphicalSystem 27 | sceGuInit(); 28 | sceGuStart(GU_DIRECT,list); 29 | sceGuDrawBuffer(GU_PSM_8888,(void*)0,512); 30 | sceGuDispBuffer(480,272,(void*)0x88000,512); 31 | sceGuDepthBuffer((void*)0x110000,512); 32 | sceGuOffset(2048 - (480/2),2048 - (272/2)); 33 | 34 | // create a viewport centered at 2048,2048 width 480 and height 272 35 | sceGuViewport(2048,2048,480,272); 36 | sceGuDepthRange(0xc350,0x2710); 37 | 38 | sceGuScissor(0,0,480,272); 39 | sceGuEnable(GU_SCISSOR_TEST); 40 | sceGuDepthFunc(GU_GEQUAL); 41 | sceGuEnable(GU_DEPTH_TEST); 42 | sceGuFrontFace(GU_CW); 43 | sceGuShadeModel(GU_SMOOTH); 44 | sceGuEnable(GU_CULL_FACE); 45 | sceGuEnable(GU_TEXTURE_2D); 46 | sceGuEnable(GU_CLIP_PLANES); 47 | sceGuEnable(GU_LIGHTING); 48 | sceGuEnable(GU_BLEND); 49 | sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0); 50 | sceGuFinish(); 51 | // wait untill the list has finished. 52 | sceGuSync(0,0); 53 | // turn on the display 54 | sceGuDisplay(GU_TRUE); 55 | 56 | return true; 57 | } 58 | 59 | -------------------------------------------------------------------------------- /Tutorialm2/GraphicsObject.cpp: -------------------------------------------------------------------------------- 1 | #include "GraphicsObject.h" 2 | #include 3 | 4 | static unsigned int __attribute__((aligned(16))) list[262144]; 5 | 6 | GraphicsObject* GraphicsObject::_instance = 0;// initialize pointer 7 | 8 | GraphicsObject* GraphicsObject::Instance (void) { 9 | 10 | if (_instance == 0){ 11 | _instance = new GraphicsObject; // create sole instance 12 | } 13 | return _instance; // address of sole instance 14 | } 15 | 16 | GraphicsObject::GraphicsObject(void) { 17 | // creation of object 18 | } 19 | 20 | GraphicsObject::~GraphicsObject(void) { 21 | // clean up 22 | } 23 | 24 | bool GraphicsObject::Init3DGraphics(void) { 25 | 26 | // Initialize the GraphicalSystem 27 | sceGuInit(); 28 | sceGuStart(GU_DIRECT,list); 29 | sceGuDrawBuffer(GU_PSM_8888,(void*)0,512); 30 | sceGuDispBuffer(480,272,(void*)0x88000,512); 31 | sceGuDepthBuffer((void*)0x110000,512); 32 | sceGuOffset(2048 - (480/2),2048 - (272/2)); 33 | 34 | // create a viewport centered at 2048,2048 width 480 and height 272 35 | sceGuViewport(2048,2048,480,272); 36 | sceGuDepthRange(0xc350,0x2710); 37 | 38 | sceGuScissor(0,0,480,272); 39 | sceGuEnable(GU_SCISSOR_TEST); 40 | sceGuDepthFunc(GU_GEQUAL); 41 | sceGuEnable(GU_DEPTH_TEST); 42 | sceGuFrontFace(GU_CW); 43 | sceGuShadeModel(GU_SMOOTH); 44 | sceGuEnable(GU_CULL_FACE); 45 | sceGuEnable(GU_TEXTURE_2D); 46 | sceGuEnable(GU_CLIP_PLANES); 47 | sceGuEnable(GU_LIGHTING); 48 | sceGuEnable(GU_BLEND); 49 | sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0); 50 | sceGuFinish(); 51 | // wait untill the list has finished. 52 | sceGuSync(0,0); 53 | // turn on the display 54 | sceGuDisplay(GU_TRUE); 55 | 56 | return true; 57 | } 58 | 59 | -------------------------------------------------------------------------------- /Tutorialm5/GraphicsObject.cpp: -------------------------------------------------------------------------------- 1 | #include "GraphicsObject.h" 2 | #include 3 | 4 | static unsigned int __attribute__((aligned(16))) list[262144]; 5 | 6 | GraphicsObject* GraphicsObject::_instance = 0;// initialize pointer 7 | 8 | GraphicsObject* GraphicsObject::Instance (void) { 9 | 10 | if (_instance == 0){ 11 | _instance = new GraphicsObject; // create sole instance 12 | } 13 | return _instance; // address of sole instance 14 | } 15 | 16 | GraphicsObject::GraphicsObject(void) { 17 | // creation of object 18 | } 19 | 20 | GraphicsObject::~GraphicsObject(void) { 21 | // clean up 22 | } 23 | 24 | bool GraphicsObject::Init3DGraphics(void) { 25 | 26 | // Initialize the GraphicalSystem 27 | sceGuInit(); 28 | sceGuStart(GU_DIRECT,list); 29 | sceGuDrawBuffer(GU_PSM_8888,(void*)0,512); 30 | sceGuDispBuffer(480,272,(void*)0x88000,512); 31 | sceGuDepthBuffer((void*)0x110000,512); 32 | sceGuOffset(2048 - (480/2),2048 - (272/2)); 33 | 34 | // create a viewport centered at 2048,2048 width 480 and height 272 35 | sceGuViewport(2048,2048,480,272); 36 | sceGuDepthRange(0xc350,0x2710); 37 | 38 | sceGuScissor(0,0,480,272); 39 | sceGuEnable(GU_SCISSOR_TEST); 40 | sceGuDepthFunc(GU_GEQUAL); 41 | sceGuEnable(GU_DEPTH_TEST); 42 | sceGuFrontFace(GU_CW); 43 | sceGuShadeModel(GU_SMOOTH); 44 | sceGuEnable(GU_CULL_FACE); 45 | sceGuEnable(GU_TEXTURE_2D); 46 | sceGuEnable(GU_CLIP_PLANES); 47 | sceGuEnable(GU_LIGHTING); 48 | sceGuEnable(GU_BLEND); 49 | sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0); 50 | sceGuFinish(); 51 | // wait untill the list has finished. 52 | sceGuSync(0,0); 53 | // turn on the display 54 | sceGuDisplay(GU_TRUE); 55 | 56 | return true; 57 | } 58 | 59 | -------------------------------------------------------------------------------- /Tutorialm9/GraphicsObject.cpp: -------------------------------------------------------------------------------- 1 | #include "GraphicsObject.h" 2 | #include 3 | 4 | static unsigned int __attribute__((aligned(16))) list[262144]; 5 | 6 | GraphicsObject* GraphicsObject::_instance = 0;// initialize pointer 7 | 8 | GraphicsObject* GraphicsObject::Instance (void) { 9 | 10 | if (_instance == 0){ 11 | _instance = new GraphicsObject; // create sole instance 12 | } 13 | return _instance; // address of sole instance 14 | } 15 | 16 | GraphicsObject::GraphicsObject(void) { 17 | // creation of object 18 | } 19 | 20 | GraphicsObject::~GraphicsObject(void) { 21 | // clean up 22 | } 23 | 24 | bool GraphicsObject::Init3DGraphics(void) { 25 | 26 | // Initialize the GraphicalSystem 27 | sceGuInit(); 28 | sceGuStart(GU_DIRECT,list); 29 | sceGuDrawBuffer(GU_PSM_8888,(void*)0,512); 30 | sceGuDispBuffer(480,272,(void*)0x88000,512); 31 | sceGuDepthBuffer((void*)0x110000,512); 32 | sceGuOffset(2048 - (480/2),2048 - (272/2)); 33 | 34 | // create a viewport centered at 2048,2048 width 480 and height 272 35 | sceGuViewport(2048,2048,480,272); 36 | sceGuDepthRange(0xc350,0x2710); 37 | 38 | sceGuScissor(0,0,480,272); 39 | sceGuEnable(GU_SCISSOR_TEST); 40 | sceGuDepthFunc(GU_GEQUAL); 41 | sceGuEnable(GU_DEPTH_TEST); 42 | sceGuFrontFace(GU_CW); 43 | sceGuShadeModel(GU_SMOOTH); 44 | sceGuEnable(GU_CULL_FACE); 45 | sceGuEnable(GU_TEXTURE_2D); 46 | sceGuEnable(GU_CLIP_PLANES); 47 | sceGuEnable(GU_LIGHTING); 48 | sceGuEnable(GU_BLEND); 49 | sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0); 50 | sceGuFinish(); 51 | // wait untill the list has finished. 52 | sceGuSync(0,0); 53 | // turn on the display 54 | sceGuDisplay(GU_TRUE); 55 | 56 | return true; 57 | } 58 | 59 | -------------------------------------------------------------------------------- /Tutorialm1/GameApp.cpp: -------------------------------------------------------------------------------- 1 | #include "GameApp.h" 2 | #include "GraphicsObject.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | 10 | GameApp::GameApp() { 11 | 12 | } 13 | 14 | GameApp::~GameApp() { 15 | delete timer; 16 | } 17 | 18 | int GameApp::Run() { 19 | 20 | if(!Load()) 21 | return 1; 22 | 23 | // game loop 24 | while(1) { 25 | if (Controls() == 9) 26 | break; 27 | Render(); 28 | } 29 | return 0; 30 | } 31 | 32 | bool GameApp::Load() { 33 | // get pointer to Graphics object. 34 | gfx = GraphicsObject::Instance(); 35 | // set up the environment. 36 | gfx->Init3DGraphics(); 37 | 38 | // load timer object 39 | timer = new Timer(); 40 | // start the timer 41 | timer->startTimer(); 42 | 43 | return true; 44 | } 45 | 46 | int GameApp::Controls() { 47 | // reading controls 48 | SceCtrlData pad; 49 | sceCtrlReadBufferPositive(&pad, 1); 50 | 51 | // check for input 52 | if (pad.Buttons != 0){ 53 | if (pad.Buttons & PSP_CTRL_CROSS){ 54 | if(buttonCross == 0) { 55 | buttonCross = 1; 56 | timer->resetTimer(); 57 | } 58 | } 59 | if (pad.Buttons & PSP_CTRL_SQUARE){ 60 | if(buttonSquare == 0) { 61 | buttonSquare = 1; 62 | timer->startTimer(); 63 | } 64 | } 65 | } 66 | else { 67 | buttonCross = 0; 68 | buttonSquare = 0; 69 | } 70 | 71 | return 0; 72 | 73 | } 74 | 75 | void GameApp::Render() { 76 | // render information. 77 | pspDebugScreenSetXY(10, 5); 78 | pspDebugScreenPrintf("%d seconds elapsed\n", timer->getTimer()); 79 | pspDebugScreenSetXY(4, 15); 80 | pspDebugScreenPrintf("Press Cross to reset timer.\n"); 81 | pspDebugScreenSetXY(4, 20); 82 | pspDebugScreenPrintf("Press Square to start timer.\n"); 83 | sceDisplayWaitVblankStart(); 84 | sceGuSwapBuffers(); 85 | } 86 | -------------------------------------------------------------------------------- /Tutorial0/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "GraphicsObject.h" 6 | #include 7 | #include 8 | 9 | 10 | // MODULE INITIALISATION 11 | 12 | PSP_MODULE_INFO("Tutorial0", 0x0000, 1, 1); 13 | 14 | 15 | /*! 16 | * \fn int exit_callback(int arg1, int arg2, void *common) 17 | * \brief Exits the game. 18 | * 19 | * @return 0 20 | */ 21 | int exit_callback(int arg1, int arg2, void *common) { 22 | sceKernelExitGame(); 23 | return 0; 24 | } 25 | 26 | 27 | /*! 28 | * \fn int CallbackThread(SceSize args, void *argp) 29 | * \brief callback thread. 30 | * 31 | * @return 0 32 | */ 33 | int CallbackThread(SceSize args, void *argp) { 34 | int cbid; 35 | 36 | cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL); 37 | sceKernelRegisterExitCallback(cbid); 38 | 39 | sceKernelSleepThreadCB(); 40 | 41 | return 0; 42 | } 43 | 44 | 45 | /*! 46 | * \fn int SetupCallbacks(void) 47 | * \brief Creates a callback thread and returns the thread ID. 48 | * 49 | * @return thid 50 | */ 51 | int SetupCallbacks(void) { 52 | int thid = 0; 53 | 54 | thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0); //als er foutenzijn dan kan het hieraanliggen 55 | if(thid >= 0) { 56 | sceKernelStartThread(thid, 0, 0); 57 | } 58 | 59 | return thid; 60 | } 61 | 62 | 63 | 64 | /*! 65 | * \fn int Main(void) 66 | * \brief The main function 67 | * 68 | * @return 0 69 | */ 70 | int main (void) { 71 | 72 | // setup the callbacks 73 | SetupCallbacks(); 74 | 75 | // setup the environment 76 | GraphicsObject* gfx = GraphicsObject::Instance(); 77 | // init the 3D environment 78 | gfx->Init3DGraphics(); 79 | 80 | // shutdown 81 | sceGuTerm(); 82 | sceKernelExitGame(); 83 | 84 | return 0; 85 | } 86 | 87 | -------------------------------------------------------------------------------- /Tutorial1/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "GameApp.h" 6 | #include 7 | #include 8 | 9 | 10 | // MODULE INITIALISATION 11 | 12 | PSP_MODULE_INFO("Tutorial0", 0x0000, 1, 1); 13 | 14 | 15 | /*! 16 | * \fn int exit_callback(int arg1, int arg2, void *common) 17 | * \brief Exits the game. 18 | * 19 | * @return 0 20 | */ 21 | int exit_callback(int arg1, int arg2, void *common) { 22 | sceKernelExitGame(); 23 | return 0; 24 | } 25 | 26 | 27 | /*! 28 | * \fn int CallbackThread(SceSize args, void *argp) 29 | * \brief callback thread. 30 | * 31 | * @return 0 32 | */ 33 | int CallbackThread(SceSize args, void *argp) { 34 | int cbid; 35 | 36 | cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL); 37 | sceKernelRegisterExitCallback(cbid); 38 | 39 | sceKernelSleepThreadCB(); 40 | 41 | return 0; 42 | } 43 | 44 | 45 | /*! 46 | * \fn int SetupCallbacks(void) 47 | * \brief Creates a callback thread and returns the thread ID. 48 | * 49 | * @return thid 50 | */ 51 | int SetupCallbacks(void) { 52 | int thid = 0; 53 | 54 | thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0); //als er foutenzijn dan kan het hieraanliggen 55 | if(thid >= 0) { 56 | sceKernelStartThread(thid, 0, 0); 57 | } 58 | 59 | return thid; 60 | } 61 | 62 | 63 | 64 | /*! 65 | * \fn int Main(void) 66 | * \brief The main function 67 | * 68 | * @return 0 69 | */ 70 | int main (void) { 71 | 72 | // init the debug screen functions 73 | pspDebugScreenInit(); 74 | 75 | // setup the callbacks 76 | SetupCallbacks(); 77 | 78 | // creating the game object 79 | GameApp* game = new GameApp(); 80 | // run the game app and get return value 81 | int ret = game->Run(); 82 | 83 | // shutdown 84 | sceGuTerm(); 85 | sceKernelExitGame(); 86 | 87 | return 0; 88 | } 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /Tutorial11/GameApp.cpp: -------------------------------------------------------------------------------- 1 | #include "GameApp.h" 2 | #include "GraphicsObject.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | static unsigned int __attribute__((aligned(16))) list[262144]; 10 | 11 | 12 | GameApp::GameApp() { 13 | 14 | } 15 | 16 | GameApp::~GameApp() { 17 | 18 | } 19 | 20 | int GameApp::Run() { 21 | 22 | if(!Load()) 23 | return 1; 24 | 25 | // game loop 26 | while(1) { 27 | if (Controls() == 9) 28 | break; 29 | Render(); 30 | } 31 | return 0; 32 | } 33 | 34 | bool GameApp::Load() { 35 | // get pointer to Graphics object. 36 | gfx = GraphicsObject::Instance(); 37 | // set up the environment. 38 | gfx->Init3DGraphics(); 39 | 40 | // create the loading thread 41 | loadscr = new LoadingScreen(); 42 | 43 | // set frameCount 44 | frameCount = 0; 45 | 46 | for(int i=0;i<300;i++){ 47 | //wait everytime for the screen blank, total 5 seconds 48 | sceDisplayWaitVblankStart(); 49 | } 50 | 51 | // we stop the loading screen 52 | loadscr->KillLoadingScreen(); 53 | // we remove it from memory 54 | delete(loadscr); 55 | 56 | return true; 57 | } 58 | 59 | int GameApp::Controls() { 60 | // reading controls 61 | SceCtrlData pad; 62 | sceCtrlReadBufferPositive(&pad, 1); 63 | 64 | // check for input 65 | if (pad.Buttons != 0){ 66 | if (pad.Buttons & PSP_CTRL_CROSS){ 67 | return 9; 68 | } 69 | } 70 | 71 | return 0; 72 | 73 | } 74 | 75 | void GameApp::Render() { 76 | 77 | // render information. 78 | sceGuStart(GU_DIRECT,list); 79 | 80 | // clear screen 81 | sceGuClearColor(0xff000000); 82 | sceGuClearDepth(0); 83 | sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT); 84 | 85 | frameCount++; 86 | pspDebugScreenSetXY(1,1); 87 | pspDebugScreenPrintf("Rendering frame %d\n", frameCount); 88 | 89 | // ending rendering 90 | sceGuFinish(); 91 | sceGuSync(0,0); 92 | sceDisplayWaitVblankStart(); 93 | sceGuSwapBuffers(); 94 | } 95 | -------------------------------------------------------------------------------- /Tutorial11/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "GameApp.h" 6 | #include 7 | #include 8 | 9 | 10 | // MODULE INITIALISATION 11 | 12 | PSP_MODULE_INFO("Tutorial0", 0x0000, 1, 1); 13 | 14 | 15 | /*! 16 | * \fn int exit_callback(int arg1, int arg2, void *common) 17 | * \brief Exits the game. 18 | * 19 | * @return 0 20 | */ 21 | int exit_callback(int arg1, int arg2, void *common) { 22 | sceKernelExitGame(); 23 | return 0; 24 | } 25 | 26 | 27 | /*! 28 | * \fn int CallbackThread(SceSize args, void *argp) 29 | * \brief callback thread. 30 | * 31 | * @return 0 32 | */ 33 | int CallbackThread(SceSize args, void *argp) { 34 | int cbid; 35 | 36 | cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL); 37 | sceKernelRegisterExitCallback(cbid); 38 | 39 | sceKernelSleepThreadCB(); 40 | 41 | return 0; 42 | } 43 | 44 | 45 | /*! 46 | * \fn int SetupCallbacks(void) 47 | * \brief Creates a callback thread and returns the thread ID. 48 | * 49 | * @return thid 50 | */ 51 | int SetupCallbacks(void) { 52 | int thid = 0; 53 | 54 | thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0); //als er foutenzijn dan kan het hieraanliggen 55 | if(thid >= 0) { 56 | sceKernelStartThread(thid, 0, 0); 57 | } 58 | 59 | return thid; 60 | } 61 | 62 | 63 | 64 | /*! 65 | * \fn int Main(void) 66 | * \brief The main function 67 | * 68 | * @return 0 69 | */ 70 | int main (void) { 71 | 72 | // init the debug screen functions 73 | pspDebugScreenInit(); 74 | 75 | // setup the callbacks 76 | SetupCallbacks(); 77 | 78 | // creating the game object 79 | GameApp* game = new GameApp(); 80 | // run the game app and get return value 81 | int ret = game->Run(); 82 | 83 | // shutdown 84 | sceGuTerm(); 85 | sceKernelExitGame(); 86 | 87 | return 0; 88 | } 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /Tutorial6a/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "GameApp.h" 6 | #include 7 | #include 8 | 9 | 10 | // MODULE INITIALISATION 11 | 12 | PSP_MODULE_INFO("Tutorial0", 0x0000, 1, 1); 13 | 14 | 15 | /*! 16 | * \fn int exit_callback(int arg1, int arg2, void *common) 17 | * \brief Exits the game. 18 | * 19 | * @return 0 20 | */ 21 | int exit_callback(int arg1, int arg2, void *common) { 22 | sceKernelExitGame(); 23 | return 0; 24 | } 25 | 26 | 27 | /*! 28 | * \fn int CallbackThread(SceSize args, void *argp) 29 | * \brief callback thread. 30 | * 31 | * @return 0 32 | */ 33 | int CallbackThread(SceSize args, void *argp) { 34 | int cbid; 35 | 36 | cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL); 37 | sceKernelRegisterExitCallback(cbid); 38 | 39 | sceKernelSleepThreadCB(); 40 | 41 | return 0; 42 | } 43 | 44 | 45 | /*! 46 | * \fn int SetupCallbacks(void) 47 | * \brief Creates a callback thread and returns the thread ID. 48 | * 49 | * @return thid 50 | */ 51 | int SetupCallbacks(void) { 52 | int thid = 0; 53 | 54 | thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0); //als er foutenzijn dan kan het hieraanliggen 55 | if(thid >= 0) { 56 | sceKernelStartThread(thid, 0, 0); 57 | } 58 | 59 | return thid; 60 | } 61 | 62 | 63 | 64 | /*! 65 | * \fn int Main(void) 66 | * \brief The main function 67 | * 68 | * @return 0 69 | */ 70 | int main (void) { 71 | 72 | // init the debug screen functions 73 | pspDebugScreenInit(); 74 | 75 | // setup the callbacks 76 | SetupCallbacks(); 77 | 78 | // creating the game object 79 | GameApp* game = new GameApp(); 80 | // run the game app and get return value 81 | int ret = game->Run(); 82 | 83 | // shutdown 84 | sceGuTerm(); 85 | sceKernelExitGame(); 86 | 87 | return 0; 88 | } 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /Tutorial6b/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "GameApp.h" 6 | #include 7 | #include 8 | 9 | 10 | // MODULE INITIALISATION 11 | 12 | PSP_MODULE_INFO("Tutorial0", 0x0000, 1, 1); 13 | 14 | 15 | /*! 16 | * \fn int exit_callback(int arg1, int arg2, void *common) 17 | * \brief Exits the game. 18 | * 19 | * @return 0 20 | */ 21 | int exit_callback(int arg1, int arg2, void *common) { 22 | sceKernelExitGame(); 23 | return 0; 24 | } 25 | 26 | 27 | /*! 28 | * \fn int CallbackThread(SceSize args, void *argp) 29 | * \brief callback thread. 30 | * 31 | * @return 0 32 | */ 33 | int CallbackThread(SceSize args, void *argp) { 34 | int cbid; 35 | 36 | cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL); 37 | sceKernelRegisterExitCallback(cbid); 38 | 39 | sceKernelSleepThreadCB(); 40 | 41 | return 0; 42 | } 43 | 44 | 45 | /*! 46 | * \fn int SetupCallbacks(void) 47 | * \brief Creates a callback thread and returns the thread ID. 48 | * 49 | * @return thid 50 | */ 51 | int SetupCallbacks(void) { 52 | int thid = 0; 53 | 54 | thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0); //als er foutenzijn dan kan het hieraanliggen 55 | if(thid >= 0) { 56 | sceKernelStartThread(thid, 0, 0); 57 | } 58 | 59 | return thid; 60 | } 61 | 62 | 63 | 64 | /*! 65 | * \fn int Main(void) 66 | * \brief The main function 67 | * 68 | * @return 0 69 | */ 70 | int main (void) { 71 | 72 | // init the debug screen functions 73 | pspDebugScreenInit(); 74 | 75 | // setup the callbacks 76 | SetupCallbacks(); 77 | 78 | // creating the game object 79 | GameApp* game = new GameApp(); 80 | // run the game app and get return value 81 | int ret = game->Run(); 82 | 83 | // shutdown 84 | sceGuTerm(); 85 | sceKernelExitGame(); 86 | 87 | return 0; 88 | } 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /Tutorialm1/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "GameApp.h" 6 | #include 7 | #include 8 | 9 | 10 | // MODULE INITIALISATION 11 | 12 | PSP_MODULE_INFO("Tutorial0", 0x0000, 1, 1); 13 | 14 | 15 | /*! 16 | * \fn int exit_callback(int arg1, int arg2, void *common) 17 | * \brief Exits the game. 18 | * 19 | * @return 0 20 | */ 21 | int exit_callback(int arg1, int arg2, void *common) { 22 | sceKernelExitGame(); 23 | return 0; 24 | } 25 | 26 | 27 | /*! 28 | * \fn int CallbackThread(SceSize args, void *argp) 29 | * \brief callback thread. 30 | * 31 | * @return 0 32 | */ 33 | int CallbackThread(SceSize args, void *argp) { 34 | int cbid; 35 | 36 | cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL); 37 | sceKernelRegisterExitCallback(cbid); 38 | 39 | sceKernelSleepThreadCB(); 40 | 41 | return 0; 42 | } 43 | 44 | 45 | /*! 46 | * \fn int SetupCallbacks(void) 47 | * \brief Creates a callback thread and returns the thread ID. 48 | * 49 | * @return thid 50 | */ 51 | int SetupCallbacks(void) { 52 | int thid = 0; 53 | 54 | thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0); //als er foutenzijn dan kan het hieraanliggen 55 | if(thid >= 0) { 56 | sceKernelStartThread(thid, 0, 0); 57 | } 58 | 59 | return thid; 60 | } 61 | 62 | 63 | 64 | /*! 65 | * \fn int Main(void) 66 | * \brief The main function 67 | * 68 | * @return 0 69 | */ 70 | int main (void) { 71 | 72 | // init the debug screen functions 73 | pspDebugScreenInit(); 74 | 75 | // setup the callbacks 76 | SetupCallbacks(); 77 | 78 | // creating the game object 79 | GameApp* game = new GameApp(); 80 | // run the game app and get return value 81 | int ret = game->Run(); 82 | 83 | // shutdown 84 | sceGuTerm(); 85 | sceKernelExitGame(); 86 | 87 | return 0; 88 | } 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /Tutorialm2/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "GameApp.h" 6 | #include 7 | #include 8 | 9 | 10 | // MODULE INITIALISATION 11 | 12 | PSP_MODULE_INFO("Tutorial0", 0x0000, 1, 1); 13 | 14 | 15 | /*! 16 | * \fn int exit_callback(int arg1, int arg2, void *common) 17 | * \brief Exits the game. 18 | * 19 | * @return 0 20 | */ 21 | int exit_callback(int arg1, int arg2, void *common) { 22 | sceKernelExitGame(); 23 | return 0; 24 | } 25 | 26 | 27 | /*! 28 | * \fn int CallbackThread(SceSize args, void *argp) 29 | * \brief callback thread. 30 | * 31 | * @return 0 32 | */ 33 | int CallbackThread(SceSize args, void *argp) { 34 | int cbid; 35 | 36 | cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL); 37 | sceKernelRegisterExitCallback(cbid); 38 | 39 | sceKernelSleepThreadCB(); 40 | 41 | return 0; 42 | } 43 | 44 | 45 | /*! 46 | * \fn int SetupCallbacks(void) 47 | * \brief Creates a callback thread and returns the thread ID. 48 | * 49 | * @return thid 50 | */ 51 | int SetupCallbacks(void) { 52 | int thid = 0; 53 | 54 | thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0); //als er foutenzijn dan kan het hieraanliggen 55 | if(thid >= 0) { 56 | sceKernelStartThread(thid, 0, 0); 57 | } 58 | 59 | return thid; 60 | } 61 | 62 | 63 | 64 | /*! 65 | * \fn int Main(void) 66 | * \brief The main function 67 | * 68 | * @return 0 69 | */ 70 | int main (void) { 71 | 72 | // init the debug screen functions 73 | pspDebugScreenInit(); 74 | 75 | // setup the callbacks 76 | SetupCallbacks(); 77 | 78 | // creating the game object 79 | GameApp* game = new GameApp(); 80 | // run the game app and get return value 81 | int ret = game->Run(); 82 | 83 | // shutdown 84 | sceGuTerm(); 85 | sceKernelExitGame(); 86 | 87 | return 0; 88 | } 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /Tutorialm5/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "GameApp.h" 6 | #include 7 | #include 8 | 9 | 10 | // MODULE INITIALISATION 11 | 12 | PSP_MODULE_INFO("Tutorial0", 0x0000, 1, 1); 13 | 14 | 15 | /*! 16 | * \fn int exit_callback(int arg1, int arg2, void *common) 17 | * \brief Exits the game. 18 | * 19 | * @return 0 20 | */ 21 | int exit_callback(int arg1, int arg2, void *common) { 22 | sceKernelExitGame(); 23 | return 0; 24 | } 25 | 26 | 27 | /*! 28 | * \fn int CallbackThread(SceSize args, void *argp) 29 | * \brief callback thread. 30 | * 31 | * @return 0 32 | */ 33 | int CallbackThread(SceSize args, void *argp) { 34 | int cbid; 35 | 36 | cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL); 37 | sceKernelRegisterExitCallback(cbid); 38 | 39 | sceKernelSleepThreadCB(); 40 | 41 | return 0; 42 | } 43 | 44 | 45 | /*! 46 | * \fn int SetupCallbacks(void) 47 | * \brief Creates a callback thread and returns the thread ID. 48 | * 49 | * @return thid 50 | */ 51 | int SetupCallbacks(void) { 52 | int thid = 0; 53 | 54 | thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0); //als er foutenzijn dan kan het hieraanliggen 55 | if(thid >= 0) { 56 | sceKernelStartThread(thid, 0, 0); 57 | } 58 | 59 | return thid; 60 | } 61 | 62 | 63 | 64 | /*! 65 | * \fn int Main(void) 66 | * \brief The main function 67 | * 68 | * @return 0 69 | */ 70 | int main (void) { 71 | 72 | // init the debug screen functions 73 | pspDebugScreenInit(); 74 | 75 | // setup the callbacks 76 | SetupCallbacks(); 77 | 78 | // creating the game object 79 | GameApp* game = new GameApp(); 80 | // run the game app and get return value 81 | int ret = game->Run(); 82 | 83 | // shutdown 84 | sceGuTerm(); 85 | sceKernelExitGame(); 86 | 87 | return 0; 88 | } 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /Tutorialm9/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "GameApp.h" 6 | #include 7 | #include 8 | 9 | 10 | // MODULE INITIALISATION 11 | 12 | PSP_MODULE_INFO("Tutorial0", 0x0000, 1, 1); 13 | 14 | 15 | /*! 16 | * \fn int exit_callback(int arg1, int arg2, void *common) 17 | * \brief Exits the game. 18 | * 19 | * @return 0 20 | */ 21 | int exit_callback(int arg1, int arg2, void *common) { 22 | sceKernelExitGame(); 23 | return 0; 24 | } 25 | 26 | 27 | /*! 28 | * \fn int CallbackThread(SceSize args, void *argp) 29 | * \brief callback thread. 30 | * 31 | * @return 0 32 | */ 33 | int CallbackThread(SceSize args, void *argp) { 34 | int cbid; 35 | 36 | cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL); 37 | sceKernelRegisterExitCallback(cbid); 38 | 39 | sceKernelSleepThreadCB(); 40 | 41 | return 0; 42 | } 43 | 44 | 45 | /*! 46 | * \fn int SetupCallbacks(void) 47 | * \brief Creates a callback thread and returns the thread ID. 48 | * 49 | * @return thid 50 | */ 51 | int SetupCallbacks(void) { 52 | int thid = 0; 53 | 54 | thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0); //als er foutenzijn dan kan het hieraanliggen 55 | if(thid >= 0) { 56 | sceKernelStartThread(thid, 0, 0); 57 | } 58 | 59 | return thid; 60 | } 61 | 62 | 63 | 64 | /*! 65 | * \fn int Main(void) 66 | * \brief The main function 67 | * 68 | * @return 0 69 | */ 70 | int main (void) { 71 | 72 | // init the debug screen functions 73 | pspDebugScreenInit(); 74 | 75 | // setup the callbacks 76 | SetupCallbacks(); 77 | 78 | // creating the game object 79 | GameApp* game = new GameApp(); 80 | // run the game app and get return value 81 | int ret = game->Run(); 82 | 83 | // shutdown 84 | sceGuTerm(); 85 | sceKernelExitGame(); 86 | 87 | return 0; 88 | } 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /Tutorial2/GameApp.cpp: -------------------------------------------------------------------------------- 1 | #include "GameApp.h" 2 | #include "GraphicsObject.h" 3 | #include "Triangle.h" 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "stdio.h" 10 | #include 11 | 12 | 13 | static unsigned int __attribute__((aligned(16))) list[262144]; 14 | 15 | 16 | GameApp::GameApp() { 17 | 18 | } 19 | 20 | GameApp::~GameApp() { 21 | 22 | } 23 | 24 | int GameApp::Run() { 25 | 26 | if(!Load()) 27 | return 1; 28 | 29 | // game loop 30 | while(1) { 31 | if (Controls() == 9) 32 | break; 33 | Render(); 34 | } 35 | return 0; 36 | } 37 | 38 | bool GameApp::Load() { 39 | // get pointer to Graphics object. 40 | gfx = GraphicsObject::Instance(); 41 | // set up the environment. 42 | gfx->Init3DGraphics(); 43 | 44 | // create the triangle 45 | triangle = new Triangle(); 46 | 47 | // setting the projection 48 | sceGumMatrixMode(GU_PROJECTION); 49 | sceGumLoadIdentity(); 50 | sceGumPerspective(45.0f,16.0f/9.0f,2.0f,1000.0f); 51 | 52 | return true; 53 | } 54 | 55 | int GameApp::Controls() { 56 | 57 | // reading controls 58 | SceCtrlData pad; 59 | sceCtrlPeekBufferPositive(&pad, 1); 60 | 61 | // check for input 62 | if (pad.Buttons != 0){ 63 | if (pad.Buttons & PSP_CTRL_CROSS){ 64 | return 9; 65 | } 66 | } 67 | 68 | return 0; 69 | 70 | } 71 | 72 | void GameApp::Render() { 73 | // render information. 74 | sceGuStart(GU_DIRECT,list); 75 | 76 | // clear screen 77 | sceGuClearColor(0xff000000); 78 | sceGuClearDepth(0); 79 | sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT); 80 | 81 | // set the ambient light 82 | sceGuAmbient(0xffffffff); 83 | 84 | // setting the view 85 | sceGumMatrixMode(GU_VIEW); 86 | sceGumLoadIdentity(); 87 | 88 | // model 89 | triangle->Render(); 90 | 91 | // ending rendering 92 | sceGuFinish(); 93 | sceGuSync(0,0); 94 | sceDisplayWaitVblankStart(); 95 | sceGuSwapBuffers(); 96 | } 97 | -------------------------------------------------------------------------------- /Tutorial4a/GameApp.cpp: -------------------------------------------------------------------------------- 1 | #include "GameApp.h" 2 | #include "GraphicsObject.h" 3 | #include "Triangle.h" 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "stdio.h" 10 | #include 11 | 12 | 13 | static unsigned int __attribute__((aligned(16))) list[262144]; 14 | 15 | 16 | GameApp::GameApp() { 17 | 18 | } 19 | 20 | GameApp::~GameApp() { 21 | 22 | } 23 | 24 | int GameApp::Run() { 25 | 26 | if(!Load()) 27 | return 1; 28 | 29 | // game loop 30 | while(1) { 31 | if (Controls() == 9) 32 | break; 33 | Render(); 34 | } 35 | return 0; 36 | } 37 | 38 | bool GameApp::Load() { 39 | // get pointer to Graphics object. 40 | gfx = GraphicsObject::Instance(); 41 | // set up the environment. 42 | gfx->Init3DGraphics(); 43 | 44 | // create the triangle 45 | triangle = new Triangle(); 46 | 47 | // setting the projection 48 | sceGumMatrixMode(GU_PROJECTION); 49 | sceGumLoadIdentity(); 50 | sceGumPerspective(45.0f,16.0f/9.0f,2.0f,1000.0f); 51 | 52 | return true; 53 | } 54 | 55 | int GameApp::Controls() { 56 | 57 | // reading controls 58 | SceCtrlData pad; 59 | sceCtrlPeekBufferPositive(&pad, 1); 60 | 61 | // check for input 62 | if (pad.Buttons != 0){ 63 | if (pad.Buttons & PSP_CTRL_CROSS){ 64 | return 9; 65 | } 66 | } 67 | 68 | return 0; 69 | 70 | } 71 | 72 | void GameApp::Render() { 73 | // render information. 74 | sceGuStart(GU_DIRECT,list); 75 | 76 | // clear screen 77 | sceGuClearColor(0xff000000); 78 | sceGuClearDepth(0); 79 | sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT); 80 | 81 | // set the ambient light 82 | sceGuAmbient(0xffffffff); 83 | 84 | // setting the view 85 | sceGumMatrixMode(GU_VIEW); 86 | sceGumLoadIdentity(); 87 | 88 | // model 89 | triangle->Render(); 90 | 91 | // ending rendering 92 | sceGuFinish(); 93 | sceGuSync(0,0); 94 | sceDisplayWaitVblankStart(); 95 | sceGuSwapBuffers(); 96 | } 97 | -------------------------------------------------------------------------------- /Tutorial12/krat.obj: -------------------------------------------------------------------------------- 1 | # This file uses centimeters as units for non-parametric coordinates. 2 | 3 | mtllib krat.mtl 4 | g default 5 | v -2.200467 0.047225 2.200467 6 | v 2.200467 0.047225 2.200467 7 | v -2.200467 4.448160 2.200467 8 | v 2.200467 4.448160 2.200467 9 | v -2.200467 4.448160 -2.200467 10 | v 2.200467 4.448160 -2.200467 11 | v -2.200467 0.047225 -2.200467 12 | v 2.200467 0.047225 -2.200467 13 | vt 0.000000 0.000000 14 | vt 1.000000 0.000000 15 | vt 0.000000 1.000000 16 | vt 1.000000 1.000000 17 | vt 0.000000 2.000000 18 | vt 1.000000 2.000000 19 | vt 0.000000 3.000000 20 | vt 1.000000 3.000000 21 | vt 0.000000 4.000000 22 | vt 1.000000 4.000000 23 | vt 2.000000 0.000000 24 | vt 2.000000 1.000000 25 | vt -1.000000 0.000000 26 | vt -1.000000 1.000000 27 | vn 0.000000 0.000000 -1.000000 28 | vn 0.000000 0.000000 -1.000000 29 | vn 0.000000 0.000000 -1.000000 30 | vn 0.000000 0.000000 -1.000000 31 | vn 0.000000 -1.000000 0.000000 32 | vn 0.000000 -1.000000 0.000000 33 | vn 0.000000 -1.000000 0.000000 34 | vn 0.000000 -1.000000 0.000000 35 | vn 0.000000 0.000000 1.000000 36 | vn 0.000000 0.000000 1.000000 37 | vn 0.000000 0.000000 1.000000 38 | vn 0.000000 0.000000 1.000000 39 | vn 0.000000 1.000000 0.000000 40 | vn 0.000000 1.000000 0.000000 41 | vn 0.000000 1.000000 0.000000 42 | vn 0.000000 1.000000 0.000000 43 | vn -1.000000 0.000000 0.000000 44 | vn -1.000000 0.000000 0.000000 45 | vn -1.000000 0.000000 0.000000 46 | vn -1.000000 0.000000 0.000000 47 | vn 1.000000 0.000000 0.000000 48 | vn 1.000000 0.000000 0.000000 49 | vn 1.000000 0.000000 0.000000 50 | vn 1.000000 0.000000 0.000000 51 | g pCube1 52 | usemtl initialShadingGroup 53 | f 1/1/1 3/3/2 2/2/3 54 | f 2/2/3 3/3/2 4/4/4 55 | f 3/3/5 5/5/6 4/4/7 56 | f 4/4/7 5/5/6 6/6/8 57 | f 5/5/9 7/7/10 6/6/11 58 | f 6/6/11 7/7/10 8/8/12 59 | f 7/7/13 1/9/14 8/8/15 60 | f 8/8/15 1/9/14 2/10/16 61 | f 2/2/17 4/4/18 8/11/19 62 | f 8/11/19 4/4/18 6/12/20 63 | f 7/13/21 5/14/22 1/1/23 64 | f 1/1/23 5/14/22 3/3/24 65 | EndGroup 66 | empty -------------------------------------------------------------------------------- /Tutorial5/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "GameApp.h" 6 | #include 7 | #include 8 | extern "C" { 9 | #include "graphics.h" 10 | } 11 | 12 | 13 | // MODULE INITIALISATION 14 | 15 | PSP_MODULE_INFO("Tutorial0", 0x0000, 1, 1); 16 | 17 | 18 | /*! 19 | * \fn int exit_callback(int arg1, int arg2, void *common) 20 | * \brief Exits the game. 21 | * 22 | * @return 0 23 | */ 24 | int exit_callback(int arg1, int arg2, void *common) { 25 | sceKernelExitGame(); 26 | return 0; 27 | } 28 | 29 | 30 | /*! 31 | * \fn int CallbackThread(SceSize args, void *argp) 32 | * \brief callback thread. 33 | * 34 | * @return 0 35 | */ 36 | int CallbackThread(SceSize args, void *argp) { 37 | int cbid; 38 | 39 | cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL); 40 | sceKernelRegisterExitCallback(cbid); 41 | 42 | sceKernelSleepThreadCB(); 43 | 44 | return 0; 45 | } 46 | 47 | 48 | /*! 49 | * \fn int SetupCallbacks(void) 50 | * \brief Creates a callback thread and returns the thread ID. 51 | * 52 | * @return thid 53 | */ 54 | int SetupCallbacks(void) { 55 | int thid = 0; 56 | 57 | thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0); //als er foutenzijn dan kan het hieraanliggen 58 | if(thid >= 0) { 59 | sceKernelStartThread(thid, 0, 0); 60 | } 61 | 62 | return thid; 63 | } 64 | 65 | 66 | 67 | /*! 68 | * \fn int Main(void) 69 | * \brief The main function 70 | * 71 | * @return 0 72 | */ 73 | int main (void) { 74 | 75 | // init the debug screen functions 76 | pspDebugScreenInit(); 77 | 78 | // setup the callbacks 79 | SetupCallbacks(); 80 | 81 | initGraphics(); 82 | 83 | // creating the game object 84 | GameApp* game = new GameApp(); 85 | // run the game app and get return value 86 | int ret = game->Run(); 87 | 88 | // shutdown 89 | sceGuTerm(); 90 | sceKernelExitGame(); 91 | 92 | return 0; 93 | } 94 | 95 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /TutorialFX2/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "GameApp.h" 6 | #include 7 | #include 8 | extern "C" { 9 | #include "graphics.h" 10 | } 11 | 12 | 13 | // MODULE INITIALISATION 14 | 15 | PSP_MODULE_INFO("Tutorial0", 0x0000, 1, 1); 16 | 17 | 18 | /*! 19 | * \fn int exit_callback(int arg1, int arg2, void *common) 20 | * \brief Exits the game. 21 | * 22 | * @return 0 23 | */ 24 | int exit_callback(int arg1, int arg2, void *common) { 25 | sceKernelExitGame(); 26 | return 0; 27 | } 28 | 29 | 30 | /*! 31 | * \fn int CallbackThread(SceSize args, void *argp) 32 | * \brief callback thread. 33 | * 34 | * @return 0 35 | */ 36 | int CallbackThread(SceSize args, void *argp) { 37 | int cbid; 38 | 39 | cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL); 40 | sceKernelRegisterExitCallback(cbid); 41 | 42 | sceKernelSleepThreadCB(); 43 | 44 | return 0; 45 | } 46 | 47 | 48 | /*! 49 | * \fn int SetupCallbacks(void) 50 | * \brief Creates a callback thread and returns the thread ID. 51 | * 52 | * @return thid 53 | */ 54 | int SetupCallbacks(void) { 55 | int thid = 0; 56 | 57 | thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0); //als er foutenzijn dan kan het hieraanliggen 58 | if(thid >= 0) { 59 | sceKernelStartThread(thid, 0, 0); 60 | } 61 | 62 | return thid; 63 | } 64 | 65 | 66 | 67 | /*! 68 | * \fn int Main(void) 69 | * \brief The main function 70 | * 71 | * @return 0 72 | */ 73 | int main (void) { 74 | 75 | // init the debug screen functions 76 | pspDebugScreenInit(); 77 | 78 | // setup the callbacks 79 | SetupCallbacks(); 80 | 81 | initGraphics(); 82 | 83 | // creating the game object 84 | GameApp* game = new GameApp(); 85 | // run the game app and get return value 86 | int ret = game->Run(); 87 | 88 | // shutdown 89 | sceGuTerm(); 90 | sceKernelExitGame(); 91 | 92 | return 0; 93 | } 94 | 95 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /Tutorial12/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "GameApp.h" 6 | #include 7 | #include 8 | #include 9 | 10 | 11 | // MODULE INITIALISATION 12 | 13 | PSP_MODULE_INFO("Tutorial2", 0x0000, 1, 1); 14 | 15 | 16 | /*! 17 | * \fn int exit_callback(int arg1, int arg2, void *common) 18 | * \brief Exits the game. 19 | * 20 | * @return 0 21 | */ 22 | int exit_callback(int arg1, int arg2, void *common) { 23 | sceKernelExitGame(); 24 | return 0; 25 | } 26 | 27 | 28 | /*! 29 | * \fn int CallbackThread(SceSize args, void *argp) 30 | * \brief callback thread. 31 | * 32 | * @return 0 33 | */ 34 | int CallbackThread(SceSize args, void *argp) { 35 | int cbid; 36 | 37 | cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL); 38 | sceKernelRegisterExitCallback(cbid); 39 | 40 | sceKernelSleepThreadCB(); 41 | 42 | return 0; 43 | } 44 | 45 | 46 | /*! 47 | * \fn int SetupCallbacks(void) 48 | * \brief Creates a callback thread and returns the thread ID. 49 | * 50 | * @return thid 51 | */ 52 | int SetupCallbacks(void) { 53 | int thid = 0; 54 | 55 | thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0); //als er foutenzijn dan kan het hieraanliggen 56 | if(thid >= 0) { 57 | sceKernelStartThread(thid, 0, 0); 58 | } 59 | 60 | return thid; 61 | } 62 | 63 | 64 | 65 | /*! 66 | * \fn int Main(void) 67 | * \brief The main function 68 | * 69 | * @return 0 70 | */ 71 | int main (void) { 72 | 73 | // set the speed better 74 | //scePowerSetClockFrequency(333, 333, 166); 75 | 76 | // init the debug screen functions 77 | pspDebugScreenInit(); 78 | 79 | // setup the callbacks 80 | SetupCallbacks(); 81 | 82 | // creating the game object 83 | GameApp* game = new GameApp(); 84 | // run the game app and get return value 85 | int ret = game->Run(); 86 | 87 | // shutdown 88 | sceGuTerm(); 89 | sceKernelExitGame(); 90 | 91 | return 0; 92 | } 93 | 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /Tutorial17/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "GameApp.h" 6 | #include 7 | #include 8 | #include 9 | 10 | 11 | // MODULE INITIALISATION 12 | 13 | PSP_MODULE_INFO("Tutorial2", 0x0000, 1, 1); 14 | 15 | 16 | /*! 17 | * \fn int exit_callback(int arg1, int arg2, void *common) 18 | * \brief Exits the game. 19 | * 20 | * @return 0 21 | */ 22 | int exit_callback(int arg1, int arg2, void *common) { 23 | sceKernelExitGame(); 24 | return 0; 25 | } 26 | 27 | 28 | /*! 29 | * \fn int CallbackThread(SceSize args, void *argp) 30 | * \brief callback thread. 31 | * 32 | * @return 0 33 | */ 34 | int CallbackThread(SceSize args, void *argp) { 35 | int cbid; 36 | 37 | cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL); 38 | sceKernelRegisterExitCallback(cbid); 39 | 40 | sceKernelSleepThreadCB(); 41 | 42 | return 0; 43 | } 44 | 45 | 46 | /*! 47 | * \fn int SetupCallbacks(void) 48 | * \brief Creates a callback thread and returns the thread ID. 49 | * 50 | * @return thid 51 | */ 52 | int SetupCallbacks(void) { 53 | int thid = 0; 54 | 55 | thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0); //als er foutenzijn dan kan het hieraanliggen 56 | if(thid >= 0) { 57 | sceKernelStartThread(thid, 0, 0); 58 | } 59 | 60 | return thid; 61 | } 62 | 63 | 64 | 65 | /*! 66 | * \fn int Main(void) 67 | * \brief The main function 68 | * 69 | * @return 0 70 | */ 71 | int main (void) { 72 | 73 | // set the speed better 74 | //scePowerSetClockFrequency(333, 333, 166); 75 | 76 | // init the debug screen functions 77 | pspDebugScreenInit(); 78 | 79 | // setup the callbacks 80 | SetupCallbacks(); 81 | 82 | // creating the game object 83 | GameApp* game = new GameApp(); 84 | // run the game app and get return value 85 | int ret = game->Run(); 86 | 87 | // shutdown 88 | sceGuTerm(); 89 | sceKernelExitGame(); 90 | 91 | return 0; 92 | } 93 | 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /Tutorial2/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "GameApp.h" 6 | #include 7 | #include 8 | #include 9 | 10 | 11 | // MODULE INITIALISATION 12 | 13 | PSP_MODULE_INFO("Tutorial2", 0x0000, 1, 1); 14 | 15 | 16 | /*! 17 | * \fn int exit_callback(int arg1, int arg2, void *common) 18 | * \brief Exits the game. 19 | * 20 | * @return 0 21 | */ 22 | int exit_callback(int arg1, int arg2, void *common) { 23 | sceKernelExitGame(); 24 | return 0; 25 | } 26 | 27 | 28 | /*! 29 | * \fn int CallbackThread(SceSize args, void *argp) 30 | * \brief callback thread. 31 | * 32 | * @return 0 33 | */ 34 | int CallbackThread(SceSize args, void *argp) { 35 | int cbid; 36 | 37 | cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL); 38 | sceKernelRegisterExitCallback(cbid); 39 | 40 | sceKernelSleepThreadCB(); 41 | 42 | return 0; 43 | } 44 | 45 | 46 | /*! 47 | * \fn int SetupCallbacks(void) 48 | * \brief Creates a callback thread and returns the thread ID. 49 | * 50 | * @return thid 51 | */ 52 | int SetupCallbacks(void) { 53 | int thid = 0; 54 | 55 | thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0); //als er foutenzijn dan kan het hieraanliggen 56 | if(thid >= 0) { 57 | sceKernelStartThread(thid, 0, 0); 58 | } 59 | 60 | return thid; 61 | } 62 | 63 | 64 | 65 | /*! 66 | * \fn int Main(void) 67 | * \brief The main function 68 | * 69 | * @return 0 70 | */ 71 | int main (void) { 72 | 73 | // set the speed better 74 | //scePowerSetClockFrequency(333, 333, 166); 75 | 76 | // init the debug screen functions 77 | pspDebugScreenInit(); 78 | 79 | // setup the callbacks 80 | SetupCallbacks(); 81 | 82 | // creating the game object 83 | GameApp* game = new GameApp(); 84 | // run the game app and get return value 85 | int ret = game->Run(); 86 | 87 | // shutdown 88 | sceGuTerm(); 89 | sceKernelExitGame(); 90 | 91 | return 0; 92 | } 93 | 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /Tutorial4a/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "GameApp.h" 6 | #include 7 | #include 8 | #include 9 | 10 | 11 | // MODULE INITIALISATION 12 | 13 | PSP_MODULE_INFO("Tutorial2", 0x0000, 1, 1); 14 | 15 | 16 | /*! 17 | * \fn int exit_callback(int arg1, int arg2, void *common) 18 | * \brief Exits the game. 19 | * 20 | * @return 0 21 | */ 22 | int exit_callback(int arg1, int arg2, void *common) { 23 | sceKernelExitGame(); 24 | return 0; 25 | } 26 | 27 | 28 | /*! 29 | * \fn int CallbackThread(SceSize args, void *argp) 30 | * \brief callback thread. 31 | * 32 | * @return 0 33 | */ 34 | int CallbackThread(SceSize args, void *argp) { 35 | int cbid; 36 | 37 | cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL); 38 | sceKernelRegisterExitCallback(cbid); 39 | 40 | sceKernelSleepThreadCB(); 41 | 42 | return 0; 43 | } 44 | 45 | 46 | /*! 47 | * \fn int SetupCallbacks(void) 48 | * \brief Creates a callback thread and returns the thread ID. 49 | * 50 | * @return thid 51 | */ 52 | int SetupCallbacks(void) { 53 | int thid = 0; 54 | 55 | thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0); //als er foutenzijn dan kan het hieraanliggen 56 | if(thid >= 0) { 57 | sceKernelStartThread(thid, 0, 0); 58 | } 59 | 60 | return thid; 61 | } 62 | 63 | 64 | 65 | /*! 66 | * \fn int Main(void) 67 | * \brief The main function 68 | * 69 | * @return 0 70 | */ 71 | int main (void) { 72 | 73 | // set the speed better 74 | //scePowerSetClockFrequency(333, 333, 166); 75 | 76 | // init the debug screen functions 77 | pspDebugScreenInit(); 78 | 79 | // setup the callbacks 80 | SetupCallbacks(); 81 | 82 | // creating the game object 83 | GameApp* game = new GameApp(); 84 | // run the game app and get return value 85 | int ret = game->Run(); 86 | 87 | // shutdown 88 | sceGuTerm(); 89 | sceKernelExitGame(); 90 | 91 | return 0; 92 | } 93 | 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /Tutorial11/LoadingScreen.cpp: -------------------------------------------------------------------------------- 1 | #include "LoadingScreen.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "GraphicsObject.h" 7 | extern "C" { 8 | #include "graphics.h" 9 | } 10 | 11 | static unsigned int __attribute__((aligned(16))) list[262144]; 12 | Image* load1; 13 | Image* load2; 14 | 15 | LoadingScreen::LoadingScreen() { 16 | // the loadingscreen is loaded as a thread 17 | thid_ = sceKernelCreateThread("LoadingThread", RunLoadingScreen, 0x18, 0x10000, 0, NULL); 18 | // start the thread 19 | sceKernelStartThread(thid_, 0, 0); 20 | } 21 | 22 | 23 | void LoadingScreen::KillLoadingScreen() { 24 | // shut down the loading screen again. 25 | sceKernelTerminateDeleteThread(thid_); 26 | // free the mem space of the images 27 | freeImage(load1); 28 | freeImage(load2); 29 | } 30 | 31 | 32 | int LoadingScreen::RunLoadingScreen(SceSize args, void *argp) { 33 | 34 | // first create the graphicspart 35 | GraphicsObject* gfx = GraphicsObject::Instance(); 36 | 37 | // load up the images 38 | load1 = loadImage("load1.png"); 39 | load2 = loadImage("load2.png"); 40 | 41 | // set animation to 0 42 | int animation_ = 0; 43 | 44 | // start the render loop 45 | while(1) { 46 | 47 | // render information. 48 | sceGuStart(GU_DIRECT,list); 49 | 50 | // clear screen 51 | sceGuClearColor(0xff000000); 52 | sceGuClearDepth(0); 53 | sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT); 54 | 55 | // set the ambient light 56 | sceGuAmbient(0xffffffff); 57 | 58 | // setting the view 59 | sceGumMatrixMode(GU_VIEW); 60 | sceGumLoadIdentity(); 61 | 62 | // the loading graphics :) 63 | animation_++; 64 | if(animation_ > 19) 65 | animation_ = 0; 66 | 67 | // switch images now and then 68 | if (animation_ < 10) 69 | gfx->Render2DImageOn3D(117, 100, load1); 70 | else if (animation_ < 20) 71 | gfx->Render2DImageOn3D(117, 100, load2); 72 | 73 | // ending rendering 74 | sceGuFinish(); 75 | sceGuSync(0,0); 76 | sceDisplayWaitVblankStart(); 77 | sceGuSwapBuffers(); 78 | } 79 | return 0; 80 | } 81 | 82 | -------------------------------------------------------------------------------- /Tutorialm2/GameApp.cpp: -------------------------------------------------------------------------------- 1 | #include "GameApp.h" 2 | #include "GraphicsObject.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | 10 | GameApp::GameApp() { 11 | 12 | } 13 | 14 | GameApp::~GameApp() { 15 | 16 | } 17 | 18 | int GameApp::Run() { 19 | 20 | if(!Load()) 21 | return 1; 22 | 23 | // game loop 24 | while(1) { 25 | if (Controls() == 9) 26 | break; 27 | Render(); 28 | } 29 | return 0; 30 | } 31 | 32 | bool GameApp::Load() { 33 | // get pointer to Graphics object. 34 | gfx = GraphicsObject::Instance(); 35 | // set up the environment. 36 | gfx->Init3DGraphics(); 37 | 38 | // load the UtilObject 39 | utils = UtilObject::Instance(); 40 | 41 | // initialize the randomizer. 42 | utils->InitRandomizer(); 43 | 44 | // setting the initial state of the variables 45 | this->goodRandom = 0; 46 | this->badRandom = 0; 47 | 48 | return true; 49 | } 50 | 51 | int GameApp::Controls() { 52 | // reading controls 53 | SceCtrlData pad; 54 | sceCtrlReadBufferPositive(&pad, 1); 55 | 56 | // check for input 57 | if (pad.Buttons != 0){ 58 | if (pad.Buttons & PSP_CTRL_CROSS){ 59 | if(buttonCross == 0) { 60 | buttonCross = 1; 61 | this->badRandom = utils->getRandomIntBad(0,9); 62 | } 63 | } 64 | if (pad.Buttons & PSP_CTRL_SQUARE){ 65 | if(buttonSquare == 0) { 66 | buttonSquare = 1; 67 | this->goodRandom = utils->getRandomIntGood(0,9); 68 | } 69 | } 70 | } 71 | else { 72 | buttonCross = 0; 73 | buttonSquare = 0; 74 | } 75 | 76 | return 0; 77 | 78 | } 79 | 80 | void GameApp::Render() { 81 | // render information. 82 | pspDebugScreenSetXY(10, 5); 83 | pspDebugScreenPrintf("The bad randomizer: %d", this->badRandom); 84 | pspDebugScreenSetXY(10, 6); 85 | pspDebugScreenPrintf("The good randomizer: %d", this->goodRandom); 86 | pspDebugScreenSetXY(4, 15); 87 | pspDebugScreenPrintf("Press Cross to get bad random number.\n"); 88 | pspDebugScreenSetXY(4, 20); 89 | pspDebugScreenPrintf("Press Square to get real random number.\n"); 90 | sceDisplayWaitVblankStart(); 91 | sceGuSwapBuffers(); 92 | } 93 | -------------------------------------------------------------------------------- /Tutorial6b/GameApp.cpp: -------------------------------------------------------------------------------- 1 | #include "GameApp.h" 2 | #include "GraphicsObject.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | static unsigned int __attribute__((aligned(16))) list[262144]; 10 | 11 | 12 | GameApp::GameApp() { 13 | 14 | } 15 | 16 | GameApp::~GameApp() { 17 | 18 | } 19 | 20 | int GameApp::Run() { 21 | 22 | if(!Load()) 23 | return 1; 24 | 25 | // game loop 26 | while(1) { 27 | if (Controls() == 9) 28 | break; 29 | Render(); 30 | } 31 | return 0; 32 | } 33 | 34 | bool GameApp::Load() { 35 | // get pointer to Graphics object. 36 | gfx = GraphicsObject::Instance(); 37 | // set up the environment. 38 | gfx->Init3DGraphics(); 39 | 40 | // set frameCount 41 | frameCount = 0; 42 | 43 | // setting the projection 44 | sceGumMatrixMode(GU_PROJECTION); 45 | sceGumLoadIdentity(); 46 | sceGumPerspective(45.0f,16.0f/9.0f,2.0f,1000.0f); 47 | 48 | return true; 49 | } 50 | 51 | int GameApp::Controls() { 52 | // reading controls 53 | SceCtrlData pad; 54 | sceCtrlReadBufferPositive(&pad, 1); 55 | 56 | // check for input 57 | if (pad.Buttons != 0){ 58 | if (pad.Buttons & PSP_CTRL_CROSS){ 59 | return 9; 60 | } 61 | } 62 | 63 | return 0; 64 | 65 | } 66 | 67 | void GameApp::Render() { 68 | // render information. 69 | sceGuStart(GU_DIRECT,list); 70 | 71 | // clear screen 72 | sceGuClearColor(0xff000000); 73 | sceGuClearDepth(0); 74 | sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT); 75 | 76 | // set the ambient light 77 | sceGuAmbient(0xffffffff); 78 | 79 | ScePspFVector3 pos = {0.0f,10.0f,30.0f}; 80 | ScePspFVector3 at = {0.0f,0.0f,0.0f}; 81 | ScePspFVector3 up = {0.0f,1.0f,0.0f}; 82 | // setting the view 83 | sceGumMatrixMode(GU_VIEW); 84 | sceGumLoadIdentity(); 85 | sceGumLookAt(&pos, &at, &up); 86 | sceGumUpdateMatrix(); 87 | 88 | gfx->Render3DLine(0.0f,0.0f, 0.0f, 0.0f, 4.0f, 0.0f, 0xffff6b38); 89 | gfx->Render2DLineOn3D(5,5, 475, 268, 0xffffffff); 90 | 91 | // ending rendering 92 | sceGuFinish(); 93 | sceGuSync(0,0); 94 | sceDisplayWaitVblankStart(); 95 | sceGuSwapBuffers(); 96 | } 97 | -------------------------------------------------------------------------------- /Tutorial5/GameApp.cpp: -------------------------------------------------------------------------------- 1 | #include "GameApp.h" 2 | #include "GraphicsObject.h" 3 | #include "Triangle.h" 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "stdio.h" 10 | #include 11 | 12 | static unsigned int __attribute__((aligned(16))) list[262144]; 13 | 14 | 15 | GameApp::GameApp() { 16 | 17 | } 18 | 19 | GameApp::~GameApp() { 20 | 21 | } 22 | 23 | int GameApp::Run() { 24 | 25 | if(!Load()) 26 | return 1; 27 | 28 | // game loop 29 | while(1) { 30 | if (Controls() == 9) 31 | break; 32 | Render(); 33 | } 34 | return 0; 35 | } 36 | 37 | bool GameApp::Load() { 38 | // get pointer to Graphics object. 39 | gfx = GraphicsObject::Instance(); 40 | // set up the environment. 41 | gfx->Init3DGraphics(); 42 | 43 | // create the triangle 44 | triangle = new Triangle(); 45 | 46 | // create the 2d pic 47 | char sBuffer[250]; 48 | sprintf(sBuffer, "texture.png"); 49 | pic = loadImage(sBuffer); 50 | 51 | // setting the projection 52 | sceGumMatrixMode(GU_PROJECTION); 53 | sceGumLoadIdentity(); 54 | sceGumPerspective(45.0f,16.0f/9.0f,2.0f,1000.0f); 55 | 56 | return true; 57 | } 58 | 59 | int GameApp::Controls() { 60 | 61 | // reading controls 62 | SceCtrlData pad; 63 | sceCtrlPeekBufferPositive(&pad, 1); 64 | 65 | // check for input 66 | if (pad.Buttons != 0){ 67 | if (pad.Buttons & PSP_CTRL_CROSS){ 68 | return 9; 69 | } 70 | } 71 | 72 | return 0; 73 | 74 | } 75 | 76 | void GameApp::Render() { 77 | // render information. 78 | sceGuStart(GU_DIRECT,list); 79 | 80 | // clear screen 81 | sceGuClearColor(0xff000000); 82 | sceGuClearDepth(0); 83 | sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT); 84 | 85 | // set the ambient light 86 | sceGuAmbient(0xffffffff); 87 | 88 | // setting the view 89 | sceGumMatrixMode(GU_VIEW); 90 | sceGumLoadIdentity(); 91 | 92 | // model 93 | triangle->Render(); 94 | 95 | // 2d on 3d 96 | gfx->Render2DImageOn3D(1.0f, 1.0f, pic); 97 | 98 | // ending rendering 99 | sceGuFinish(); 100 | sceGuSync(0,0); 101 | sceDisplayWaitVblankStart(); 102 | sceGuSwapBuffers(); 103 | } 104 | -------------------------------------------------------------------------------- /Tutorial17/GameApp.cpp: -------------------------------------------------------------------------------- 1 | #include "GameApp.h" 2 | #include "GraphicsObject.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "stdio.h" 9 | #include 10 | 11 | 12 | 13 | static unsigned int __attribute__((aligned(16))) list[262144]; 14 | 15 | 16 | GameApp::GameApp() { 17 | 18 | } 19 | 20 | GameApp::~GameApp() { 21 | 22 | } 23 | 24 | int GameApp::Run() { 25 | 26 | if(!Load()) 27 | return 1; 28 | 29 | // game loop 30 | while(1) { 31 | if (Controls() == 9) 32 | break; 33 | Render(); 34 | } 35 | return 0; 36 | } 37 | 38 | bool GameApp::Load() { 39 | // get pointer to Graphics object. 40 | gfx = GraphicsObject::Instance(); 41 | // set up the environment. 42 | gfx->Init3DGraphics(); 43 | 44 | // load up the skybox 45 | sky = new SkyBox(); 46 | 47 | // setting the projection 48 | sceGumMatrixMode(GU_PROJECTION); 49 | sceGumLoadIdentity(); 50 | sceGumPerspective(45.0f,16.0f/9.0f,2.0f,1000.0f); 51 | 52 | // rotation of the camera 53 | rot = 0.0f; 54 | 55 | return true; 56 | } 57 | 58 | int GameApp::Controls() { 59 | 60 | // reading controls 61 | SceCtrlData pad; 62 | sceCtrlPeekBufferPositive(&pad, 1); 63 | 64 | // check for input 65 | if (pad.Buttons != 0){ 66 | if (pad.Buttons & PSP_CTRL_CROSS){ 67 | return 9; 68 | } 69 | } 70 | 71 | return 0; 72 | 73 | } 74 | 75 | void GameApp::Render() { 76 | // first set our position 77 | ScePspFVector3 pos = {0.0f, 0.0f, 0.0f}; 78 | rot += 0.01f; 79 | 80 | // render information. 81 | sceGuStart(GU_DIRECT,list); 82 | 83 | // clear screen 84 | sceGuClearColor(0xff000000); 85 | sceGuClearDepth(0); 86 | sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT); 87 | 88 | // set the ambient light. 89 | sceGuAmbient(0xffffffff); 90 | 91 | // setting the view. 92 | sceGumMatrixMode(GU_VIEW); 93 | sceGumLoadIdentity(); 94 | sceGumRotateY(rot); 95 | sceGumTranslate(&pos); 96 | 97 | // render the skybox. 98 | sky->Render(pos); 99 | 100 | // ending rendering 101 | sceGuFinish(); 102 | sceGuSync(0,0); 103 | sceDisplayWaitVblankStart(); 104 | sceGuSwapBuffers(); 105 | } 106 | -------------------------------------------------------------------------------- /Tutorial12/GameApp.cpp: -------------------------------------------------------------------------------- 1 | #include "GameApp.h" 2 | #include "GraphicsObject.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "stdio.h" 9 | #include 10 | #include "Model.h" 11 | 12 | 13 | 14 | static unsigned int __attribute__((aligned(16))) list[262144]; 15 | 16 | 17 | GameApp::GameApp() { 18 | 19 | } 20 | 21 | GameApp::~GameApp() { 22 | 23 | } 24 | 25 | int GameApp::Run() { 26 | 27 | if(!Load()) 28 | return 1; 29 | 30 | // game loop 31 | while(1) { 32 | if (Controls() == 9) 33 | break; 34 | Render(); 35 | } 36 | return 0; 37 | } 38 | 39 | bool GameApp::Load() { 40 | // get pointer to Graphics object. 41 | gfx = GraphicsObject::Instance(); 42 | // set up the environment. 43 | gfx->Init3DGraphics(); 44 | 45 | // load up the skybox 46 | model = new Model("DesertHouse.obj", "DesertHouse.mtl"); 47 | 48 | // setting the projection 49 | sceGumMatrixMode(GU_PROJECTION); 50 | sceGumLoadIdentity(); 51 | sceGumPerspective(45.0f,16.0f/9.0f,2.0f,1000.0f); 52 | 53 | return true; 54 | } 55 | 56 | int GameApp::Controls() { 57 | 58 | // reading controls 59 | SceCtrlData pad; 60 | sceCtrlPeekBufferPositive(&pad, 1); 61 | 62 | // check for input 63 | if (pad.Buttons != 0){ 64 | if (pad.Buttons & PSP_CTRL_CROSS){ 65 | return 9; 66 | } 67 | } 68 | 69 | return 0; 70 | 71 | } 72 | 73 | void GameApp::Render() { 74 | 75 | // render information. 76 | sceGuStart(GU_DIRECT,list); 77 | 78 | // clear screen 79 | sceGuClearColor(0xff000000); 80 | sceGuClearDepth(0); 81 | sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT); 82 | 83 | // set the ambient light. 84 | sceGuAmbient(0xffffffff); 85 | 86 | // setting the view. 87 | sceGumMatrixMode(GU_VIEW); 88 | sceGumLoadIdentity(); 89 | ScePspFVector3 pos = {-10.0f,50.0f,100.0f}; 90 | ScePspFVector3 at = {0.0f,4.0f,-10.0f}; 91 | ScePspFVector3 up = {0.0f,1.0f,0.0f}; 92 | sceGumLookAt(&pos, &at, &up); 93 | 94 | // render the skybox. 95 | model->Render(); 96 | 97 | // ending rendering 98 | sceGuFinish(); 99 | sceGuSync(0,0); 100 | sceDisplayWaitVblankStart(); 101 | sceGuSwapBuffers(); 102 | } 103 | -------------------------------------------------------------------------------- /TutorialFX2/GameApp.cpp: -------------------------------------------------------------------------------- 1 | #include "GameApp.h" 2 | #include "GraphicsObject.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "stdio.h" 9 | #include 10 | 11 | static unsigned int __attribute__((aligned(16))) list[262144]; 12 | 13 | 14 | GameApp::GameApp() { 15 | 16 | } 17 | 18 | GameApp::~GameApp() { 19 | 20 | } 21 | 22 | int GameApp::Run() { 23 | 24 | if(!Load()) 25 | return 1; 26 | 27 | // game loop 28 | while(1) { 29 | if (Controls() == 9) 30 | break; 31 | Render(); 32 | } 33 | return 0; 34 | } 35 | 36 | bool GameApp::Load() { 37 | // get pointer to Graphics object. 38 | gfx = GraphicsObject::Instance(); 39 | // set up the environment. 40 | gfx->Init3DGraphics(); 41 | 42 | // create the 2d pic 43 | char sBuffer[250]; 44 | sprintf(sBuffer, "texture.png"); 45 | pic = loadImage(sBuffer); 46 | 47 | // setting the projection 48 | sceGumMatrixMode(GU_PROJECTION); 49 | sceGumLoadIdentity(); 50 | sceGumPerspective(45.0f,16.0f/9.0f,2.0f,1000.0f); 51 | 52 | // setting fadeout to false 53 | fadeout = false; 54 | fade = 0; 55 | 56 | return true; 57 | } 58 | 59 | int GameApp::Controls() { 60 | 61 | // reading controls 62 | SceCtrlData pad; 63 | sceCtrlPeekBufferPositive(&pad, 1); 64 | 65 | // check for input 66 | if (pad.Buttons != 0){ 67 | if (pad.Buttons & PSP_CTRL_CROSS){ 68 | fadeout = true; 69 | } 70 | } 71 | 72 | return 0; 73 | 74 | } 75 | 76 | void GameApp::Render() { 77 | // render information. 78 | sceGuStart(GU_DIRECT,list); 79 | 80 | // clear screen 81 | sceGuClearColor(0xff000000); 82 | sceGuClearDepth(0); 83 | sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT); 84 | 85 | // set the ambient light 86 | sceGuAmbient(0xffffffff); 87 | 88 | // setting the view 89 | sceGumMatrixMode(GU_VIEW); 90 | sceGumLoadIdentity(); 91 | 92 | // 2d on 3d 93 | gfx->Render2DImageOn3D(208.0f, 104.0f, pic); 94 | 95 | // fade the screen 96 | if(fadeout) { 97 | fade++; 98 | if(fade>254) 99 | fadeout=false; 100 | } 101 | gfx->RenderScreenFade(0,0,0,fade); 102 | 103 | 104 | // ending rendering 105 | sceGuFinish(); 106 | sceGuSync(0,0); 107 | sceDisplayWaitVblankStart(); 108 | sceGuSwapBuffers(); 109 | } 110 | -------------------------------------------------------------------------------- /Tutorial6a/GraphicsObject.cpp: -------------------------------------------------------------------------------- 1 | #include "GraphicsObject.h" 2 | #include 3 | 4 | static unsigned int __attribute__((aligned(16))) list[262144]; 5 | 6 | GraphicsObject* GraphicsObject::_instance = 0;// initialize pointer 7 | 8 | GraphicsObject* GraphicsObject::Instance (void) { 9 | 10 | if (_instance == 0){ 11 | _instance = new GraphicsObject; // create sole instance 12 | } 13 | return _instance; // address of sole instance 14 | } 15 | 16 | GraphicsObject::GraphicsObject(void) { 17 | // creation of object 18 | } 19 | 20 | GraphicsObject::~GraphicsObject(void) { 21 | // clean up 22 | } 23 | 24 | bool GraphicsObject::Init3DGraphics(void) { 25 | 26 | // Initialize the GraphicalSystem 27 | sceGuInit(); 28 | sceGuStart(GU_DIRECT,list); 29 | sceGuDrawBuffer(GU_PSM_8888,(void*)0,512); 30 | sceGuDispBuffer(480,272,(void*)0x88000,512); 31 | sceGuDepthBuffer((void*)0x110000,512); 32 | sceGuOffset(2048 - (480/2),2048 - (272/2)); 33 | 34 | // create a viewport centered at 2048,2048 width 480 and height 272 35 | sceGuViewport(2048,2048,480,272); 36 | sceGuDepthRange(0xc350,0x2710); 37 | 38 | sceGuScissor(0,0,480,272); 39 | sceGuEnable(GU_SCISSOR_TEST); 40 | sceGuDepthFunc(GU_GEQUAL); 41 | sceGuEnable(GU_DEPTH_TEST); 42 | sceGuFrontFace(GU_CW); 43 | sceGuShadeModel(GU_SMOOTH); 44 | sceGuEnable(GU_CULL_FACE); 45 | sceGuEnable(GU_TEXTURE_2D); 46 | sceGuEnable(GU_CLIP_PLANES); 47 | sceGuEnable(GU_LIGHTING); 48 | sceGuEnable(GU_BLEND); 49 | sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0); 50 | sceGuFinish(); 51 | // wait untill the list has finished. 52 | sceGuSync(0,0); 53 | // turn on the display 54 | sceGuDisplay(GU_TRUE); 55 | 56 | return true; 57 | } 58 | 59 | 60 | int GraphicsObject::Render2DLineOn3D(const float x1, const float y1, const float x2, const float y2, const unsigned int color) { 61 | 62 | sceGuDisable(GU_TEXTURE_2D); 63 | sceGuDisable(GU_DEPTH_TEST); 64 | 65 | lineVertex* Line = (lineVertex*)sceGuGetMemory(2 * sizeof(lineVertex)); 66 | 67 | Line[0].color = color; 68 | Line[0].x = x1; 69 | Line[0].y = y1; 70 | Line[0].z = 0.0f; 71 | 72 | Line[1].color = color; 73 | Line[1].x = x2; 74 | Line[1].y = y2; 75 | Line[1].z = 0.0f; 76 | 77 | 78 | sceGuDrawArray(GU_LINES, GU_COLOR_8888 | GU_VERTEX_32BITF | GU_TRANSFORM_2D, 2, 0, Line); 79 | 80 | sceGuEnable(GU_DEPTH_TEST); 81 | sceGuEnable(GU_TEXTURE_2D); 82 | 83 | return 0; 84 | 85 | } 86 | -------------------------------------------------------------------------------- /Tutorialm5/GameApp.cpp: -------------------------------------------------------------------------------- 1 | #include "GameApp.h" 2 | #include "GraphicsObject.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | GameApp::GameApp() { 10 | 11 | } 12 | 13 | GameApp::~GameApp() { 14 | 15 | } 16 | 17 | int GameApp::Run() { 18 | 19 | if(!Load()) 20 | return 1; 21 | 22 | // game loop 23 | while(1) { 24 | if (Controls() == 9) 25 | break; 26 | Render(); 27 | } 28 | return 0; 29 | } 30 | 31 | bool GameApp::Load() { 32 | // get pointer to Graphics object. 33 | gfx = GraphicsObject::Instance(); 34 | // set up the environment. 35 | gfx->Init3DGraphics(); 36 | 37 | // set frameCount 38 | frameCount = 0; 39 | 40 | // turn on the analog stick 41 | sceCtrlSetSamplingCycle(0); 42 | sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG); 43 | 44 | return true; 45 | } 46 | 47 | int GameApp::Controls() { 48 | // reading controls 49 | SceCtrlData pad; 50 | 51 | sceCtrlPeekBufferPositive(&pad, 1); 52 | 53 | float movementHorizontal, movementVertical; 54 | 55 | // getting the analog stick 56 | movementHorizontal = (float)(pad.Lx)-128.0f; 57 | //pspDebugScreenPrintf("Horizontal = %f\n",movementHorizontal); 58 | movementVertical = (float)(pad.Ly)-128.0f; 59 | //pspDebugScreenPrintf("movementVertical = %f\n",movementVertical); 60 | 61 | if (pad.Buttons != 0){ 62 | if (pad.Buttons & PSP_CTRL_LEFT){ 63 | pspDebugScreenPrintf("Pressed the left button...\n"); 64 | } 65 | if (pad.Buttons & PSP_CTRL_RIGHT){ 66 | pspDebugScreenPrintf("Pressed the right button...\n"); 67 | } 68 | if (pad.Buttons & PSP_CTRL_UP){ 69 | pspDebugScreenPrintf("Pressed the up button...\n"); 70 | } 71 | if (pad.Buttons & PSP_CTRL_DOWN){ 72 | pspDebugScreenPrintf("Pressed the down button...\n"); 73 | } 74 | if (pad.Buttons & PSP_CTRL_CROSS){ 75 | pspDebugScreenPrintf("Pressed the cross button...\n"); 76 | } 77 | if (pad.Buttons & PSP_CTRL_SQUARE){ 78 | pspDebugScreenPrintf("Pressed the square button...\n"); 79 | } 80 | if (pad.Buttons & PSP_CTRL_TRIANGLE){ 81 | pspDebugScreenPrintf("Pressed the triangle button...\n"); 82 | } 83 | if (pad.Buttons & PSP_CTRL_CIRCLE){ 84 | pspDebugScreenPrintf("Pressed the circle button...\n"); 85 | } 86 | if (pad.Buttons & PSP_CTRL_START){ 87 | pspDebugScreenPrintf("Pressed the start button...\n"); 88 | } 89 | if (pad.Buttons & PSP_CTRL_SELECT){ 90 | pspDebugScreenPrintf("Pressed the select button...\n"); 91 | } 92 | if (pad.Buttons & PSP_CTRL_RTRIGGER){ 93 | pspDebugScreenPrintf("Pressed the Right trigger button...\n"); 94 | } 95 | if (pad.Buttons & PSP_CTRL_LTRIGGER){ 96 | pspDebugScreenPrintf("Pressed the Left trigger button...\n"); 97 | } 98 | } 99 | 100 | return 0; 101 | } 102 | 103 | 104 | void GameApp::Render() { 105 | // render information. 106 | //frameCount++; 107 | //pspDebugScreenPrintf("Rendering frame %d\n", frameCount); 108 | sceDisplayWaitVblankStart(); 109 | sceGuSwapBuffers(); 110 | } 111 | -------------------------------------------------------------------------------- /Tutorial6b/GraphicsObject.cpp: -------------------------------------------------------------------------------- 1 | #include "GraphicsObject.h" 2 | #include 3 | #include 4 | 5 | static unsigned int __attribute__((aligned(16))) list[262144]; 6 | 7 | GraphicsObject* GraphicsObject::_instance = 0;// initialize pointer 8 | 9 | GraphicsObject* GraphicsObject::Instance (void) { 10 | 11 | if (_instance == 0){ 12 | _instance = new GraphicsObject; // create sole instance 13 | } 14 | return _instance; // address of sole instance 15 | } 16 | 17 | GraphicsObject::GraphicsObject(void) { 18 | // creation of object 19 | } 20 | 21 | GraphicsObject::~GraphicsObject(void) { 22 | // clean up 23 | } 24 | 25 | bool GraphicsObject::Init3DGraphics(void) { 26 | 27 | // Initialize the GraphicalSystem 28 | sceGuInit(); 29 | gumInit(); 30 | sceGuStart(GU_DIRECT,list); 31 | sceGuDrawBuffer(GU_PSM_8888,(void*)0,512); 32 | sceGuDispBuffer(480,272,(void*)0x88000,512); 33 | sceGuDepthBuffer((void*)0x110000,512); 34 | sceGuOffset(2048 - (480/2),2048 - (272/2)); 35 | 36 | // create a viewport centered at 2048,2048 width 480 and height 272 37 | sceGuViewport(2048,2048,480,272); 38 | sceGuDepthRange(0xc350,0x2710); 39 | 40 | sceGuScissor(0,0,480,272); 41 | sceGuEnable(GU_SCISSOR_TEST); 42 | sceGuDepthFunc(GU_GEQUAL); 43 | sceGuEnable(GU_DEPTH_TEST); 44 | sceGuFrontFace(GU_CW); 45 | sceGuShadeModel(GU_SMOOTH); 46 | sceGuEnable(GU_CULL_FACE); 47 | //sceGuEnable(GU_TEXTURE_2D); 48 | sceGuEnable(GU_CLIP_PLANES); 49 | sceGuEnable(GU_LIGHTING); 50 | //sceGuEnable(GU_BLEND); 51 | //sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0); 52 | sceGuFinish(); 53 | // wait untill the list has finished. 54 | sceGuSync(0,0); 55 | // turn on the display 56 | sceGuDisplay(GU_TRUE); 57 | 58 | return true; 59 | } 60 | 61 | 62 | int GraphicsObject::Render2DLineOn3D(const float x1, const float y1, const float x2, const float y2, const unsigned int color) { 63 | 64 | sceGuDisable(GU_TEXTURE_2D); 65 | sceGuDisable(GU_DEPTH_TEST); 66 | 67 | lineVertex* Line = (lineVertex*)sceGuGetMemory(2 * sizeof(lineVertex)); 68 | 69 | Line[0].color = color; 70 | Line[0].x = x1; 71 | Line[0].y = y1; 72 | Line[0].z = 0.0f; 73 | 74 | Line[1].color = color; 75 | Line[1].x = x2; 76 | Line[1].y = y2; 77 | Line[1].z = 0.0f; 78 | 79 | 80 | sceGuDrawArray(GU_LINES, GU_COLOR_8888 | GU_VERTEX_32BITF | GU_TRANSFORM_2D, 2, 0, Line); 81 | 82 | sceGuEnable(GU_DEPTH_TEST); 83 | sceGuEnable(GU_TEXTURE_2D); 84 | 85 | return 0; 86 | 87 | } 88 | 89 | int GraphicsObject::Render3DLine(const float x1, const float y1, const float z1, const float x2, const float y2, const float z2, const unsigned int color) { 90 | 91 | sceGuDisable(GU_TEXTURE_2D); 92 | 93 | lineVertex* Line = (lineVertex*)sceGuGetMemory(2 * sizeof(lineVertex)); 94 | 95 | Line[0].color = color; 96 | Line[0].x = x1; 97 | Line[0].y = y1; 98 | Line[0].z = z1; 99 | 100 | Line[1].color = color; 101 | Line[1].x = x2; 102 | Line[1].y = y2; 103 | Line[1].z = z1; 104 | 105 | sceGumMatrixMode(GU_MODEL); 106 | sceGumLoadIdentity(); 107 | sceGuDrawArray(GU_LINES, GU_COLOR_8888 | GU_VERTEX_32BITF | GU_TRANSFORM_3D, 2, 0, Line); 108 | sceGuEnable(GU_TEXTURE_2D); 109 | 110 | return 0; 111 | 112 | } 113 | -------------------------------------------------------------------------------- /Tutorial5/GraphicsObject.cpp: -------------------------------------------------------------------------------- 1 | #include "GraphicsObject.h" 2 | #include 3 | #include 4 | 5 | static unsigned int __attribute__((aligned(16))) list[262144]; 6 | 7 | GraphicsObject* GraphicsObject::_instance = 0;// initialize pointer 8 | 9 | GraphicsObject* GraphicsObject::Instance (void) { 10 | 11 | if (_instance == 0){ 12 | _instance = new GraphicsObject; // create sole instance 13 | } 14 | return _instance; // address of sole instance 15 | } 16 | 17 | GraphicsObject::GraphicsObject(void) { 18 | // creation of object 19 | } 20 | 21 | GraphicsObject::~GraphicsObject(void) { 22 | // clean up 23 | } 24 | 25 | bool GraphicsObject::Init3DGraphics(void) { 26 | 27 | // Initialize the GraphicalSystem 28 | sceGuInit(); 29 | sceGuStart(GU_DIRECT,list); 30 | sceGuDrawBuffer(GU_PSM_8888,(void*)0,512); 31 | sceGuDispBuffer(480,272,(void*)0x88000,512); 32 | sceGuDepthBuffer((void*)0x110000,512); 33 | sceGuOffset(2048 - (480/2),2048 - (272/2)); 34 | 35 | // create a viewport centered at 2048,2048 width 480 and height 272 36 | sceGuViewport(2048,2048,480,272); 37 | sceGuDepthRange(0xc350,0x2710); 38 | 39 | sceGuScissor(0,0,480,272); 40 | sceGuEnable(GU_SCISSOR_TEST); 41 | sceGuDepthFunc(GU_GEQUAL); 42 | sceGuEnable(GU_DEPTH_TEST); 43 | sceGuFrontFace(GU_CW); 44 | sceGuShadeModel(GU_SMOOTH); 45 | sceGuEnable(GU_CULL_FACE); 46 | sceGuEnable(GU_TEXTURE_2D); 47 | sceGuEnable(GU_CLIP_PLANES); 48 | 49 | sceGuFinish(); 50 | // wait untill the list has finished. 51 | sceGuSync(0,0); 52 | // turn on the display 53 | sceGuDisplay(GU_TRUE); 54 | 55 | return true; 56 | } 57 | 58 | 59 | int GraphicsObject::Render2DImageOn3D(float left, float top, const Image* texture) { 60 | 61 | vertex2d* DisplayVertices = (vertex2d*) sceGuGetMemory(4 * sizeof(vertex2d)); 62 | 63 | // we do not need to test for depth 64 | sceGuDisable(GU_DEPTH_TEST); 65 | // setting the texture 66 | sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA); 67 | sceGuTexMode(GU_PSM_8888, 0 ,0 ,0); 68 | sceGuTexImage(0, texture->textureWidth, texture->textureHeight, texture->textureWidth, (void*) texture->data); 69 | 70 | // setting the 4 vertices 71 | DisplayVertices[0].u = 0.0f; 72 | DisplayVertices[0].v = 0.0f; 73 | DisplayVertices[0].x = left; 74 | DisplayVertices[0].y = top; 75 | DisplayVertices[0].z = 0.0f; 76 | 77 | DisplayVertices[1].u = texture->textureWidth-1; 78 | DisplayVertices[1].v = 0.0f; 79 | DisplayVertices[1].x = left + texture->textureWidth; 80 | DisplayVertices[1].y = top; 81 | DisplayVertices[1].z = 0.0f; 82 | 83 | DisplayVertices[2].u = 0.0f; 84 | DisplayVertices[2].v = texture->textureHeight-1; 85 | DisplayVertices[2].x = left; 86 | DisplayVertices[2].y = top + texture->textureHeight; 87 | DisplayVertices[2].z = 0.0f; 88 | 89 | DisplayVertices[3].u = texture->textureWidth-1; 90 | DisplayVertices[3].v = texture->textureHeight-1; 91 | DisplayVertices[3].x = left + texture->textureWidth; 92 | DisplayVertices[3].y = top + texture->textureHeight; 93 | DisplayVertices[3].z = 0.0f; 94 | 95 | // draw the trianglestrip with transform 2D 96 | sceGuDrawArray(GU_TRIANGLE_STRIP, GU_TEXTURE_32BITF | GU_VERTEX_32BITF | GU_TRANSFORM_2D, 4, 0, DisplayVertices); 97 | 98 | // enable the depthtesting again. 99 | sceGuEnable(GU_DEPTH_TEST); 100 | 101 | return 0; 102 | } 103 | 104 | -------------------------------------------------------------------------------- /Tutorial11/GraphicsObject.cpp: -------------------------------------------------------------------------------- 1 | #include "GraphicsObject.h" 2 | #include 3 | 4 | static unsigned int __attribute__((aligned(16))) list[262144]; 5 | 6 | GraphicsObject* GraphicsObject::_instance = 0;// initialize pointer 7 | 8 | GraphicsObject* GraphicsObject::Instance (void) { 9 | 10 | if (_instance == 0){ 11 | _instance = new GraphicsObject; // create sole instance 12 | } 13 | return _instance; // address of sole instance 14 | } 15 | 16 | GraphicsObject::GraphicsObject(void) { 17 | // creation of object 18 | } 19 | 20 | GraphicsObject::~GraphicsObject(void) { 21 | // clean up 22 | } 23 | 24 | bool GraphicsObject::Init3DGraphics(void) { 25 | 26 | // Initialize the GraphicalSystem 27 | sceGuInit(); 28 | sceGuStart(GU_DIRECT,list); 29 | sceGuDrawBuffer(GU_PSM_8888,(void*)0,512); 30 | sceGuDispBuffer(480,272,(void*)0x88000,512); 31 | sceGuDepthBuffer((void*)0x110000,512); 32 | sceGuOffset(2048 - (480/2),2048 - (272/2)); 33 | 34 | // create a viewport centered at 2048,2048 width 480 and height 272 35 | sceGuViewport(2048,2048,480,272); 36 | sceGuDepthRange(0xc350,0x2710); 37 | 38 | sceGuScissor(0,0,480,272); 39 | sceGuEnable(GU_SCISSOR_TEST); 40 | sceGuDepthFunc(GU_GEQUAL); 41 | sceGuEnable(GU_DEPTH_TEST); 42 | sceGuFrontFace(GU_CW); 43 | sceGuShadeModel(GU_SMOOTH); 44 | sceGuEnable(GU_CULL_FACE); 45 | sceGuEnable(GU_TEXTURE_2D); 46 | sceGuEnable(GU_CLIP_PLANES); 47 | sceGuEnable(GU_LIGHTING); 48 | sceGuEnable(GU_BLEND); 49 | sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0); 50 | sceGuFinish(); 51 | // wait untill the list has finished. 52 | sceGuSync(0,0); 53 | // turn on the display 54 | sceGuDisplay(GU_TRUE); 55 | 56 | return true; 57 | } 58 | 59 | int GraphicsObject::Render2DImageOn3D(float left, float top, const Image* texture) { 60 | 61 | vertex2d* DisplayVertices = (vertex2d*) sceGuGetMemory(4 * sizeof(vertex2d)); 62 | 63 | // we do not need to test for depth 64 | sceGuDisable(GU_DEPTH_TEST); 65 | // setting the texture 66 | sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA); 67 | sceGuTexMode(GU_PSM_8888, 0 ,0 ,0); 68 | sceGuTexImage(0, texture->textureWidth, texture->textureHeight, texture->textureWidth, (void*) texture->data); 69 | 70 | // setting the 4 vertices 71 | DisplayVertices[0].u = 0.0f; 72 | DisplayVertices[0].v = 0.0f; 73 | DisplayVertices[0].x = left; 74 | DisplayVertices[0].y = top; 75 | DisplayVertices[0].z = 0.0f; 76 | 77 | DisplayVertices[1].u = texture->textureWidth-1; 78 | DisplayVertices[1].v = 0.0f; 79 | DisplayVertices[1].x = left + texture->textureWidth; 80 | DisplayVertices[1].y = top; 81 | DisplayVertices[1].z = 0.0f; 82 | 83 | DisplayVertices[2].u = 0.0f; 84 | DisplayVertices[2].v = texture->textureHeight-1; 85 | DisplayVertices[2].x = left; 86 | DisplayVertices[2].y = top + texture->textureHeight; 87 | DisplayVertices[2].z = 0.0f; 88 | 89 | DisplayVertices[3].u = texture->textureWidth-1; 90 | DisplayVertices[3].v = texture->textureHeight-1; 91 | DisplayVertices[3].x = left + texture->textureWidth; 92 | DisplayVertices[3].y = top + texture->textureHeight; 93 | DisplayVertices[3].z = 0.0f; 94 | 95 | // draw the trianglestrip with transform 2D 96 | sceGuDrawArray(GU_TRIANGLE_STRIP, GU_TEXTURE_32BITF | GU_VERTEX_32BITF | GU_TRANSFORM_2D, 4, 0, DisplayVertices); 97 | 98 | // enable the depthtesting again. 99 | sceGuEnable(GU_DEPTH_TEST); 100 | 101 | return 0; 102 | } 103 | 104 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## 3D-PSP-Tutorials 2 | 3 | Created by Ghoti. 4 | 5 | ### Setup: 6 | 7 | - Tutorial setup: [Cygwin](https://web.archive.org/web/20090228213800/http://www.psp-programming.com/tutorials/c/lesson01.htm) 8 | - Tutorial setup: [Visual Studio 6.0](https://web.archive.org/web/20090228213800/http://forums.ps2dev.org/viewtopic.php?t=2916&highlight=visual%2Bstudio) (my setup) 9 | - Tutorial setup: [Visual Studio .NET](https://web.archive.org/web/20090228213800/http://forums.ps2dev.org/viewtopic.php?t=2493&highlight=visual%2Bstudio) (for those without VS 6.0, have not done this myself) 10 | 11 | ### The 3D tutorials (C++): 12 | 13 | - Tutorial 0: [Setting up the 3D environment](https://web.archive.org/web/20090228213800/http://www.ghoti.nl/PSPtutorial1.php). 14 | - Tutorial 1: [The game loop](https://web.archive.org/web/20090228213800/http://www.ghoti.nl/PSPtutorial2.php) 15 | - Tutorial 2: [Rendering a triangle](https://web.archive.org/web/20090228213800/http://www.ghoti.nl/PSPtutorial3.php). 16 | - Tutorial 3: [Using the Projection, View and Model matrices](https://web.archive.org/web/20090228213800/http://www.ghoti.nl/PSPtutorial4.php) 17 | - Tutorial 4a: [Texturing: The beginning](https://web.archive.org/web/20090228213800/http://www.ghoti.nl/PSPtutorial4a.php) 18 | - Tutorial 4b: Texturing: Other formats 19 | - Tutorial 4c: Texturing: Mipmapping and Swizzling 20 | - Tutorial 5: Lights 21 | - Tutorial 6: [Creating 2D on 3D](https://web.archive.org/web/20090228213800/http://www.ghoti.nl/PSPtutorial6.php) 22 | - Tutorial 7: [Lines](https://web.archive.org/web/20090228213800/http://www.ghoti.nl/PSPtutorial7.php) 23 | - Tutorial 8: Bezier and Splines 24 | - Tutorial 9: Rendering text 25 | - Tutorial 10: Creating menu's 26 | - Tutorial 11: [Animated loading screen](https://web.archive.org/web/20090228213800/http://www.ghoti.nl/PSPtutorial11.php) 27 | - Tutorial 12a: [3D Models part 1: The basics](https://web.archive.org/web/20090228213800/http://www.ghoti.nl/PSPtutorial12.php) 28 | - Tutorial 12b: 3D Models part 2: A step further 29 | - Tutorial 13: Collision Detection 30 | - Tutorial 14: Heightmaps 31 | - Tutorial 15: Billboarding 32 | - Tutorial 16: Particle effects 33 | - Tutorial 17: [Skybox](https://web.archive.org/web/20090228213800/http://www.ghoti.nl/PSPtutorial17.php) 34 | 35 | ### The Special FX tutorials: 36 | 37 | - Tutorial FX1: Glow 38 | - Tutorial FX2: [Screenfading](https://web.archive.org/web/20090228213800/http://www.ghoti.nl/PSPtutorialFX2.php) 39 | 40 | ### The optimization tutorials: 41 | 42 | - Tutorial Optimization part I: [The basics](https://web.archive.org/web/20090228213800/http://www.ghoti.nl/PSPtutorialOp1.php) 43 | - Tutorial Optimization part II: [A step further](https://web.archive.org/web/20090228213800/http://www.ghoti.nl/PSPtutorialOp2.php) 44 | - Tutorial Optimization part III: Some bizar tips 45 | - Tutorial Optimization part IV: [Using the VFPU](https://web.archive.org/web/20090228213800/http://www.ghoti.nl/PSPtutorialOp4.php) 46 | - Tutorial Optimization part V: Graphics 47 | - Tutorial Optimization part VI: Design Patterns 48 | 49 | ### The Miscellaneous tutorials: 50 | 51 | - Tutorial m0: [Convert FW 1.5 code to FW 3.x code](https://web.archive.org/web/20090228213800/http://www.ghoti.nl/PSPtutorialm0.php) 52 | - Tutorial m1: [Timers](https://web.archive.org/web/20090228213800/http://www.ghoti.nl/PSPtutorialm1.php) 53 | - Tutorial m2: [Randomizers](https://web.archive.org/web/20090228213800/http://www.ghoti.nl/PSPtutorialm2.php) 54 | - Tutorial m3: Saving files 55 | - Tutorial m4: Encrypting files 56 | - Tutorial m5: [Controls revisited](https://web.archive.org/web/20090228213800/http://www.ghoti.nl/PSPtutorialm5.php) 57 | - Tutorial m6: [PSP types (datastructures)](https://web.archive.org/web/20090228213800/http://www.ghoti.nl/PSPtutorialm6.php) 58 | - Tutorial m7: Camera work revisited 59 | - Tutorial m8: Taking Screenshots 60 | - Tutorial m9: [Frames per second counter](https://web.archive.org/web/20090228213800/http://www.ghoti.nl/PSPtutorialm9.php) 61 | - Tutorial m10: Threads revisited 62 | -------------------------------------------------------------------------------- /TutorialFX2/GraphicsObject.cpp: -------------------------------------------------------------------------------- 1 | #include "GraphicsObject.h" 2 | #include 3 | #include 4 | 5 | static unsigned int __attribute__((aligned(16))) list[262144]; 6 | 7 | GraphicsObject* GraphicsObject::_instance = 0;// initialize pointer 8 | 9 | GraphicsObject* GraphicsObject::Instance (void) { 10 | 11 | if (_instance == 0){ 12 | _instance = new GraphicsObject; // create sole instance 13 | } 14 | return _instance; // address of sole instance 15 | } 16 | 17 | GraphicsObject::GraphicsObject(void) { 18 | // creation of object 19 | } 20 | 21 | GraphicsObject::~GraphicsObject(void) { 22 | // clean up 23 | } 24 | 25 | bool GraphicsObject::Init3DGraphics(void) { 26 | 27 | // Initialize the GraphicalSystem 28 | sceGuInit(); 29 | sceGuStart(GU_DIRECT,list); 30 | sceGuDrawBuffer(GU_PSM_8888,(void*)0,512); 31 | sceGuDispBuffer(480,272,(void*)0x88000,512); 32 | sceGuDepthBuffer((void*)0x110000,512); 33 | sceGuOffset(2048 - (480/2),2048 - (272/2)); 34 | 35 | // create a viewport centered at 2048,2048 width 480 and height 272 36 | sceGuViewport(2048,2048,480,272); 37 | sceGuDepthRange(0xc350,0x2710); 38 | 39 | sceGuScissor(0,0,480,272); 40 | sceGuEnable(GU_SCISSOR_TEST); 41 | sceGuDepthFunc(GU_GEQUAL); 42 | sceGuEnable(GU_DEPTH_TEST); 43 | sceGuFrontFace(GU_CW); 44 | sceGuShadeModel(GU_SMOOTH); 45 | sceGuEnable(GU_CULL_FACE); 46 | sceGuEnable(GU_TEXTURE_2D); 47 | sceGuEnable(GU_CLIP_PLANES); 48 | 49 | sceGuEnable(GU_BLEND); 50 | sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0); 51 | 52 | sceGuFinish(); 53 | // wait untill the list has finished. 54 | sceGuSync(0,0); 55 | // turn on the display 56 | sceGuDisplay(GU_TRUE); 57 | 58 | return true; 59 | } 60 | 61 | 62 | int GraphicsObject::Render2DImageOn3D(float left, float top, const Image* texture) { 63 | 64 | vertex2d* DisplayVertices = (vertex2d*) sceGuGetMemory(4 * sizeof(vertex2d)); 65 | 66 | // we do not need to test for depth 67 | sceGuDisable(GU_DEPTH_TEST); 68 | // setting the texture 69 | sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA); 70 | sceGuTexMode(GU_PSM_8888, 0 ,0 ,0); 71 | sceGuTexImage(0, texture->textureWidth, texture->textureHeight, texture->textureWidth, (void*) texture->data); 72 | 73 | // setting the 4 vertices 74 | DisplayVertices[0].u = 0.0f; 75 | DisplayVertices[0].v = 0.0f; 76 | DisplayVertices[0].x = left; 77 | DisplayVertices[0].y = top; 78 | DisplayVertices[0].z = 0.0f; 79 | 80 | DisplayVertices[1].u = texture->textureWidth-1; 81 | DisplayVertices[1].v = 0.0f; 82 | DisplayVertices[1].x = left + texture->textureWidth; 83 | DisplayVertices[1].y = top; 84 | DisplayVertices[1].z = 0.0f; 85 | 86 | DisplayVertices[2].u = 0.0f; 87 | DisplayVertices[2].v = texture->textureHeight-1; 88 | DisplayVertices[2].x = left; 89 | DisplayVertices[2].y = top + texture->textureHeight; 90 | DisplayVertices[2].z = 0.0f; 91 | 92 | DisplayVertices[3].u = texture->textureWidth-1; 93 | DisplayVertices[3].v = texture->textureHeight-1; 94 | DisplayVertices[3].x = left + texture->textureWidth; 95 | DisplayVertices[3].y = top + texture->textureHeight; 96 | DisplayVertices[3].z = 0.0f; 97 | 98 | // draw the trianglestrip with transform 2D 99 | sceGuDrawArray(GU_TRIANGLE_STRIP, GU_TEXTURE_32BITF | GU_VERTEX_32BITF | GU_TRANSFORM_2D, 4, 0, DisplayVertices); 100 | 101 | // enable the depthtesting again. 102 | sceGuEnable(GU_DEPTH_TEST); 103 | 104 | return 0; 105 | }; 106 | 107 | int GraphicsObject::RenderScreenFade(const unsigned int r, const unsigned int g,const unsigned int b,const int alphaPercentage) { 108 | 109 | sceGuDisable(GU_DEPTH_TEST); 110 | sceGuDisable(GU_TEXTURE_2D); 111 | 112 | vertexc2d* vertices = (vertexc2d*) sceGuGetMemory(2 * sizeof(vertexc2d)); 113 | 114 | vertices[0].color = GU_RGBA(r, g, b, alphaPercentage); 115 | vertices[0].x = 0; 116 | vertices[0].y = 0; 117 | vertices[0].z = 0; 118 | vertices[1].color = GU_RGBA(r, g, b, alphaPercentage); 119 | vertices[1].x = 480; 120 | vertices[1].y = 272; 121 | vertices[1].z = 0; 122 | 123 | sceGuDrawArray(GU_SPRITES, GU_COLOR_8888 | GU_VERTEX_32BITF | GU_TRANSFORM_2D, 2, 0, vertices); 124 | 125 | sceGuEnable(GU_TEXTURE_2D); 126 | sceGuEnable(GU_DEPTH_TEST); 127 | 128 | return 0; 129 | }; 130 | 131 | 132 | 133 | -------------------------------------------------------------------------------- /Tutorial17/SkyBox.cpp: -------------------------------------------------------------------------------- 1 | // PSP includes 2 | #include 3 | #include 4 | 5 | // Misc includes 6 | #include "malloc.h" 7 | 8 | // Own includes 9 | #include "SkyBox.h" 10 | 11 | 12 | SkyBox::SkyBox() { 13 | 14 | // loading the images 15 | texture1 = loadImage("land1.png"); 16 | texture2 = loadImage("land2.png"); 17 | texture3 = loadImage("land3.png"); 18 | texture4 = loadImage("land4.png"); 19 | 20 | // create the skybox geometry 21 | CreateBox(); 22 | } 23 | 24 | SkyBox::~SkyBox() { 25 | // free images 26 | freeImage(texture1); 27 | freeImage(texture2); 28 | freeImage(texture3); 29 | freeImage(texture4); 30 | 31 | // free vertices 32 | delete(boxside1); 33 | delete(boxside2); 34 | delete(boxside3); 35 | delete(boxside4); 36 | } 37 | 38 | void SkyBox::CreateBox() { 39 | 40 | // side 1 41 | boxside1 = (vertex2d*)memalign(16,4 * sizeof(vertex2d)); 42 | boxside1[0].u = 0.0f; 43 | boxside1[0].v = 0.0f; 44 | boxside1[0].x = -3.5f; 45 | boxside1[0].y = 3.5f; 46 | boxside1[0].z = -3.5f; 47 | 48 | boxside1[1].u = 1.0f; 49 | boxside1[1].v = 0.0f; 50 | boxside1[1].x = 3.5f; 51 | boxside1[1].y = 3.5f; 52 | boxside1[1].z = -3.5f; 53 | 54 | boxside1[2].u = 0.0f; 55 | boxside1[2].v = 1.0f; 56 | boxside1[2].x = -3.5f; 57 | boxside1[2].y = -3.5f; 58 | boxside1[2].z = -3.5f; 59 | 60 | boxside1[3].u = 1.0f; 61 | boxside1[3].v = 1.0f; 62 | boxside1[3].x = 3.5f; 63 | boxside1[3].y = -3.5f; 64 | boxside1[3].z = -3.5f; 65 | 66 | // side 2 67 | boxside2 = (vertex2d*)memalign(16,4 * sizeof(vertex2d)); 68 | boxside2[0].u = 0.0f; 69 | boxside2[0].v = 0.0f; 70 | boxside2[0].x = 3.5f; 71 | boxside2[0].y = 3.5f; 72 | boxside2[0].z = -3.5f; 73 | 74 | boxside2[1].u = 1.0f; 75 | boxside2[1].v = 0.0f; 76 | boxside2[1].x = 3.5f; 77 | boxside2[1].y = 3.5f; 78 | boxside2[1].z = 3.5f; 79 | 80 | boxside2[2].u = 0.0f; 81 | boxside2[2].v = 1.0f; 82 | boxside2[2].x = 3.5f; 83 | boxside2[2].y = -3.5f; 84 | boxside2[2].z = -3.5f; 85 | 86 | boxside2[3].u = 1.0f; 87 | boxside2[3].v = 1.0f; 88 | boxside2[3].x = 3.5f; 89 | boxside2[3].y = -3.5f; 90 | boxside2[3].z = 3.5f; 91 | 92 | // side 3 93 | boxside3 = (vertex2d*)memalign(16,4 * sizeof(vertex2d)); 94 | boxside3[0].u = 0.0f; 95 | boxside3[0].v = 0.0f; 96 | boxside3[0].x = 3.5f; 97 | boxside3[0].y = 3.5f; 98 | boxside3[0].z = 3.5f; 99 | 100 | boxside3[1].u = 1.0f; 101 | boxside3[1].v = 0.0f; 102 | boxside3[1].x = -3.5f; 103 | boxside3[1].y = 3.5f; 104 | boxside3[1].z = 3.5f; 105 | 106 | boxside3[2].u = 0.0f; 107 | boxside3[2].v = 1.0f; 108 | boxside3[2].x = 3.5f; 109 | boxside3[2].y = -3.5f; 110 | boxside3[2].z = 3.5f; 111 | 112 | boxside3[3].u = 1.0f; 113 | boxside3[3].v = 1.0f; 114 | boxside3[3].x = -3.5f; 115 | boxside3[3].y = -3.5f; 116 | boxside3[3].z = 3.5f; 117 | 118 | // side 4 119 | boxside4 = (vertex2d*)memalign(16,4 * sizeof(vertex2d)); 120 | boxside4[0].u = 0.0f; 121 | boxside4[0].v = 0.0f; 122 | boxside4[0].x = -3.5f; 123 | boxside4[0].y = 3.5f; 124 | boxside4[0].z = 3.5f; 125 | 126 | boxside4[1].u = 1.0f; 127 | boxside4[1].v = 0.0f; 128 | boxside4[1].x = -3.5f; 129 | boxside4[1].y = 3.5f; 130 | boxside4[1].z = -3.5f; 131 | 132 | boxside4[2].u = 0.0f; 133 | boxside4[2].v = 1.0f; 134 | boxside4[2].x = -3.5f; 135 | boxside4[2].y = -3.5f; 136 | boxside4[2].z = 3.5f; 137 | 138 | boxside4[3].u = 1.0f; 139 | boxside4[3].v = 1.0f; 140 | boxside4[3].x = -3.5f; 141 | boxside4[3].y = -3.5f; 142 | boxside4[3].z = -3.5f; 143 | 144 | 145 | } 146 | 147 | 148 | void SkyBox::Render(ScePspFVector3 pos) { 149 | 150 | sceGuDepthMask(GU_TRUE); // disable writes to the depth buffer 151 | 152 | sceGumMatrixMode(GU_MODEL); 153 | sceGumLoadIdentity(); 154 | sceGumTranslate(&pos); 155 | 156 | sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA); 157 | sceGuTexMode(GU_PSM_8888, 0 ,0 ,0); 158 | sceGuTexFilter(GU_LINEAR,GU_LINEAR); 159 | sceGuTexWrap(GU_CLAMP, GU_CLAMP); 160 | 161 | sceGuTexImage(0, texture1->textureWidth, texture1->textureHeight, texture1->textureWidth, (void*)texture1->data); 162 | sceGumDrawArray(GU_TRIANGLE_STRIP,GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_3D,4,0,boxside1); 163 | sceGuTexImage(0, texture2->textureWidth, texture2->textureHeight, texture2->textureWidth, (void*)texture2->data); 164 | sceGumDrawArray(GU_TRIANGLE_STRIP,GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_3D,4,0,boxside2); 165 | sceGuTexImage(0, texture3->textureWidth, texture3->textureHeight, texture3->textureWidth, (void*)texture3->data); 166 | sceGumDrawArray(GU_TRIANGLE_STRIP,GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_3D,4,0,boxside3); 167 | sceGuTexImage(0, texture4->textureWidth, texture4->textureHeight, texture4->textureWidth, (void*)texture4->data); 168 | sceGumDrawArray(GU_TRIANGLE_STRIP,GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_3D,4,0,boxside4); 169 | 170 | sceGuDepthMask(GU_FALSE); // enable writes to the depth buffer 171 | } 172 | -------------------------------------------------------------------------------- /Tutorial12/Model.cpp: -------------------------------------------------------------------------------- 1 | #include "Model.h" 2 | #include 3 | #include 4 | #include "stdio.h" 5 | #include "string.h" 6 | #include "malloc.h" 7 | 8 | 9 | Model::Model(const char* file, const char* mtl) { 10 | Load(file, mtl); 11 | } 12 | 13 | bool Model::Load(const char* file, const char* mtl) { 14 | 15 | char Textures[100][256]; // 2D array to store paths of the textures. 16 | char ReadBuffer[256]; // buffer use for reading files. 17 | char sBuffer[256]; 18 | 19 | int textureCount = 0; // variable to keep count of the number of textures in the model. 20 | 21 | // creating a FILE pointer 22 | FILE *fp = NULL; 23 | 24 | // check whether the file can be opened. 25 | if ((fp = fopen(mtl, "rb")) == NULL) { return false; } 26 | 27 | // loop through the lines. 28 | while(!feof(fp)) { 29 | // get new line. 30 | fgets(ReadBuffer, 256, fp); 31 | // check if a texture is present. 32 | if (strncmp("map_Kd ", ReadBuffer, 7) == 0 ) { 33 | sprintf(Textures[textureCount],"%s", strtok((ReadBuffer+7),"#")); 34 | textureCount++; 35 | } 36 | } 37 | // close the file. 38 | fclose(fp); 39 | 40 | 41 | // read the object file 42 | // this is the first read. This reads how many elements there are. 43 | // With that information we can create the data structures. 44 | fpos_t position; 45 | int groupCount = 0; // amount of groups in object file. 46 | int vertexCount = 0; // amount of vertices in object file. 47 | int textureCoordCount = 0; // amount of texture coordinates in object file. 48 | int faceCount = 0; // amount of face in object file. 49 | int normalCount = 0; // amount of normal in object file. 50 | 51 | 52 | if ((fp = fopen(file, "rb")) == NULL) { return false; } 53 | // we save the position so we can go back to the beginning 54 | fgetpos (fp, &position); 55 | while(!feof(fp)) { 56 | // read the line 57 | fgets(ReadBuffer, 256, fp); 58 | // check what kind of object is given in the line. 59 | if (strncmp("g default", ReadBuffer, 9) == 0 ) groupCount++; 60 | else if (strncmp("v ", ReadBuffer, 2) == 0 ) vertexCount++; 61 | else if (strncmp("vt ", ReadBuffer, 3) == 0 ) textureCoordCount++; 62 | else if (strncmp("f ", ReadBuffer, 2) == 0 ) faceCount++; 63 | else if (strncmp("vn ", ReadBuffer, 3) == 0 ) normalCount++; 64 | } 65 | 66 | 67 | // prepare the arrays 68 | ScePspFVector3 Vertices[ vertexCount ]; 69 | ScePspFTVector2 TexCoords[ textureCoordCount ]; 70 | FaceObj Faces[ faceCount ]; 71 | ScePspFVector3 Normals[ normalCount ]; 72 | // setting the number of modelgroups and get some memory for it. 73 | parts = (ObjMeshPart*)malloc(groupCount * sizeof(ObjMeshPart)); 74 | // save the number of groups/parts 75 | partCount = groupCount; 76 | 77 | // go to the first line in the file. 78 | fsetpos(fp, &position); 79 | 80 | // variables 81 | int group = 0; 82 | int v = 0; 83 | int n = 0; 84 | int t = 0; 85 | int face = 0; 86 | int i = 0; 87 | int l = 0; 88 | int Correction = 0; 89 | int j = 0; 90 | int k = 0; 91 | 92 | 93 | while(!feof(fp)) 94 | { 95 | fgets(ReadBuffer, 256, fp); 96 | 97 | if (strncmp("v ", ReadBuffer, 2) == 0 ) 98 | { 99 | sscanf((ReadBuffer+2), "%f%f%f",&Vertices[ v ].x, &Vertices[ v ].y, &Vertices[ v ].z); 100 | v++; 101 | } 102 | else if (strncmp("vn ", ReadBuffer, 3) == 0 ) 103 | { 104 | sscanf((ReadBuffer+3), "%f%f%f",&Normals[ n ].x, &Normals[ n ].y, &Normals[ n ].z); 105 | n++; 106 | } 107 | else if (strncmp("vt ", ReadBuffer, 3) == 0 ) 108 | { 109 | sscanf((ReadBuffer+3), "%f%f",&TexCoords[ t ].u, &TexCoords[ t ].v); 110 | t++; 111 | } 112 | 113 | else if (strncmp("f ", ReadBuffer, 2) == 0 ) 114 | { 115 | 116 | char *pSplitString = NULL; 117 | i=0; 118 | pSplitString = strtok((ReadBuffer+2)," \t\n"); 119 | 120 | do { 121 | 122 | sscanf((pSplitString), "%d/%d/%d",&Faces[ face ].vertices[ i ], &Faces[ face ].textc[ i ], &Faces[ face ].normals[ i ]); 123 | Faces[ face ].textc[ i ] -= 1; // 1 down because the obj file objects start at 1 and arrays start at 0 124 | Faces[ face ].vertices[ i ] -= 1; 125 | Faces[ face ].normals[ i ] -= 1; 126 | pSplitString = strtok(NULL," \t\n"); 127 | i += 1; 128 | } 129 | while( pSplitString ); 130 | 131 | face++; 132 | } 133 | 134 | else if (strncmp("EndGroup", ReadBuffer, 8) == 0 ) 135 | { 136 | parts[group].Vertices = (vertexfull*)malloc((face-Correction) * 3 * sizeof(vertexfull)); 137 | parts[group].faceCount = (face-Correction); 138 | l = 0; 139 | 140 | for (j=Correction;jtextureWidth, parts[i].texture->textureHeight, parts[i].texture->textureWidth, (void*)parts[i].texture->data); 228 | sceGumDrawArray(GU_TRIANGLES,GU_TEXTURE_32BITF|GU_COLOR_8888|GU_NORMAL_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_3D,parts[i].faceCount*3,0,parts[i].Vertices); 229 | } 230 | } 231 | 232 | -------------------------------------------------------------------------------- /Tutorial11/graphics.h: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHICS_H 2 | #define GRAPHICS_H 3 | 4 | #include 5 | 6 | #define PSP_LINE_SIZE 512 7 | #define SCREEN_WIDTH 480 8 | #define SCREEN_HEIGHT 272 9 | 10 | typedef u32 Color; 11 | #define A(color) ((u8)(color >> 24 & 0xFF)) 12 | #define B(color) ((u8)(color >> 16 & 0xFF)) 13 | #define G(color) ((u8)(color >> 8 & 0xFF)) 14 | #define R(color) ((u8)(color & 0xFF)) 15 | 16 | typedef struct 17 | { 18 | int textureWidth; // the real width of data, 2^n with n>=0 19 | int textureHeight; // the real height of data, 2^n with n>=0 20 | int imageWidth; // the image width 21 | int imageHeight; 22 | Color* data; 23 | } Image; 24 | 25 | /** 26 | * Load a PNG image. 27 | * 28 | * @pre filename != NULL 29 | * @param filename - filename of the PNG image to load 30 | * @return pointer to a new allocated Image struct, or NULL on failure 31 | */ 32 | extern Image* loadImage(const char* filename); 33 | 34 | /** 35 | * Blit a rectangle part of an image to another image. 36 | * 37 | * @pre source != NULL && destination != NULL && 38 | * sx >= 0 && sy >= 0 && 39 | * width > 0 && height > 0 && 40 | * sx + width <= source->width && sy + height <= source->height && 41 | * dx + width <= destination->width && dy + height <= destination->height 42 | * @param sx - left position of rectangle in source image 43 | * @param sy - top position of rectangle in source image 44 | * @param width - width of rectangle in source image 45 | * @param height - height of rectangle in source image 46 | * @param source - pointer to Image struct of the source image 47 | * @param dx - left target position in destination image 48 | * @param dy - top target position in destination image 49 | * @param destination - pointer to Image struct of the destination image 50 | */ 51 | extern void blitImageToImage(int sx, int sy, int width, int height, Image* source, int dx, int dy, Image* destination); 52 | 53 | /** 54 | * Blit a rectangle part of an image to screen. 55 | * 56 | * @pre source != NULL && destination != NULL && 57 | * sx >= 0 && sy >= 0 && 58 | * width > 0 && height > 0 && 59 | * sx + width <= source->width && sy + height <= source->height && 60 | * dx + width <= SCREEN_WIDTH && dy + height <= SCREEN_HEIGHT 61 | * @param sx - left position of rectangle in source image 62 | * @param sy - top position of rectangle in source image 63 | * @param width - width of rectangle in source image 64 | * @param height - height of rectangle in source image 65 | * @param source - pointer to Image struct of the source image 66 | * @param dx - left target position in destination image 67 | * @param dy - top target position in destination image 68 | */ 69 | extern void blitImageToScreen(int sx, int sy, int width, int height, Image* source, int dx, int dy); 70 | 71 | /** 72 | * Blit a rectangle part of an image to another image without alpha pixels in source image. 73 | * 74 | * @pre source != NULL && destination != NULL && 75 | * sx >= 0 && sy >= 0 && 76 | * width > 0 && height > 0 && 77 | * sx + width <= source->width && sy + height <= source->height && 78 | * dx + width <= destination->width && dy + height <= destination->height 79 | * @param sx - left position of rectangle in source image 80 | * @param sy - top position of rectangle in source image 81 | * @param width - width of rectangle in source image 82 | * @param height - height of rectangle in source image 83 | * @param source - pointer to Image struct of the source image 84 | * @param dx - left target position in destination image 85 | * @param dy - top target position in destination image 86 | * @param destination - pointer to Image struct of the destination image 87 | */ 88 | extern void blitAlphaImageToImage(int sx, int sy, int width, int height, Image* source, int dx, int dy, Image* destination); 89 | 90 | /** 91 | * Blit a rectangle part of an image to screen without alpha pixels in source image. 92 | * 93 | * @pre source != NULL && destination != NULL && 94 | * sx >= 0 && sy >= 0 && 95 | * width > 0 && height > 0 && 96 | * sx + width <= source->width && sy + height <= source->height && 97 | * dx + width <= SCREEN_WIDTH && dy + height <= SCREEN_HEIGHT 98 | * @param sx - left position of rectangle in source image 99 | * @param sy - top position of rectangle in source image 100 | * @param width - width of rectangle in source image 101 | * @param height - height of rectangle in source image 102 | * @param source - pointer to Image struct of the source image 103 | * @param dx - left target position in destination image 104 | * @param dy - top target position in destination image 105 | */ 106 | extern void blitAlphaImageToScreen(int sx, int sy, int width, int height, Image* source, int dx, int dy); 107 | 108 | /** 109 | * Create an empty image. 110 | * 111 | * @pre width > 0 && height > 0 && width <= 512 && height <= 512 112 | * @param width - width of the new image 113 | * @param height - height of the new image 114 | * @return pointer to a new allocated Image struct, all pixels initialized to color 0, or NULL on failure 115 | */ 116 | extern Image* createImage(int width, int height); 117 | 118 | /** 119 | * Frees an allocated image. 120 | * 121 | * @pre image != null 122 | * @param image a pointer to an image struct 123 | */ 124 | extern void freeImage(Image* image); 125 | 126 | /** 127 | * Initialize all pixels of an image with a color. 128 | * 129 | * @pre image != NULL 130 | * @param color - new color for the pixels 131 | * @param image - image to clear 132 | */ 133 | extern void clearImage(Color color, Image* image); 134 | 135 | /** 136 | * Initialize all pixels of the screen with a color. 137 | * 138 | * @param color - new color for the pixels 139 | */ 140 | extern void clearScreen(Color color); 141 | 142 | /** 143 | * Fill a rectangle of an image with a color. 144 | * 145 | * @pre image != NULL 146 | * @param color - new color for the pixels 147 | * @param x0 - left position of rectangle in image 148 | * @param y0 - top position of rectangle in image 149 | * @param width - width of rectangle in image 150 | * @param height - height of rectangle in image 151 | * @param image - image 152 | */ 153 | extern void fillImageRect(Color color, int x0, int y0, int width, int height, Image* image); 154 | 155 | /** 156 | * Fill a rectangle of an image with a color. 157 | * 158 | * @pre image != NULL 159 | * @param color - new color for the pixels 160 | * @param x0 - left position of rectangle in image 161 | * @param y0 - top position of rectangle in image 162 | * @param width - width of rectangle in image 163 | * @param height - height of rectangle in image 164 | */ 165 | extern void fillScreenRect(Color color, int x0, int y0, int width, int height); 166 | 167 | /** 168 | * Set a pixel on screen to the specified color. 169 | * 170 | * @pre x >= 0 && x < SCREEN_WIDTH && y >= 0 && y < SCREEN_HEIGHT 171 | * @param color - new color for the pixels 172 | * @param x - left position of the pixel 173 | * @param y - top position of the pixel 174 | */ 175 | extern void putPixelScreen(Color color, int x, int y); 176 | 177 | /** 178 | * Set a pixel in an image to the specified color. 179 | * 180 | * @pre x >= 0 && x < image->imageWidth && y >= 0 && y < image->imageHeight && image != NULL 181 | * @param color - new color for the pixels 182 | * @param x - left position of the pixel 183 | * @param y - top position of the pixel 184 | */ 185 | extern void putPixelImage(Color color, int x, int y, Image* image); 186 | 187 | /** 188 | * Get the color of a pixel on screen. 189 | * 190 | * @pre x >= 0 && x < SCREEN_WIDTH && y >= 0 && y < SCREEN_HEIGHT 191 | * @param x - left position of the pixel 192 | * @param y - top position of the pixel 193 | * @return the color of the pixel 194 | */ 195 | extern Color getPixelScreen(int x, int y); 196 | 197 | /** 198 | * Get the color of a pixel of an image. 199 | * 200 | * @pre x >= 0 && x < image->imageWidth && y >= 0 && y < image->imageHeight && image != NULL 201 | * @param x - left position of the pixel 202 | * @param y - top position of the pixel 203 | * @return the color of the pixel 204 | */ 205 | extern Color getPixelImage(int x, int y, Image* image); 206 | 207 | /** 208 | * Print a text (pixels out of the screen or image are clipped). 209 | * 210 | * @param x - left position of text 211 | * @param y - top position of text 212 | * @param text - the text to print 213 | * @param color - new color for the pixels 214 | */ 215 | extern void printTextScreen(int x, int y, const char* text, u32 color); 216 | 217 | /** 218 | * Print a text (pixels out of the screen or image are clipped). 219 | * 220 | * @param x - left position of text 221 | * @param y - top position of text 222 | * @param text - the text to print 223 | * @param color - new color for the pixels 224 | * @param image - image 225 | */ 226 | extern void printTextImage(int x, int y, const char* text, u32 color, Image* image); 227 | 228 | /** 229 | * Save an image or the screen in PNG format. 230 | * 231 | * @pre filename != NULL 232 | * @param filename - filename of the PNG image 233 | * @param data - start of Color type pixel data (can be getVramDisplayBuffer()) 234 | * @param width - logical width of the image or SCREEN_WIDTH 235 | * @param height - height of the image or SCREEN_HEIGHT 236 | * @param lineSize - physical width of the image or PSP_LINE_SIZE 237 | * @param saveAlpha - if 0, image is saved without alpha channel 238 | */ 239 | extern void saveImage(const char* filename, Color* data, int width, int height, int lineSize, int saveAlpha); 240 | 241 | /** 242 | * Exchange display buffer and drawing buffer. 243 | */ 244 | extern void flipScreen(); 245 | 246 | /** 247 | * Initialize the graphics. 248 | */ 249 | extern void initGraphics(); 250 | 251 | /** 252 | * Disable graphics, used for debug text output. 253 | */ 254 | extern void disableGraphics(); 255 | 256 | /** 257 | * Draw a line to screen. 258 | * 259 | * @pre x0 >= 0 && x0 < SCREEN_WIDTH && y0 >= 0 && y0 < SCREEN_HEIGHT && 260 | * x1 >= 0 && x1 < SCREEN_WIDTH && y1 >= 0 && y1 < SCREEN_HEIGHT 261 | * @param x0 - x line start position 262 | * @param y0 - y line start position 263 | * @param x1 - x line end position 264 | * @param y1 - y line end position 265 | */ 266 | void drawLineScreen(int x0, int y0, int x1, int y1, Color color); 267 | 268 | /** 269 | * Draw a line to screen. 270 | * 271 | * @pre x0 >= 0 && x0 < image->imageWidth && y0 >= 0 && y0 < image->imageHeight && 272 | * x1 >= 0 && x1 < image->imageWidth && y1 >= 0 && y1 < image->imageHeight 273 | * @param x0 - x line start position 274 | * @param y0 - y line start position 275 | * @param x1 - x line end position 276 | * @param y1 - y line end position 277 | */ 278 | extern void drawLineImage(int x0, int y0, int x1, int y1, Color color, Image* image); 279 | 280 | /** 281 | * Get the current draw buffer for fast unchecked access. 282 | * 283 | * @return the start address of the current draw buffer 284 | */ 285 | extern Color* getVramDrawBuffer(); 286 | 287 | /** 288 | * Get the current display buffer for fast unchecked access. 289 | * 290 | * @return the start address of the current display buffer 291 | */ 292 | extern Color* getVramDisplayBuffer(); 293 | 294 | extern void guStart(); 295 | 296 | #endif 297 | -------------------------------------------------------------------------------- /Tutorial12/graphics.h: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHICS_H 2 | #define GRAPHICS_H 3 | 4 | #include 5 | 6 | #define PSP_LINE_SIZE 512 7 | #define SCREEN_WIDTH 480 8 | #define SCREEN_HEIGHT 272 9 | 10 | typedef u32 Color; 11 | #define A(color) ((u8)(color >> 24 & 0xFF)) 12 | #define B(color) ((u8)(color >> 16 & 0xFF)) 13 | #define G(color) ((u8)(color >> 8 & 0xFF)) 14 | #define R(color) ((u8)(color & 0xFF)) 15 | 16 | typedef struct 17 | { 18 | int textureWidth; // the real width of data, 2^n with n>=0 19 | int textureHeight; // the real height of data, 2^n with n>=0 20 | int imageWidth; // the image width 21 | int imageHeight; 22 | Color* data; 23 | } Image; 24 | 25 | /** 26 | * Load a PNG image. 27 | * 28 | * @pre filename != NULL 29 | * @param filename - filename of the PNG image to load 30 | * @return pointer to a new allocated Image struct, or NULL on failure 31 | */ 32 | extern Image* loadImage(const char* filename); 33 | 34 | /** 35 | * Blit a rectangle part of an image to another image. 36 | * 37 | * @pre source != NULL && destination != NULL && 38 | * sx >= 0 && sy >= 0 && 39 | * width > 0 && height > 0 && 40 | * sx + width <= source->width && sy + height <= source->height && 41 | * dx + width <= destination->width && dy + height <= destination->height 42 | * @param sx - left position of rectangle in source image 43 | * @param sy - top position of rectangle in source image 44 | * @param width - width of rectangle in source image 45 | * @param height - height of rectangle in source image 46 | * @param source - pointer to Image struct of the source image 47 | * @param dx - left target position in destination image 48 | * @param dy - top target position in destination image 49 | * @param destination - pointer to Image struct of the destination image 50 | */ 51 | extern void blitImageToImage(int sx, int sy, int width, int height, Image* source, int dx, int dy, Image* destination); 52 | 53 | /** 54 | * Blit a rectangle part of an image to screen. 55 | * 56 | * @pre source != NULL && destination != NULL && 57 | * sx >= 0 && sy >= 0 && 58 | * width > 0 && height > 0 && 59 | * sx + width <= source->width && sy + height <= source->height && 60 | * dx + width <= SCREEN_WIDTH && dy + height <= SCREEN_HEIGHT 61 | * @param sx - left position of rectangle in source image 62 | * @param sy - top position of rectangle in source image 63 | * @param width - width of rectangle in source image 64 | * @param height - height of rectangle in source image 65 | * @param source - pointer to Image struct of the source image 66 | * @param dx - left target position in destination image 67 | * @param dy - top target position in destination image 68 | */ 69 | extern void blitImageToScreen(int sx, int sy, int width, int height, Image* source, int dx, int dy); 70 | 71 | /** 72 | * Blit a rectangle part of an image to another image without alpha pixels in source image. 73 | * 74 | * @pre source != NULL && destination != NULL && 75 | * sx >= 0 && sy >= 0 && 76 | * width > 0 && height > 0 && 77 | * sx + width <= source->width && sy + height <= source->height && 78 | * dx + width <= destination->width && dy + height <= destination->height 79 | * @param sx - left position of rectangle in source image 80 | * @param sy - top position of rectangle in source image 81 | * @param width - width of rectangle in source image 82 | * @param height - height of rectangle in source image 83 | * @param source - pointer to Image struct of the source image 84 | * @param dx - left target position in destination image 85 | * @param dy - top target position in destination image 86 | * @param destination - pointer to Image struct of the destination image 87 | */ 88 | extern void blitAlphaImageToImage(int sx, int sy, int width, int height, Image* source, int dx, int dy, Image* destination); 89 | 90 | /** 91 | * Blit a rectangle part of an image to screen without alpha pixels in source image. 92 | * 93 | * @pre source != NULL && destination != NULL && 94 | * sx >= 0 && sy >= 0 && 95 | * width > 0 && height > 0 && 96 | * sx + width <= source->width && sy + height <= source->height && 97 | * dx + width <= SCREEN_WIDTH && dy + height <= SCREEN_HEIGHT 98 | * @param sx - left position of rectangle in source image 99 | * @param sy - top position of rectangle in source image 100 | * @param width - width of rectangle in source image 101 | * @param height - height of rectangle in source image 102 | * @param source - pointer to Image struct of the source image 103 | * @param dx - left target position in destination image 104 | * @param dy - top target position in destination image 105 | */ 106 | extern void blitAlphaImageToScreen(int sx, int sy, int width, int height, Image* source, int dx, int dy); 107 | 108 | /** 109 | * Create an empty image. 110 | * 111 | * @pre width > 0 && height > 0 && width <= 512 && height <= 512 112 | * @param width - width of the new image 113 | * @param height - height of the new image 114 | * @return pointer to a new allocated Image struct, all pixels initialized to color 0, or NULL on failure 115 | */ 116 | extern Image* createImage(int width, int height); 117 | 118 | /** 119 | * Frees an allocated image. 120 | * 121 | * @pre image != null 122 | * @param image a pointer to an image struct 123 | */ 124 | extern void freeImage(Image* image); 125 | 126 | /** 127 | * Initialize all pixels of an image with a color. 128 | * 129 | * @pre image != NULL 130 | * @param color - new color for the pixels 131 | * @param image - image to clear 132 | */ 133 | extern void clearImage(Color color, Image* image); 134 | 135 | /** 136 | * Initialize all pixels of the screen with a color. 137 | * 138 | * @param color - new color for the pixels 139 | */ 140 | extern void clearScreen(Color color); 141 | 142 | /** 143 | * Fill a rectangle of an image with a color. 144 | * 145 | * @pre image != NULL 146 | * @param color - new color for the pixels 147 | * @param x0 - left position of rectangle in image 148 | * @param y0 - top position of rectangle in image 149 | * @param width - width of rectangle in image 150 | * @param height - height of rectangle in image 151 | * @param image - image 152 | */ 153 | extern void fillImageRect(Color color, int x0, int y0, int width, int height, Image* image); 154 | 155 | /** 156 | * Fill a rectangle of an image with a color. 157 | * 158 | * @pre image != NULL 159 | * @param color - new color for the pixels 160 | * @param x0 - left position of rectangle in image 161 | * @param y0 - top position of rectangle in image 162 | * @param width - width of rectangle in image 163 | * @param height - height of rectangle in image 164 | */ 165 | extern void fillScreenRect(Color color, int x0, int y0, int width, int height); 166 | 167 | /** 168 | * Set a pixel on screen to the specified color. 169 | * 170 | * @pre x >= 0 && x < SCREEN_WIDTH && y >= 0 && y < SCREEN_HEIGHT 171 | * @param color - new color for the pixels 172 | * @param x - left position of the pixel 173 | * @param y - top position of the pixel 174 | */ 175 | extern void putPixelScreen(Color color, int x, int y); 176 | 177 | /** 178 | * Set a pixel in an image to the specified color. 179 | * 180 | * @pre x >= 0 && x < image->imageWidth && y >= 0 && y < image->imageHeight && image != NULL 181 | * @param color - new color for the pixels 182 | * @param x - left position of the pixel 183 | * @param y - top position of the pixel 184 | */ 185 | extern void putPixelImage(Color color, int x, int y, Image* image); 186 | 187 | /** 188 | * Get the color of a pixel on screen. 189 | * 190 | * @pre x >= 0 && x < SCREEN_WIDTH && y >= 0 && y < SCREEN_HEIGHT 191 | * @param x - left position of the pixel 192 | * @param y - top position of the pixel 193 | * @return the color of the pixel 194 | */ 195 | extern Color getPixelScreen(int x, int y); 196 | 197 | /** 198 | * Get the color of a pixel of an image. 199 | * 200 | * @pre x >= 0 && x < image->imageWidth && y >= 0 && y < image->imageHeight && image != NULL 201 | * @param x - left position of the pixel 202 | * @param y - top position of the pixel 203 | * @return the color of the pixel 204 | */ 205 | extern Color getPixelImage(int x, int y, Image* image); 206 | 207 | /** 208 | * Print a text (pixels out of the screen or image are clipped). 209 | * 210 | * @param x - left position of text 211 | * @param y - top position of text 212 | * @param text - the text to print 213 | * @param color - new color for the pixels 214 | */ 215 | extern void printTextScreen(int x, int y, const char* text, u32 color); 216 | 217 | /** 218 | * Print a text (pixels out of the screen or image are clipped). 219 | * 220 | * @param x - left position of text 221 | * @param y - top position of text 222 | * @param text - the text to print 223 | * @param color - new color for the pixels 224 | * @param image - image 225 | */ 226 | extern void printTextImage(int x, int y, const char* text, u32 color, Image* image); 227 | 228 | /** 229 | * Save an image or the screen in PNG format. 230 | * 231 | * @pre filename != NULL 232 | * @param filename - filename of the PNG image 233 | * @param data - start of Color type pixel data (can be getVramDisplayBuffer()) 234 | * @param width - logical width of the image or SCREEN_WIDTH 235 | * @param height - height of the image or SCREEN_HEIGHT 236 | * @param lineSize - physical width of the image or PSP_LINE_SIZE 237 | * @param saveAlpha - if 0, image is saved without alpha channel 238 | */ 239 | extern void saveImage(const char* filename, Color* data, int width, int height, int lineSize, int saveAlpha); 240 | 241 | /** 242 | * Exchange display buffer and drawing buffer. 243 | */ 244 | extern void flipScreen(); 245 | 246 | /** 247 | * Initialize the graphics. 248 | */ 249 | extern void initGraphics(); 250 | 251 | /** 252 | * Disable graphics, used for debug text output. 253 | */ 254 | extern void disableGraphics(); 255 | 256 | /** 257 | * Draw a line to screen. 258 | * 259 | * @pre x0 >= 0 && x0 < SCREEN_WIDTH && y0 >= 0 && y0 < SCREEN_HEIGHT && 260 | * x1 >= 0 && x1 < SCREEN_WIDTH && y1 >= 0 && y1 < SCREEN_HEIGHT 261 | * @param x0 - x line start position 262 | * @param y0 - y line start position 263 | * @param x1 - x line end position 264 | * @param y1 - y line end position 265 | */ 266 | void drawLineScreen(int x0, int y0, int x1, int y1, Color color); 267 | 268 | /** 269 | * Draw a line to screen. 270 | * 271 | * @pre x0 >= 0 && x0 < image->imageWidth && y0 >= 0 && y0 < image->imageHeight && 272 | * x1 >= 0 && x1 < image->imageWidth && y1 >= 0 && y1 < image->imageHeight 273 | * @param x0 - x line start position 274 | * @param y0 - y line start position 275 | * @param x1 - x line end position 276 | * @param y1 - y line end position 277 | */ 278 | extern void drawLineImage(int x0, int y0, int x1, int y1, Color color, Image* image); 279 | 280 | /** 281 | * Get the current draw buffer for fast unchecked access. 282 | * 283 | * @return the start address of the current draw buffer 284 | */ 285 | extern Color* getVramDrawBuffer(); 286 | 287 | /** 288 | * Get the current display buffer for fast unchecked access. 289 | * 290 | * @return the start address of the current display buffer 291 | */ 292 | extern Color* getVramDisplayBuffer(); 293 | 294 | extern void guStart(); 295 | 296 | #endif 297 | -------------------------------------------------------------------------------- /Tutorial17/graphics.h: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHICS_H 2 | #define GRAPHICS_H 3 | 4 | #include 5 | 6 | #define PSP_LINE_SIZE 512 7 | #define SCREEN_WIDTH 480 8 | #define SCREEN_HEIGHT 272 9 | 10 | typedef u32 Color; 11 | #define A(color) ((u8)(color >> 24 & 0xFF)) 12 | #define B(color) ((u8)(color >> 16 & 0xFF)) 13 | #define G(color) ((u8)(color >> 8 & 0xFF)) 14 | #define R(color) ((u8)(color & 0xFF)) 15 | 16 | typedef struct 17 | { 18 | int textureWidth; // the real width of data, 2^n with n>=0 19 | int textureHeight; // the real height of data, 2^n with n>=0 20 | int imageWidth; // the image width 21 | int imageHeight; 22 | Color* data; 23 | } Image; 24 | 25 | /** 26 | * Load a PNG image. 27 | * 28 | * @pre filename != NULL 29 | * @param filename - filename of the PNG image to load 30 | * @return pointer to a new allocated Image struct, or NULL on failure 31 | */ 32 | extern Image* loadImage(const char* filename); 33 | 34 | /** 35 | * Blit a rectangle part of an image to another image. 36 | * 37 | * @pre source != NULL && destination != NULL && 38 | * sx >= 0 && sy >= 0 && 39 | * width > 0 && height > 0 && 40 | * sx + width <= source->width && sy + height <= source->height && 41 | * dx + width <= destination->width && dy + height <= destination->height 42 | * @param sx - left position of rectangle in source image 43 | * @param sy - top position of rectangle in source image 44 | * @param width - width of rectangle in source image 45 | * @param height - height of rectangle in source image 46 | * @param source - pointer to Image struct of the source image 47 | * @param dx - left target position in destination image 48 | * @param dy - top target position in destination image 49 | * @param destination - pointer to Image struct of the destination image 50 | */ 51 | extern void blitImageToImage(int sx, int sy, int width, int height, Image* source, int dx, int dy, Image* destination); 52 | 53 | /** 54 | * Blit a rectangle part of an image to screen. 55 | * 56 | * @pre source != NULL && destination != NULL && 57 | * sx >= 0 && sy >= 0 && 58 | * width > 0 && height > 0 && 59 | * sx + width <= source->width && sy + height <= source->height && 60 | * dx + width <= SCREEN_WIDTH && dy + height <= SCREEN_HEIGHT 61 | * @param sx - left position of rectangle in source image 62 | * @param sy - top position of rectangle in source image 63 | * @param width - width of rectangle in source image 64 | * @param height - height of rectangle in source image 65 | * @param source - pointer to Image struct of the source image 66 | * @param dx - left target position in destination image 67 | * @param dy - top target position in destination image 68 | */ 69 | extern void blitImageToScreen(int sx, int sy, int width, int height, Image* source, int dx, int dy); 70 | 71 | /** 72 | * Blit a rectangle part of an image to another image without alpha pixels in source image. 73 | * 74 | * @pre source != NULL && destination != NULL && 75 | * sx >= 0 && sy >= 0 && 76 | * width > 0 && height > 0 && 77 | * sx + width <= source->width && sy + height <= source->height && 78 | * dx + width <= destination->width && dy + height <= destination->height 79 | * @param sx - left position of rectangle in source image 80 | * @param sy - top position of rectangle in source image 81 | * @param width - width of rectangle in source image 82 | * @param height - height of rectangle in source image 83 | * @param source - pointer to Image struct of the source image 84 | * @param dx - left target position in destination image 85 | * @param dy - top target position in destination image 86 | * @param destination - pointer to Image struct of the destination image 87 | */ 88 | extern void blitAlphaImageToImage(int sx, int sy, int width, int height, Image* source, int dx, int dy, Image* destination); 89 | 90 | /** 91 | * Blit a rectangle part of an image to screen without alpha pixels in source image. 92 | * 93 | * @pre source != NULL && destination != NULL && 94 | * sx >= 0 && sy >= 0 && 95 | * width > 0 && height > 0 && 96 | * sx + width <= source->width && sy + height <= source->height && 97 | * dx + width <= SCREEN_WIDTH && dy + height <= SCREEN_HEIGHT 98 | * @param sx - left position of rectangle in source image 99 | * @param sy - top position of rectangle in source image 100 | * @param width - width of rectangle in source image 101 | * @param height - height of rectangle in source image 102 | * @param source - pointer to Image struct of the source image 103 | * @param dx - left target position in destination image 104 | * @param dy - top target position in destination image 105 | */ 106 | extern void blitAlphaImageToScreen(int sx, int sy, int width, int height, Image* source, int dx, int dy); 107 | 108 | /** 109 | * Create an empty image. 110 | * 111 | * @pre width > 0 && height > 0 && width <= 512 && height <= 512 112 | * @param width - width of the new image 113 | * @param height - height of the new image 114 | * @return pointer to a new allocated Image struct, all pixels initialized to color 0, or NULL on failure 115 | */ 116 | extern Image* createImage(int width, int height); 117 | 118 | /** 119 | * Frees an allocated image. 120 | * 121 | * @pre image != null 122 | * @param image a pointer to an image struct 123 | */ 124 | extern void freeImage(Image* image); 125 | 126 | /** 127 | * Initialize all pixels of an image with a color. 128 | * 129 | * @pre image != NULL 130 | * @param color - new color for the pixels 131 | * @param image - image to clear 132 | */ 133 | extern void clearImage(Color color, Image* image); 134 | 135 | /** 136 | * Initialize all pixels of the screen with a color. 137 | * 138 | * @param color - new color for the pixels 139 | */ 140 | extern void clearScreen(Color color); 141 | 142 | /** 143 | * Fill a rectangle of an image with a color. 144 | * 145 | * @pre image != NULL 146 | * @param color - new color for the pixels 147 | * @param x0 - left position of rectangle in image 148 | * @param y0 - top position of rectangle in image 149 | * @param width - width of rectangle in image 150 | * @param height - height of rectangle in image 151 | * @param image - image 152 | */ 153 | extern void fillImageRect(Color color, int x0, int y0, int width, int height, Image* image); 154 | 155 | /** 156 | * Fill a rectangle of an image with a color. 157 | * 158 | * @pre image != NULL 159 | * @param color - new color for the pixels 160 | * @param x0 - left position of rectangle in image 161 | * @param y0 - top position of rectangle in image 162 | * @param width - width of rectangle in image 163 | * @param height - height of rectangle in image 164 | */ 165 | extern void fillScreenRect(Color color, int x0, int y0, int width, int height); 166 | 167 | /** 168 | * Set a pixel on screen to the specified color. 169 | * 170 | * @pre x >= 0 && x < SCREEN_WIDTH && y >= 0 && y < SCREEN_HEIGHT 171 | * @param color - new color for the pixels 172 | * @param x - left position of the pixel 173 | * @param y - top position of the pixel 174 | */ 175 | extern void putPixelScreen(Color color, int x, int y); 176 | 177 | /** 178 | * Set a pixel in an image to the specified color. 179 | * 180 | * @pre x >= 0 && x < image->imageWidth && y >= 0 && y < image->imageHeight && image != NULL 181 | * @param color - new color for the pixels 182 | * @param x - left position of the pixel 183 | * @param y - top position of the pixel 184 | */ 185 | extern void putPixelImage(Color color, int x, int y, Image* image); 186 | 187 | /** 188 | * Get the color of a pixel on screen. 189 | * 190 | * @pre x >= 0 && x < SCREEN_WIDTH && y >= 0 && y < SCREEN_HEIGHT 191 | * @param x - left position of the pixel 192 | * @param y - top position of the pixel 193 | * @return the color of the pixel 194 | */ 195 | extern Color getPixelScreen(int x, int y); 196 | 197 | /** 198 | * Get the color of a pixel of an image. 199 | * 200 | * @pre x >= 0 && x < image->imageWidth && y >= 0 && y < image->imageHeight && image != NULL 201 | * @param x - left position of the pixel 202 | * @param y - top position of the pixel 203 | * @return the color of the pixel 204 | */ 205 | extern Color getPixelImage(int x, int y, Image* image); 206 | 207 | /** 208 | * Print a text (pixels out of the screen or image are clipped). 209 | * 210 | * @param x - left position of text 211 | * @param y - top position of text 212 | * @param text - the text to print 213 | * @param color - new color for the pixels 214 | */ 215 | extern void printTextScreen(int x, int y, const char* text, u32 color); 216 | 217 | /** 218 | * Print a text (pixels out of the screen or image are clipped). 219 | * 220 | * @param x - left position of text 221 | * @param y - top position of text 222 | * @param text - the text to print 223 | * @param color - new color for the pixels 224 | * @param image - image 225 | */ 226 | extern void printTextImage(int x, int y, const char* text, u32 color, Image* image); 227 | 228 | /** 229 | * Save an image or the screen in PNG format. 230 | * 231 | * @pre filename != NULL 232 | * @param filename - filename of the PNG image 233 | * @param data - start of Color type pixel data (can be getVramDisplayBuffer()) 234 | * @param width - logical width of the image or SCREEN_WIDTH 235 | * @param height - height of the image or SCREEN_HEIGHT 236 | * @param lineSize - physical width of the image or PSP_LINE_SIZE 237 | * @param saveAlpha - if 0, image is saved without alpha channel 238 | */ 239 | extern void saveImage(const char* filename, Color* data, int width, int height, int lineSize, int saveAlpha); 240 | 241 | /** 242 | * Exchange display buffer and drawing buffer. 243 | */ 244 | extern void flipScreen(); 245 | 246 | /** 247 | * Initialize the graphics. 248 | */ 249 | extern void initGraphics(); 250 | 251 | /** 252 | * Disable graphics, used for debug text output. 253 | */ 254 | extern void disableGraphics(); 255 | 256 | /** 257 | * Draw a line to screen. 258 | * 259 | * @pre x0 >= 0 && x0 < SCREEN_WIDTH && y0 >= 0 && y0 < SCREEN_HEIGHT && 260 | * x1 >= 0 && x1 < SCREEN_WIDTH && y1 >= 0 && y1 < SCREEN_HEIGHT 261 | * @param x0 - x line start position 262 | * @param y0 - y line start position 263 | * @param x1 - x line end position 264 | * @param y1 - y line end position 265 | */ 266 | void drawLineScreen(int x0, int y0, int x1, int y1, Color color); 267 | 268 | /** 269 | * Draw a line to screen. 270 | * 271 | * @pre x0 >= 0 && x0 < image->imageWidth && y0 >= 0 && y0 < image->imageHeight && 272 | * x1 >= 0 && x1 < image->imageWidth && y1 >= 0 && y1 < image->imageHeight 273 | * @param x0 - x line start position 274 | * @param y0 - y line start position 275 | * @param x1 - x line end position 276 | * @param y1 - y line end position 277 | */ 278 | extern void drawLineImage(int x0, int y0, int x1, int y1, Color color, Image* image); 279 | 280 | /** 281 | * Get the current draw buffer for fast unchecked access. 282 | * 283 | * @return the start address of the current draw buffer 284 | */ 285 | extern Color* getVramDrawBuffer(); 286 | 287 | /** 288 | * Get the current display buffer for fast unchecked access. 289 | * 290 | * @return the start address of the current display buffer 291 | */ 292 | extern Color* getVramDisplayBuffer(); 293 | 294 | extern void guStart(); 295 | 296 | #endif 297 | -------------------------------------------------------------------------------- /Tutorial4a/graphics.h: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHICS_H 2 | #define GRAPHICS_H 3 | 4 | #include 5 | 6 | #define PSP_LINE_SIZE 512 7 | #define SCREEN_WIDTH 480 8 | #define SCREEN_HEIGHT 272 9 | 10 | typedef u32 Color; 11 | #define A(color) ((u8)(color >> 24 & 0xFF)) 12 | #define B(color) ((u8)(color >> 16 & 0xFF)) 13 | #define G(color) ((u8)(color >> 8 & 0xFF)) 14 | #define R(color) ((u8)(color & 0xFF)) 15 | 16 | typedef struct 17 | { 18 | int textureWidth; // the real width of data, 2^n with n>=0 19 | int textureHeight; // the real height of data, 2^n with n>=0 20 | int imageWidth; // the image width 21 | int imageHeight; 22 | Color* data; 23 | } Image; 24 | 25 | /** 26 | * Load a PNG image. 27 | * 28 | * @pre filename != NULL 29 | * @param filename - filename of the PNG image to load 30 | * @return pointer to a new allocated Image struct, or NULL on failure 31 | */ 32 | extern Image* loadImage(const char* filename); 33 | 34 | /** 35 | * Blit a rectangle part of an image to another image. 36 | * 37 | * @pre source != NULL && destination != NULL && 38 | * sx >= 0 && sy >= 0 && 39 | * width > 0 && height > 0 && 40 | * sx + width <= source->width && sy + height <= source->height && 41 | * dx + width <= destination->width && dy + height <= destination->height 42 | * @param sx - left position of rectangle in source image 43 | * @param sy - top position of rectangle in source image 44 | * @param width - width of rectangle in source image 45 | * @param height - height of rectangle in source image 46 | * @param source - pointer to Image struct of the source image 47 | * @param dx - left target position in destination image 48 | * @param dy - top target position in destination image 49 | * @param destination - pointer to Image struct of the destination image 50 | */ 51 | extern void blitImageToImage(int sx, int sy, int width, int height, Image* source, int dx, int dy, Image* destination); 52 | 53 | /** 54 | * Blit a rectangle part of an image to screen. 55 | * 56 | * @pre source != NULL && destination != NULL && 57 | * sx >= 0 && sy >= 0 && 58 | * width > 0 && height > 0 && 59 | * sx + width <= source->width && sy + height <= source->height && 60 | * dx + width <= SCREEN_WIDTH && dy + height <= SCREEN_HEIGHT 61 | * @param sx - left position of rectangle in source image 62 | * @param sy - top position of rectangle in source image 63 | * @param width - width of rectangle in source image 64 | * @param height - height of rectangle in source image 65 | * @param source - pointer to Image struct of the source image 66 | * @param dx - left target position in destination image 67 | * @param dy - top target position in destination image 68 | */ 69 | extern void blitImageToScreen(int sx, int sy, int width, int height, Image* source, int dx, int dy); 70 | 71 | /** 72 | * Blit a rectangle part of an image to another image without alpha pixels in source image. 73 | * 74 | * @pre source != NULL && destination != NULL && 75 | * sx >= 0 && sy >= 0 && 76 | * width > 0 && height > 0 && 77 | * sx + width <= source->width && sy + height <= source->height && 78 | * dx + width <= destination->width && dy + height <= destination->height 79 | * @param sx - left position of rectangle in source image 80 | * @param sy - top position of rectangle in source image 81 | * @param width - width of rectangle in source image 82 | * @param height - height of rectangle in source image 83 | * @param source - pointer to Image struct of the source image 84 | * @param dx - left target position in destination image 85 | * @param dy - top target position in destination image 86 | * @param destination - pointer to Image struct of the destination image 87 | */ 88 | extern void blitAlphaImageToImage(int sx, int sy, int width, int height, Image* source, int dx, int dy, Image* destination); 89 | 90 | /** 91 | * Blit a rectangle part of an image to screen without alpha pixels in source image. 92 | * 93 | * @pre source != NULL && destination != NULL && 94 | * sx >= 0 && sy >= 0 && 95 | * width > 0 && height > 0 && 96 | * sx + width <= source->width && sy + height <= source->height && 97 | * dx + width <= SCREEN_WIDTH && dy + height <= SCREEN_HEIGHT 98 | * @param sx - left position of rectangle in source image 99 | * @param sy - top position of rectangle in source image 100 | * @param width - width of rectangle in source image 101 | * @param height - height of rectangle in source image 102 | * @param source - pointer to Image struct of the source image 103 | * @param dx - left target position in destination image 104 | * @param dy - top target position in destination image 105 | */ 106 | extern void blitAlphaImageToScreen(int sx, int sy, int width, int height, Image* source, int dx, int dy); 107 | 108 | /** 109 | * Create an empty image. 110 | * 111 | * @pre width > 0 && height > 0 && width <= 512 && height <= 512 112 | * @param width - width of the new image 113 | * @param height - height of the new image 114 | * @return pointer to a new allocated Image struct, all pixels initialized to color 0, or NULL on failure 115 | */ 116 | extern Image* createImage(int width, int height); 117 | 118 | /** 119 | * Frees an allocated image. 120 | * 121 | * @pre image != null 122 | * @param image a pointer to an image struct 123 | */ 124 | extern void freeImage(Image* image); 125 | 126 | /** 127 | * Initialize all pixels of an image with a color. 128 | * 129 | * @pre image != NULL 130 | * @param color - new color for the pixels 131 | * @param image - image to clear 132 | */ 133 | extern void clearImage(Color color, Image* image); 134 | 135 | /** 136 | * Initialize all pixels of the screen with a color. 137 | * 138 | * @param color - new color for the pixels 139 | */ 140 | extern void clearScreen(Color color); 141 | 142 | /** 143 | * Fill a rectangle of an image with a color. 144 | * 145 | * @pre image != NULL 146 | * @param color - new color for the pixels 147 | * @param x0 - left position of rectangle in image 148 | * @param y0 - top position of rectangle in image 149 | * @param width - width of rectangle in image 150 | * @param height - height of rectangle in image 151 | * @param image - image 152 | */ 153 | extern void fillImageRect(Color color, int x0, int y0, int width, int height, Image* image); 154 | 155 | /** 156 | * Fill a rectangle of an image with a color. 157 | * 158 | * @pre image != NULL 159 | * @param color - new color for the pixels 160 | * @param x0 - left position of rectangle in image 161 | * @param y0 - top position of rectangle in image 162 | * @param width - width of rectangle in image 163 | * @param height - height of rectangle in image 164 | */ 165 | extern void fillScreenRect(Color color, int x0, int y0, int width, int height); 166 | 167 | /** 168 | * Set a pixel on screen to the specified color. 169 | * 170 | * @pre x >= 0 && x < SCREEN_WIDTH && y >= 0 && y < SCREEN_HEIGHT 171 | * @param color - new color for the pixels 172 | * @param x - left position of the pixel 173 | * @param y - top position of the pixel 174 | */ 175 | extern void putPixelScreen(Color color, int x, int y); 176 | 177 | /** 178 | * Set a pixel in an image to the specified color. 179 | * 180 | * @pre x >= 0 && x < image->imageWidth && y >= 0 && y < image->imageHeight && image != NULL 181 | * @param color - new color for the pixels 182 | * @param x - left position of the pixel 183 | * @param y - top position of the pixel 184 | */ 185 | extern void putPixelImage(Color color, int x, int y, Image* image); 186 | 187 | /** 188 | * Get the color of a pixel on screen. 189 | * 190 | * @pre x >= 0 && x < SCREEN_WIDTH && y >= 0 && y < SCREEN_HEIGHT 191 | * @param x - left position of the pixel 192 | * @param y - top position of the pixel 193 | * @return the color of the pixel 194 | */ 195 | extern Color getPixelScreen(int x, int y); 196 | 197 | /** 198 | * Get the color of a pixel of an image. 199 | * 200 | * @pre x >= 0 && x < image->imageWidth && y >= 0 && y < image->imageHeight && image != NULL 201 | * @param x - left position of the pixel 202 | * @param y - top position of the pixel 203 | * @return the color of the pixel 204 | */ 205 | extern Color getPixelImage(int x, int y, Image* image); 206 | 207 | /** 208 | * Print a text (pixels out of the screen or image are clipped). 209 | * 210 | * @param x - left position of text 211 | * @param y - top position of text 212 | * @param text - the text to print 213 | * @param color - new color for the pixels 214 | */ 215 | extern void printTextScreen(int x, int y, const char* text, u32 color); 216 | 217 | /** 218 | * Print a text (pixels out of the screen or image are clipped). 219 | * 220 | * @param x - left position of text 221 | * @param y - top position of text 222 | * @param text - the text to print 223 | * @param color - new color for the pixels 224 | * @param image - image 225 | */ 226 | extern void printTextImage(int x, int y, const char* text, u32 color, Image* image); 227 | 228 | /** 229 | * Save an image or the screen in PNG format. 230 | * 231 | * @pre filename != NULL 232 | * @param filename - filename of the PNG image 233 | * @param data - start of Color type pixel data (can be getVramDisplayBuffer()) 234 | * @param width - logical width of the image or SCREEN_WIDTH 235 | * @param height - height of the image or SCREEN_HEIGHT 236 | * @param lineSize - physical width of the image or PSP_LINE_SIZE 237 | * @param saveAlpha - if 0, image is saved without alpha channel 238 | */ 239 | extern void saveImage(const char* filename, Color* data, int width, int height, int lineSize, int saveAlpha); 240 | 241 | /** 242 | * Exchange display buffer and drawing buffer. 243 | */ 244 | extern void flipScreen(); 245 | 246 | /** 247 | * Initialize the graphics. 248 | */ 249 | extern void initGraphics(); 250 | 251 | /** 252 | * Disable graphics, used for debug text output. 253 | */ 254 | extern void disableGraphics(); 255 | 256 | /** 257 | * Draw a line to screen. 258 | * 259 | * @pre x0 >= 0 && x0 < SCREEN_WIDTH && y0 >= 0 && y0 < SCREEN_HEIGHT && 260 | * x1 >= 0 && x1 < SCREEN_WIDTH && y1 >= 0 && y1 < SCREEN_HEIGHT 261 | * @param x0 - x line start position 262 | * @param y0 - y line start position 263 | * @param x1 - x line end position 264 | * @param y1 - y line end position 265 | */ 266 | void drawLineScreen(int x0, int y0, int x1, int y1, Color color); 267 | 268 | /** 269 | * Draw a line to screen. 270 | * 271 | * @pre x0 >= 0 && x0 < image->imageWidth && y0 >= 0 && y0 < image->imageHeight && 272 | * x1 >= 0 && x1 < image->imageWidth && y1 >= 0 && y1 < image->imageHeight 273 | * @param x0 - x line start position 274 | * @param y0 - y line start position 275 | * @param x1 - x line end position 276 | * @param y1 - y line end position 277 | */ 278 | extern void drawLineImage(int x0, int y0, int x1, int y1, Color color, Image* image); 279 | 280 | /** 281 | * Get the current draw buffer for fast unchecked access. 282 | * 283 | * @return the start address of the current draw buffer 284 | */ 285 | extern Color* getVramDrawBuffer(); 286 | 287 | /** 288 | * Get the current display buffer for fast unchecked access. 289 | * 290 | * @return the start address of the current display buffer 291 | */ 292 | extern Color* getVramDisplayBuffer(); 293 | 294 | extern void guStart(); 295 | 296 | #endif 297 | -------------------------------------------------------------------------------- /Tutorial5/graphics.h: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHICS_H 2 | #define GRAPHICS_H 3 | 4 | #include 5 | 6 | #define PSP_LINE_SIZE 512 7 | #define SCREEN_WIDTH 480 8 | #define SCREEN_HEIGHT 272 9 | 10 | typedef u32 Color; 11 | #define A(color) ((u8)(color >> 24 & 0xFF)) 12 | #define B(color) ((u8)(color >> 16 & 0xFF)) 13 | #define G(color) ((u8)(color >> 8 & 0xFF)) 14 | #define R(color) ((u8)(color & 0xFF)) 15 | 16 | typedef struct 17 | { 18 | int textureWidth; // the real width of data, 2^n with n>=0 19 | int textureHeight; // the real height of data, 2^n with n>=0 20 | int imageWidth; // the image width 21 | int imageHeight; 22 | Color* data; 23 | } Image; 24 | 25 | /** 26 | * Load a PNG image. 27 | * 28 | * @pre filename != NULL 29 | * @param filename - filename of the PNG image to load 30 | * @return pointer to a new allocated Image struct, or NULL on failure 31 | */ 32 | extern Image* loadImage(const char* filename); 33 | 34 | /** 35 | * Blit a rectangle part of an image to another image. 36 | * 37 | * @pre source != NULL && destination != NULL && 38 | * sx >= 0 && sy >= 0 && 39 | * width > 0 && height > 0 && 40 | * sx + width <= source->width && sy + height <= source->height && 41 | * dx + width <= destination->width && dy + height <= destination->height 42 | * @param sx - left position of rectangle in source image 43 | * @param sy - top position of rectangle in source image 44 | * @param width - width of rectangle in source image 45 | * @param height - height of rectangle in source image 46 | * @param source - pointer to Image struct of the source image 47 | * @param dx - left target position in destination image 48 | * @param dy - top target position in destination image 49 | * @param destination - pointer to Image struct of the destination image 50 | */ 51 | extern void blitImageToImage(int sx, int sy, int width, int height, Image* source, int dx, int dy, Image* destination); 52 | 53 | /** 54 | * Blit a rectangle part of an image to screen. 55 | * 56 | * @pre source != NULL && destination != NULL && 57 | * sx >= 0 && sy >= 0 && 58 | * width > 0 && height > 0 && 59 | * sx + width <= source->width && sy + height <= source->height && 60 | * dx + width <= SCREEN_WIDTH && dy + height <= SCREEN_HEIGHT 61 | * @param sx - left position of rectangle in source image 62 | * @param sy - top position of rectangle in source image 63 | * @param width - width of rectangle in source image 64 | * @param height - height of rectangle in source image 65 | * @param source - pointer to Image struct of the source image 66 | * @param dx - left target position in destination image 67 | * @param dy - top target position in destination image 68 | */ 69 | extern void blitImageToScreen(int sx, int sy, int width, int height, Image* source, int dx, int dy); 70 | 71 | /** 72 | * Blit a rectangle part of an image to another image without alpha pixels in source image. 73 | * 74 | * @pre source != NULL && destination != NULL && 75 | * sx >= 0 && sy >= 0 && 76 | * width > 0 && height > 0 && 77 | * sx + width <= source->width && sy + height <= source->height && 78 | * dx + width <= destination->width && dy + height <= destination->height 79 | * @param sx - left position of rectangle in source image 80 | * @param sy - top position of rectangle in source image 81 | * @param width - width of rectangle in source image 82 | * @param height - height of rectangle in source image 83 | * @param source - pointer to Image struct of the source image 84 | * @param dx - left target position in destination image 85 | * @param dy - top target position in destination image 86 | * @param destination - pointer to Image struct of the destination image 87 | */ 88 | extern void blitAlphaImageToImage(int sx, int sy, int width, int height, Image* source, int dx, int dy, Image* destination); 89 | 90 | /** 91 | * Blit a rectangle part of an image to screen without alpha pixels in source image. 92 | * 93 | * @pre source != NULL && destination != NULL && 94 | * sx >= 0 && sy >= 0 && 95 | * width > 0 && height > 0 && 96 | * sx + width <= source->width && sy + height <= source->height && 97 | * dx + width <= SCREEN_WIDTH && dy + height <= SCREEN_HEIGHT 98 | * @param sx - left position of rectangle in source image 99 | * @param sy - top position of rectangle in source image 100 | * @param width - width of rectangle in source image 101 | * @param height - height of rectangle in source image 102 | * @param source - pointer to Image struct of the source image 103 | * @param dx - left target position in destination image 104 | * @param dy - top target position in destination image 105 | */ 106 | extern void blitAlphaImageToScreen(int sx, int sy, int width, int height, Image* source, int dx, int dy); 107 | 108 | /** 109 | * Create an empty image. 110 | * 111 | * @pre width > 0 && height > 0 && width <= 512 && height <= 512 112 | * @param width - width of the new image 113 | * @param height - height of the new image 114 | * @return pointer to a new allocated Image struct, all pixels initialized to color 0, or NULL on failure 115 | */ 116 | extern Image* createImage(int width, int height); 117 | 118 | /** 119 | * Frees an allocated image. 120 | * 121 | * @pre image != null 122 | * @param image a pointer to an image struct 123 | */ 124 | extern void freeImage(Image* image); 125 | 126 | /** 127 | * Initialize all pixels of an image with a color. 128 | * 129 | * @pre image != NULL 130 | * @param color - new color for the pixels 131 | * @param image - image to clear 132 | */ 133 | extern void clearImage(Color color, Image* image); 134 | 135 | /** 136 | * Initialize all pixels of the screen with a color. 137 | * 138 | * @param color - new color for the pixels 139 | */ 140 | extern void clearScreen(Color color); 141 | 142 | /** 143 | * Fill a rectangle of an image with a color. 144 | * 145 | * @pre image != NULL 146 | * @param color - new color for the pixels 147 | * @param x0 - left position of rectangle in image 148 | * @param y0 - top position of rectangle in image 149 | * @param width - width of rectangle in image 150 | * @param height - height of rectangle in image 151 | * @param image - image 152 | */ 153 | extern void fillImageRect(Color color, int x0, int y0, int width, int height, Image* image); 154 | 155 | /** 156 | * Fill a rectangle of an image with a color. 157 | * 158 | * @pre image != NULL 159 | * @param color - new color for the pixels 160 | * @param x0 - left position of rectangle in image 161 | * @param y0 - top position of rectangle in image 162 | * @param width - width of rectangle in image 163 | * @param height - height of rectangle in image 164 | */ 165 | extern void fillScreenRect(Color color, int x0, int y0, int width, int height); 166 | 167 | /** 168 | * Set a pixel on screen to the specified color. 169 | * 170 | * @pre x >= 0 && x < SCREEN_WIDTH && y >= 0 && y < SCREEN_HEIGHT 171 | * @param color - new color for the pixels 172 | * @param x - left position of the pixel 173 | * @param y - top position of the pixel 174 | */ 175 | extern void putPixelScreen(Color color, int x, int y); 176 | 177 | /** 178 | * Set a pixel in an image to the specified color. 179 | * 180 | * @pre x >= 0 && x < image->imageWidth && y >= 0 && y < image->imageHeight && image != NULL 181 | * @param color - new color for the pixels 182 | * @param x - left position of the pixel 183 | * @param y - top position of the pixel 184 | */ 185 | extern void putPixelImage(Color color, int x, int y, Image* image); 186 | 187 | /** 188 | * Get the color of a pixel on screen. 189 | * 190 | * @pre x >= 0 && x < SCREEN_WIDTH && y >= 0 && y < SCREEN_HEIGHT 191 | * @param x - left position of the pixel 192 | * @param y - top position of the pixel 193 | * @return the color of the pixel 194 | */ 195 | extern Color getPixelScreen(int x, int y); 196 | 197 | /** 198 | * Get the color of a pixel of an image. 199 | * 200 | * @pre x >= 0 && x < image->imageWidth && y >= 0 && y < image->imageHeight && image != NULL 201 | * @param x - left position of the pixel 202 | * @param y - top position of the pixel 203 | * @return the color of the pixel 204 | */ 205 | extern Color getPixelImage(int x, int y, Image* image); 206 | 207 | /** 208 | * Print a text (pixels out of the screen or image are clipped). 209 | * 210 | * @param x - left position of text 211 | * @param y - top position of text 212 | * @param text - the text to print 213 | * @param color - new color for the pixels 214 | */ 215 | extern void printTextScreen(int x, int y, const char* text, u32 color); 216 | 217 | /** 218 | * Print a text (pixels out of the screen or image are clipped). 219 | * 220 | * @param x - left position of text 221 | * @param y - top position of text 222 | * @param text - the text to print 223 | * @param color - new color for the pixels 224 | * @param image - image 225 | */ 226 | extern void printTextImage(int x, int y, const char* text, u32 color, Image* image); 227 | 228 | /** 229 | * Save an image or the screen in PNG format. 230 | * 231 | * @pre filename != NULL 232 | * @param filename - filename of the PNG image 233 | * @param data - start of Color type pixel data (can be getVramDisplayBuffer()) 234 | * @param width - logical width of the image or SCREEN_WIDTH 235 | * @param height - height of the image or SCREEN_HEIGHT 236 | * @param lineSize - physical width of the image or PSP_LINE_SIZE 237 | * @param saveAlpha - if 0, image is saved without alpha channel 238 | */ 239 | extern void saveImage(const char* filename, Color* data, int width, int height, int lineSize, int saveAlpha); 240 | 241 | /** 242 | * Exchange display buffer and drawing buffer. 243 | */ 244 | extern void flipScreen(); 245 | 246 | /** 247 | * Initialize the graphics. 248 | */ 249 | extern void initGraphics(); 250 | 251 | /** 252 | * Disable graphics, used for debug text output. 253 | */ 254 | extern void disableGraphics(); 255 | 256 | /** 257 | * Draw a line to screen. 258 | * 259 | * @pre x0 >= 0 && x0 < SCREEN_WIDTH && y0 >= 0 && y0 < SCREEN_HEIGHT && 260 | * x1 >= 0 && x1 < SCREEN_WIDTH && y1 >= 0 && y1 < SCREEN_HEIGHT 261 | * @param x0 - x line start position 262 | * @param y0 - y line start position 263 | * @param x1 - x line end position 264 | * @param y1 - y line end position 265 | */ 266 | void drawLineScreen(int x0, int y0, int x1, int y1, Color color); 267 | 268 | /** 269 | * Draw a line to screen. 270 | * 271 | * @pre x0 >= 0 && x0 < image->imageWidth && y0 >= 0 && y0 < image->imageHeight && 272 | * x1 >= 0 && x1 < image->imageWidth && y1 >= 0 && y1 < image->imageHeight 273 | * @param x0 - x line start position 274 | * @param y0 - y line start position 275 | * @param x1 - x line end position 276 | * @param y1 - y line end position 277 | */ 278 | extern void drawLineImage(int x0, int y0, int x1, int y1, Color color, Image* image); 279 | 280 | /** 281 | * Get the current draw buffer for fast unchecked access. 282 | * 283 | * @return the start address of the current draw buffer 284 | */ 285 | extern Color* getVramDrawBuffer(); 286 | 287 | /** 288 | * Get the current display buffer for fast unchecked access. 289 | * 290 | * @return the start address of the current display buffer 291 | */ 292 | extern Color* getVramDisplayBuffer(); 293 | 294 | extern void guStart(); 295 | 296 | #endif 297 | -------------------------------------------------------------------------------- /TutorialFX2/graphics.h: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHICS_H 2 | #define GRAPHICS_H 3 | 4 | #include 5 | 6 | #define PSP_LINE_SIZE 512 7 | #define SCREEN_WIDTH 480 8 | #define SCREEN_HEIGHT 272 9 | 10 | typedef u32 Color; 11 | #define A(color) ((u8)(color >> 24 & 0xFF)) 12 | #define B(color) ((u8)(color >> 16 & 0xFF)) 13 | #define G(color) ((u8)(color >> 8 & 0xFF)) 14 | #define R(color) ((u8)(color & 0xFF)) 15 | 16 | typedef struct 17 | { 18 | int textureWidth; // the real width of data, 2^n with n>=0 19 | int textureHeight; // the real height of data, 2^n with n>=0 20 | int imageWidth; // the image width 21 | int imageHeight; 22 | Color* data; 23 | } Image; 24 | 25 | /** 26 | * Load a PNG image. 27 | * 28 | * @pre filename != NULL 29 | * @param filename - filename of the PNG image to load 30 | * @return pointer to a new allocated Image struct, or NULL on failure 31 | */ 32 | extern Image* loadImage(const char* filename); 33 | 34 | /** 35 | * Blit a rectangle part of an image to another image. 36 | * 37 | * @pre source != NULL && destination != NULL && 38 | * sx >= 0 && sy >= 0 && 39 | * width > 0 && height > 0 && 40 | * sx + width <= source->width && sy + height <= source->height && 41 | * dx + width <= destination->width && dy + height <= destination->height 42 | * @param sx - left position of rectangle in source image 43 | * @param sy - top position of rectangle in source image 44 | * @param width - width of rectangle in source image 45 | * @param height - height of rectangle in source image 46 | * @param source - pointer to Image struct of the source image 47 | * @param dx - left target position in destination image 48 | * @param dy - top target position in destination image 49 | * @param destination - pointer to Image struct of the destination image 50 | */ 51 | extern void blitImageToImage(int sx, int sy, int width, int height, Image* source, int dx, int dy, Image* destination); 52 | 53 | /** 54 | * Blit a rectangle part of an image to screen. 55 | * 56 | * @pre source != NULL && destination != NULL && 57 | * sx >= 0 && sy >= 0 && 58 | * width > 0 && height > 0 && 59 | * sx + width <= source->width && sy + height <= source->height && 60 | * dx + width <= SCREEN_WIDTH && dy + height <= SCREEN_HEIGHT 61 | * @param sx - left position of rectangle in source image 62 | * @param sy - top position of rectangle in source image 63 | * @param width - width of rectangle in source image 64 | * @param height - height of rectangle in source image 65 | * @param source - pointer to Image struct of the source image 66 | * @param dx - left target position in destination image 67 | * @param dy - top target position in destination image 68 | */ 69 | extern void blitImageToScreen(int sx, int sy, int width, int height, Image* source, int dx, int dy); 70 | 71 | /** 72 | * Blit a rectangle part of an image to another image without alpha pixels in source image. 73 | * 74 | * @pre source != NULL && destination != NULL && 75 | * sx >= 0 && sy >= 0 && 76 | * width > 0 && height > 0 && 77 | * sx + width <= source->width && sy + height <= source->height && 78 | * dx + width <= destination->width && dy + height <= destination->height 79 | * @param sx - left position of rectangle in source image 80 | * @param sy - top position of rectangle in source image 81 | * @param width - width of rectangle in source image 82 | * @param height - height of rectangle in source image 83 | * @param source - pointer to Image struct of the source image 84 | * @param dx - left target position in destination image 85 | * @param dy - top target position in destination image 86 | * @param destination - pointer to Image struct of the destination image 87 | */ 88 | extern void blitAlphaImageToImage(int sx, int sy, int width, int height, Image* source, int dx, int dy, Image* destination); 89 | 90 | /** 91 | * Blit a rectangle part of an image to screen without alpha pixels in source image. 92 | * 93 | * @pre source != NULL && destination != NULL && 94 | * sx >= 0 && sy >= 0 && 95 | * width > 0 && height > 0 && 96 | * sx + width <= source->width && sy + height <= source->height && 97 | * dx + width <= SCREEN_WIDTH && dy + height <= SCREEN_HEIGHT 98 | * @param sx - left position of rectangle in source image 99 | * @param sy - top position of rectangle in source image 100 | * @param width - width of rectangle in source image 101 | * @param height - height of rectangle in source image 102 | * @param source - pointer to Image struct of the source image 103 | * @param dx - left target position in destination image 104 | * @param dy - top target position in destination image 105 | */ 106 | extern void blitAlphaImageToScreen(int sx, int sy, int width, int height, Image* source, int dx, int dy); 107 | 108 | /** 109 | * Create an empty image. 110 | * 111 | * @pre width > 0 && height > 0 && width <= 512 && height <= 512 112 | * @param width - width of the new image 113 | * @param height - height of the new image 114 | * @return pointer to a new allocated Image struct, all pixels initialized to color 0, or NULL on failure 115 | */ 116 | extern Image* createImage(int width, int height); 117 | 118 | /** 119 | * Frees an allocated image. 120 | * 121 | * @pre image != null 122 | * @param image a pointer to an image struct 123 | */ 124 | extern void freeImage(Image* image); 125 | 126 | /** 127 | * Initialize all pixels of an image with a color. 128 | * 129 | * @pre image != NULL 130 | * @param color - new color for the pixels 131 | * @param image - image to clear 132 | */ 133 | extern void clearImage(Color color, Image* image); 134 | 135 | /** 136 | * Initialize all pixels of the screen with a color. 137 | * 138 | * @param color - new color for the pixels 139 | */ 140 | extern void clearScreen(Color color); 141 | 142 | /** 143 | * Fill a rectangle of an image with a color. 144 | * 145 | * @pre image != NULL 146 | * @param color - new color for the pixels 147 | * @param x0 - left position of rectangle in image 148 | * @param y0 - top position of rectangle in image 149 | * @param width - width of rectangle in image 150 | * @param height - height of rectangle in image 151 | * @param image - image 152 | */ 153 | extern void fillImageRect(Color color, int x0, int y0, int width, int height, Image* image); 154 | 155 | /** 156 | * Fill a rectangle of an image with a color. 157 | * 158 | * @pre image != NULL 159 | * @param color - new color for the pixels 160 | * @param x0 - left position of rectangle in image 161 | * @param y0 - top position of rectangle in image 162 | * @param width - width of rectangle in image 163 | * @param height - height of rectangle in image 164 | */ 165 | extern void fillScreenRect(Color color, int x0, int y0, int width, int height); 166 | 167 | /** 168 | * Set a pixel on screen to the specified color. 169 | * 170 | * @pre x >= 0 && x < SCREEN_WIDTH && y >= 0 && y < SCREEN_HEIGHT 171 | * @param color - new color for the pixels 172 | * @param x - left position of the pixel 173 | * @param y - top position of the pixel 174 | */ 175 | extern void putPixelScreen(Color color, int x, int y); 176 | 177 | /** 178 | * Set a pixel in an image to the specified color. 179 | * 180 | * @pre x >= 0 && x < image->imageWidth && y >= 0 && y < image->imageHeight && image != NULL 181 | * @param color - new color for the pixels 182 | * @param x - left position of the pixel 183 | * @param y - top position of the pixel 184 | */ 185 | extern void putPixelImage(Color color, int x, int y, Image* image); 186 | 187 | /** 188 | * Get the color of a pixel on screen. 189 | * 190 | * @pre x >= 0 && x < SCREEN_WIDTH && y >= 0 && y < SCREEN_HEIGHT 191 | * @param x - left position of the pixel 192 | * @param y - top position of the pixel 193 | * @return the color of the pixel 194 | */ 195 | extern Color getPixelScreen(int x, int y); 196 | 197 | /** 198 | * Get the color of a pixel of an image. 199 | * 200 | * @pre x >= 0 && x < image->imageWidth && y >= 0 && y < image->imageHeight && image != NULL 201 | * @param x - left position of the pixel 202 | * @param y - top position of the pixel 203 | * @return the color of the pixel 204 | */ 205 | extern Color getPixelImage(int x, int y, Image* image); 206 | 207 | /** 208 | * Print a text (pixels out of the screen or image are clipped). 209 | * 210 | * @param x - left position of text 211 | * @param y - top position of text 212 | * @param text - the text to print 213 | * @param color - new color for the pixels 214 | */ 215 | extern void printTextScreen(int x, int y, const char* text, u32 color); 216 | 217 | /** 218 | * Print a text (pixels out of the screen or image are clipped). 219 | * 220 | * @param x - left position of text 221 | * @param y - top position of text 222 | * @param text - the text to print 223 | * @param color - new color for the pixels 224 | * @param image - image 225 | */ 226 | extern void printTextImage(int x, int y, const char* text, u32 color, Image* image); 227 | 228 | /** 229 | * Save an image or the screen in PNG format. 230 | * 231 | * @pre filename != NULL 232 | * @param filename - filename of the PNG image 233 | * @param data - start of Color type pixel data (can be getVramDisplayBuffer()) 234 | * @param width - logical width of the image or SCREEN_WIDTH 235 | * @param height - height of the image or SCREEN_HEIGHT 236 | * @param lineSize - physical width of the image or PSP_LINE_SIZE 237 | * @param saveAlpha - if 0, image is saved without alpha channel 238 | */ 239 | extern void saveImage(const char* filename, Color* data, int width, int height, int lineSize, int saveAlpha); 240 | 241 | /** 242 | * Exchange display buffer and drawing buffer. 243 | */ 244 | extern void flipScreen(); 245 | 246 | /** 247 | * Initialize the graphics. 248 | */ 249 | extern void initGraphics(); 250 | 251 | /** 252 | * Disable graphics, used for debug text output. 253 | */ 254 | extern void disableGraphics(); 255 | 256 | /** 257 | * Draw a line to screen. 258 | * 259 | * @pre x0 >= 0 && x0 < SCREEN_WIDTH && y0 >= 0 && y0 < SCREEN_HEIGHT && 260 | * x1 >= 0 && x1 < SCREEN_WIDTH && y1 >= 0 && y1 < SCREEN_HEIGHT 261 | * @param x0 - x line start position 262 | * @param y0 - y line start position 263 | * @param x1 - x line end position 264 | * @param y1 - y line end position 265 | */ 266 | void drawLineScreen(int x0, int y0, int x1, int y1, Color color); 267 | 268 | /** 269 | * Draw a line to screen. 270 | * 271 | * @pre x0 >= 0 && x0 < image->imageWidth && y0 >= 0 && y0 < image->imageHeight && 272 | * x1 >= 0 && x1 < image->imageWidth && y1 >= 0 && y1 < image->imageHeight 273 | * @param x0 - x line start position 274 | * @param y0 - y line start position 275 | * @param x1 - x line end position 276 | * @param y1 - y line end position 277 | */ 278 | extern void drawLineImage(int x0, int y0, int x1, int y1, Color color, Image* image); 279 | 280 | /** 281 | * Get the current draw buffer for fast unchecked access. 282 | * 283 | * @return the start address of the current draw buffer 284 | */ 285 | extern Color* getVramDrawBuffer(); 286 | 287 | /** 288 | * Get the current display buffer for fast unchecked access. 289 | * 290 | * @return the start address of the current display buffer 291 | */ 292 | extern Color* getVramDisplayBuffer(); 293 | 294 | extern void guStart(); 295 | 296 | #endif 297 | --------------------------------------------------------------------------------