# Prefix all object file names with the compilation directory
objects ::= $(addprefix out/, \
- main.o debugutil.o level.o performance.o \
- render.o tga.o ui.o)
+ main.o debugutil.o level.o logger.o \
+ performance.o render.o tga.o ui.o)
# Set executable extension for the platform
ifeq ($(OS),Windows_NT)
#include <stdlib.h>
#include <string.h>
-#include "assimp_types.h"
+//#include "assimp_types.h"
char* getGlInfoString() {
const char* glVersion = (const char*) glGetString(GL_VERSION);
return glInfoString;
}
-
+/*
void dumpScene(FILE* stream, const AiScene* scene) {
if (scene == NULL) {
fprintf(stream, "NULL");
(*node).mNumMeshes,
(void*) (*node).mMeshes);
}
+*/
#include <GL/gl.h>
#include <assimp/cimport.h>
-#include <stdio.h> // TODO remove
#include "level.h"
+#include "logger.h"
const AiScene* levelScene = NULL;
const AiScene* importScene(const char* path) {
const AiScene* scene = aiImportFile(path, 0u);
if (scene == NULL) {
- fprintf(stderr, "Asset import failed at file %s\n", path); // TODO factor logging the heck outta here
+ logError("Asset import failed (file: %s)", path);
}
return scene;
// TODO aiReleaseImport(scene);
--- /dev/null
+#include <stdarg.h>
+#include <stdio.h>
+
+#include "logger.h"
+
+LogLevel logLevel = LOGLEVEL_DEBUG;
+
+void logMessage(LogLevel msgLevel, const char* file, int line, const char* message, ...) {
+ if (msgLevel > logLevel) {
+ return;
+ }
+
+ const char* msgLevelString;
+ switch (msgLevel) {
+ case LOGLEVEL_ERROR:
+ msgLevelString = "error: ";
+ break;
+ case LOGLEVEL_WARNING:
+ msgLevelString = "warning: ";
+ break;
+ case LOGLEVEL_INFO:
+ msgLevelString = "";
+ break;
+ case LOGLEVEL_DEBUG:
+ msgLevelString = "debug: ";
+ break;
+ default:
+ msgLevelString = "(invalid message level!) ";
+ break;
+ }
+
+ va_list args;
+ va_start(args, message);
+
+ fprintf(stderr, "%s:%i: %s", file, line, msgLevelString);
+ vfprintf(stderr, message, args);
+ fputc('\n', stderr);
+
+ va_end(args);
+}
--- /dev/null
+#ifndef LOGGER_H_
+#define LOGGER_H_
+
+typedef enum {
+ LOGLEVEL_ERROR,
+ LOGLEVEL_WARNING,
+ LOGLEVEL_INFO,
+ LOGLEVEL_DEBUG
+} LogLevel;
+
+LogLevel logLevel;
+
+#define logError(...) logMessage(LOGLEVEL_ERROR, __FILE__, __LINE__, __VA_ARGS__)
+#define logWarning(...) logMessage(LOGLEVEL_WARNING, __FILE__, __LINE__, __VA_ARGS__)
+#define logInfo(...) logMessage(LOGLEVEL_INFO, __FILE__, __LINE__, __VA_ARGS__)
+#define log(...) logMessage(LOGLEVEL_DEBUG, __FILE__, __LINE__, __VA_ARGS__)
+
+void logMessage(LogLevel msgLevel, const char* file, int line, const char* message, ...);
+
+#endif
#include <GL/glxew.h>
#include <GL/glut.h>
-#include <stdio.h>
#include "debugutil.h"
#include "level.h"
+#include "logger.h"
#include "performance.h"
#include "render.h"
#include "ui.h"
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutCreateWindow(NULL);
- glutSetWindowTitle(getGlInfoString());
+ // glutSetWindowTitle(getGlInfoString());
+ glutSetWindowTitle("shadowclad");
+
+ logInfo("OpenGL %s", (const char*) glGetString(GL_VERSION));
+ logInfo("GLSL %s", (const char*) glGetString(GL_SHADING_LANGUAGE_VERSION));
+ logInfo("%s", (const char*) glGetString(GL_RENDERER));
GLenum glewInitStatus = glewInit();
if (glewInitStatus != GLEW_OK) {
- fprintf(stderr, "GLEW init failed: %s\n", glewGetErrorString(glewInitStatus));
+ logError("GLEW init failed: %s", (const char*) glewGetErrorString(glewInitStatus));
return 1;
}
- printf("GLEW %s\n", glewGetString(GLEW_VERSION));
+ logInfo("GLEW %s", (const char*) glewGetString(GLEW_VERSION));
if (GLXEW_EXT_swap_control) {
Display* display = glXGetCurrentDisplay();
glXSwapIntervalEXT(display, drawable, 1);
}
else {
- fprintf(stderr, "Drawable is not here\n");
+ logWarning("Drawable is not here ¯\\_(ツ)_/¯");
+ logWarning("Could not enable vsync (GLX_EXT_swap_control)");
}
}
else if (GLXEW_MESA_swap_control) {
glXSwapIntervalMESA(1);
- printf("Swap interval %d\n", glXGetSwapIntervalMESA());
+ log("Vsync enabled with GLX_MESA_swap_control, swap interval %d", glXGetSwapIntervalMESA());
}
else {
- fprintf(stderr, "Could not enable vsync\n");
+ logWarning("Could not enable vsync (extensions not supported)");
}
glutDisplayFunc(renderScene);
initPerformanceMetering();
initLevel();
- /*
- fprintf(stderr, "*model = ");
- print_struct_aiScene(stderr, model);
- fprintf(stderr, "\n*(*model).mRootNode = ");
- print_struct_aiNode(stderr, (*model).mRootNode);
- fprintf(stderr, "\n");
- */
glutMainLoop();
return 0;
}
#include <stdio.h> // TODO remove
#include <time.h>
+#include "logger.h"
+
typedef struct timespec Timepoint;
static Timepoint lastDisplayTime;
void initPerformanceMetering() {
if (clock_gettime(CLOCK_MONOTONIC, &lastDisplayTime) != 0) {
- fprintf(stderr, "Clock read failed, performance metering unavailable\n");
+ logWarning("Clock read failed, performance metering unavailable");
}
else {
meteringEnabled = true;
Timepoint now;
if (clock_gettime(CLOCK_MONOTONIC, &now) != 0) {
- fprintf(stderr, "Clock read failed, stopping performance metering\n");
+ logWarning("Clock read failed, stopping performance metering");
meteringEnabled = false;
return;
}
if (fullSeconds > 0) {
float seconds = (now.tv_nsec - lastDisplayTime.tv_nsec) / 1000000000.0f;
seconds += (float) (now.tv_sec - lastDisplayTime.tv_sec);
+ // This goes to STDOUT because it's, uh, temporary
printf("frametime avg %.1f ms; fps avg %.f\n", (seconds / frames) * 1000.0f, (frames / seconds));
lastDisplayTime = now;
frames = 0;