|
|
|
|
@ -90,6 +90,10 @@ gl_render_group* g_entity_render_group = rgCreateGroup();
|
|
|
|
|
camera g_camera; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: testing lighting
|
|
|
|
|
renPointLight g_test_light; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool |
|
|
|
|
addTexture(SDL_Handles &handles, const char * path) |
|
|
|
|
{ |
|
|
|
|
@ -375,7 +379,7 @@ createScene(std::vector<hex_info>* hexes, Entity* entities, uint32 entity_count)
|
|
|
|
|
int hex_count = (int) hexes->size(); |
|
|
|
|
// 6 triangles * 3 vertices per triangle * 3 floats per vertex = 54
|
|
|
|
|
int vbuf_len = hex_count * 6 * 3 * 3; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: surely there's a way to use indexed drawing for line vertices eg) line_loop
|
|
|
|
|
// and still use one buffer for multiple shapes/paths gldrawarraysintanced?, gldrawelements?
|
|
|
|
|
// https://gamedev.stackexchange.com/questions/104310/opengl-4-5-primitive-restart-vs-base-index
|
|
|
|
|
@ -389,19 +393,31 @@ createScene(std::vector<hex_info>* hexes, Entity* entities, uint32 entity_count)
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < hex_count; i++) |
|
|
|
|
fillTriangleBufferFromHex(vbuf, 54 * i, (*hexes)[i]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rgInitGLBufferObject(&g_filled_hex_render_group->vertex_buffer, vbuf_len, |
|
|
|
|
GL_DYNAMIC_DRAW, GL_ARRAY_BUFFER, vbuf); |
|
|
|
|
|
|
|
|
|
// color data for hex vertices
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rgFillColorBuffer(cbuf, vbuf_len, hexes); |
|
|
|
|
rgInitGLBufferObject(&g_filled_hex_render_group->color_buffer, vbuf_len, |
|
|
|
|
GL_DYNAMIC_DRAW, GL_ARRAY_BUFFER, cbuf); |
|
|
|
|
|
|
|
|
|
// hex line vertex data
|
|
|
|
|
// cheat at vertex normals since all hexes lay flat on z-axis
|
|
|
|
|
|
|
|
|
|
GLfloat* normal_buf = (GLfloat*) std::calloc(vbuf_len, sizeof(GLfloat)); |
|
|
|
|
for (int i = 0; i < vbuf_len; i += 3) { |
|
|
|
|
normal_buf[i] = 0; |
|
|
|
|
normal_buf[i + 1] = 0; |
|
|
|
|
normal_buf[i + 2] = 1; |
|
|
|
|
} |
|
|
|
|
rgInitGLBufferObject(&g_filled_hex_render_group->vertex_normals, vbuf_len, |
|
|
|
|
GL_STATIC_DRAW, GL_ARRAY_BUFFER, normal_buf); |
|
|
|
|
g_filled_hex_render_group->use_normals = true; |
|
|
|
|
|
|
|
|
|
// hex line vertex data
|
|
|
|
|
|
|
|
|
|
fillHexLineBuffer(line_buf, line_buf_len, hexes); |
|
|
|
|
rgInitGLBufferObject(&g_hex_line_render_group->vertex_buffer, line_buf_len, |
|
|
|
|
GL_STATIC_DRAW, GL_ARRAY_BUFFER, line_buf); |
|
|
|
|
@ -412,7 +428,8 @@ createScene(std::vector<hex_info>* hexes, Entity* entities, uint32 entity_count)
|
|
|
|
|
std::free(vbuf); |
|
|
|
|
std::free(cbuf); |
|
|
|
|
std::free(line_buf); |
|
|
|
|
vbuf = cbuf = line_buf = nullptr; |
|
|
|
|
std::free(normal_buf); |
|
|
|
|
vbuf = cbuf = line_buf = normal_buf = nullptr; |
|
|
|
|
|
|
|
|
|
// debug draw vertexes
|
|
|
|
|
int len = 4 * 3; // 4 vertices, 3 floats per vertex
|
|
|
|
|
@ -421,9 +438,20 @@ createScene(std::vector<hex_info>* hexes, Entity* entities, uint32 entity_count)
|
|
|
|
|
|
|
|
|
|
// entities
|
|
|
|
|
|
|
|
|
|
// TODO: wtf, I only accounted for 1 entity in the entity render group :(
|
|
|
|
|
// probably need one render_group struct for each entity
|
|
|
|
|
for (uint i = 0; i < entity_count; i++) |
|
|
|
|
rgInitEntity(g_entity_render_group, &entities[i]); |
|
|
|
|
|
|
|
|
|
// lights
|
|
|
|
|
// TODO: load light properties from scene/level files
|
|
|
|
|
|
|
|
|
|
g_test_light.light_ID = glGetUniformLocation(g_entity_render_group->program_id, "light_position"); |
|
|
|
|
g_test_light.position = glm::vec3(640, 500, 400); // above center of hexgrid
|
|
|
|
|
g_test_light.direction = glm::vec3(0, 0, 0) - g_test_light.position; // back towards test entity
|
|
|
|
|
g_test_light.color = glm::vec3(1.f, 1.f, 1.f); |
|
|
|
|
g_test_light.intensity = 1.f; |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -527,21 +555,26 @@ renderFrame(std::vector<hex_info> *hexes, Entity* entities, uint32 entity_count)
|
|
|
|
|
// get new colors every frame
|
|
|
|
|
gl_render_group* rg = g_filled_hex_render_group; |
|
|
|
|
rgFillColorBuffer(rg->color_buffer.buffer, rg->color_buffer.buffer_len, hexes); |
|
|
|
|
rgDraw(rg, GL_TRIANGLES, m_model, m_view, m_projection); |
|
|
|
|
rgDraw(rg, GL_TRIANGLES, m_model, m_view, m_projection, |
|
|
|
|
g_test_light.position, g_test_light.light_ID); |
|
|
|
|
|
|
|
|
|
// hex lines
|
|
|
|
|
|
|
|
|
|
rgDraw(g_hex_line_render_group, GL_LINES, m_model, m_view, m_projection); |
|
|
|
|
//rgDraw(g_hex_line_render_group, GL_LINES, m_model, m_view, m_projection);
|
|
|
|
|
|
|
|
|
|
// TODO: update and send array of lights (pos, dir, color, intesity to shaders
|
|
|
|
|
// every frame through rgDrawIndexed()
|
|
|
|
|
// entities
|
|
|
|
|
for (uint i = 0; i < entity_count; i++) { |
|
|
|
|
rgDrawIndexed( |
|
|
|
|
g_entity_render_group, GL_TRIANGLES, |
|
|
|
|
entities[i].mesh->model_transform, m_view, m_projection |
|
|
|
|
entities[i].mesh->model_transform, m_view, m_projection, |
|
|
|
|
g_test_light.position, g_test_light.light_ID |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#if 0 |
|
|
|
|
void |
|
|
|
|
renderDebug(std::vector<Point> &vertices) |
|
|
|
|
{ |
|
|
|
|
@ -561,6 +594,7 @@ renderDebug(std::vector<Point> &vertices)
|
|
|
|
|
rgDraw(rg, GL_LINE_LOOP, g_scene_matrices.model, g_scene_matrices.view, |
|
|
|
|
g_scene_matrices.projection, true); |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
freeBuffers() |
|
|
|
|
|