Browse Source

remove scene light dependancy on entity array

master
cinnaboot 8 years ago
parent
commit
d045374f9f
  1. 8
      src/render_group.cpp
  2. 34
      src/renderer.cpp

8
src/render_group.cpp

@ -288,12 +288,12 @@ drawRenderObject(render_group* rg, render_object* ro,
glUniformMatrix4fv(rg->shader.model_matrix_id, 1, GL_FALSE, &model_matrix[0][0]); glUniformMatrix4fv(rg->shader.model_matrix_id, 1, GL_FALSE, &model_matrix[0][0]);
glUniformMatrix4fv(rg->shader.view_matrix_id, 1, GL_FALSE, &view_matrix[0][0]); glUniformMatrix4fv(rg->shader.view_matrix_id, 1, GL_FALSE, &view_matrix[0][0]);
glUniformMatrix4fv(rg->shader.projection_matrix_id, 1, GL_FALSE, &projection_matrix[0][0]); glUniformMatrix4fv(rg->shader.projection_matrix_id, 1, GL_FALSE, &projection_matrix[0][0]);
// 1st attribute buffer : vertices // 1st attribute buffer : vertices
glEnableVertexAttribArray(0); glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, ro->vertex_buffer.buffer_id); glBindBuffer(GL_ARRAY_BUFFER, ro->vertex_buffer.buffer_id);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*) 0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*) 0);
if (update_vertex_data) if (update_vertex_data)
{ {
glBufferSubData(GL_ARRAY_BUFFER, 0, ro->vertex_buffer.buffer_len * sizeof(GLfloat), glBufferSubData(GL_ARRAY_BUFFER, 0, ro->vertex_buffer.buffer_len * sizeof(GLfloat),
@ -306,7 +306,7 @@ drawRenderObject(render_group* rg, render_object* ro,
glEnableVertexAttribArray(1); glEnableVertexAttribArray(1);
glBindBuffer(GL_ARRAY_BUFFER, ro->color_buffer.buffer_id); glBindBuffer(GL_ARRAY_BUFFER, ro->color_buffer.buffer_id);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*) 0); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*) 0);
// TODO: maybe add an option to not send color data every frame? // TODO: maybe add an option to not send color data every frame?
glBufferSubData(GL_ARRAY_BUFFER, 0, ro->color_buffer.buffer_len * sizeof(GLfloat), glBufferSubData(GL_ARRAY_BUFFER, 0, ro->color_buffer.buffer_len * sizeof(GLfloat),
ro->color_buffer.buffer); ro->color_buffer.buffer);
@ -331,7 +331,7 @@ drawRenderObject(render_group* rg, render_object* ro,
} else { } else {
glDrawArrays(rg->draw_mode, 0, ro->vertex_buffer.buffer_len / 3); glDrawArrays(rg->draw_mode, 0, ro->vertex_buffer.buffer_len / 3);
} }
// cleanup // cleanup
glDisableVertexAttribArray(0); glDisableVertexAttribArray(0);
if (ro->color_buffer.buffer) if (ro->color_buffer.buffer)

34
src/renderer.cpp

