dreamcast-opengl/gl.c

86 lines
1.9 KiB
C
Raw Normal View History

2024-03-11 04:39:58 +00:00
#include <kos.h>
#include <stdio.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glkos.h>
#include <sys/time.h>
float angle = 0;
float deltaTime = 1.0/60.0;
const float microSecond = 0.000001f;
float speed = 5.0f;
void initScreen() {
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
}
void displayStuff() {
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotatef(angle, 0, 0, 1);
glColor3f(1.0f, 1.0f, 1.0f);
glBegin(GL_POLYGON);
glVertex3f(0.25f, 0.25f, 0.0f);
glVertex3f(0.75f, 0.25f, 0.0f);
glVertex3f(0.75f, 0.75f, 0.0f);
glVertex3f(0.25f, 0.75f, 0.0f);
glEnd();
glPopMatrix();
// glFlush();
glKosSwapBuffers();
}
void process_input() {
maple_device_t *controller;
cont_state_t *controller_state;
controller = maple_enum_type(0, MAPLE_FUNC_CONTROLLER);
if (controller) {
controller_state = (cont_state_t *)maple_dev_status(controller);
if (!controller_state) {
printf("An error has occured while trying to read the controller.\n");
}
if (controller_state->buttons & CONT_DPAD_RIGHT) {
speed += 1.0f;
} else if (controller_state->buttons & CONT_DPAD_LEFT) {
speed -= 1.0f;
}
if (speed < 1.0f) {
speed = 1.0f;
}
angle += (controller_state->joyx / 127.0f) * deltaTime * speed;
}
}
int main() {
glKosInit();
initScreen();
printf("GL_VENDOR: %s\n", glGetString(GL_VENDOR));
printf("GL_RENDERER: %s\n", glGetString(GL_RENDERER));
printf("GL_VERSION: %s\n", glGetString(GL_VERSION));
printf("GL_EXTENSIONS: %s\n", glGetString(GL_EXTENSIONS));
struct timeval beginningOfFrame, endOfFrame;
while (1) {
gettimeofday(&beginningOfFrame, 0);
process_input();
displayStuff();
gettimeofday(&endOfFrame, 0);
float time = ((float)(endOfFrame.tv_usec) * microSecond) - ((float)(beginningOfFrame.tv_usec) * microSecond);
if (time > 0.0f) {
deltaTime = time;
}
}
}