|
|
|
@ -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); |
|
|
|
} |
|
|
|
} |
|
|
|
|