@ -7,7 +7,7 @@
//#include <GL/glew.h> //#include <GL/glew.h>
#include <GL/gl3w.h> #include <GL/gl3w.h>
#if defined (_WIN32) #if defined (_WIN32)
#include <SDL.h> #include <SDL.h>
#else #else
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
@ -104,7 +104,7 @@ initRenderer(SDL_Handles &handles, v2i vpDims)
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
SDL_GetCurrentDisplayMode(0, &handles.currentDisplayMode); SDL_GetCurrentDisplayMode(0, &handles.currentDisplayMode);
handles.window = handles.window =
SDL_CreateWindow("hexgame", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SDL_CreateWindow("hexgame", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
vpDims.x, vpDims.y, SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE); vpDims.x, vpDims.y, SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE);
@ -112,7 +112,7 @@ initRenderer(SDL_Handles &handles, v2i vpDims)
LOG(ERROR) << "Error creating window: " << SDL_GetError() << "\n"; LOG(ERROR) << "Error creating window: " << SDL_GetError() << "\n";
return false; return false;
} }
handles.glContext = SDL_GL_CreateContext(handles.window); handles.glContext = SDL_GL_CreateContext(handles.window);
if (!handles.glContext) { if (!handles.glContext) {
@ -133,7 +133,7 @@ initRenderer(SDL_Handles &handles, v2i vpDims)
LOG(INFO) << "opengl vendor: " << glGetString(GL_VENDOR) << "\n"; LOG(INFO) << "opengl vendor: " << glGetString(GL_VENDOR) << "\n";
LOG(INFO)<< "opengl renderer: " << glGetString(GL_RENDERER) << "\n"; LOG(INFO)<< "opengl renderer: " << glGetString(GL_RENDERER) << "\n";
LOG(INFO) << "opengl version: " << glGetString(GL_VERSION) << "\n"; LOG(INFO) << "opengl version: " << glGetString(GL_VERSION) << "\n";
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glEnable(GL_LINE_SMOOTH); glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND); glEnable(GL_BLEND);
@ -256,15 +256,11 @@ createScene(std::vector<hex_info>* hexes, Entity* entities, uint32 entity_count)
// lights // lights
// TODO: load light properties from scene/level files // TODO: load light properties from scene/level files
g_test_light.light_ID = glGetUniformLocation(g_default_shader.program_id, "light_position");
//g_test_light.light_ID = glGetUniformLocation(g_entity_render_group.program_id, "light_position"); g_test_light.position = glm::vec3(800, 300, 400); // above center of hexgrid
if (entities[0].ren_group != nullptr) { g_test_light.direction = glm::vec3(0, 0, 0) - g_test_light.position; // back towards test entity
g_test_light.light_ID = glGetUniformLocation(entities[0].ren_group->shader.program_id, "light_position"); g_test_light.color = glm::vec3(1.f, 1.f, 1.f);
g_test_light.position = glm::vec3(800, 300, 400); // above center of hexgrid g_test_light.intensity = 1.f;
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; return true;
} }
@ -280,7 +276,7 @@ moveCamera(bool up, bool left, bool down, bool right, bool forward, bool backwar
glm::vec3 old = g_camera.position; glm::vec3 old = g_camera.position;
glm::vec3 &p = g_camera.position; glm::vec3 &p = g_camera.position;
glm::vec3 v(0.f); // normalized direction glm::vec3 v(0.f); // normalized direction
// TODO: still seems like we're adding magnitude when moving in 2 directions // TODO: still seems like we're adding magnitude when moving in 2 directions
#if 0 #if 0
if (forward) v = glm::normalize(v + f); if (forward) v = glm::normalize(v + f);
@ -301,7 +297,7 @@ moveCamera(bool up, bool left, bool down, bool right, bool forward, bool backwar
p += (v * MOVE_SPEED); p += (v * MOVE_SPEED);
glm::vec3 diff = old - p; glm::vec3 diff = old - p;
g_scene_matrices.view = glm::translate(g_scene_matrices.view, diff); g_scene_matrices.view = glm::translate(g_scene_matrices.view, diff);
g_scene_matrices.MVP = g_scene_matrices.projection * g_scene_matrices.view * g_scene_matrices.model; g_scene_matrices.MVP = g_scene_matrices.projection * g_scene_matrices.view * g_scene_matrices.model;
} }
void void
@ -317,7 +313,7 @@ rotateCamera(int32 xrel, int32 yrel)
float a = glm::radians(CAMERA_Z_CLAMP_ANGLE); float a = glm::radians(CAMERA_Z_CLAMP_ANGLE);
if (v < (-1 * a)) v = (-1 * a); if (v < (-1 * a)) v = (-1 * a);
if (v > a) v = a; if (v > a) v = a;
c.forward = glm::vec3( c.forward = glm::vec3(
glm::cos(v) * glm::sin(h), glm::cos(v) * glm::sin(h),
glm::cos(v) * glm::cos(h), glm::cos(v) * glm::cos(h),
@ -330,7 +326,7 @@ rotateCamera(int32 xrel, int32 yrel)
c.up = glm::normalize(glm::cross(c.left, c.forward)); c.up = glm::normalize(glm::cross(c.left, c.forward));
g_scene_matrices.view = glm::lookAt(c.position, c.position + c.forward, c.up); g_scene_matrices.view = glm::lookAt(c.position, c.position + c.forward, c.up);
g_scene_matrices.MVP = g_scene_matrices.projection * g_scene_matrices.view * g_scene_matrices.model; g_scene_matrices.MVP = g_scene_matrices.projection * g_scene_matrices.view * g_scene_matrices.model;
} }
// NOTE: don't need this yet // NOTE: don't need this yet
@ -350,7 +346,7 @@ rollCamera(bool CW, bool CCW)
v = v * m; v = v * m;
g_camera.up = glm::vec3(v.x, v.y, v.z); g_camera.up = glm::vec3(v.x, v.y, v.z);
g_scene_matrices.view *= m; g_scene_matrices.view *= m;
g_scene_matrices.MVP = g_scene_matrices.projection * g_scene_matrices.view * g_scene_matrices.model; g_scene_matrices.MVP = g_scene_matrices.projection * g_scene_matrices.view * g_scene_matrices.model;
#endif #endif
} }
@ -405,7 +401,7 @@ freeBuffers()
g_hex_line_render_group, g_hex_line_render_group,
g_debug_render_group, g_debug_render_group,
}; };
for (render_group* group : groups) for (render_group* group : groups)
rgFree(group); rgFree(group);
} }

Loading…
Cancel
Save