organized the MyGLWindow::setup() in subfunctions, added support for indexed items in Dataset, added a Sphere object in Dataset
This commit is contained in:
parent
4fbdc1a180
commit
2fbd67f9c6
@ -146,8 +146,7 @@
|
|||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="CheckeredFloor.cpp" />
|
<ClCompile Include="Dataset.cpp" />
|
||||||
<ClCompile Include="ColorCube.cpp" />
|
|
||||||
<ClCompile Include="imgui\imgui.cpp" />
|
<ClCompile Include="imgui\imgui.cpp" />
|
||||||
<ClCompile Include="imgui\imgui_demo.cpp" />
|
<ClCompile Include="imgui\imgui_demo.cpp" />
|
||||||
<ClCompile Include="imgui\imgui_draw.cpp" />
|
<ClCompile Include="imgui\imgui_draw.cpp" />
|
||||||
@ -162,8 +161,6 @@
|
|||||||
<ClCompile Include="Viewer.cpp" />
|
<ClCompile Include="Viewer.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="CheckeredFloor.h" />
|
|
||||||
<ClInclude Include="ColorCube.h" />
|
|
||||||
<ClInclude Include="Dataset.h" />
|
<ClInclude Include="Dataset.h" />
|
||||||
<ClInclude Include="imgui\imconfig.h" />
|
<ClInclude Include="imgui\imconfig.h" />
|
||||||
<ClInclude Include="imgui\imgui.h" />
|
<ClInclude Include="imgui\imgui.h" />
|
||||||
@ -185,10 +182,12 @@
|
|||||||
<ClInclude Include="Viewer.h" />
|
<ClInclude Include="Viewer.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<None Include="base_light.frag" />
|
||||||
<None Include="fog.frag" />
|
<None Include="fog.frag" />
|
||||||
<None Include="fog.vert" />
|
<None Include="fog.vert" />
|
||||||
<None Include="light.frag" />
|
<None Include="base_light.vert" />
|
||||||
<None Include="light.vert">
|
<None Include="tex_base_light.frag" />
|
||||||
|
<None Include="tex_base_light.vert">
|
||||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Geometry</ShaderType>
|
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Geometry</ShaderType>
|
||||||
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">4.0</ShaderModel>
|
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">4.0</ShaderModel>
|
||||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Geometry</ShaderType>
|
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Geometry</ShaderType>
|
||||||
|
|||||||
@ -30,15 +30,9 @@
|
|||||||
<ClCompile Include="MyGLWindow.cpp">
|
<ClCompile Include="MyGLWindow.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="ColorCube.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Viewer.cpp">
|
<ClCompile Include="Viewer.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="CheckeredFloor.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="imgui\imgui.cpp">
|
<ClCompile Include="imgui\imgui.cpp">
|
||||||
<Filter>imgui</Filter>
|
<Filter>imgui</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
@ -66,6 +60,9 @@
|
|||||||
<ClCompile Include="Shader.cpp">
|
<ClCompile Include="Shader.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="Dataset.cpp">
|
||||||
|
<Filter>Models</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="ModelView.h">
|
<ClInclude Include="ModelView.h">
|
||||||
@ -107,12 +104,6 @@
|
|||||||
<ClInclude Include="Models\Mesh.h">
|
<ClInclude Include="Models\Mesh.h">
|
||||||
<Filter>Models</Filter>
|
<Filter>Models</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="ColorCube.h">
|
|
||||||
<Filter>Models</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="CheckeredFloor.h">
|
|
||||||
<Filter>Models</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="Light.h">
|
<ClInclude Include="Light.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
@ -136,15 +127,9 @@
|
|||||||
<None Include="simple.frag">
|
<None Include="simple.frag">
|
||||||
<Filter>Shaders</Filter>
|
<Filter>Shaders</Filter>
|
||||||
</None>
|
</None>
|
||||||
<None Include="light.vert">
|
|
||||||
<Filter>Shaders</Filter>
|
|
||||||
</None>
|
|
||||||
<None Include="simple.vert">
|
<None Include="simple.vert">
|
||||||
<Filter>Shaders</Filter>
|
<Filter>Shaders</Filter>
|
||||||
</None>
|
</None>
|
||||||
<None Include="light.frag">
|
|
||||||
<Filter>Shaders</Filter>
|
|
||||||
</None>
|
|
||||||
<None Include="onelight.frag">
|
<None Include="onelight.frag">
|
||||||
<Filter>Shaders</Filter>
|
<Filter>Shaders</Filter>
|
||||||
</None>
|
</None>
|
||||||
@ -163,6 +148,18 @@
|
|||||||
<None Include="fog.vert">
|
<None Include="fog.vert">
|
||||||
<Filter>Shaders</Filter>
|
<Filter>Shaders</Filter>
|
||||||
</None>
|
</None>
|
||||||
|
<None Include="tex_base_light.frag">
|
||||||
|
<Filter>Shaders</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="tex_base_light.vert">
|
||||||
|
<Filter>Shaders</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="base_light.frag">
|
||||||
|
<Filter>Shaders</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="base_light.vert">
|
||||||
|
<Filter>Shaders</Filter>
|
||||||
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Image Include="brick1.jpg">
|
<Image Include="brick1.jpg">
|
||||||
|
|||||||
@ -1,99 +0,0 @@
|
|||||||
//#include "CheckeredFloor.h"
|
|
||||||
//
|
|
||||||
//void CheckeredFloor::genVertices(std::vector<glm::vec4> &vertices,
|
|
||||||
// std::vector<glm::vec3> &colors)
|
|
||||||
//{
|
|
||||||
// float maxX = _size / 2.f, maxY = _size / 2.f;
|
|
||||||
// float minX = -_size / 2.f, minY = -_size / 2.f;
|
|
||||||
// float side_size = _size / (float)_squares;
|
|
||||||
// int color = 1;
|
|
||||||
//
|
|
||||||
// for (float x = minX; x < maxX; x += side_size)
|
|
||||||
// {
|
|
||||||
// for (float y = minY; y < maxY; y += side_size)
|
|
||||||
// {
|
|
||||||
// color *= -1;
|
|
||||||
// glm::vec3 tile_color = (color > 0) ? _light_color : _dark_color;
|
|
||||||
// //gen 1 carré
|
|
||||||
// vertices.emplace_back(x, 0, y, 1); //upleft
|
|
||||||
// vertices.emplace_back(x, 0, y + side_size, 1); //downleft
|
|
||||||
// vertices.emplace_back(x + side_size, 0, y + side_size, 1); //downright
|
|
||||||
//
|
|
||||||
// vertices.emplace_back(x + side_size, 0, y + side_size, 1); //downright
|
|
||||||
// vertices.emplace_back(x + side_size, 0, y, 1); //upright
|
|
||||||
// vertices.emplace_back(x, 0, y, 1); //upleft
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// for (int z = 0; z < 6; z++)
|
|
||||||
// colors.push_back(tile_color);
|
|
||||||
// }
|
|
||||||
// color *= -1;
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//void CheckeredFloor::setup()
|
|
||||||
//{
|
|
||||||
// std::vector<glm::vec4> floor_vertices;
|
|
||||||
// std::vector<glm::vec3> floor_colors;
|
|
||||||
//
|
|
||||||
// glGenVertexArrays(1, &_vaoHandle);
|
|
||||||
// glBindVertexArray(_vaoHandle);
|
|
||||||
//
|
|
||||||
// genVertices(floor_vertices, floor_colors);
|
|
||||||
//
|
|
||||||
// glGenBuffers(1, &_vbo_vertices);
|
|
||||||
// glBindBuffer(GL_ARRAY_BUFFER, _vbo_vertices);
|
|
||||||
// glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * floor_vertices.size() * 4, floor_vertices.data(), GL_STATIC_DRAW);
|
|
||||||
//
|
|
||||||
// glVertexAttribPointer(
|
|
||||||
// 0, //attr number = 0
|
|
||||||
// 4,
|
|
||||||
// GL_FLOAT,
|
|
||||||
// GL_FALSE,
|
|
||||||
// 0,
|
|
||||||
// (void*)0);
|
|
||||||
// glEnableVertexAttribArray(0); //attr number = 0
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// glGenBuffers(1, &_vbo_colors);
|
|
||||||
// glBindBuffer(GL_ARRAY_BUFFER, _vbo_colors);
|
|
||||||
// glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * floor_colors.size() * 3, floor_colors.data(), GL_STATIC_DRAW);
|
|
||||||
//
|
|
||||||
// glVertexAttribPointer(
|
|
||||||
// 1,
|
|
||||||
// 3,
|
|
||||||
// GL_FLOAT,
|
|
||||||
// GL_FALSE,
|
|
||||||
// 0,
|
|
||||||
// (void *)0);
|
|
||||||
// glEnableVertexAttribArray(1);
|
|
||||||
//
|
|
||||||
// glBindVertexArray(0);
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//CheckeredFloor::CheckeredFloor(int size, int squares) :
|
|
||||||
// _size(size), _squares(squares)
|
|
||||||
//{
|
|
||||||
// setup();
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//CheckeredFloor::~CheckeredFloor()
|
|
||||||
//{
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//void CheckeredFloor::draw(ShaderProgram * shader, glm::mat4x4 proj_matrix, glm::mat4x4 view_matrix)
|
|
||||||
//{
|
|
||||||
// _model.glPushMatrix();
|
|
||||||
// effectTransformations();
|
|
||||||
// glBindVertexArray(_vaoHandle);
|
|
||||||
// glm::mat4 mvpMatrix = proj_matrix * view_matrix * _model.getMatrix();
|
|
||||||
// glUniformMatrix4fv(shader->uniform("mvp"), 1, GL_FALSE, glm::value_ptr(mvpMatrix));
|
|
||||||
// glDrawArrays(GL_TRIANGLES, 0, _squares * _squares * 6);
|
|
||||||
// _model.glPopMatrix();
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//DrawableType CheckeredFloor::getType()
|
|
||||||
//{
|
|
||||||
// return DrawableType::CHECKERED_FLOOR;
|
|
||||||
//}
|
|
||||||
@ -1,31 +0,0 @@
|
|||||||
//#pragma once
|
|
||||||
//#define GLM_SWIZZLE
|
|
||||||
//#define GLM_ENABLE_EXPERIMENTAL
|
|
||||||
//#include <glm/glm.hpp>
|
|
||||||
//#include <glm/gtx/string_cast.hpp>
|
|
||||||
//#include <vector>
|
|
||||||
//#include "ADrawable.h"
|
|
||||||
//
|
|
||||||
//class CheckeredFloor : public ADrawable
|
|
||||||
//{
|
|
||||||
//private :
|
|
||||||
// GLuint _vaoHandle;
|
|
||||||
// GLuint _vbo_vertices, _vbo_colors;
|
|
||||||
//
|
|
||||||
// void genVertices(std::vector<glm::vec4> &vertices,
|
|
||||||
// std::vector<glm::vec3> &colors);
|
|
||||||
// void setup();
|
|
||||||
//
|
|
||||||
// glm::vec3 _light_color = {.7f, .7f, .7f};
|
|
||||||
// glm::vec3 _dark_color = {.3f, .3f, .3f};
|
|
||||||
//
|
|
||||||
// int _size;
|
|
||||||
// int _squares;
|
|
||||||
//
|
|
||||||
//public :
|
|
||||||
// CheckeredFloor(int size, int squares);
|
|
||||||
// ~CheckeredFloor();
|
|
||||||
// void draw(ShaderProgram *shader, glm::mat4x4 proj_matrix, glm::mat4x4 view_matrix) override;
|
|
||||||
// DrawableType getType() override;
|
|
||||||
//
|
|
||||||
//};
|
|
||||||
@ -1,211 +0,0 @@
|
|||||||
//#include "ColorCube.h"
|
|
||||||
//
|
|
||||||
//glm::vec3 computeNormal(glm::vec3 p1, glm::vec3 p2, glm::vec3 p3)
|
|
||||||
//{
|
|
||||||
// glm::vec3 v1 = p2 - p1;
|
|
||||||
// glm::vec3 v2 = p3 - p1;
|
|
||||||
//
|
|
||||||
// return glm::normalize(glm::cross(v1, v2));
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//void ColorCube::iboSetup()
|
|
||||||
//{
|
|
||||||
// std::vector<glm::vec3> cube_vertices =
|
|
||||||
// { { -1.0, -1.0, 1.0},
|
|
||||||
// { 1.0, -1.0, 1.0},
|
|
||||||
// { 1.0, 1.0, 1.0},
|
|
||||||
// { -1.0, 1.0, 1.0},
|
|
||||||
// { -1.0, -1.0, -1.0},
|
|
||||||
// { 1.0, -1.0, -1.0},
|
|
||||||
// { 1.0, 1.0, -1.0},
|
|
||||||
// { -1.0, 1.0, -1.0} };
|
|
||||||
//
|
|
||||||
// GLfloat cube_colors[] = {
|
|
||||||
// // front colors
|
|
||||||
// 1.0, 0.0, 0.0,
|
|
||||||
// 0.0, 1.0, 0.0,
|
|
||||||
// 0.0, 0.0, 1.0,
|
|
||||||
// 1.0, 1.0, 1.0,
|
|
||||||
// // back colors
|
|
||||||
// 1.0, 0.0, 0.0,
|
|
||||||
// 0.0, 1.0, 0.0,
|
|
||||||
// 0.0, 0.0, 1.0,
|
|
||||||
// 1.0, 1.0, 1.0,
|
|
||||||
// };
|
|
||||||
//
|
|
||||||
// GLushort cube_elements[] = {
|
|
||||||
// 0, 1, 2, 2, 3, 0, 1, 5, 6,
|
|
||||||
// 6, 2, 1, 7, 6, 5, 5, 4, 7,
|
|
||||||
// 4, 0, 3, 3, 7, 4, 4, 5, 1,
|
|
||||||
// 1, 0, 4, 3, 2, 6, 6, 7, 3,
|
|
||||||
// };
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// glGenVertexArrays(1, &_vaoHandle);
|
|
||||||
// glBindVertexArray(_vaoHandle);
|
|
||||||
//
|
|
||||||
// glGenBuffers(1, &_vbo_vertices);
|
|
||||||
// glBindBuffer(GL_ARRAY_BUFFER, _vbo_vertices);
|
|
||||||
// glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * cube_vertices.size() * 3, cube_vertices.data(), GL_STATIC_DRAW);
|
|
||||||
//
|
|
||||||
// glVertexAttribPointer(
|
|
||||||
// 0, //attr number = 0
|
|
||||||
// 3,
|
|
||||||
// GL_FLOAT,
|
|
||||||
// GL_FALSE,
|
|
||||||
// 0,
|
|
||||||
// (void*)0);
|
|
||||||
// glEnableVertexAttribArray(0); //attr number = 0
|
|
||||||
//
|
|
||||||
// glGenBuffers(1, &_vbo_colors);
|
|
||||||
// glBindBuffer(GL_ARRAY_BUFFER, _vbo_colors);
|
|
||||||
// glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 24, cube_colors, GL_STATIC_DRAW);
|
|
||||||
//
|
|
||||||
// glVertexAttribPointer(
|
|
||||||
// 1,
|
|
||||||
// 3,
|
|
||||||
// GL_FLOAT,
|
|
||||||
// GL_FALSE,
|
|
||||||
// 0,
|
|
||||||
// (void*)0);
|
|
||||||
// glEnableVertexAttribArray(1);
|
|
||||||
//
|
|
||||||
// glGenBuffers(1, &_iboHandle);
|
|
||||||
// glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _iboHandle);
|
|
||||||
// glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(cube_elements), cube_elements, GL_STATIC_DRAW);
|
|
||||||
//
|
|
||||||
// glBindVertexArray(0);
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//void ColorCube::vaoSetup()
|
|
||||||
//{
|
|
||||||
// std::vector<glm::vec3> cube_vertices =
|
|
||||||
// { { -1.0, -1.0, 1.0}, { 1.0, -1.0, 1.0}, { 1.0, 1.0, 1.0},
|
|
||||||
// { 1.0, 1.0, 1.0}, { -1.0, 1.0, 1.0}, { -1.0, -1.0, 1.0},
|
|
||||||
// { 1.0, -1.0, 1.0}, { 1.0, -1.0, -1.0}, { 1.0, 1.0, -1.0},
|
|
||||||
// { 1.0, 1.0, -1.0}, { 1.0, 1.0, 1.0}, { 1.0, -1.0, 1.0},
|
|
||||||
// { -1.0, 1.0, -1.0}, { 1.0, 1.0, -1.0}, { 1.0, -1.0, -1.0},
|
|
||||||
// { 1.0, -1.0, -1.0}, { -1.0, -1.0, -1.0}, { -1.0, 1.0, -1.0},
|
|
||||||
// { -1.0, -1.0, -1.0}, { -1.0, -1.0, 1.0}, { -1.0, 1.0, 1.0},
|
|
||||||
// { -1.0, 1.0, 1.0}, { -1.0, 1.0, -1.0}, { -1.0, -1.0, -1.0},
|
|
||||||
// { -1.0, -1.0, -1.0}, { 1.0, -1.0, -1.0}, { 1.0, -1.0, 1.0},
|
|
||||||
// { 1.0, -1.0, 1.0}, { -1.0, -1.0, 1.0}, { -1.0, -1.0, -1.0},
|
|
||||||
// { -1.0, 1.0, 1.0}, { 1.0, 1.0, 1.0}, { 1.0, 1.0, -1.0},
|
|
||||||
// { 1.0, 1.0, -1.0}, { -1.0, 1.0, -1.0}, { -1.0, 1.0, 1.0} };
|
|
||||||
//
|
|
||||||
// std::vector<GLfloat> cube_colors = {
|
|
||||||
// 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0,
|
|
||||||
// 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0,
|
|
||||||
// 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0,
|
|
||||||
// 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0,
|
|
||||||
// 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0,
|
|
||||||
// 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0,
|
|
||||||
// 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0,
|
|
||||||
// 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0,
|
|
||||||
// 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0,
|
|
||||||
// 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0,
|
|
||||||
// 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0,
|
|
||||||
// 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0
|
|
||||||
// };
|
|
||||||
//
|
|
||||||
// std::vector<glm::vec3> cube_normals;
|
|
||||||
//
|
|
||||||
// for (int i = 0; i < cube_vertices.size() - 2; i += 3)
|
|
||||||
// {
|
|
||||||
// glm::vec3 norm = computeNormal(
|
|
||||||
// cube_vertices[i], cube_vertices[i + 1], cube_vertices[i + 2]);
|
|
||||||
// cube_normals.push_back(norm); cube_normals.push_back(norm); cube_normals.push_back(norm);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// glGenVertexArrays(1, &_vaoHandle);
|
|
||||||
// glBindVertexArray(_vaoHandle);
|
|
||||||
//
|
|
||||||
// glGenBuffers(1, &_vbo_vertices);
|
|
||||||
// glBindBuffer(GL_ARRAY_BUFFER, _vbo_vertices);
|
|
||||||
// glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * cube_vertices.size() * 3, cube_vertices.data(), GL_STATIC_DRAW);
|
|
||||||
//
|
|
||||||
// glVertexAttribPointer(
|
|
||||||
// 0, //attr number = 0
|
|
||||||
// 3,
|
|
||||||
// GL_FLOAT,
|
|
||||||
// GL_FALSE,
|
|
||||||
// 0,
|
|
||||||
// (void*)0);
|
|
||||||
// glEnableVertexAttribArray(0); //attr number = 0
|
|
||||||
//
|
|
||||||
// glGenBuffers(1, &_vbo_normals);
|
|
||||||
// glBindBuffer(GL_ARRAY_BUFFER, _vbo_normals);
|
|
||||||
// glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * cube_normals.size() * 3, cube_normals.data(), GL_STATIC_DRAW);
|
|
||||||
//
|
|
||||||
// glVertexAttribPointer(
|
|
||||||
// 1,
|
|
||||||
// 3,
|
|
||||||
// GL_FLOAT,
|
|
||||||
// GL_FALSE,
|
|
||||||
// 0,
|
|
||||||
// (void*)0);
|
|
||||||
// glEnableVertexAttribArray(1);
|
|
||||||
//
|
|
||||||
// glGenBuffers(1, &_vbo_colors);
|
|
||||||
// glBindBuffer(GL_ARRAY_BUFFER, _vbo_colors);
|
|
||||||
// glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * cube_colors.size(), cube_colors.data(), GL_STATIC_DRAW);
|
|
||||||
//
|
|
||||||
// glVertexAttribPointer(
|
|
||||||
// 2,
|
|
||||||
// 3,
|
|
||||||
// GL_FLOAT,
|
|
||||||
// GL_FALSE,
|
|
||||||
// 0,
|
|
||||||
// (void*)0);
|
|
||||||
// glEnableVertexAttribArray(2);
|
|
||||||
//
|
|
||||||
// glBindVertexArray(0);
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//ColorCube::ColorCube(bool usingIBO)
|
|
||||||
//{
|
|
||||||
// ibo_used = usingIBO;
|
|
||||||
// if (usingIBO)
|
|
||||||
// iboSetup();
|
|
||||||
// else
|
|
||||||
// vaoSetup();
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//void ColorCube::draw(ShaderProgram *shader, glm::mat4x4 proj_matrix, glm::mat4x4 view_matrix)
|
|
||||||
//{
|
|
||||||
// _model.glPushMatrix();
|
|
||||||
// effectTransformations();
|
|
||||||
// glBindVertexArray(_vaoHandle);
|
|
||||||
// glm::mat4 mvpMatrix = proj_matrix * view_matrix * _model.getMatrix();
|
|
||||||
// glUniformMatrix4fv(shader->uniform("mvp"), 1, GL_FALSE, glm::value_ptr(mvpMatrix));
|
|
||||||
// glm::mat4 modelview = view_matrix * _model.getMatrix();
|
|
||||||
// _model.glPopMatrix();
|
|
||||||
// glUniform4fv(shader->uniform("LightLocation"), 1, glm::value_ptr(view_matrix * glm::vec4(50, 50, 50, 1)));
|
|
||||||
// glUniformMatrix4fv(shader->uniform("ModelViewMatrix"), 1, GL_FALSE, glm::value_ptr(modelview));
|
|
||||||
// glm::mat4 inverseModelView = glm::inverse(modelview);
|
|
||||||
// glm::mat3 normalMatrix = glm::mat3(glm::transpose(inverseModelView));
|
|
||||||
// glUniformMatrix3fv(shader->uniform("NormalMatrix"), 1, GL_FALSE, glm::value_ptr(normalMatrix));
|
|
||||||
//
|
|
||||||
// if (ibo_used)
|
|
||||||
// {
|
|
||||||
// int size;
|
|
||||||
// glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &size);
|
|
||||||
// glDrawElements(GL_TRIANGLES, size / sizeof(GLushort), GL_UNSIGNED_SHORT, 0);
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// glDrawArrays(GL_TRIANGLES, 0, 36);
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//DrawableType ColorCube::getType()
|
|
||||||
//{
|
|
||||||
// return DrawableType::COLOR_CUBE;
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//ColorCube::~ColorCube()
|
|
||||||
//{
|
|
||||||
//}
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
//#include <iostream>
|
|
||||||
//#include <string>
|
|
||||||
//#include <vector>
|
|
||||||
//#include <glm/vec4.hpp>
|
|
||||||
// #include "ADrawable.h"
|
|
||||||
//
|
|
||||||
//#pragma once
|
|
||||||
//class ColorCube : public ADrawable
|
|
||||||
//{
|
|
||||||
//private:
|
|
||||||
// GLuint _vaoHandle;
|
|
||||||
// GLuint _iboHandle;
|
|
||||||
// GLuint _vbo_vertices, _vbo_colors, _vbo_normals;
|
|
||||||
//
|
|
||||||
// bool ibo_used;
|
|
||||||
//
|
|
||||||
// void iboSetup();
|
|
||||||
// void vaoSetup();
|
|
||||||
//
|
|
||||||
//public:
|
|
||||||
// ColorCube(bool usingIBO);
|
|
||||||
//
|
|
||||||
// void draw(ShaderProgram *shader, glm::mat4x4 proj_matrix, glm::mat4x4 view_matrix) override;
|
|
||||||
// DrawableType getType() override;
|
|
||||||
// ~ColorCube();
|
|
||||||
//};
|
|
||||||
//
|
|
||||||
148
BaseGLProject/Dataset.cpp
Normal file
148
BaseGLProject/Dataset.cpp
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
#include "Dataset.h"
|
||||||
|
|
||||||
|
void Dataset::sphere(float radius, GLuint slices, GLuint stacks)
|
||||||
|
{
|
||||||
|
clear();
|
||||||
|
|
||||||
|
// Generate vertexes and normals
|
||||||
|
GLfloat theta, phi;
|
||||||
|
GLfloat thetaFac = glm::two_pi<float>() / slices;
|
||||||
|
GLfloat phiFac = glm::pi<float>() / stacks;
|
||||||
|
GLfloat nx, ny, nz, s, t;
|
||||||
|
GLuint idx = 0, tIdx = 0;
|
||||||
|
for (GLuint i = 0; i <= slices; i++) {
|
||||||
|
theta = i * thetaFac;
|
||||||
|
s = (GLfloat)i / slices;
|
||||||
|
for (GLuint j = 0; j <= stacks; j++) {
|
||||||
|
phi = j * phiFac;
|
||||||
|
t = (GLfloat)j / stacks;
|
||||||
|
nx = sinf(phi) * cosf(theta);
|
||||||
|
ny = sinf(phi) * sinf(theta);
|
||||||
|
nz = cosf(phi);
|
||||||
|
vertices.emplace_back(radius * nx, radius * ny, radius * nz);
|
||||||
|
normals.emplace_back(nx, ny, nz);
|
||||||
|
idx++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate the element list
|
||||||
|
idx = 0;
|
||||||
|
for (GLuint i = 0; i < slices; i++) {
|
||||||
|
GLuint stackStart = i * (stacks + 1);
|
||||||
|
GLuint nextStackStart = (i + 1) * (stacks + 1);
|
||||||
|
for (GLuint j = 0; j < stacks; j++) {
|
||||||
|
if (j == 0) {
|
||||||
|
GLuint a[3] = { stackStart, stackStart + 1, nextStackStart + 1 };
|
||||||
|
indexes.insert(indexes.end(), std::begin(a), std::end(a));
|
||||||
|
}
|
||||||
|
else if (j == stacks - 1) {
|
||||||
|
GLuint a[3] = { stackStart + j, stackStart + 1 + j, nextStackStart + j };
|
||||||
|
indexes.insert(indexes.end(), std::begin(a), std::end(a));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
GLuint a[6] = { stackStart + j, stackStart + 1 + j, nextStackStart + j + 1,
|
||||||
|
nextStackStart + j, stackStart + j, nextStackStart + j + 1 };
|
||||||
|
indexes.insert(indexes.end(), std::begin(a), std::end(a));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Dataset::simpleCube()
|
||||||
|
{
|
||||||
|
clear();
|
||||||
|
vertices = { { -1.0, -1.0, 1.0 },{ 1.0, -1.0, 1.0 },{ 1.0, 1.0, 1.0 },
|
||||||
|
{ 1.0, 1.0, 1.0 },{ -1.0, 1.0, 1.0 },{ -1.0, -1.0, 1.0 },
|
||||||
|
{ 1.0, -1.0, 1.0 },{ 1.0, -1.0, -1.0 },{ 1.0, 1.0, -1.0 },
|
||||||
|
{ 1.0, 1.0, -1.0 },{ 1.0, 1.0, 1.0 },{ 1.0, -1.0, 1.0 },
|
||||||
|
{ -1.0, 1.0, -1.0 },{ 1.0, 1.0, -1.0 },{ 1.0, -1.0, -1.0 },
|
||||||
|
{ 1.0, -1.0, -1.0 },{ -1.0, -1.0, -1.0 },{ -1.0, 1.0, -1.0 },
|
||||||
|
{ -1.0, -1.0, -1.0 },{ -1.0, -1.0, 1.0 },{ -1.0, 1.0, 1.0 },
|
||||||
|
{ -1.0, 1.0, 1.0 },{ -1.0, 1.0, -1.0 },{ -1.0, -1.0, -1.0 },
|
||||||
|
{ -1.0, -1.0, -1.0 },{ 1.0, -1.0, -1.0 },{ 1.0, -1.0, 1.0 },
|
||||||
|
{ 1.0, -1.0, 1.0 },{ -1.0, -1.0, 1.0 },{ -1.0, -1.0, -1.0 },
|
||||||
|
{ -1.0, 1.0, 1.0 },{ 1.0, 1.0, 1.0 },{ 1.0, 1.0, -1.0 },
|
||||||
|
{ 1.0, 1.0, -1.0 },{ -1.0, 1.0, -1.0 },{ -1.0, 1.0, 1.0 } };
|
||||||
|
|
||||||
|
tex_mapping = {
|
||||||
|
{ 0.0f, 0.0f },{ 1.0f, 0.0f },{ 1.0f, 1.0f }, // one triangle
|
||||||
|
{ 0.0f, 0.0f },{ 1.0f, 1.0f },{ 0.0f, 1.0f }, //the other triangle
|
||||||
|
{ 0.0f, 0.0f },{ 1.0f, 0.0f },{ 1.0f, 1.0f }, // one triangle
|
||||||
|
{ 0.0f, 0.0f },{ 1.0f, 1.0f },{ 0.0f, 1.0f }, //the other triangle
|
||||||
|
{ 0.0f, 0.0f },{ 1.0f, 0.0f },{ 1.0f, 1.0f }, // one triangle
|
||||||
|
{ 0.0f, 0.0f },{ 1.0f, 1.0f },{ 0.0f, 1.0f }, //the other triangle
|
||||||
|
{ 0.0f, 0.0f },{ 1.0f, 0.0f },{ 1.0f, 1.0f }, // one triangle
|
||||||
|
{ 0.0f, 0.0f },{ 1.0f, 1.0f },{ 0.0f, 1.0f }, //the other triangle
|
||||||
|
{ 0.0f, 0.0f },{ 1.0f, 0.0f },{ 1.0f, 1.0f }, // one triangle
|
||||||
|
{ 0.0f, 0.0f },{ 1.0f, 1.0f },{ 0.0f, 1.0f }, //the other triangle
|
||||||
|
{ 0.0f, 0.0f },{ 1.0f, 0.0f },{ 1.0f, 1.0f }, // one triangle
|
||||||
|
{ 0.0f, 0.0f },{ 1.0f, 1.0f },{ 0.0f, 1.0f }, //the other triangle
|
||||||
|
};
|
||||||
|
|
||||||
|
colors = {
|
||||||
|
{ 1.0, 0.0, 0.0 },{ 0.0, 1.0, 0.0 },{ 0.0, 0.0, 1.0 },
|
||||||
|
{ 0.0, 0.0, 1.0 },{ 1.0, 1.0, 1.0 },{ 1.0, 0.0, 0.0 },
|
||||||
|
{ 0.0, 1.0, 0.0 },{ 0.0, 1.0, 0.0 },{ 0.0, 0.0, 1.0 },
|
||||||
|
{ 0.0, 0.0, 1.0 },{ 0.0, 0.0, 1.0 },{ 0.0, 1.0, 0.0 },
|
||||||
|
{ 1.0, 1.0, 1.0 },{ 0.0, 0.0, 1.0 },{ 0.0, 1.0, 0.0 },
|
||||||
|
{ 0.0, 1.0, 0.0 },{ 1.0, 0.0, 0.0 },{ 1.0, 1.0, 1.0 },
|
||||||
|
{ 1.0, 0.0, 0.0 },{ 1.0, 0.0, 0.0 },{ 1.0, 1.0, 1.0 },
|
||||||
|
{ 1.0, 1.0, 1.0 },{ 1.0, 1.0, 1.0 },{ 1.0, 0.0, 0.0 },
|
||||||
|
{ 1.0, 0.0, 0.0 },{ 0.0, 1.0, 0.0 },{ 0.0, 1.0, 0.0 },
|
||||||
|
{ 0.0, 1.0, 0.0 },{ 1.0, 0.0, 0.0 },{ 1.0, 0.0, 0.0 },
|
||||||
|
{ 1.0, 1.0, 1.0 },{ 0.0, 0.0, 1.0 },{ 0.0, 0.0, 1.0 },
|
||||||
|
{ 0.0, 0.0, 1.0 },{ 1.0, 1.0, 1.0 },{ 1.0, 1.0, 1.0 }
|
||||||
|
},
|
||||||
|
|
||||||
|
genNormals();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Dataset::simpleFloor()
|
||||||
|
{
|
||||||
|
clear();
|
||||||
|
vertices = { { -10.0, 0.0, -10.0 },{ -10.0, 0.0, 10.0 },{ 10.0, 0.0, -10.0 },
|
||||||
|
{ 10.0, 0.0, 10.0 },{ 10.0, 0.0, -10.0 },{ -10.0, 0.0, 10.0 } };
|
||||||
|
|
||||||
|
colors = { { 0.7, 0.7, 0.7 },{ 0.7, 0.7, 0.7 },{ 0.7, 0.7, 0.7 },
|
||||||
|
{ 0.7, 0.7, 0.7 },{ 0.7, 0.7, 0.7 },{ 0.7, 0.7, 0.7 } };
|
||||||
|
genNormals();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Dataset::checkeredFloor(float size, int squares, glm::vec3 light_color, glm::vec3 dark_color)
|
||||||
|
{
|
||||||
|
clear();
|
||||||
|
float maxX = size / 2.f, maxY = size / 2.f;
|
||||||
|
float minX = -size / 2.f, minY = -size / 2.f;
|
||||||
|
float side_size = size / (float)squares;
|
||||||
|
int color = 1;
|
||||||
|
|
||||||
|
for (float x = minX; x < maxX; x += side_size)
|
||||||
|
{
|
||||||
|
for (float y = minY; y < maxY; y += side_size)
|
||||||
|
{
|
||||||
|
color *= -1;
|
||||||
|
glm::vec3 tile_color = (color > 0) ? light_color : dark_color;
|
||||||
|
//gen 1 carré
|
||||||
|
vertices.emplace_back(x, 0, y); //upleft
|
||||||
|
vertices.emplace_back(x, 0, y + side_size); //downleft
|
||||||
|
vertices.emplace_back(x + side_size, 0, y + side_size); //downright
|
||||||
|
vertices.emplace_back(x + side_size, 0, y + side_size); //downright
|
||||||
|
vertices.emplace_back(x + side_size, 0, y); //upright
|
||||||
|
vertices.emplace_back(x, 0, y); //upleft
|
||||||
|
|
||||||
|
for (int z = 0; z < 6; z++)
|
||||||
|
colors.push_back(tile_color);
|
||||||
|
}
|
||||||
|
color *= -1;
|
||||||
|
}
|
||||||
|
genNormals();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Dataset::genNormals()
|
||||||
|
{
|
||||||
|
for (unsigned int i = 0; i < vertices.size() - 2; i += 3)
|
||||||
|
{
|
||||||
|
glm::vec3 norm = glm::cross(vertices[i + 1] - vertices[i], vertices[i + 2] - vertices[i]);
|
||||||
|
normals.push_back(norm); normals.push_back(norm); normals.push_back(norm);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,4 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
#include <glm/gtc/constants.hpp>
|
||||||
|
#include <vector>
|
||||||
|
#include "GL/glew.h"
|
||||||
|
|
||||||
class Dataset
|
class Dataset
|
||||||
{
|
{
|
||||||
@ -10,6 +14,7 @@ public:
|
|||||||
std::vector<glm::vec3> normals;
|
std::vector<glm::vec3> normals;
|
||||||
std::vector<glm::vec3> colors;
|
std::vector<glm::vec3> colors;
|
||||||
std::vector<glm::vec2> tex_mapping;
|
std::vector<glm::vec2> tex_mapping;
|
||||||
|
std::vector<GLuint> indexes;
|
||||||
|
|
||||||
void clear()
|
void clear()
|
||||||
{
|
{
|
||||||
@ -17,107 +22,19 @@ public:
|
|||||||
normals.clear();
|
normals.clear();
|
||||||
colors.clear();
|
colors.clear();
|
||||||
tex_mapping.clear();
|
tex_mapping.clear();
|
||||||
|
indexes.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void simpleCube()
|
void sphere(float radius, GLuint slices, GLuint stacks);
|
||||||
{
|
|
||||||
clear();
|
|
||||||
vertices = { { -1.0, -1.0, 1.0}, { 1.0, -1.0, 1.0}, { 1.0, 1.0, 1.0},
|
|
||||||
{ 1.0, 1.0, 1.0}, { -1.0, 1.0, 1.0}, { -1.0, -1.0, 1.0},
|
|
||||||
{ 1.0, -1.0, 1.0}, { 1.0, -1.0, -1.0}, { 1.0, 1.0, -1.0},
|
|
||||||
{ 1.0, 1.0, -1.0}, { 1.0, 1.0, 1.0}, { 1.0, -1.0, 1.0},
|
|
||||||
{ -1.0, 1.0, -1.0}, { 1.0, 1.0, -1.0}, { 1.0, -1.0, -1.0},
|
|
||||||
{ 1.0, -1.0, -1.0}, { -1.0, -1.0, -1.0}, { -1.0, 1.0, -1.0},
|
|
||||||
{ -1.0, -1.0, -1.0}, { -1.0, -1.0, 1.0}, { -1.0, 1.0, 1.0},
|
|
||||||
{ -1.0, 1.0, 1.0}, { -1.0, 1.0, -1.0}, { -1.0, -1.0, -1.0},
|
|
||||||
{ -1.0, -1.0, -1.0}, { 1.0, -1.0, -1.0}, { 1.0, -1.0, 1.0},
|
|
||||||
{ 1.0, -1.0, 1.0}, { -1.0, -1.0, 1.0}, { -1.0, -1.0, -1.0},
|
|
||||||
{ -1.0, 1.0, 1.0}, { 1.0, 1.0, 1.0}, { 1.0, 1.0, -1.0},
|
|
||||||
{ 1.0, 1.0, -1.0}, { -1.0, 1.0, -1.0}, { -1.0, 1.0, 1.0} };
|
|
||||||
|
|
||||||
tex_mapping = {
|
void simpleCube();
|
||||||
{0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, // one triangle
|
|
||||||
{0.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f}, //the other triangle
|
|
||||||
{0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, // one triangle
|
|
||||||
{0.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f}, //the other triangle
|
|
||||||
{0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, // one triangle
|
|
||||||
{0.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f}, //the other triangle
|
|
||||||
{0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, // one triangle
|
|
||||||
{0.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f}, //the other triangle
|
|
||||||
{0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, // one triangle
|
|
||||||
{0.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f}, //the other triangle
|
|
||||||
{0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, // one triangle
|
|
||||||
{0.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f}, //the other triangle
|
|
||||||
};
|
|
||||||
|
|
||||||
colors = {
|
void simpleFloor();
|
||||||
{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0},
|
|
||||||
{0.0, 0.0, 1.0}, {1.0, 1.0, 1.0}, {1.0, 0.0, 0.0},
|
|
||||||
{0.0, 1.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0},
|
|
||||||
{0.0, 0.0, 1.0}, {0.0, 0.0, 1.0}, {0.0, 1.0, 0.0},
|
|
||||||
{1.0, 1.0, 1.0}, {0.0, 0.0, 1.0}, {0.0, 1.0, 0.0},
|
|
||||||
{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 1.0, 1.0},
|
|
||||||
{1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 1.0, 1.0},
|
|
||||||
{1.0, 1.0, 1.0}, {1.0, 1.0, 1.0}, {1.0, 0.0, 0.0},
|
|
||||||
{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 1.0, 0.0},
|
|
||||||
{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0},
|
|
||||||
{1.0, 1.0, 1.0}, {0.0, 0.0, 1.0}, {0.0, 0.0, 1.0},
|
|
||||||
{0.0, 0.0, 1.0}, {1.0, 1.0, 1.0}, {1.0, 1.0, 1.0}
|
|
||||||
},
|
|
||||||
|
|
||||||
genNormals();
|
|
||||||
}
|
|
||||||
|
|
||||||
void simpleFloor()
|
|
||||||
{
|
|
||||||
clear();
|
|
||||||
vertices = {{-10.0, 0.0, -10.0}, {-10.0, 0.0, 10.0}, {10.0, 0.0, -10.0},
|
|
||||||
{10.0, 0.0, 10.0}, {10.0, 0.0, -10.0}, {-10.0, 0.0, 10.0}};
|
|
||||||
|
|
||||||
colors = { {0.7, 0.7, 0.7}, {0.7, 0.7, 0.7}, {0.7, 0.7, 0.7},
|
|
||||||
{0.7, 0.7, 0.7}, {0.7, 0.7, 0.7}, {0.7, 0.7, 0.7} };
|
|
||||||
genNormals();
|
|
||||||
}
|
|
||||||
|
|
||||||
void checkeredFloor(float size, int squares,
|
void checkeredFloor(float size, int squares,
|
||||||
glm::vec3 light_color, glm::vec3 dark_color)
|
glm::vec3 light_color, glm::vec3 dark_color);
|
||||||
{
|
|
||||||
clear();
|
|
||||||
float maxX = size / 2.f, maxY = size / 2.f;
|
|
||||||
float minX = -size / 2.f, minY = -size / 2.f;
|
|
||||||
float side_size = size / (float)squares;
|
|
||||||
int color = 1;
|
|
||||||
|
|
||||||
for (float x = minX; x < maxX; x += side_size)
|
|
||||||
{
|
|
||||||
for (float y = minY; y < maxY; y += side_size)
|
|
||||||
{
|
|
||||||
color *= -1;
|
|
||||||
glm::vec3 tile_color = (color > 0) ? light_color : dark_color;
|
|
||||||
//gen 1 carré
|
|
||||||
vertices.emplace_back(x, 0, y); //upleft
|
|
||||||
vertices.emplace_back(x, 0, y + side_size); //downleft
|
|
||||||
vertices.emplace_back(x + side_size, 0, y + side_size); //downright
|
|
||||||
vertices.emplace_back(x + side_size, 0, y + side_size); //downright
|
|
||||||
vertices.emplace_back(x + side_size, 0, y); //upright
|
|
||||||
vertices.emplace_back(x, 0, y); //upleft
|
|
||||||
|
|
||||||
for (int z = 0; z < 6; z++)
|
|
||||||
colors.push_back(tile_color);
|
|
||||||
}
|
|
||||||
color *= -1;
|
|
||||||
}
|
|
||||||
genNormals();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void genNormals()
|
void genNormals();
|
||||||
{
|
|
||||||
for (unsigned int i = 0; i < vertices.size() - 2; i += 3)
|
|
||||||
{
|
|
||||||
glm::vec3 norm = glm::cross(vertices[i + 1] - vertices[i], vertices[i + 2] - vertices[i]);
|
|
||||||
normals.push_back(norm); normals.push_back(norm); normals.push_back(norm);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
@ -73,6 +73,20 @@ Mesh::MeshEntry::MeshEntry(Dataset &set, Mesh *m)
|
|||||||
glEnableVertexAttribArray(COLOR_BUFFER);
|
glEnableVertexAttribArray(COLOR_BUFFER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Copy indexes to VBO
|
||||||
|
if (set.indexes.size() > 0)
|
||||||
|
{
|
||||||
|
renderType = OBJ;
|
||||||
|
|
||||||
|
glGenBuffers(1, &vbo[INDEX_BUFFER]);
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo[INDEX_BUFFER]);
|
||||||
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, set.indexes.size() * sizeof(GLuint), set.indexes.data(), GL_STATIC_DRAW);
|
||||||
|
|
||||||
|
glVertexAttribPointer(INDEX_BUFFER, 3, GL_FLOAT, GL_FALSE, 0, NULL);
|
||||||
|
glEnableVertexAttribArray(INDEX_BUFFER);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
dset_size = set.vertices.size();
|
dset_size = set.vertices.size();
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
|
|||||||
@ -55,7 +55,7 @@ void MyGlWindow::setBgColor(float bgColor[3])
|
|||||||
_bgColor[2] = bgColor[2];
|
_bgColor[2] = bgColor[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyGlWindow::setup()
|
void MyGlWindow::textureSetup()
|
||||||
{
|
{
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glGenTextures(1, &_scnctx.textures); //tex_2d is a member variable
|
glGenTextures(1, &_scnctx.textures); //tex_2d is a member variable
|
||||||
@ -75,7 +75,32 @@ void MyGlWindow::setup()
|
|||||||
|
|
||||||
stbi_image_free(image);
|
stbi_image_free(image);
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyGlWindow::shaderSetup()
|
||||||
|
{
|
||||||
|
shaders["Simple"] = new Shader("simple.vert", "simple.frag");
|
||||||
|
shaders["Simple"]->uniformFlags = ShaderFlags::MVP_FLAG;
|
||||||
|
|
||||||
|
shaders["BaseLight"] = new Shader("base_light.vert", "base_light.frag");
|
||||||
|
shaders["Fog"] = new Shader("fog.vert", "fog.frag");
|
||||||
|
|
||||||
|
shaders["TexBaseLight"] = new Shader("tex_base_light.vert", "tex_base_light.frag");
|
||||||
|
shaders["TexBaseLight"]->addUniform("tex1", 0);
|
||||||
|
|
||||||
|
shaders["Silhouette"] = new Shader("silhouette.vert", "silhouette.frag");
|
||||||
|
shaders["Silhouette"]->uniformFlags = ShaderFlags::MVP_FLAG;
|
||||||
|
shaders["Silhouette"]->addUniform("fColor", glm::vec3(237 / 255, 229 / 255, 194 / 255));
|
||||||
|
shaders["Silhouette"]->addUniform("sil_offset", 0.1f);
|
||||||
|
|
||||||
|
shaders["Toon"] = new Shader("base_light.vert", "toon.frag");
|
||||||
|
//Removing useless specular component
|
||||||
|
shaders["Toon"]->uniformFlags &= ~ShaderFlags::KS_FLAG;
|
||||||
|
shaders["Toon"]->uniformFlags &= ~ShaderFlags::SHINE_FLAG;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyGlWindow::lightSetup()
|
||||||
|
{
|
||||||
//Showcase lights
|
//Showcase lights
|
||||||
_scnctx.lights.emplace("Light1", Light(glm::vec3(0.8f), glm::vec4(3, 10, 5, 1)));
|
_scnctx.lights.emplace("Light1", Light(glm::vec3(0.8f), glm::vec4(3, 10, 5, 1)));
|
||||||
|
|
||||||
@ -85,38 +110,34 @@ void MyGlWindow::setup()
|
|||||||
_scnctx.lights.emplace("Light3", Light(glm::vec3(0.5f, 0.0f, 0.0f), glm::vec4(-8.09, 10, 5.87, 1)));
|
_scnctx.lights.emplace("Light3", Light(glm::vec3(0.5f, 0.0f, 0.0f), glm::vec4(-8.09, 10, 5.87, 1)));
|
||||||
_scnctx.lights.emplace("Light4", Light(glm::vec3(0.0f, 0.5f, 0.0f), glm::vec4(-8.09, 10, -5.87, 1)));
|
_scnctx.lights.emplace("Light4", Light(glm::vec3(0.0f, 0.5f, 0.0f), glm::vec4(-8.09, 10, -5.87, 1)));
|
||||||
_scnctx.lights.emplace("Light5", Light(glm::vec3(0.5f, 0.5f, 0.5f), glm::vec4(3.09, 10, -9.51, 1)));*/
|
_scnctx.lights.emplace("Light5", Light(glm::vec3(0.5f, 0.5f, 0.5f), glm::vec4(3.09, 10, -9.51, 1)));*/
|
||||||
|
}
|
||||||
|
|
||||||
shaders["Simple"] = new Shader("simple.vert", "simple.frag");
|
void MyGlWindow::setup()
|
||||||
shaders["Simple"]->uniformFlags = ShaderFlags::MVP_FLAG;
|
{
|
||||||
|
textureSetup();
|
||||||
|
shaderSetup();
|
||||||
|
lightSetup();
|
||||||
|
|
||||||
shaders["Light"] = new Shader("light.vert", "light.frag");
|
Dataset moddata;
|
||||||
shaders["Light"]->addUniform("tex1", 0);
|
moddata.checkeredFloor(20, 20, glm::vec3(0.1, 0.1, 0.1), glm::vec3(0.7, 0.7, 0.7));
|
||||||
shaders["Fog"] = new Shader("fog.vert", "fog.frag");
|
meshes.push_back(new Mesh(moddata, shaders["Simple"]));
|
||||||
|
|
||||||
shaders["Silhouette"] = new Shader("silhouette.vert", "silhouette.frag");
|
|
||||||
shaders["Silhouette"]->uniformFlags = ShaderFlags::MVP_FLAG;
|
|
||||||
shaders["Silhouette"]->addUniform("fColor", glm::vec3(237/255, 229/255, 194/255));
|
|
||||||
shaders["Silhouette"]->addUniform("sil_offset", 0.1f);
|
|
||||||
|
|
||||||
shaders["Toon"] = new Shader("light.vert", "toon.frag");
|
|
||||||
//Removing useless specular component
|
|
||||||
shaders["Toon"]->uniformFlags &= ~ShaderFlags::KS_FLAG;
|
|
||||||
shaders["Toon"]->uniformFlags &= ~ShaderFlags::SHINE_FLAG;
|
|
||||||
|
|
||||||
Dataset floor;
|
|
||||||
floor.checkeredFloor(20, 20, glm::vec3(0.1, 0.1, 0.1), glm::vec3(0.7, 0.7, 0.7));
|
|
||||||
meshes.push_back(new Mesh(floor, shaders["Simple"]));
|
|
||||||
meshes.back()->addTranslation(glm::vec4(0, -0.05, 0, 1));
|
meshes.back()->addTranslation(glm::vec4(0, -0.05, 0, 1));
|
||||||
meshes.back()->cullMode = BACK;
|
meshes.back()->cullMode = BACK;
|
||||||
|
|
||||||
floor.simpleCube();
|
moddata.simpleCube();
|
||||||
meshes.push_back(new Mesh(floor, shaders["Light"]));
|
meshes.push_back(new Mesh(moddata, shaders["TexBaseLight"]));
|
||||||
meshes.back()->addTranslation(glm::vec4(0, 1, 0, 1));
|
meshes.back()->addTranslation(glm::vec4(0, 1, 0, 1));
|
||||||
|
|
||||||
/*meshes.push_back(new Mesh("teapot.obj", shaders["Silhouette"]));
|
moddata.sphere(1, 100, 100);
|
||||||
|
meshes.push_back(new Mesh(moddata, shaders["BaseLight"]));
|
||||||
|
meshes.back()->addTranslation(glm::vec4(-5, 1, -3, 1));
|
||||||
|
|
||||||
|
meshes.push_back(new Mesh("teapot.obj", shaders["Silhouette"]));
|
||||||
|
meshes.back()->addTranslation(glm::vec4(5, 0 ,3, 1));
|
||||||
meshes.back()->cullMode = FRONT;
|
meshes.back()->cullMode = FRONT;
|
||||||
meshes.push_back(new Mesh("teapot.obj", shaders["Toon"]));
|
meshes.push_back(new Mesh("teapot.obj", shaders["Toon"]));
|
||||||
meshes.back()->cullMode = BACK; */
|
meshes.back()->addTranslation(glm::vec4(5, 0, 3, 1));
|
||||||
|
meshes.back()->cullMode = BACK;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -41,5 +41,8 @@ private:
|
|||||||
GLuint _vaoHandle;
|
GLuint _vaoHandle;
|
||||||
GLuint _iboHandle;
|
GLuint _iboHandle;
|
||||||
|
|
||||||
|
void textureSetup();
|
||||||
|
void shaderSetup();
|
||||||
|
void lightSetup();
|
||||||
void setup();
|
void setup();
|
||||||
};
|
};
|
||||||
|
|||||||
52
BaseGLProject/base_light.frag
Normal file
52
BaseGLProject/base_light.frag
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
#version 440
|
||||||
|
|
||||||
|
in vec3 f_color;
|
||||||
|
out vec4 FragColors;
|
||||||
|
|
||||||
|
uniform vec3 Kd;
|
||||||
|
uniform vec3 Ka;
|
||||||
|
uniform vec3 Ks;
|
||||||
|
uniform float Shininess;
|
||||||
|
|
||||||
|
struct LightInfo {
|
||||||
|
vec4 Position;
|
||||||
|
vec3 Intensity;
|
||||||
|
};
|
||||||
|
|
||||||
|
uniform LightInfo Light[64];
|
||||||
|
uniform int LightCount;
|
||||||
|
|
||||||
|
|
||||||
|
in vec3 fNormal;
|
||||||
|
in vec3 pos;
|
||||||
|
|
||||||
|
in vec2 texCoord;
|
||||||
|
uniform sampler2D tex1;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
|
||||||
|
vec3 finalColor;
|
||||||
|
vec3 diffuse_sum;
|
||||||
|
vec3 specular_sum;
|
||||||
|
vec3 ambient;
|
||||||
|
|
||||||
|
ambient = Ka * Light[0].Intensity;
|
||||||
|
for (int i=0; i<LightCount; i++)
|
||||||
|
{
|
||||||
|
vec3 L = normalize(Light[i].Position.xyz - pos);
|
||||||
|
vec3 N = fNormal;
|
||||||
|
vec3 V = normalize(-pos);
|
||||||
|
//vec3 R = normalize(reflect(-L, N));
|
||||||
|
vec3 H = normalize(V + L);
|
||||||
|
|
||||||
|
vec3 diffuse = Kd * Light[i].Intensity * max(dot(L, N), 0.0);
|
||||||
|
vec3 specular = Ks * Light[i].Intensity * pow(max(dot(H, N), 0.0), Shininess);
|
||||||
|
diffuse_sum += diffuse;
|
||||||
|
specular_sum += specular;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
vec4 texColor = texture(tex1, texCoord);
|
||||||
|
FragColors = (vec4(diffuse_sum + ambient, 1) * texColor + vec4(specular_sum, 1.0));
|
||||||
|
}
|
||||||
24
BaseGLProject/base_light.vert
Normal file
24
BaseGLProject/base_light.vert
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#version 440
|
||||||
|
|
||||||
|
layout(location=0) in vec3 coord3d;
|
||||||
|
layout(location=1) in vec3 v_normal;
|
||||||
|
layout(location=2) in vec3 v_color;
|
||||||
|
layout(location=3) in vec2 v_texmap;
|
||||||
|
|
||||||
|
uniform mat4 mvp;
|
||||||
|
uniform mat3 NormalMatrix;
|
||||||
|
uniform mat4 ModelViewMatrix;
|
||||||
|
|
||||||
|
out vec3 fNormal;
|
||||||
|
out vec3 pos;
|
||||||
|
out vec2 texCoord;
|
||||||
|
|
||||||
|
void main(void)
|
||||||
|
{
|
||||||
|
fNormal = normalize(NormalMatrix * v_normal);
|
||||||
|
pos = (ModelViewMatrix * vec4(coord3d, 1.0)).xyz;
|
||||||
|
|
||||||
|
texCoord = v_texmap;
|
||||||
|
|
||||||
|
gl_Position = mvp * vec4(coord3d, 1.0f);
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user