|
|
|
|
@ -58,6 +58,7 @@ void fillHexLineBuffer(GLfloat buf[], int len, std::vector<hex_info>* hexes);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// globals
|
|
|
|
|
// TODO: store scene_matrices on camera object
|
|
|
|
|
static gl_matrix_info g_scene_matrices; |
|
|
|
|
static render_group* g_filled_hex_render_group; |
|
|
|
|
static render_group* g_hex_line_render_group; |
|
|
|
|
@ -67,11 +68,13 @@ static rg_shader_program g_default_shader;
|
|
|
|
|
static camera g_camera; |
|
|
|
|
|
|
|
|
|
// TODO: testing lighting
|
|
|
|
|
static renPointLight g_test_light; |
|
|
|
|
//static renPointLight g_test_light;
|
|
|
|
|
// TODO: maybe keep all these globals in the render_state object?
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// interface
|
|
|
|
|
|
|
|
|
|
// TODO: maybe make this a contructor for render_state?
|
|
|
|
|
bool |
|
|
|
|
initRenderer(SDL_Handles &handles, v2i vpDims) |
|
|
|
|
{ |
|
|
|
|
@ -146,6 +149,21 @@ initRenderer(SDL_Handles &handles, v2i vpDims)
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
freeBuffers(render_state* rs) |
|
|
|
|
{ |
|
|
|
|
utilSafeFree(rs->lights); |
|
|
|
|
|
|
|
|
|
std::vector<render_group*> groups = { |
|
|
|
|
g_filled_hex_render_group, |
|
|
|
|
g_hex_line_render_group, |
|
|
|
|
g_debug_render_group, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
for (render_group* group : groups) |
|
|
|
|
rgFree(group); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool |
|
|
|
|
addTexture(SDL_Handles &handles, const char * path) |
|
|
|
|
{ |
|
|
|
|
@ -201,7 +219,7 @@ getCameraPosition()
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool |
|
|
|
|
createScene(std::vector<hex_info>* hexes, Entity* entities, uint32 entity_count) |
|
|
|
|
createScene(render_state* rs, std::vector<hex_info>* hexes, Entity* entities, uint32 entity_count) |
|
|
|
|
{ |
|
|
|
|
// entities
|
|
|
|
|
|
|
|
|
|
@ -245,11 +263,16 @@ createScene(std::vector<hex_info>* hexes, Entity* entities, uint32 entity_count)
|
|
|
|
|
// lights
|
|
|
|
|
|
|
|
|
|
// TODO: load light properties from scene/level files
|
|
|
|
|
g_test_light.light_ID = glGetUniformLocation(g_default_shader.program_id, "light_position"); |
|
|
|
|
g_test_light.position = glm::vec3(800, 300, 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; |
|
|
|
|
// light testing
|
|
|
|
|
// TODO: allocate this in scene_loader... or initRenderer?
|
|
|
|
|
rs->lights = UTIL_ALLOC(rs->max_lights, rg_point_light); |
|
|
|
|
#if 1 |
|
|
|
|
rs->lights[0].light_ID = 0; |
|
|
|
|
rs->lights[0].position = glm::vec3(0.f, 0.f, 200.f); |
|
|
|
|
rs->lights[0].color = glm::vec3(1.f, 1.f, 1.f); |
|
|
|
|
rs->lights[0].intensity = 1.f; |
|
|
|
|
rs->num_lights = 1; |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
@ -340,7 +363,7 @@ rollCamera(bool CW, bool CCW)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
renderFrame(std::vector<hex_info> *hexes, Entity* entities, uint32 entity_count) |
|
|
|
|
renderFrame(render_state* rs, std::vector<hex_info> *hexes, Entity* entities, uint32 entity_count) |
|
|
|
|
{ |
|
|
|
|
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); |
|
|
|
|
@ -356,21 +379,21 @@ renderFrame(std::vector<hex_info> *hexes, Entity* entities, uint32 entity_count)
|
|
|
|
|
gl_buffer& color_buf = rg->render_objects[0]->color_buffer; |
|
|
|
|
fillColorBuffer(color_buf.buffer, color_buf.buffer_len, hexes); |
|
|
|
|
rgDraw(rg, m_model, m_view, m_projection, |
|
|
|
|
g_test_light.position, g_test_light.light_ID, false, true); |
|
|
|
|
rs->lights, rs->num_lights, false, true); |
|
|
|
|
|
|
|
|
|
// hex lines
|
|
|
|
|
rgDraw(g_hex_line_render_group, m_model, m_view, m_projection, |
|
|
|
|
g_test_light.position, g_test_light.light_ID); |
|
|
|
|
rs->lights, rs->num_lights); |
|
|
|
|
|
|
|
|
|
// entities
|
|
|
|
|
for (uint i = 0; i < entity_count; i++) { |
|
|
|
|
rgDraw(entities[i].ren_group, entities[i].world_transform , m_view, m_projection, |
|
|
|
|
g_test_light.position, g_test_light.light_ID); |
|
|
|
|
rs->lights, rs->num_lights); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
renderDebug(std::vector<Point> &vertices) |
|
|
|
|
renderDebug(render_state* rs, std::vector<Point> &vertices) |
|
|
|
|
{ |
|
|
|
|
GLfloat* buf = g_debug_render_group->render_objects[0]->vertex_buffer.buffer; |
|
|
|
|
buf[0] = vertices[0].x; buf[1] = vertices[0].y; buf[2] = 0; |
|
|
|
|
@ -379,20 +402,7 @@ renderDebug(std::vector<Point> &vertices)
|
|
|
|
|
buf[9] = vertices[3].x; buf[10] = vertices[3].y; buf[11] = 0; |
|
|
|
|
|
|
|
|
|
rgDraw(g_debug_render_group, g_scene_matrices.model, g_scene_matrices.view, |
|
|
|
|
g_scene_matrices.projection, g_test_light.position, g_test_light.light_ID, true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
freeBuffers() |
|
|
|
|
{ |
|
|
|
|
std::vector<render_group*> groups = { |
|
|
|
|
g_filled_hex_render_group, |
|
|
|
|
g_hex_line_render_group, |
|
|
|
|
g_debug_render_group, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
for (render_group* group : groups) |
|
|
|
|
rgFree(group); |
|
|
|
|
g_scene_matrices.projection, rs->lights, rs->num_lights, true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|