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