Browse Source

added aixlog for better logging

master
dummy 9 years ago
parent
commit
8259fd6180
  1. 2
      src/Makefile
  2. 62
      src/hexgame.cpp
  3. 1
      src/hexgame.h
  4. 28
      src/renderer.h

2
src/Makefile

@ -1,6 +1,6 @@
CXXFLAGS = -std=c++11 -g -Wall
INCLUDES =
INCLUDES = -I../ext/aixlog/include
# libGLEW needs to be >= 2.0.0 to use opengl core context
# don't know a good way to require this in make without forcing a specific version
LDFLAGS = -lSDL2 -lGLEW -lGL

62
src/hexgame.cpp

@ -1,30 +1,6 @@
/*
* TODO:
*
* - Platform Layer:
* - make a global debug logging function in hexgame.h
* - centralize memory allocation/deallocation
* - custom dynamic arrays in C:
* https://stackoverflow.com/questions/3536153/c-dynamically-growing-array
* - File IO
*
* - Debug UI:
* - font metrics
* - render lines of glyphs to texture
* - simple buttons to select game states
*
* - game states:
* - hex fill, line draw, 'cone' fill, pathfinding, line of sight
*
* - utility functions:
* - SafeRatio(): don't divide by zero
* - SafeTruncate() for various types: check for input size before losing high bits
*/
#include <string>
#include <vector>
#include <sstream>
#if defined(_WIN32)
#include <windows.h>
@ -34,27 +10,14 @@
#include <GL/glew.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_opengl.h>
#include "aixlog.hpp"
#include "hexgame.h"
#include "hexlib.h"
#include "renderer.h"
using std::string;
using std::stringstream;
using std::vector;
// TODO: maybe switch to c-style strings for errors? working with stringstream
// is annoying and too verbose
void
debugLog(string error)
{
#if defined(_WIN32) && !defined(__MINGW32__)
error.push_back('\n');
OutputDebugString((LPCSTR) error.c_str());
#else
std::cout << error << '\n';
#endif
}
// TODO: global variables
v2i viewportDims(1280, 720);
@ -497,36 +460,29 @@ int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
int main(int argc, char* argv[])
#endif
{
// init fancy new logger
AixLog::Log::init<AixLog::SinkCout>(AixLog::Severity::trace, AixLog::Type::normal);
LOG(INFO) << "Application started\n";
hexInfoArray = new vector<hex_info>;
createHexes(hexInfoArray);
SDL_Handles handles;
if (SDL_Init(SDL_INIT_VIDEO) != 0)
{
stringstream ss;
ss << "Error, SDL_Init: " << SDL_GetError();
debugLog(ss.str());
LOG(ERROR) << "Error, SDL_Init: " << SDL_GetError() << "\n";
return 1;
}
if (!initRenderer(handles, viewportDims))
{
stringstream ss;
ss << "Unable to initialize graphics, exiting";
debugLog(ss.str());
LOG(ERROR) << "Unable to initialize graphics, exiting\n";
return 1;
}
createScene(hexInfoArray);
#if 0
if (InitGooey(viewportDims) == false)
{
stringstream ss;
ss << "Unable to initialize gooey, exiting";
debugLog(ss.str());
return 1;
}
#endif
// TODO: rewrite gooey
enterLoop(handles);
cleanUp(handles);

1
src/hexgame.h

@ -3,7 +3,6 @@
#define HEXGAME_H
#include <vector>
#include <limits>
#include <cassert>
#include <SDL2/SDL.h>

28
src/renderer.h

@ -3,8 +3,6 @@
#define RENDERER_H
#include <vector>
// TODO: remove for better logging
#include <iostream> // std::cout
#include <GL/glew.h>
#include <SDL2/SDL.h>
@ -82,16 +80,13 @@ initRenderer(SDL_Handles &handles, v2i vpDims)
//glewExperimental = true; // Needed for core profile
GLenum err = glewInit();
if (err != GLEW_OK) {
// TODO: better logging
std::cout << "Failed to initilize GLEW" << glewGetErrorString(err) << "\n";
LOG(ERROR) << "Failed to initilize GLEW" << glewGetErrorString(err) << "\n";
return false;
}
// TODO: better logging
// see what kind of context we got
std::cout << "opengl vendor: " << glGetString(GL_VENDOR) << "\n";
std::cout << "opengl renderer: " << glGetString(GL_RENDERER) << "\n";
std::cout << "opengl version: " << glGetString(GL_VERSION) << "\n";
LOG(INFO) << "opengl vendor: " << glGetString(GL_VENDOR) << "\n";
LOG(INFO)<< "opengl renderer: " << glGetString(GL_RENDERER) << "\n";
LOG(INFO) << "opengl version: " << glGetString(GL_VERSION) << "\n";
// TODO: blending, these options break the http://www.opengl-tutorial.org tutorials atm
// Setup render state: alpha-blending enabled, polygon fill
@ -385,8 +380,8 @@ void
openglDebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity,
GLsizei length, const GLchar* message, const void* userParam)
{
// TODO: update error logging
std::cout << "openGLDebugCallback: "
LOG((type == GL_DEBUG_TYPE_ERROR) ? ERROR : DEBUG)
<< "openGLDebugCallback: "
<< (type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : "")
<< ", type: " << type
<< ", severity: " << severity
@ -399,7 +394,9 @@ renderFrame(std::vector<hex_info> *hexes)
glClearColor(g_clear_col.R, g_clear_col.G, g_clear_col.B, g_clear_col.A);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
#if 1
// filled hexes
glUseProgram(g_hex_programID);
// Send our transformation to the currently bound shader, in the "g_MVP" uniform
glUniformMatrix4fv(g_matrixID, 1, GL_FALSE, &g_MVP[0][0]);
@ -419,9 +416,10 @@ renderFrame(std::vector<hex_info> *hexes)
glDrawArrays(GL_TRIANGLES, 0, g_vertex_buffer_triangle_count);
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
#endif
#if 1
// hex lines
glUseProgram(g_line_programID);
// Send our transformation to the currently bound shader, in the "g_MVP" uniform
glUniformMatrix4fv(g_matrixID, 1, GL_FALSE, &g_MVP[0][0]);
@ -431,9 +429,7 @@ renderFrame(std::vector<hex_info> *hexes)
glEnableVertexAttribArray(attrib_index);
glBindBuffer(GL_ARRAY_BUFFER, g_hex_line_vertexbuffer);
glVertexAttribPointer(attrib_index, 3, GL_FLOAT, GL_FALSE, 0, (void*) 0);
glDrawArrays(GL_LINES, 0, g_line_buf_size / 3);
#endif
}
void

Loading…
Cancel
Save