#include <nds.h>
#include <malloc.h>
#include <nds/arm9/image.h>
#include <stdlib.h>
#include "Star_pcx.h"
int DrawGLScene();
bool twinkle;
bool tp;
const int num=50;
typedef struct
{
int r, g, b;
float dist,
angle;
}stars;
stars star[num];
float zoom=-15.0f;
float tilt=90.0f;
float spin;
int loop;
int texture[1];
int LoadGLTextures() {
sImage pcx;
loadPCX((u8*)Star_pcx, &pcx);
image8to16trans(&pcx, 0);
glGenTextures(1, &texture[0]);
glBindTexture(0, texture[0]);
glTexImage2D(0, 0, GL_RGBA, 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_ANTIALIAS);
glClearColor(0,0,0,31);
glClearPolyID(63);
glClearDepth(0x7FFF);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glViewport(0,0,255,191);
LoadGLTextures();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(70, 256.0 / 192.0, 0.1, 100);
glColor3f(1,1,1);
glLight(0, RGB15(31,31,31) , 0, 0,floattov10(-1.0));
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();
glPolyFmt(POLY_ALPHA(15) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0);
glMatrixMode(GL_MODELVIEW);
while (1) {
DrawGLScene();
glFlush(0);
swiWaitForVBlank();
}
return 0;
}
int DrawGLScene()
{
glBindTexture(GL_TEXTURE_2D, texture[0]);
for (loop=0; loop<num; loop++)
{
glLoadIdentity();
glTranslatef(0.0f,0.0f,zoom);
glRotatef(tilt,1.0f,0.0f,0.0f);
glRotatef(star[loop].angle,0.0f,1.0f,0.0f);
glTranslatef(star[loop].dist,0.0f,0.0f);
glRotatef(-star[loop].angle,0.0f,1.0f,0.0f);
glRotatef(-tilt,1.0f,0.0f,0.0f);
if (twinkle)
{
glColor3b(star[(num-loop)-1].r,star[(num-loop)-1].g,star[(num-loop)-1].b);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,-1.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,-1.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 0.0f);
glEnd();
}
glRotatef(spin,0.0f,0.0f,1.0f);
glColor3b(star[loop].r,star[loop].g,star[loop].b);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,-1.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,-1.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 0.0f);
glEnd();
spin+=0.01f;
star[loop].angle+=float(loop)/num;
star[loop].dist-=0.01f;
if (star[loop].dist<0.0f)
{
star[loop].dist+=5.0f;
star[loop].r=rand()%256;
star[loop].g=rand()%256;
star[loop].b=rand()%256;
}
}
return TRUE;
}