[ADDED] smoke and some small changes

This commit is contained in:
Menno
2021-05-21 14:12:30 +02:00
parent e2f6bd720d
commit e10aea5a15
10 changed files with 4617 additions and 11 deletions

View File

@@ -1,7 +1,10 @@
#include <GL/glew.h>
#include <glm/vec3.hpp>
#include "../stb_image.h"
#include "loader.h"
#include <iostream>
namespace render_engine
{
namespace loader
@@ -9,6 +12,7 @@ namespace render_engine
static GLuint CreateVao();
static void StoreDataInAttributeList(int attribute_number, int coordinate_size, std::vector<float>& data);
static void BindIndicesBuffer(std::vector<unsigned int>& indices);
static glm::vec3 GetSizeModel(std::vector<float>& positions);
static std::vector<GLuint> vaos;
static std::vector<GLuint> vbos;
@@ -19,13 +23,16 @@ namespace render_engine
*/
models::RawModel LoadToVAO(std::vector<float>& positions, std::vector<float>& texture_coords, std::vector<float>& normals, std::vector<unsigned int>& indices)
{
GLuint vao_id = CreateVao();
const GLuint vao_id = CreateVao();
BindIndicesBuffer(indices);
StoreDataInAttributeList(0, 3, positions);
StoreDataInAttributeList(1, 2, texture_coords);
StoreDataInAttributeList(2, 3, normals);
glBindVertexArray(0);
return { vao_id, static_cast<int>(indices.size()) };
const glm::vec3 model_size = GetSizeModel(positions);
return { vao_id, static_cast<int>(indices.size()), model_size };
}
/*
@@ -41,6 +48,12 @@ namespace render_engine
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture_id);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, imgData);
// Set mipmapping with a constant LOD
glGenerateMipmap(GL_TEXTURE_2D);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_LOD_BIAS, -0.4f);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
@@ -114,5 +127,67 @@ namespace render_engine
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo_id);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(int) * indices.size(), &indices[0], GL_STATIC_DRAW);
}
static glm::vec3 GetSizeModel(std::vector<float>& positions)
{
float minX = 100;
float maxX = -100;
float minY = 100;
float maxY = -100;
float minZ = 100;
float maxZ = -100;
for (int i = 0; i < positions.size(); ++i)
{
const int index = i % 3;
const float value = positions[i];
switch (index)
{
case 0: // x
{
if (value < minX)
{
minX = value;
} else if (value > maxX)
{
maxX = value;
}
break;
}
case 1: // y
{
if (value < minY)
{
minY = value;
}
else if (value > maxY)
{
maxY = value;
}
break;
}
case 2: // z
{
if (value < minZ)
{
minZ = value;
}
else if (value > maxZ)
{
maxZ = value;
}
break;
}
}
}
const float sizeX = maxX - minX;
const float sizeY = maxY - minY;
const float sizeZ = maxZ - minZ;
return { sizeX, sizeY, sizeZ };
}
}
}

View File

@@ -37,7 +37,7 @@ namespace render_engine
{
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.3f, 0.4f, 0.6f, 1.0f);
glClearColor(SKY_COLOR.r, SKY_COLOR.g, SKY_COLOR.b, 1.0f);
}
/*

View File

@@ -7,6 +7,8 @@ namespace render_engine
{
namespace renderer
{
const glm::vec3 SKY_COLOR = { 0.3f, 0.4f, 0.6f };
/*
Call this function when starting the program
*/