|
|
|
|
@ -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 |
|
|
|
|
|