dsgmLib/examples/Basic3D/source/project.c
2014-10-05 11:50:34 +01:00

230 lines
4.0 KiB
C

#include "DSGM.h"
#include "DSGM_projectHelper.h"
// User variables / declarations
int rx = 50;
int ry = 15;
// Resources
DSGM_Sound DSGM_Sounds[DSGM_SOUND_COUNT] = {
};
DSGM_Background DSGM_Backgrounds[DSGM_BACKGROUND_COUNT] = {
};
DSGM_Palette DSGM_Palettes[DSGM_PALETTE_COUNT] = {
};
DSGM_Sprite DSGM_Sprites[DSGM_SPRITE_COUNT] = {
};
DSGM_Object DSGM_Objects[DSGM_OBJECT_COUNT] = {
// hello
{
DSGM_NO_SPRITE,
(DSGM_Event)hello_create,
(DSGM_Event)hello_loop,
DSGM_NO_EVENT,
DSGM_NO_EVENT,
NULL, 0,
sizeof(*((helloObjectInstance *)0)->variables)
},
};
DSGM_Room DSGM_Rooms[DSGM_ROOM_COUNT] = {
// Room_1
{
// Backgrounds
{
// Bottom screen
{
// Layer 0
{
DSGM_DEFAULT_FONT, // Background
DSGM_BOTTOM, // Screen
0, // Layer
false, // Attached to view system
7, // Map base
0, // Tile base
0, 0, 0
},
// Layer 1
{
DSGM_NO_BACKGROUND, // Background
DSGM_BOTTOM, // Screen
1, // Layer
true, // Attached to view system
0, // Map base
0, // Tile base
0, 0, 0
},
// Layer 2
{
DSGM_NO_BACKGROUND, // Background
DSGM_BOTTOM, // Screen
2, // Layer
true, // Attached to view system
0, // Map base
0, // Tile base
0, 0, 0
},
// Layer 3
{
DSGM_NO_BACKGROUND, // Background
DSGM_BOTTOM, // Screen
3, // Layer
true, // Attached to view system
0, // Map base
0, // Tile base
0, 0, 0
},
},
// Top screen
{
// Only top screen layer 0 can be a 3D renderer
// Layer 0
{
DSGM_3D_RENDERER, // Background
DSGM_TOP, // Screen
0, // Layer
false, // Attached to view system
0, // Map base
0, // Tile base
0, 0, 0
},
// Layer 1
{
DSGM_NO_BACKGROUND, // Background
DSGM_TOP, // Screen
1, // Layer
true, // Attached to view system
0, // Map base
0, // Tile base
0, 0, 0
},
// Layer 2
{
DSGM_NO_BACKGROUND, // Background
DSGM_TOP, // Screen
2, // Layer
true, // Attached to view system
0, // Map base
0, // Tile base
0, 0, 0
},
// Layer 3
{
DSGM_NO_BACKGROUND, // Background
DSGM_TOP, // Screen
3, // Layer
true, // Attached to view system
0, // Map base
0, // Tile base
0, 0, 0
},
}
},
// Initial views
{
// Bottom screen
{
0, 0
},
// Top screen
{
0, 0
}
},
// Views
{
// Bottom screen
{
0, 0
},
// Top screen
{
0, 0
}
},
NULL,
// Object groups are dynamic, so must be set up at run time, see DSGM_SetupRooms.
{
NULL,
NULL
},
{
0,
0
}
},
};
int DSGM_currentRoom = Room_1;
void DSGM_SetupRooms(int room) {
if(room != DSGM_ALL_ROOMS) {
switch(room) {
case Room_1: goto Room_1; break;
}
}
Room_1:
DSGM_Debug("Room_1 reset\n");
DSGM_LeaveRoom(&DSGM_Rooms[Room_1]);
DSGM_SetupViews(&DSGM_Rooms[Room_1]);
DSGM_SetupObjectGroups(&DSGM_Rooms[Room_1], DSGM_TOP, 0);
DSGM_SetupObjectGroups(&DSGM_Rooms[Room_1], DSGM_BOTTOM, 1);
DSGM_SetupObjectInstances(&DSGM_Rooms[Room_1].objectGroups[DSGM_BOTTOM][0], &DSGM_Objects[hello], DSGM_BOTTOM, 1,
0, 0
);
if(room != DSGM_ALL_ROOMS) return;
}
void hello_create(helloObjectInstance *me) {
glInit();
glEnable(GL_ANTIALIAS);
glClearColor(0, 0, 0, 31);
glClearPolyID(63);
glClearDepth(0x7FFF);
glViewport(0, 0, 255, 191);
}
void hello_loop(helloObjectInstance *me) {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(70, 256.0 / 192.0, 0.1, 10);
glPolyFmt(POLY_ALPHA(31) | POLY_CULL_FRONT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0, 0, -5);
glRotateX(ry++);
glRotateY(rx++);
DSGM_DrawCube(-1, -1, -1, 2, 2, 2);
}