Skip to content

Instantly share code, notes, and snippets.

@fincs
Created January 13, 2012 23:32
Show Gist options
  • Save fincs/1609352 to your computer and use it in GitHub Desktop.
Save fincs/1609352 to your computer and use it in GitHub Desktop.
NeHe Lesson 4 FeOS port
#include <feos.h>
#include <feos3d.h>
static void init3D()
{
videoSetMode(MODE_0_3D);
glInit();
// enable antialiasing
glEnable(GL_ANTIALIAS);
// setup the rear plane
glClearColor(0,0,0,31); // BG must be opaque for AA to work
glClearPolyID(63); // BG must have a unique polygon ID for AA to work
glClearDepth(0x7FFF);
// Set our viewport to be the same size as the screen
glViewport(0,0,255,191);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(70, 256.0 / 192.0, 0.1, 100);
//ds specific, several attributes can be set here
glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE);
// Set the current matrix to be the model matrix
glMatrixMode(GL_MODELVIEW);
}
static void drawScene();
int rtri, rquad;
int main()
{
FeOS_DirectMode();
init3D();
for(;;)
{
swiWaitForVBlank();
if (keysDown() & KEY_START) break;
drawScene();
glFlush(0);
}
glDeinit();
FeOS_ConsoleMode();
return 0;
}
#define deg2ang(x) ((int)(degreesToAngle(x)))
void drawScene()
{
/*ds does this automagicaly*///glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity(); // Reset The Current Modelview Matrix
glTranslatef(-1.5f,0.0f,-6.0f); // Move Left 1.5 Units And Into The Screen 6.0
glRotatef32i(rtri,floattof32(0.0f),floattof32(1.0f),floattof32(0.0f)); // Rotate The Triangle On The Y axis ( NEW )
glColor3f(1, 1, 1); // set the vertex color
glBegin(GL_TRIANGLES); // Start Drawing A Triangle
glColor3f(1.0f,0.0f,0.0f); // Set Top Point Of Triangle To Red
glVertex3f( 0.0f, 1.0f, 0.0f); // First Point Of The Triangle
glColor3f(0.0f,1.0f,0.0f); // Set Left Point Of Triangle To Green
glVertex3f(-1.0f,-1.0f, 0.0f); // Second Point Of The Triangle
glColor3f(0.0f,0.0f,1.0f); // Set Right Point Of Triangle To Blue
glVertex3f( 1.0f,-1.0f, 0.0f); // Third Point Of The Triangle
glEnd(); // Done Drawing The Triangle
glLoadIdentity(); // Reset The Current Modelview Matrix
glTranslatef(1.5f,0.0f,-6.0f); // Move Right 1.5 Units And Into The Screen 6.0
glRotatef32i(rquad,floattof32(1.0f),floattof32(0.0f),floattof32(0.0f)); // Rotate The Quad On The X axis ( NEW )
glColor3f(0.5f,0.5f,1.0f); // Set The Color To Blue One Time Only
glBegin(GL_QUADS); // Draw A Quad
glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
glVertex3f( 1.0f, 1.0f, 0.0f); // Top Right
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
glEnd(); // Done Drawing The Quad
rtri+=deg2ang(0.9f); // Increase The Rotation Variable For The Triangle ( NEW )
rquad-=deg2ang(0.75f); // Decrease The Rotation Variable For The Quad ( NEW )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment