Fries
23dd7ace18
Right now the implementation is extremely unoptimized and draw call heavy as I just copy and pasted that from the docs for tiny obj loader but added gl calls.
73 lines
1.8 KiB
C++
73 lines
1.8 KiB
C++
#define TINYOBJLOADER_IMPLEMENTATION
|
|
|
|
#include "engine.hh"
|
|
|
|
#include <GL/gl.h>
|
|
#include <GL/glkos.h>
|
|
|
|
#include <cstdio>
|
|
#include <functional>
|
|
|
|
void Engine::initScreen() {
|
|
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
|
glViewport(0, 0, 640, 480);
|
|
glMatrixMode(GL_MODELVIEW);
|
|
glLoadIdentity();
|
|
glOrtho(0, 640, 0, 480, -100, 100);
|
|
glMatrixMode(GL_PROJECTION);
|
|
glLoadIdentity();
|
|
}
|
|
|
|
void Engine::printSystemInformation() {
|
|
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));
|
|
}
|
|
|
|
void Engine::initializeEngine() {
|
|
glKosInit();
|
|
initScreen();
|
|
printSystemInformation();
|
|
}
|
|
|
|
template <typename T>
|
|
void Engine::deltaTimeLoop(T&& callback, struct timeval& beginningOfFrame,
|
|
struct timeval& endOfFrame) {
|
|
gettimeofday(&beginningOfFrame, 0);
|
|
(this->*callback)();
|
|
gettimeofday(&endOfFrame, 0);
|
|
float time = ((float)(endOfFrame.tv_usec) * microSecond) -
|
|
((float)(beginningOfFrame.tv_usec) * microSecond);
|
|
if (time > 0.0f) {
|
|
deltaTime = time;
|
|
}
|
|
}
|
|
|
|
void Engine::initializeGameLoop() {
|
|
struct timeval beginningOfFrame, endOfFrame;
|
|
|
|
while (1) {
|
|
deltaTimeLoop(&Engine::gameLoop, beginningOfFrame, endOfFrame);
|
|
}
|
|
}
|
|
|
|
void Engine::pressButton(cont_state_t* controller_state, int button,
|
|
std::function<void()> callback) {
|
|
if (controller_state->buttons & button) {
|
|
if (!(buttonsPressed & button)) {
|
|
buttonsPressed |= button;
|
|
|
|
callback();
|
|
}
|
|
} else if ((buttonsPressed & button) &&
|
|
~(controller_state->buttons & button)) {
|
|
buttonsPressed &= ~button;
|
|
}
|
|
}
|
|
|
|
void Engine::glVertex3fNormalized(float x, float y, float z) {
|
|
constexpr int xSize = 640, ySize = 480;
|
|
|
|
glVertex3f(x * xSize, y * ySize, z);
|
|
}
|