OBJ Loader

This commit is contained in:
Ben
2019-02-17 01:08:41 +00:00
parent fd20b12351
commit 8ff9122b23
44 changed files with 3239 additions and 53 deletions

View File

@@ -1,5 +1,6 @@
// General includes
#include <chrono>
#include <vector>
// GL includes
#include <glad/glad.h>
@@ -19,78 +20,38 @@
// Custom includes
#include <logger.h>
#include "init.h"
#include "timers.h"
#include "object.h"
int main(int argc, char** argv) {
std::cout << "----- OpenGL Playground -----" << std::endl;
std::cout << "-------- Version 1.0 --------" << std::endl;
std::cout << "----- ©Benjamin Kyd 2019 ----" << std::endl << std::endl;
// Get global variables ready
Logger logger;
SDL_Window* window = nullptr;
SDL_GLContext glContext;
bool isWindowClosed = true;
logger << LOGGER_DEBUG << "debug" << LOGGER_ENDL;
logger << LOGGER_INFO << "info" << LOGGER_ENDL;
logger << LOGGER_WARN << "warn" << LOGGER_ENDL;
logger << LOGGER_ERROR << "error" << LOGGER_ENDL;
logger << LOGGER_PANIC << "panic" << LOGGER_ENDL << LOGGER_ENDL;
bool isWindowOpen = false;
// Initialize SDL and OpenGL
SDL_Init(SDL_INIT_EVERYTHING);
isWindowOpen = init(logger, window, glContext);
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 5);
window = SDL_CreateWindow("OpenGL Playground V1.0",
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
1000, 1000,
SDL_WINDOW_OPENGL);
glContext = SDL_GL_CreateContext(window);
SDL_GL_SetSwapInterval(0);
gladLoadGLLoader(SDL_GL_GetProcAddress);
isWindowClosed = false;
logger << LOGGER_INFO << "OpenGL and SDL initialized" << LOGGER_ENDL;
// Various timers needed for FPS counting
std::chrono::high_resolution_clock timer;
auto FPSCalculateLast = timer.now();
auto FPSClock = SDL_GetTicks();
auto UpdateClock = SDL_GetTicks();
std::vector<glm::vec4> vertices;
std::vector<glm::vec3> normals;
std::vector<GLushort> elements;
LoadOBJ(logger, "./resources/dragon.obj", vertices, normals, elements);
SDL_Event event;
while (!isWindowClosed) {
// Calculate and display framerate
if (SDL_GetTicks() - FPSClock >= 1000) {
auto deltaTime = std::chrono::duration_cast<std::chrono::nanoseconds>(timer.now() - FPSCalculateLast).count();
logger << LOGGER_INFO << "FPS: " << (int)(1 / ((float)deltaTime * 1e-9)) << LOGGER_ENDL;
FPSClock = SDL_GetTicks();
}
FPSCalculateLast = timer.now();
while (isWindowOpen) {
FPSCount(logger);
// Update tick (60ups)
if (SDL_GetTicks() - UpdateClock >= 10) {
if (UPSTimer()) {
}
// Handle events
while (SDL_PollEvent(&event) != 0)
if (event.type == SDL_QUIT)
isWindowClosed = true;
isWindowOpen = false;
// Swap GL frame buffers
SDL_GL_SwapWindow(window);