Skip to content

Instantly share code, notes, and snippets.

@DarkMorford
Last active January 13, 2017 23:38
Show Gist options
  • Select an option

  • Save DarkMorford/5ca6daa77e769013e2db9b62aa6ca0ec to your computer and use it in GitHub Desktop.

Select an option

Save DarkMorford/5ca6daa77e769013e2db9b62aa6ca0ec to your computer and use it in GitHub Desktop.
#include <kos.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
bool exitProgram = false;
GLfloat rotation = 0;
// Initialize KOS
KOS_INIT_FLAGS(INIT_DEFAULT);
// Initialize the romdisk
extern uint8 romdisk[];
KOS_INIT_ROMDISK(romdisk);
void Setup()
{
// Set the background color
glClearColor(0.3f, 0.3f, 0.3f, 1.0f);
// Set up the camera
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0f, vid_mode->width / vid_mode->height, 0.1f, 100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void Loop()
{
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glLoadIdentity();
gluLookAt(
0.0f, 0.0f, 5.0f,
0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f
);
glRotatef(rotation++, 0, 0, 1);
glColor3f(1, 1, 1);
glBegin(GL_QUADS);
glVertex3f(1, 1, 0);
glVertex3f(-1, 1, 0);
glVertex3f(-1, -1, 0);
glVertex3f(1, -1, 0);
glEnd();
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char *argv[])
{
printf("Square demo beginning!\n");
// Initialize GL
glKosInit();
Setup();
while (!exitProgram) {
maple_device_t *controller = maple_enum_type(0, MAPLE_FUNC_CONTROLLER);
if (!controller) {
printf("Controller not found!\n");
break;
}
cont_state_t *controllerState = reinterpret_cast<cont_state_t*>(maple_dev_status(controller));
if (!controllerState) {
printf("Error reading controller!\n");
break;
}
if (controllerState->buttons & CONT_START) {
printf("Pressed START!\n");
exitProgram = true;
}
Loop();
}
printf("Square demo finished!\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment