#include "orgfx_plus.h"
|
#include "orgfx_plus.h"
|
#include "orgfx_3d.h"
|
#include "orgfx_3d.h"
|
#include "orgfx.h"
|
#include "orgfx.h"
|
#include "orgfx_bitmap_font.h"
|
#include "orgfx_bitmap_font.h"
|
#include <math.h>
|
#include <math.h>
|
|
|
#include "cube.obj.h"
|
#include "cube.obj.h"
|
#include "humanoid_tri.obj.h"
|
#include "humanoid_tri.obj.h"
|
#include "Bahamut_cc.png.h"
|
#include "Bahamut_cc.png.h"
|
|
|
#include "franklin_font.h"
|
#include "franklin_font.h"
|
|
|
// State defines
|
// State defines
|
enum
|
enum
|
{
|
{
|
STATE_ORSOC_SPLASH = 0,
|
STATE_ORSOC_SPLASH = 0,
|
STATE_GEOMETRY,
|
STATE_GEOMETRY,
|
STATE_FILLMODES,
|
STATE_FILLMODES,
|
STATE_COLORKEY,
|
STATE_COLORKEY,
|
STATE_3D,
|
STATE_3D,
|
|
|
LAST_STATE
|
LAST_STATE
|
};
|
};
|
|
|
// Color defines
|
// Color defines
|
#define C_RED 0xf800
|
#define C_RED 0xf800
|
#define C_WHITE 0xffff
|
#define C_WHITE 0xffff
|
#define C_BLACK 0x0000
|
#define C_BLACK 0x0000
|
#define C_BLUE 0x003f
|
#define C_BLUE 0x003f
|
#define C_GREEN 0x07c0
|
#define C_GREEN 0x07c0
|
|
|
int main(void)
|
int main(void)
|
{
|
{
|
// Initialize screen, with double buffering
|
// Initialize screen, with double buffering
|
int screen = orgfxplus_init(640, 480, 16, 1, 1);
|
int screen = orgfxplus_init(640, 480, 16, 1, 1);
|
|
|
orgfx_enable_cliprect(1);
|
orgfx_enable_cliprect(1);
|
|
|
// Initialize bahamut_sprite
|
// Initialize bahamut_sprite
|
int bahamut_sprite = init_Bahamut_cc_sprite();
|
int bahamut_sprite = init_Bahamut_cc_sprite();
|
|
|
// Initialize franklin_font
|
// Initialize franklin_font
|
orgfx_bitmap_font franklin_font = init_franklin_font(2, 16);
|
orgfx_bitmap_font franklin_font = init_franklin_font(2, 16);
|
|
|
// Initialize mesh
|
// Initialize mesh
|
orgfx_mesh mesh = init_humanoid_tri_mesh();
|
orgfx_mesh mesh = init_humanoid_tri_mesh();
|
|
|
int state = STATE_ORSOC_SPLASH;
|
int state = STATE_ORSOC_SPLASH;
|
// int state = STATE_3D;
|
// int state = STATE_3D;
|
int stateTimer = 0;
|
int stateTimer = 0;
|
const int stateTimerMax = 20;
|
const int stateTimerMax = 20;
|
int i;
|
int i;
|
|
|
orgfxplus_fill(0,0,640*FIXEDW,480*FIXEDW,C_WHITE);
|
orgfxplus_fill(0,0,640*FIXEDW,480*FIXEDW,C_WHITE);
|
orgfxplus_flip();
|
orgfxplus_flip();
|
|
|
float rad = 0;
|
float rad = 0;
|
|
|
while(1)
|
while(1)
|
{
|
{
|
// Clear screen
|
// Clear screen
|
orgfxplus_fill(0,0,640*FIXEDW,480*FIXEDW,C_WHITE);
|
orgfxplus_fill(0,0,640*FIXEDW,480*FIXEDW,C_WHITE);
|
for(i = 0; i < 1500000; ++i);
|
for(i = 0; i < 1500000; ++i);
|
|
|
orgfxplus_colorkey(0xf81f, 1);
|
orgfxplus_colorkey(0xf81f, 1);
|
|
|
// State specific logic
|
// State specific logic
|
switch(state)
|
switch(state)
|
{
|
{
|
case STATE_ORSOC_SPLASH:
|
case STATE_ORSOC_SPLASH:
|
{
|
{
|
// Add a logo
|
// Add a logo
|
|
|
orgfx_put_bitmap_text(&franklin_font, 50*FIXEDW, 300*FIXEDW,
|
orgfx_put_bitmap_text(&franklin_font, 50*FIXEDW, 300*FIXEDW,
|
L"ORSOC Graphics Accelerator Demo");
|
L"ORSOC Graphics Accelerator Demo");
|
for(i = 0; i < 500000; ++i);
|
for(i = 0; i < 500000; ++i);
|
|
|
orgfx_put_bitmap_text(&franklin_font, 50*FIXEDW, 340*FIXEDW,
|
orgfx_put_bitmap_text(&franklin_font, 50*FIXEDW, 340*FIXEDW,
|
L"Per Lenander & Anton Fosselius, 2012");
|
L"Per Lenander & Anton Fosselius, 2012");
|
break;
|
break;
|
}
|
}
|
case STATE_GEOMETRY:
|
case STATE_GEOMETRY:
|
{
|
{
|
orgfxplus_fill(50*FIXEDW, 50*FIXEDW,
|
orgfxplus_fill(50*FIXEDW, 50*FIXEDW,
|
150*FIXEDW, 150*FIXEDW,
|
150*FIXEDW, 150*FIXEDW,
|
C_RED);
|
C_RED);
|
|
|
orgfxplus_line(-350*FIXEDW,50*FIXEDW,
|
orgfxplus_line(-350*FIXEDW,50*FIXEDW,
|
450*FIXEDW,100*FIXEDW,
|
450*FIXEDW,100*FIXEDW,
|
C_RED);
|
C_RED);
|
orgfxplus_line(400*FIXEDW,50*FIXEDW,
|
orgfxplus_line(400*FIXEDW,50*FIXEDW,
|
450*FIXEDW,150*FIXEDW,
|
450*FIXEDW,150*FIXEDW,
|
C_GREEN);
|
C_GREEN);
|
orgfxplus_line(450*FIXEDW,100*FIXEDW,
|
orgfxplus_line(450*FIXEDW,100*FIXEDW,
|
350*FIXEDW,150*FIXEDW,
|
350*FIXEDW,150*FIXEDW,
|
C_BLUE);
|
C_BLUE);
|
|
|
orgfxplus_triangle(100*FIXEDW,-250*FIXEDW,
|
orgfxplus_triangle(100*FIXEDW,-250*FIXEDW,
|
200*FIXEDW,250*FIXEDW,
|
200*FIXEDW,250*FIXEDW,
|
150*FIXEDW,350*FIXEDW,
|
150*FIXEDW,350*FIXEDW,
|
C_RED);
|
C_RED);
|
|
|
orgfxplus_colorkey(0xf81f, 0);
|
orgfxplus_colorkey(0xf81f, 0);
|
orgfxplus_draw_surface(300*FIXEDW, 200*FIXEDW,
|
orgfxplus_draw_surface(300*FIXEDW, 200*FIXEDW,
|
bahamut_sprite);
|
bahamut_sprite);
|
|
|
break;
|
break;
|
}
|
}
|
case STATE_FILLMODES:
|
case STATE_FILLMODES:
|
{
|
{
|
orgfx_point3 offset = {200, 200, 0};
|
orgfx_point3 offset = {200, 200, 0};
|
orgfx_point3 rotation = {0,0,rad};
|
orgfx_point3 rotation = {0,0,rad};
|
|
|
orgfx_enable_transform(1);
|
orgfx_enable_transform(1);
|
|
|
orgfx_matrix m = orgfx3d_identity();
|
orgfx_matrix m = orgfx3d_identity();
|
m = orgfx3d_rotateX(m, rotation.x);
|
m = orgfx3d_rotateX(m, rotation.x);
|
m = orgfx3d_rotateY(m, rotation.y);
|
m = orgfx3d_rotateY(m, rotation.y);
|
m = orgfx3d_rotateZ(m, rotation.z);
|
m = orgfx3d_rotateZ(m, rotation.z);
|
m = orgfx3d_translate(m, offset);
|
m = orgfx3d_translate(m, offset);
|
orgfx3d_set_matrix(m);
|
orgfx3d_set_matrix(m);
|
|
|
orgfx_set_colors(C_RED, C_GREEN, C_BLUE);
|
orgfx_set_colors(C_RED, C_GREEN, C_BLUE);
|
|
|
// Flat color (Red)
|
// Flat color (Red)
|
orgfx_triangle(-50*FIXEDW, -50*FIXEDW,
|
orgfx_triangle(-50*FIXEDW, -50*FIXEDW,
|
50*FIXEDW, -50*FIXEDW,
|
50*FIXEDW, -50*FIXEDW,
|
0*FIXEDW, 50*FIXEDW,
|
0*FIXEDW, 50*FIXEDW,
|
0);
|
0);
|
|
|
offset.x = 50;
|
offset.x = 50;
|
|
|
m = orgfx3d_identity();
|
m = orgfx3d_identity();
|
m = orgfx3d_rotateX(m, rotation.x);
|
m = orgfx3d_rotateX(m, rotation.x);
|
m = orgfx3d_rotateY(m, rotation.y);
|
m = orgfx3d_rotateY(m, rotation.y);
|
m = orgfx3d_rotateZ(m, rotation.z);
|
m = orgfx3d_rotateZ(m, rotation.z);
|
m = orgfx3d_translate(m, offset);
|
m = orgfx3d_translate(m, offset);
|
orgfx3d_set_matrix(m);
|
orgfx3d_set_matrix(m);
|
|
|
// Interpolated color RGB
|
// Interpolated color RGB
|
orgfxplus_alpha(0x00ffffff, 1);
|
orgfxplus_alpha(0x00ffffff, 1);
|
|
|
orgfx_triangle(-50*FIXEDW, -50*FIXEDW,
|
orgfx_triangle(-50*FIXEDW, -50*FIXEDW,
|
50*FIXEDW, -50*FIXEDW,
|
50*FIXEDW, -50*FIXEDW,
|
0*FIXEDW, 50*FIXEDW,
|
0*FIXEDW, 50*FIXEDW,
|
1);
|
1);
|
orgfxplus_alpha(GFX_OPAQUE, 0);
|
orgfxplus_alpha(GFX_OPAQUE, 0);
|
|
|
offset.x = 300;
|
offset.x = 300;
|
offset.y = 300;
|
offset.y = 300;
|
|
|
m = orgfx3d_identity();
|
m = orgfx3d_identity();
|
m = orgfx3d_rotateX(m, rotation.x);
|
m = orgfx3d_rotateX(m, rotation.x);
|
m = orgfx3d_rotateY(m, rotation.y);
|
m = orgfx3d_rotateY(m, rotation.y);
|
m = orgfx3d_rotateZ(m, rotation.z);
|
m = orgfx3d_rotateZ(m, rotation.z);
|
m = orgfx3d_translate(m, offset);
|
m = orgfx3d_translate(m, offset);
|
orgfx3d_set_matrix(m);
|
orgfx3d_set_matrix(m);
|
|
|
orgfx_enable_tex0(1);
|
orgfx_enable_tex0(1);
|
orgfxplus_bind_tex0(bahamut_sprite);
|
orgfxplus_bind_tex0(bahamut_sprite);
|
|
|
// Textured triangle
|
// Textured triangle
|
orgfx_uv(0,0,186,0,0,248);
|
orgfx_uv(0,0,186,0,0,248);
|
orgfx_triangle(-98*FIXEDW, -124*FIXEDW,
|
orgfx_triangle(-98*FIXEDW, -124*FIXEDW,
|
98*FIXEDW, -124*FIXEDW,
|
98*FIXEDW, -124*FIXEDW,
|
-98*FIXEDW, 124*FIXEDW,
|
-98*FIXEDW, 124*FIXEDW,
|
1);
|
1);
|
|
|
orgfx_uv(186,0,186,248,0,248);
|
orgfx_uv(186,0,186,248,0,248);
|
orgfx_triangle(98*FIXEDW, -124*FIXEDW,
|
orgfx_triangle(98*FIXEDW, -124*FIXEDW,
|
98*FIXEDW, 124*FIXEDW,
|
98*FIXEDW, 124*FIXEDW,
|
-98*FIXEDW, 124*FIXEDW,
|
-98*FIXEDW, 124*FIXEDW,
|
1);
|
1);
|
|
|
orgfx_enable_tex0(0);
|
orgfx_enable_tex0(0);
|
|
|
orgfx_enable_transform(0);
|
orgfx_enable_transform(0);
|
|
|
break;
|
break;
|
}
|
}
|
case STATE_COLORKEY:
|
case STATE_COLORKEY:
|
{
|
{
|
|
|
orgfxplus_colorkey(0xf81f, 0);
|
orgfxplus_colorkey(0xf81f, 0);
|
orgfxplus_draw_surface(-50*FIXEDW, -50*FIXEDW,
|
orgfxplus_draw_surface(-50*FIXEDW, -50*FIXEDW,
|
bahamut_sprite);
|
bahamut_sprite);
|
|
|
orgfxplus_colorkey(0xf81f, 1);
|
orgfxplus_colorkey(0xf81f, 1);
|
orgfxplus_draw_surface(250*FIXEDW, 50*FIXEDW,
|
orgfxplus_draw_surface(250*FIXEDW, 50*FIXEDW,
|
bahamut_sprite);
|
bahamut_sprite);
|
|
|
orgfxplus_alpha(0xffffff00 | (unsigned int)((1+sin(2*rad))/2.0*0xff), 1);
|
orgfxplus_alpha(0xffffff00 | (unsigned int)((1+sin(2*rad))/2.0*0xff), 1);
|
orgfxplus_draw_surface(150*FIXEDW, 250*FIXEDW,
|
orgfxplus_draw_surface(150*FIXEDW, 250*FIXEDW,
|
bahamut_sprite);
|
bahamut_sprite);
|
orgfxplus_alpha(GFX_OPAQUE, 0);
|
orgfxplus_alpha(GFX_OPAQUE, 0);
|
break;
|
break;
|
}
|
}
|
case STATE_3D:
|
case STATE_3D:
|
{
|
{
|
orgfx_point3 offset = {200, 500, 0};
|
orgfx_point3 translation = {200, 500, 0};
|
|
orgfx_point3 rotation = {-1.5,0,rad};
|
orgfx_point3 scale = {25.0, 25.0, 25.0};
|
orgfx_point3 scale = {25.0, 25.0, 25.0};
|
orgfx_point3 rot = {-1.5,0,rad};
|
|
|
|
mesh.scale = scale;
|
orgfx3d_draw_mesh(&mesh, translation, rotation, scale, 0, 0);
|
mesh.translation = offset;
|
|
mesh.rotation = rot;
|
|
|
|
orgfx3d_draw_mesh(&mesh, 0, 0);
|
|
|
|
orgfx_clear_zbuffer();
|
orgfx_clear_zbuffer();
|
for(i = 0; i < 1500000; ++i);
|
for(i = 0; i < 1500000; ++i);
|
|
|
orgfx_enable_zbuffer(1);
|
orgfx_enable_zbuffer(1);
|
|
|
mesh.translation.x += 300;
|
translation.x += 300;
|
mesh.rotation.z = -rad;
|
rotation.z = -rad;
|
|
|
orgfx3d_draw_mesh(&mesh, 1, 0);
|
orgfx3d_draw_mesh(&mesh, translation, rotation, scale, 1, 0);
|
|
|
orgfx_enable_zbuffer(0);
|
orgfx_enable_zbuffer(0);
|
break;
|
break;
|
}
|
}
|
}
|
}
|
|
|
// Increment state
|
// Increment state
|
stateTimer++;
|
stateTimer++;
|
if(stateTimer >= stateTimerMax)
|
if(stateTimer >= stateTimerMax)
|
{
|
{
|
stateTimer = 0;
|
stateTimer = 0;
|
state++;
|
state++;
|
if(state >= LAST_STATE)
|
if(state >= LAST_STATE)
|
state = STATE_ORSOC_SPLASH;
|
state = STATE_ORSOC_SPLASH;
|
}
|
}
|
|
|
rad += 0.05;
|
rad += 0.05;
|
if(rad >= M_PI*2) rad -= M_PI*2;
|
if(rad >= M_PI*2) rad -= M_PI*2;
|
|
|
for(i = 0; i < 500000; ++i);
|
for(i = 0; i < 500000; ++i);
|
// Swap buffers
|
// Swap buffers
|
orgfxplus_flip();
|
orgfxplus_flip();
|
}
|
}
|
}
|
}
|
|
|
|
|
|
|