dreamcast-opengl/gl.cc

82 lines
1.6 KiB
C++
Raw Normal View History

2024-03-12 05:41:34 +00:00
#include <GL/gl.h>
#include <GL/glkos.h>
#include <algorithm>
#include <cstdio>
#include "engine.hh"
2024-03-12 05:41:34 +00:00
class Glcc : public Engine {
void process_input();
void displayStuff();
2024-03-12 05:41:34 +00:00
void gameLoop() override {
process_input();
displayStuff();
2024-03-12 05:41:34 +00:00
}
};
2024-03-12 05:41:34 +00:00
void Glcc::displayStuff() {
2024-03-12 05:41:34 +00:00
glClear(GL_COLOR_BUFFER_BIT);
// clang-format off
glPushMatrix();
glRotatef(angle, 0, 0, 1);
glColor3f(0.5f, 0.0f, 1.0f);
glBegin(GL_POLYGON);
glColor3f(1.0f, 0.0f, 0.0f);
2024-03-13 05:27:33 +00:00
glVertex3fNormalized(0.25f, 0.25f, 0.0f);
2024-03-12 05:41:34 +00:00
glColor3f(0.0f, 1.0f, 0.0f);
2024-03-13 05:27:33 +00:00
glVertex3fNormalized(0.75f, 0.25f, 0.0f);
2024-03-12 05:41:34 +00:00
glColor3f(0.0f, 0.0f, 1.0f);
2024-03-13 05:27:33 +00:00
glVertex3fNormalized(0.75f, 0.75f, 0.0f);
2024-03-12 05:41:34 +00:00
glColor3f(1.0f, 1.0f, 1.0f);
2024-03-13 05:27:33 +00:00
glVertex3fNormalized(0.25f, 0.75f, 0.0f);
2024-03-12 05:41:34 +00:00
glEnd();
glPopMatrix();
// clang-format on
if (thirtyfps) {
vid_waitvbl();
vid_waitvbl();
}
glKosSwapBuffers();
}
void Glcc::process_input() {
2024-03-12 05:41:34 +00:00
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");
2024-03-12 05:41:34 +00:00
}
pressButton(controller_state, CONT_DPAD_LEFT, [&]() { speed -= 1.0f; });
pressButton(controller_state, CONT_DPAD_RIGHT,
[&]() { speed += 1.0f; });
pressButton(controller_state, CONT_A,
[&]() { thirtyfps = !thirtyfps; });
2024-03-12 05:41:34 +00:00
speed = std::clamp(speed, 1.0f, 10.0f);
angle += (controller_state->joyx / 127.0f) * deltaTime * speed;
}
}
int main() {
Glcc* engine = new Glcc;
engine->initializeEngine();
engine->initializeGameLoop();
2024-03-12 05:41:34 +00:00
}