|
|
|
@ -20,7 +20,6 @@ |
|
|
|
#include "aixlog.hpp" |
|
|
|
#include "aixlog.hpp" |
|
|
|
|
|
|
|
|
|
|
|
#include "hexlib.h" |
|
|
|
#include "hexlib.h" |
|
|
|
#include "util.h" |
|
|
|
|
|
|
|
#include "hexgame.h" |
|
|
|
#include "hexgame.h" |
|
|
|
#include "renderer.h" |
|
|
|
#include "renderer.h" |
|
|
|
#include "render_group.h" |
|
|
|
#include "render_group.h" |
|
|
|
@ -31,29 +30,6 @@ |
|
|
|
//#define PROJ_TYPE ORTHOGRAPHIC
|
|
|
|
//#define PROJ_TYPE ORTHOGRAPHIC
|
|
|
|
#define PROJ_TYPE PERSPECTIVE |
|
|
|
#define PROJ_TYPE PERSPECTIVE |
|
|
|
|
|
|
|
|
|
|
|
const char * VERTEX_SHADER_CODE = |
|
|
|
|
|
|
|
"#version 330 core\n" |
|
|
|
|
|
|
|
"in vec3 vertexPosition_modelspace;\n" |
|
|
|
|
|
|
|
"in vec3 vertexColor;\n" |
|
|
|
|
|
|
|
"out vec3 fragmentColor;\n" |
|
|
|
|
|
|
|
"uniform mat4 model;\n" |
|
|
|
|
|
|
|
"uniform mat4 view;\n" |
|
|
|
|
|
|
|
"uniform mat4 projection;\n" |
|
|
|
|
|
|
|
"void main()\n" |
|
|
|
|
|
|
|
"{\n" |
|
|
|
|
|
|
|
" gl_Position = projection * view * model * vec4(vertexPosition_modelspace, 1);\n" |
|
|
|
|
|
|
|
" fragmentColor = vertexColor;\n" |
|
|
|
|
|
|
|
"}"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const char * FRAGMENT_SHADER_CODE = |
|
|
|
|
|
|
|
"#version 330 core\n" |
|
|
|
|
|
|
|
"in vec3 fragmentColor;\n" |
|
|
|
|
|
|
|
"out vec3 color;\n" |
|
|
|
|
|
|
|
"void main()\n" |
|
|
|
|
|
|
|
"{\n" |
|
|
|
|
|
|
|
" color = fragmentColor;\n" |
|
|
|
|
|
|
|
"}"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const char * LINE_FRAGMENT_SHADER_CODE = |
|
|
|
const char * LINE_FRAGMENT_SHADER_CODE = |
|
|
|
"#version 330 core\n" |
|
|
|
"#version 330 core\n" |
|
|
|
"out vec3 color;\n" |
|
|
|
"out vec3 color;\n" |
|
|
|
@ -193,11 +169,13 @@ initMatrices(projection_type p) |
|
|
|
glm::cos(v) * glm::cos(h), |
|
|
|
glm::cos(v) * glm::cos(h), |
|
|
|
glm::sin(v) |
|
|
|
glm::sin(v) |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glm::normalize(c.forward); |
|
|
|
//////
|
|
|
|
//////
|
|
|
|
|
|
|
|
|
|
|
|
g_camera.up = glm::vec3(0,1,0); |
|
|
|
g_camera.up = glm::vec3(0,1,0); |
|
|
|
g_camera.left = glm::normalize(glm::cross(g_camera.up, g_camera.forward)); |
|
|
|
g_camera.left = glm::normalize(glm::cross(g_camera.up, g_camera.forward)); |
|
|
|
g_camera.up = glm::cross(g_camera.forward, g_camera.left); |
|
|
|
g_camera.up = glm::normalize(glm::cross(g_camera.forward, g_camera.left)); |
|
|
|
|
|
|
|
|
|
|
|
g_scene_matrices.view = glm::lookAt( |
|
|
|
g_scene_matrices.view = glm::lookAt( |
|
|
|
g_camera.position, // camera position
|
|
|
|
g_camera.position, // camera position
|
|
|
|
@ -296,17 +274,20 @@ initRenderer(SDL_Handles &handles, v2i vpDims) |
|
|
|
// hide VRAM debug messages
|
|
|
|
// hide VRAM debug messages
|
|
|
|
glDebugMessageControl(GL_DONT_CARE, 33361, GL_DONT_CARE, 0, 0, GL_FALSE); |
|
|
|
glDebugMessageControl(GL_DONT_CARE, 33361, GL_DONT_CARE, 0, 0, GL_FALSE); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const char* vs_code = utilDumpTextFile("../data/default.vs"); |
|
|
|
|
|
|
|
const char* fs_code = utilDumpTextFile("../data/default.fs"); |
|
|
|
|
|
|
|
|
|
|
|
if (!rgInitShaderProgram( |
|
|
|
if (!rgInitShaderProgram( |
|
|
|
g_filled_hex_render_group, VERTEX_SHADER_CODE, FRAGMENT_SHADER_CODE, |
|
|
|
g_filled_hex_render_group, vs_code, fs_code, |
|
|
|
"model", "view", "projection") |
|
|
|
"model", "view", "projection") |
|
|
|
|| !rgInitShaderProgram( |
|
|
|
|| !rgInitShaderProgram( |
|
|
|
g_hex_line_render_group, VERTEX_SHADER_CODE, LINE_FRAGMENT_SHADER_CODE, |
|
|
|
g_hex_line_render_group, vs_code, LINE_FRAGMENT_SHADER_CODE, |
|
|
|
"model", "view", "projection") |
|
|
|
"model", "view", "projection") |
|
|
|
|| !rgInitShaderProgram( |
|
|
|
|| !rgInitShaderProgram( |
|
|
|
g_debug_render_group, VERTEX_SHADER_CODE, DEBUG_FRAGMENT_SHADER_CODE, |
|
|
|
g_debug_render_group, vs_code, DEBUG_FRAGMENT_SHADER_CODE, |
|
|
|
"model", "view", "projection") |
|
|
|
"model", "view", "projection") |
|
|
|
|| !rgInitShaderProgram( |
|
|
|
|| !rgInitShaderProgram( |
|
|
|
g_entity_render_group, VERTEX_SHADER_CODE, FRAGMENT_SHADER_CODE, |
|
|
|
g_entity_render_group, vs_code, fs_code, |
|
|
|
"model", "view", "projection")) |
|
|
|
"model", "view", "projection")) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
@ -424,6 +405,8 @@ createScene(std::vector<hex_info>* hexes, Entity* entities, uint32 entity_count) |
|
|
|
fillHexLineBuffer(line_buf, line_buf_len, hexes); |
|
|
|
fillHexLineBuffer(line_buf, line_buf_len, hexes); |
|
|
|
rgInitGLBufferObject(&g_hex_line_render_group->vertex_buffer, line_buf_len, |
|
|
|
rgInitGLBufferObject(&g_hex_line_render_group->vertex_buffer, line_buf_len, |
|
|
|
GL_STATIC_DRAW, GL_ARRAY_BUFFER, line_buf); |
|
|
|
GL_STATIC_DRAW, GL_ARRAY_BUFFER, line_buf); |
|
|
|
|
|
|
|
// TODO: add a color buffer to hex_line and debug render groups to re-use
|
|
|
|
|
|
|
|
// fragment shaders and simplify draw rgDraw()
|
|
|
|
|
|
|
|
|
|
|
|
// free temporary buffers
|
|
|
|
// free temporary buffers
|
|
|
|
std::free(vbuf); |
|
|
|
std::free(vbuf); |
|
|
|
@ -456,24 +439,23 @@ moveCamera(bool up, bool left, bool down, bool right, bool forward, bool backwar |
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
if (forward) v += f; |
|
|
|
// TODO: still seems like we're adding magnitude when moving in 2 directions
|
|
|
|
|
|
|
|
#if 0 |
|
|
|
|
|
|
|
if (forward) v = glm::normalize(v + f); |
|
|
|
|
|
|
|
if (backward) v = glm::normalize(v - f); |
|
|
|
|
|
|
|
if (up) v = glm::normalize(v + u); |
|
|
|
|
|
|
|
if (down) v = glm::normalize(v - u); |
|
|
|
|
|
|
|
if (left) v -= glm::normalize(glm::cross(f, u)); |
|
|
|
|
|
|
|
if (right) v -= glm::normalize(glm::cross(u, f)); |
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
if (forward) v += f; |
|
|
|
if (backward) v -= f; |
|
|
|
if (backward) v -= f; |
|
|
|
if (up) v += u; |
|
|
|
if (up) v += u; |
|
|
|
if (down) v -= u; |
|
|
|
if (down) v -= u; |
|
|
|
if (left) |
|
|
|
if (left) v -= glm::cross(f, u); |
|
|
|
{ |
|
|
|
if (right) v -= glm::cross(u, f); |
|
|
|
glm::vec3 l = glm::cross(f, u); |
|
|
|
#endif |
|
|
|
v -= l; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (right) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
glm::vec3 r = glm::cross(u, f); |
|
|
|
|
|
|
|
v -= r; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: this still doesn't fix side to side movement magnitude when vAngle is
|
|
|
|
|
|
|
|
// close to +- 90 degrees
|
|
|
|
|
|
|
|
glm::normalize(v); |
|
|
|
|
|
|
|
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); |
|
|
|
@ -500,8 +482,10 @@ rotateCamera(int32 xrel, int32 yrel) |
|
|
|
glm::sin(v) |
|
|
|
glm::sin(v) |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glm::normalize(c.forward); |
|
|
|
c.up = glm::vec3(0,0,1); |
|
|
|
c.up = glm::vec3(0,0,1); |
|
|
|
c.left = glm::cross(c.forward, c.up); |
|
|
|
c.left = glm::normalize(glm::cross(c.forward, c.up)); |
|
|
|
|
|
|
|
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;
|
|
|
|
@ -553,7 +537,8 @@ renderFrame(std::vector<hex_info> *hexes, Entity* entities, uint32 entity_count) |
|
|
|
for (uint i = 0; i < entity_count; i++) { |
|
|
|
for (uint i = 0; i < entity_count; i++) { |
|
|
|
rgDrawIndexed( |
|
|
|
rgDrawIndexed( |
|
|
|
g_entity_render_group, GL_TRIANGLES, |
|
|
|
g_entity_render_group, GL_TRIANGLES, |
|
|
|
entities[i].mesh->model_transform, m_view, m_projection); |
|
|
|
entities[i].mesh->model_transform, m_view, m_projection |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|