Initial bootstrap

This commit is contained in:
2014-04-02 18:01:08 +02:00
commit 700f060aaf
337 changed files with 95147 additions and 0 deletions
Executable
+9
View File
@@ -0,0 +1,9 @@
#define GLM_FORCE_RADIANS
#include <glm/glm.hpp>
#include <glm/common.hpp>
#include <glm/gtc/constants.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtx/rotate_vector.hpp>
#include <glm/gtc/quaternion.hpp>
#include <glm/gtx/quaternion.hpp>
#include <glm/gtc/type_ptr.hpp>
Executable
+4
View File
@@ -0,0 +1,4 @@
#include <GL/glew.h>
#define GLFW_INCLUDE_GLU
#include <GLFW/glfw3.h>
#include <glext.h>
+22
View File
@@ -0,0 +1,22 @@
#ifndef glerror_h__
#define glerror_h__
#include <iostream>
#include "logging.h"
inline bool _GLERROR(char* info, char* file, char* func, unsigned int line)
{
GLenum error = glGetError();
if (error != GL_NO_ERROR) {
_LOG(LOG_LEVEL_ERROR, file, func, line, "GL Error: %s %i %s", info, error, gluErrorString(error));
return true;
}
return false;
}
#define GLERROR(function) \
_GLERROR(function, __BASE_FILE__, __func__, __LINE__)
#endif // glerror_h__
+83
View File
@@ -0,0 +1,83 @@
#ifndef logging_h__
#define logging_h__
#ifdef _WIN32
// http://stackoverflow.com/a/2282433
#define __func__ __FUNCTION__
// http://stackoverflow.com/a/8488201
#define __BASE_FILE__ \
(strrchr(__FILE__, '/') \
? strrchr(__FILE__, '/') + 1 \
: (strrchr(__FILE__, '\\') \
? strrchr(__FILE__, '\\') + 1 \
: __FILE__))
#endif
#include <iostream>
#include <limits>
#include <string>
#include <stdio.h>
#include <stdarg.h>
enum _LOG_LEVEL
{
LOG_LEVEL_ERROR,
LOG_LEVEL_WARNING,
LOG_LEVEL_INFO,
LOG_LEVEL_DEBUG
};
#ifdef DEBUG
static _LOG_LEVEL LOG_LEVEL = LOG_LEVEL_DEBUG;
#else
static _LOG_LEVEL LOG_LEVEL = LOG_LEVEL_INFO;
#endif
const static char* _LOG_LEVEL_PREFIX[] =
{
"E: ",
"W: ",
"",
"D: "
};
static void _LOG(_LOG_LEVEL logLevel, char* file, char* func, unsigned int line, const char* format, ...)
{
if (logLevel > LOG_LEVEL)
return;
va_list args;
va_start(args, format);
char* message = nullptr;
size_t size = vsnprintf(message, 0, format, args);
message = new char[size + 1];
message[size] = '\0';
vsnprintf(message, size, format, args);
va_end(args);
if (logLevel == LOG_LEVEL_ERROR) {
std::cerr << file << ":" << line << " " << func << std::endl;
std::cerr << _LOG_LEVEL_PREFIX[logLevel] << message << std::endl;
} else {
std::cout << _LOG_LEVEL_PREFIX[logLevel] << message << std::endl;
}
delete[] message;
}
#define LOG(logLevel, format, ...) \
_LOG(logLevel, __BASE_FILE__, __func__, __LINE__, format, ##__VA_ARGS__)
#define LOG_ERROR(format, ...) \
LOG(LOG_LEVEL_ERROR, format, ##__VA_ARGS__)
#define LOG_WARNING(format, ...) \
LOG(LOG_LEVEL_WARNING, format, ##__VA_ARGS__)
#define LOG_INFO(format, ...) \
LOG(LOG_LEVEL_INFO, format, ##__VA_ARGS__)
#define LOG_DEBUG(format, ...) \
LOG(LOG_LEVEL_DEBUG, format, ##__VA_ARGS__)
#endif // logging_h__
Executable
+58
View File
@@ -0,0 +1,58 @@
#include <string>
#include <sstream>
#include "OpenGL.h"
#include "GLM.h"
#include "Util/logging.h"
#include "Util/glerror.h"
GLFWwindow* window;
GLint glVersion[2];
GLchar* glVendor;
int main(int argc, char* argv[])
{
// Initialize GLFW
if (!glfwInit())
{
LOG_ERROR("GLFW: Initialization failed");
return 1;
}
// Create a window
window = glfwCreateWindow(1280, 720, "OpenGL", nullptr, nullptr);
if (!window)
{
LOG_ERROR("GLFW: Failed to create window");
return 1;
}
glfwMakeContextCurrent(window);
// GL version info
glGetIntegerv(GL_MAJOR_VERSION, &glVersion[0]);
glGetIntegerv(GL_MINOR_VERSION, &glVersion[1]);
glVendor = (GLchar*)glGetString(GL_VENDOR);
std::stringstream ss;
ss << glVendor << " OpenGL " << glVersion[0] << "." << glVersion[1];
#ifdef DEBUG
ss << " DEBUG";
#endif
LOG_INFO(ss.str().c_str());
glfwSetWindowTitle(window, ss.str().c_str());
// Initialize GLEW
if (glewInit() != GLEW_OK)
{
LOG_ERROR("GLEW: Initialization failed");
return 1;
}
// Main loop
while (!glfwWindowShouldClose(window))
{
glfwPollEvents();
}
return 0;
}