From 7580d4483569a8ea0e0da54ceef21e6f346cfcb1 Mon Sep 17 00:00:00 2001 From: "Martin T. H. Sandsmark" Date: Wed, 4 Apr 2012 23:42:43 +0200 Subject: [PATCH] fix logging --- c3dsobject.cpp | 2 +- cube.cpp | 2 +- engine.cpp | 2 -- glrender.cpp | 9 +++++---- legendary.pro | 4 ++-- linux.cpp | 6 +++--- msg.cpp | 53 -------------------------------------------------- msg.h | 17 +++------------- rtt.cpp | 4 ++-- vboobject.cpp | 28 +++++++++++++++++++------- 10 files changed, 38 insertions(+), 89 deletions(-) delete mode 100644 msg.cpp diff --git a/c3dsobject.cpp b/c3dsobject.cpp index cd44678..e7478d6 100644 --- a/c3dsobject.cpp +++ b/c3dsobject.cpp @@ -114,7 +114,7 @@ void C3dsScene::parseFile(string filename) break; default: - printf("Unkown chunk %04x of length %u\n", parser.getChunkId(), parser.getChunkLength()); + LOG("Unkown chunk " << parser.getChunkId() << " of length " << parser.getChunkLength()); parser.skipChunk(); break; diff --git a/cube.cpp b/cube.cpp index 5e7ca64..2762827 100644 --- a/cube.cpp +++ b/cube.cpp @@ -8,7 +8,7 @@ Cube::Cube() : VboObject() { genBO(); m_material = new RawTexture("legendary.raw"); //mat = new CRenderToTextureMaterial; - Log("Cube VBO generated\n"); + LOG("Cube VBO generated"); } } diff --git a/engine.cpp b/engine.cpp index 816fac1..dab0637 100644 --- a/engine.cpp +++ b/engine.cpp @@ -10,7 +10,6 @@ void Engine::init() { m_cube = 0; - initLog("debug.log"); m_engine = this; } @@ -46,7 +45,6 @@ void Engine::toggleFrame() { void Engine::destroy() { delete m_render; delete m_object; - closeLog(); } double Engine::getTime() { diff --git a/glrender.cpp b/glrender.cpp index b17a1e5..079f3f2 100644 --- a/glrender.cpp +++ b/glrender.cpp @@ -78,10 +78,11 @@ void GLRender::drawFrame() void GLRender::toggleFrame() { glPolygonMode(GL_FRONT, m_fill ? GL_LINE : GL_FILL); m_fill ^= 1; - if (m_fill) - Log("Wireframe off.\n"); - else - Log("Wireframe on.\n"); + if (m_fill) { + LOG("Wireframe off."); + } else { + LOG("Wireframe on."); + } } void GLRender::loadShaders() diff --git a/legendary.pro b/legendary.pro index d610be8..e1e4831 100644 --- a/legendary.pro +++ b/legendary.pro @@ -13,7 +13,6 @@ SOURCES += \ engine.cpp \ file.cpp \ glrender.cpp \ - msg.cpp \ rtt.cpp \ c3dsparser.cpp \ rawtexture.cpp \ @@ -59,5 +58,6 @@ unix { LIBS += -lX11 \ -lGLEW \ -lvorbisfile \ - -lasound + -lasound \ + -lGL } diff --git a/linux.cpp b/linux.cpp index 779f11d..a9ce0c0 100644 --- a/linux.cpp +++ b/linux.cpp @@ -29,7 +29,7 @@ int LinuxEngine::msgBox(std::string msg) { //printf("ATTENTION: %s\n", msg); system(std::string("zenity --info --text='" + msg + "'").c_str()); //Forward to Log - Log(msg.c_str()); + LOG(msg.c_str()); return 0; } @@ -47,7 +47,7 @@ int main() { display = XOpenDisplay(NULL); if (!display) { - Log("Couldn't open display, terminating.\n"); + LOG("Couldn't open display, terminating."); delete Engine; return 1; } @@ -72,7 +72,7 @@ int main() { glXMakeCurrent(display, win, context); if (glewInit()) { - Log("FATAL! glewInit failed!\n"); + LOG("FATAL! glewInit failed!"); return 0; } diff --git a/msg.cpp b/msg.cpp deleted file mode 100644 index 6b19779..0000000 --- a/msg.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include -#include -#include -#include -#include -#include "msg.h" - -FILE *logfile; - -bool initLog(const char* filename) { - return true; - if (logfile) - if (!closeLog()) - return false; - - logfile = fopen(filename, "w"); - if (!logfile) - return false; - - time_t tmp_time; - time(&tmp_time); - Log("Legendary log system initialised %s", ctime(&tmp_time)); - - return true; -} - -bool closeLog() { - return true; - Log("Legendary log system shutting down.\n"); - if (!logfile) - return true; - if (!fclose(logfile)) - return false; - return true; -} - - -void Log(const char * format, ...) { - return; - - va_list argptr; - va_start(argptr, format); - char buf[255]; - int len = vsnprintf(buf, 256, format, argptr); - va_end(argptr); - LOG(buf); - return; - if (!logfile) - return; - if (!fwrite(buf, 1, len, logfile)) - return; - fflush(logfile); -} diff --git a/msg.h b/msg.h index e50b510..b7d63f8 100644 --- a/msg.h +++ b/msg.h @@ -1,18 +1,7 @@ -#ifndef __msg_h_ -#define __msg_h_ - -#define LOG(text) std::cout << __PRETTY_FUNCTION__ << " (" << __FILE__ << ":" << __LINE__ << "): " << text << std::endl; - +#ifndef MSG_H +#define MSG_H #include -bool initLog(const char *filename); -bool closeLog(); -void Log(const char *format, ...); - -extern FILE *logfile; -extern char *logfilename; - - -#define printf BRUK_LOG_DIN_KUKFAEN +#define LOG(text) std::cout << __PRETTY_FUNCTION__ << " (" << __FILE__ << ":" << __LINE__ << "): " << text << std::endl; #endif diff --git a/rtt.cpp b/rtt.cpp index 1b0a108..168be95 100644 --- a/rtt.cpp +++ b/rtt.cpp @@ -16,7 +16,7 @@ void RenderToTextureMaterial::genTO() { GLuint FBO; GLuint RBO; - Log("Generating texture\n"); + LOG("Generating texture"); glGenTextures(1, &TO); glBindTexture(GL_TEXTURE_2D, TO); @@ -37,7 +37,7 @@ void RenderToTextureMaterial::genTO() { glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, TO, 0); glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, RBO); if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE_EXT) - Log("Framebuffer panic!\n"); + LOG("Framebuffer panic!\n"); glPushAttrib(GL_VIEWPORT_BIT); glViewport(0, 0, 512, 512); diff --git a/vboobject.cpp b/vboobject.cpp index e31ee39..925cbf0 100644 --- a/vboobject.cpp +++ b/vboobject.cpp @@ -76,26 +76,40 @@ void VboObject::draw() { static float i=0; i+=0.20; - GLfloat transform[16] = { + + // Set an identity matrix + const GLfloat transform[16] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, loc.x, loc.y, loc.z, 1 }; glLoadMatrixf(transform); + + // Bind our buffers glBindBuffer(GL_ARRAY_BUFFER, VBO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO); + + // Enable shit glEnableClientState(GL_VERTEX_ARRAY); - //glEnableClientState(GL_COLOR_ARRAY); - //glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + + // Rotate to base glRotatef(i, 1, 1, 1); + + // Point to our vertices glVertexPointer(3, GL_FLOAT, 0, 0); - //glColorPointer(3, GL_UNSIGNED_BYTE, 0, (GLvoid *)VBO_size_vertices); - //glTexCoordPointer(2, GL_FLOAT, 0, (GLvoid *)(VBO_size_vertices+VBO_size_colours)); + + glColorPointer(3, GL_UNSIGNED_BYTE, 0, (GLvoid *)VBO_size_vertices); + glTexCoordPointer(2, GL_FLOAT, 0, (GLvoid *)(VBO_size_vertices+VBO_size_colours)); glDrawElements(GL_TRIANGLES, VBO_indices, INDEX_SIZE, 0); + + // Return to previous state glDisableClientState(GL_VERTEX_ARRAY); - //glDisableClientState(GL_COLOR_ARRAY); - //glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); }