#include <nds.h>
#include <malloc.h>
#include <nds/arm9/image.h>
#include "drunkenlogo_pcx.h"
int DrawGLScene();
float xrot;
float yrot;
float xspeed;
float yspeed;
float z=-5.0f;
float LightAmbient[]= { 0.5f, 0.5f, 0.5f, 1.0f };
float LightDiffuse[]= { 1.0f, 1.0f, 1.0f, 1.0f };
float LightPosition[]= { 0.0f, 0.0f, 2.0f, 1.0f };
int texture[3];
int LoadGLTextures()
{
sImage pcx;
loadPCX((u8*)drunkenlogo_pcx, &pcx);
image8to16(&pcx);
glGenTextures(1, &texture[0]);
glBindTexture(0, texture[0]);
glTexImage2D(0, 0, GL_RGB, TEXTURE_SIZE_128 , TEXTURE_SIZE_128, 0, TEXGEN_TEXCOORD, pcx.image.data8);
imageDestroy(&pcx);
return TRUE;
}
int main() {
videoSetMode(MODE_0_3D);
vramSetBankA(VRAM_A_TEXTURE);
glInit();
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glEnable(GL_ANTIALIAS);
glClearColor(0,0,0,31);
glClearPolyID(63);
glClearDepth(0x7FFF);
glViewport(0,0,255,191);
LoadGLTextures();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(70, 256.0 / 192.0, 0.1, 100);
glLight(0, RGB15(31,31,31) , 0, floattov10(-1.0), 0);
glColor3f(1,1,1);
glMatrixMode(GL_MODELVIEW);
glMaterialf(GL_AMBIENT, RGB15(16,16,16));
glMaterialf(GL_DIFFUSE, RGB15(16,16,16));
glMaterialf(GL_SPECULAR, BIT(15) | RGB15(8,8,8));
glMaterialf(GL_EMISSION, RGB15(16,16,16));
glMaterialShinyness();
glMatrixMode(GL_MODELVIEW);
while (1)
{
scanKeys();
if (keysHeld() & KEY_R)
{
z-=0.02f;
}
if (keysHeld() & KEY_L)
{
z+=0.02f;
}
if (keysHeld() & KEY_LEFT)
{
xspeed-=0.01f;
}
if (keysHeld() & KEY_RIGHT)
{
xspeed+=0.01f;
}
if (keysHeld() & KEY_UP)
{
yspeed+=0.01f;
}
if (keysHeld() & KEY_DOWN)
{
yspeed-=0.01f;
}
DrawGLScene();
glFlush(0);
swiWaitForVBlank();
}
return 0;
}
int DrawGLScene()
{
glLoadIdentity();
glTranslatef(0.0f,0.0f,z);
glRotatef(xrot,1.0f,0.0f,0.0f);
glRotatef(yrot,0.0f,1.0f,0.0f);
glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE | POLY_FORMAT_LIGHT0);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glBegin(GL_QUADS);
glNormal3f( 0.0f, 0.0f, 1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
glNormal3f( 0.0f, 0.0f,-1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
glNormal3f( 0.0f, 1.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
glNormal3f( 0.0f,-1.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
glNormal3f( 1.0f, 0.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
glEnd();
glPolyFmt(POLY_ALPHA(15) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0);
glBegin(GL_QUADS);
glNormal3f(-1.0f, 0.0f, 0.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
glEnd();
xrot+=xspeed;
yrot+=yspeed;
return TRUE;
}