diff --git a/src/renderer.h b/src/renderer.h index f13ce6a..6ba0004 100644 --- a/src/renderer.h +++ b/src/renderer.h @@ -2,7 +2,6 @@ #ifndef RENDERER_H #define RENDERER_H -#include // malloc/calloc // TODO: remove for better logging #include // std::cout @@ -18,18 +17,19 @@ // Interface bool initRenderer(SDL_Handles &handles, v2i vpDims); +// TODO: re-implement debug erender void debugRender(HexDrawMode mode, hex_info *startHex, hex_info *currentHex); void render(const vector *hexes); -// Implementation +// forward declarations GLuint initShaders(); // enable debug output https://www.khronos.org/opengl/wiki/OpenGL_Error void openglDebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam); void createScene(vector* hexes); -void parseHexToGLBuffer(GLfloat* buf, int idx, Point origin, vector &verts); +void parseHexToGLBuffer(GLfloat buf[], int idx, const hex_info &hex); GLuint g_vertexbuffer; GLuint g_vertex_buffer_triangle_count; @@ -183,10 +183,7 @@ createScene(vector* hexes) for (int i = 0; i < (int) hex_count; i++) { - hex_info hxi = (*hexes)[i]; - Point p(hxi.XPos, hxi.YPos); - vector verts = hxi.vertices; - parseHexToGLBuffer(vbuf_data, buf_index * i, p, verts); + parseHexToGLBuffer(vbuf_data, buf_index * i, (*hexes)[i]); } g_vertex_buffer_triangle_count = buf_size / 3; @@ -197,49 +194,48 @@ createScene(vector* hexes) } void -parseHexToGLBuffer(GLfloat buf[], int idx, Point origin, vector &verts) +parseHexToGLBuffer(GLfloat buf[], int idx, const hex_info &hex) { - int buf_idx = idx; // triangles for (int i = 0; i < 6; i++) { if (i == 5) // wrap { // vertex 0 - buf[buf_idx + 0] = (GLfloat) origin.x; - buf[buf_idx + 1] = (GLfloat) origin.y; - buf[buf_idx + 2] = (GLfloat) 0.f; + buf[idx + 0] = (GLfloat) hex.XPos; + buf[idx + 1] = (GLfloat) hex.YPos; + buf[idx + 2] = (GLfloat) 0.f; // vertex 1 - buf[buf_idx + 3] = (GLfloat) verts[i].x; - buf[buf_idx + 4] = (GLfloat) verts[i].y; - buf[buf_idx + 5] = (GLfloat) 0.f; - - // vertex 1 - buf[buf_idx + 6] = (GLfloat) verts[0].x; - buf[buf_idx + 7] = (GLfloat) verts[0].y; - buf[buf_idx + 8] = (GLfloat) 0.f; + buf[idx + 3] = (GLfloat) hex.vertices[i].x; + buf[idx + 4] = (GLfloat) hex.vertices[i].y; + buf[idx + 5] = (GLfloat) 0.f; + + // vertex 2 + buf[idx + 6] = (GLfloat) hex.vertices[0].x; + buf[idx + 7] = (GLfloat) hex.vertices[0].y; + buf[idx + 8] = (GLfloat) 0.f; } else { // vertex 0 - buf[buf_idx + 0] = (GLfloat) origin.x; - buf[buf_idx + 1] = (GLfloat) origin.y; - buf[buf_idx + 2] = (GLfloat) 0.f; - - // vertex 1 - buf[buf_idx + 3] = (GLfloat) verts[i].x; - buf[buf_idx + 4] = (GLfloat) verts[i].y; - buf[buf_idx + 5] = (GLfloat) 0.f; + buf[idx + 0] = (GLfloat) hex.XPos; + buf[idx + 1] = (GLfloat) hex.YPos; + buf[idx + 2] = (GLfloat) 0.f; // vertex 1 - buf[buf_idx + 6] = (GLfloat) verts[i + 1].x; - buf[buf_idx + 7] = (GLfloat) verts[i + 1].y; - buf[buf_idx + 8] = (GLfloat) 0.f; + buf[idx + 3] = (GLfloat) hex.vertices[i].x; + buf[idx + 4] = (GLfloat) hex.vertices[i].y; + buf[idx + 5] = (GLfloat) 0.f; + + // vertex 2 + buf[idx + 6] = (GLfloat) hex.vertices[i + 1].x; + buf[idx + 7] = (GLfloat) hex.vertices[i + 1].y; + buf[idx + 8] = (GLfloat) 0.f; } // we've added 9 GLfloats per loop - buf_idx += 9; + idx += 9; } }