diff --git a/src/hexgame.cpp b/src/hexgame.cpp index dab1812..f7d2f52 100644 --- a/src/hexgame.cpp +++ b/src/hexgame.cpp @@ -1,9 +1,9 @@ // Some defaults for the game layout -#define HEX_SIZE 25 -#define HEX_RADIUS 7 +#define HEX_SIZE 20 +#define HEX_RADIUS 9 #define HEX_ORIENTATION layout_flat -#define FILL_COLOR 0x5C5C5CFF +#define FILL_COLOR 0x565656FF #define SELECTED_FILL_COLOR 0xF46000FF #define DEBUG_DRAW true #define VIEWPORT_WIDTH 1280 @@ -35,7 +35,7 @@ void createHexes(vector *hxi_array, const Layout &layout, uint32 color) { // create a hexagonal grid of hexagons - int map_radius = 7; + int map_radius = HEX_RADIUS; for (int q = -map_radius; q <= map_radius; q++) { int r1 = std::max(-map_radius, -q - map_radius); diff --git a/src/renderer.h b/src/renderer.h index dd2ae57..99507bf 100644 --- a/src/renderer.h +++ b/src/renderer.h @@ -110,6 +110,7 @@ void openglDebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam); void fillTriangleBufferFromHex(GLfloat buf[], int idx, const hex_info &hex); void fillColorBuffer(GLfloat buf[], int len, std::vector *hexes); +void convertColor(GLfloat buf[], uint32 color); void fillHexLineBuffer(GLfloat buf[], int len, std::vector* hexes); bool checkGLBufferSize(GLenum buf_type, int expected_size, int line_num); bool initGLBufferObject(gl_buffer* buf_obj, int len, GLenum usage, GLfloat data[]); @@ -319,19 +320,34 @@ fillTriangleBufferFromHex(GLfloat buf[], int idx, const hex_info &hex) } } +// NOTE: helper for fillColorBuffer() to convert uint32 color to GLfloat triplet +void +convertColor(GLfloat buf[3], uint32 color) +{ + // NOTE: not using the alpha values for now + buf[0] = (GLfloat) ((color >> 24) & 0xFF) / (GLfloat) 255; + buf[1] = (GLfloat) ((color >> 16) & 0xFF) / (GLfloat) 255; + buf[2] = (GLfloat) ((color >> 8) & 0xFF) / (GLfloat) 255; +} + void fillColorBuffer(GLfloat buf[], int len, std::vector* hexes) { int buf_idx; int buf_len_per_hex = 54; // NOTE: 3 * 3 * 6 + GLfloat color_buf[3]; for (int i = 0; i < (int) hexes->size(); i++) { buf_idx = i * buf_len_per_hex; hex_info hxi = (*hexes)[i]; - GLfloat color = (GLfloat) hxi.current_color / (GLfloat) UINT32_MAX; - - for (int j = 0; j < buf_len_per_hex; j++) - buf[buf_idx + j] = color; + convertColor(color_buf, hxi.current_color); + + for (int j = 0; j < buf_len_per_hex; j+=3) + { + buf[buf_idx + j] = color_buf[0]; + buf[buf_idx + j + 1] = color_buf[1]; + buf[buf_idx + j + 2] = color_buf[2]; + } } }