Adding textures capabilities
* Added Texures to the two sample cubes * Modified mesh structure - mesh now contains indices and vertices - Vertices contain vertices and uv's (later on they will also contain normals) Solution definitely not perfect and needs improvement.
This commit is contained in:
parent
d019155d10
commit
16b61986a1
@ -2,9 +2,11 @@
|
|||||||
#include "glm/glm.hpp"
|
#include "glm/glm.hpp"
|
||||||
#include "graphics/Shader.h"
|
#include "graphics/Shader.h"
|
||||||
#include "graphics/Window.h"
|
#include "graphics/Window.h"
|
||||||
|
#include "graphics/Texture.h"
|
||||||
#include "graphics/Camera.h"
|
#include "graphics/Camera.h"
|
||||||
#include "graphics/Renderable.h"
|
#include "graphics/Renderable.h"
|
||||||
#include "Graphics/Material.h"
|
#include "Graphics/Material.h"
|
||||||
|
|
||||||
#include "spdlog/spdlog.h"
|
#include "spdlog/spdlog.h"
|
||||||
|
|
||||||
#include "Input/InputManager.h"
|
#include "Input/InputManager.h"
|
||||||
|
@ -1,13 +1,20 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
namespace BarinkEngine{
|
namespace BarinkEngine{
|
||||||
|
|
||||||
class Mesh {
|
|
||||||
public:
|
struct Vertex {
|
||||||
std::vector<glm::vec3> vertices;
|
glm::vec3 vertices;
|
||||||
std::vector<unsigned int > elements;
|
glm::vec2 uv;
|
||||||
std::vector<glm::vec2> uv;
|
};
|
||||||
};
|
|
||||||
|
class Mesh {
|
||||||
|
public:
|
||||||
|
std::vector<Vertex> vertices;
|
||||||
|
std::vector<unsigned int > elements;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
@ -3,6 +3,7 @@
|
|||||||
#include "Mesh.h"
|
#include "Mesh.h"
|
||||||
#include "Buffer.h"
|
#include "Buffer.h"
|
||||||
#include "Material.h"
|
#include "Material.h"
|
||||||
|
#include "Texture.h"
|
||||||
#include "VertexArray.h"
|
#include "VertexArray.h"
|
||||||
#include "Scene.h"
|
#include "Scene.h"
|
||||||
|
|
||||||
@ -14,10 +15,13 @@ public:
|
|||||||
*/
|
*/
|
||||||
Buffer vertexBuffer;
|
Buffer vertexBuffer;
|
||||||
Buffer elementBuffer;
|
Buffer elementBuffer;
|
||||||
|
//Buffer uv;
|
||||||
VertexArray VAO;
|
VertexArray VAO;
|
||||||
|
|
||||||
|
|
||||||
|
GLuint UV_id;
|
||||||
Material* material;
|
Material* material;
|
||||||
|
Texture* texture;
|
||||||
|
|
||||||
|
|
||||||
Shader* shader;
|
Shader* shader;
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
class Shader {
|
class Shader {
|
||||||
private:
|
private:
|
||||||
int id;
|
|
||||||
char* readFile (const char* filePath);
|
char* readFile (const char* filePath);
|
||||||
public:
|
public:
|
||||||
Shader(const std::string vertexShaderPath, const std::string fragmentShaderPath);
|
Shader(const std::string vertexShaderPath, const std::string fragmentShaderPath);
|
||||||
@ -22,5 +22,6 @@ class Shader {
|
|||||||
void setUniformFloat(std::string uniformName, float value)const;
|
void setUniformFloat(std::string uniformName, float value)const;
|
||||||
void setUniformInt(std::string uniformName, int value) const ;
|
void setUniformInt(std::string uniformName, int value) const ;
|
||||||
|
|
||||||
|
int id;
|
||||||
|
|
||||||
};
|
};
|
18
BarinkEngine/Include/Graphics/Texture.h
Normal file
18
BarinkEngine/Include/Graphics/Texture.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <spdlog/spdlog.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
|
class Texture {
|
||||||
|
public:
|
||||||
|
Texture(const std::string texturePath);
|
||||||
|
|
||||||
|
void Bind();
|
||||||
|
void Unbind();
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
unsigned int Id;
|
||||||
|
|
||||||
|
};
|
8007
BarinkEngine/Include/Graphics/stb_image.h
Normal file
8007
BarinkEngine/Include/Graphics/stb_image.h
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,47 +1,47 @@
|
|||||||
#include "Graphics/Buffer.h"
|
#include "Graphics/Buffer.h"
|
||||||
|
|
||||||
|
|
||||||
int Buffer::getBufferID() {
|
int Buffer::getBufferID() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Buffer::createBuffer() {
|
void Buffer::createBuffer() {
|
||||||
glGenBuffers(1, (GLuint*) &id);
|
glGenBuffers(1, (GLuint*) &id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Buffer::setBufferData(void* data, size_t dataSize, bool elementBuffer = false ) {
|
void Buffer::setBufferData(void* data, size_t dataSize, bool elementBuffer = false ) {
|
||||||
|
|
||||||
if (elementBuffer) {
|
if (elementBuffer) {
|
||||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, dataSize, data, GL_STATIC_DRAW);
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, dataSize, data, GL_STATIC_DRAW);
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
glBufferData(GL_ARRAY_BUFFER, dataSize, data, GL_STATIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, dataSize, data, GL_STATIC_DRAW);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Buffer::Bind(bool elementBuffer = false ) {
|
void Buffer::Bind(bool elementBuffer = false ) {
|
||||||
if (elementBuffer) {
|
if (elementBuffer) {
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, id);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, id);
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, id);
|
glBindBuffer(GL_ARRAY_BUFFER, id);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Buffer::Unbind(bool elementBuffer = false) {
|
void Buffer::Unbind(bool elementBuffer = false) {
|
||||||
if (elementBuffer) {
|
if (elementBuffer) {
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Buffer::Delete() {
|
void Buffer::Delete() {
|
||||||
glDeleteBuffers(1, (GLuint*) &id);
|
glDeleteBuffers(1, (GLuint*) &id);
|
||||||
}
|
}
|
@ -1,115 +1,133 @@
|
|||||||
#include "AssetManager/ModelImporter.h"
|
#include "AssetManager/ModelImporter.h"
|
||||||
|
|
||||||
|
|
||||||
void ModelImporter::ImportFBX(std::string path)
|
void ModelImporter::ImportFBX(std::string path)
|
||||||
{
|
{
|
||||||
//spdlog::warn("ImportFBX not implemented!");
|
//spdlog::warn("ImportFBX not implemented!");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelImporter::ImportBlend(std::string path)
|
void ModelImporter::ImportBlend(std::string path)
|
||||||
{
|
{
|
||||||
//spdlog::warn("ImportBlend not implemented!");
|
//spdlog::warn("ImportBlend not implemented!");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelImporter::ImportGLTF(std::string path)
|
void ModelImporter::ImportGLTF(std::string path)
|
||||||
{
|
{
|
||||||
//spdlog::warn("ImportGLTF not implemented!");
|
//spdlog::warn("ImportGLTF not implemented!");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelImporter::ImportOBJ(std::string path)
|
void ModelImporter::ImportOBJ(std::string path)
|
||||||
{
|
{
|
||||||
//spdlog::warn("ImportOBJ not implemented!");
|
//spdlog::warn("ImportOBJ not implemented!");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelImporter::Import(std::string path)
|
void ModelImporter::Import(std::string path)
|
||||||
{
|
{
|
||||||
//spdlog::warn("Import not implemented!");
|
//spdlog::warn("Import not implemented!");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<BarinkEngine::Mesh> ModelImporter::Test() {
|
std::vector<BarinkEngine::Mesh> ModelImporter::Test() {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
spdlog::info("====== Tiny GLTF ======");
|
spdlog::info("====== Tiny GLTF ======");
|
||||||
tinygltf::Model loadedModel;
|
tinygltf::Model loadedModel;
|
||||||
tinygltf::TinyGLTF loader;
|
tinygltf::TinyGLTF loader;
|
||||||
std::string error;
|
std::string error;
|
||||||
std::string warn;
|
std::string warn;
|
||||||
bool ret = loader.LoadASCIIFromFile(&loadedModel, &error, &warn, "./Build/SandboxApplication/Debug/sponza.gltf");
|
bool ret = loader.LoadASCIIFromFile(&loadedModel, &error, &warn, "./Build/SandboxApplication/Debug/sponza.gltf");
|
||||||
|
|
||||||
if (!warn.empty())
|
if (!warn.empty())
|
||||||
spdlog::warn("TinyGLTF Warning: {}", warn);
|
spdlog::warn("TinyGLTF Warning: {}", warn);
|
||||||
if (!error.empty())
|
if (!error.empty())
|
||||||
spdlog::error("TinyGLTF Error: {}", error);
|
spdlog::error("TinyGLTF Error: {}", error);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
spdlog::error("TinyGLTF Error: Failed to parse glTF");
|
spdlog::error("TinyGLTF Error: Failed to parse glTF");
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
spdlog::info("Meshes in model: {}", loadedModel.meshes.size());
|
spdlog::info("Meshes in model: {}", loadedModel.meshes.size());
|
||||||
spdlog::info("Primitives in mesh: {}", loadedModel.meshes[0].primitives.size());
|
spdlog::info("Primitives in mesh: {}", loadedModel.meshes[0].primitives.size());
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
//spdlog::info("======= Assimp ======");
|
//spdlog::info("======= Assimp ======");
|
||||||
|
|
||||||
Assimp::Importer importer;
|
Assimp::Importer importer;
|
||||||
const aiScene* scene = importer.ReadFile("build/SandboxApplication/Debug/Cube.obj", aiProcess_Triangulate | aiProcess_FlipUVs);
|
const aiScene* scene = importer.ReadFile("build/SandboxApplication/Debug/Cube.obj", aiProcess_Triangulate | aiProcess_FlipUVs);
|
||||||
|
|
||||||
aiNode* currentNode = scene->mRootNode;
|
aiNode* currentNode = scene->mRootNode;
|
||||||
|
|
||||||
return processNode(currentNode, scene);
|
return processNode(currentNode, scene);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<BarinkEngine::Mesh> ModelImporter::processNode(aiNode* node, const aiScene* scene) {
|
std::vector<BarinkEngine::Mesh> ModelImporter::processNode(aiNode* node, const aiScene* scene) {
|
||||||
std::vector<BarinkEngine::Mesh> meshes;
|
std::vector<BarinkEngine::Mesh> meshes;
|
||||||
for (unsigned int i = 0; i < node->mNumMeshes; i++) {
|
for (unsigned int i = 0; i < node->mNumMeshes; i++) {
|
||||||
aiMesh* mesh = scene->mMeshes[node->mMeshes[i]];
|
aiMesh* mesh = scene->mMeshes[node->mMeshes[i]];
|
||||||
meshes.push_back(processMesh(mesh, scene));
|
meshes.push_back(processMesh(mesh, scene));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned int i = 0; i < node->mNumChildren; i++) {
|
for (unsigned int i = 0; i < node->mNumChildren; i++) {
|
||||||
auto m2 = processNode(node->mChildren[i], scene);
|
auto m2 = processNode(node->mChildren[i], scene);
|
||||||
|
|
||||||
for(auto m : m2) {
|
for(auto m : m2) {
|
||||||
meshes.push_back(m);
|
meshes.push_back(m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return meshes;
|
return meshes;
|
||||||
}
|
}
|
||||||
|
|
||||||
BarinkEngine::Mesh ModelImporter::processMesh(aiMesh* mesh, const aiScene* scene) {
|
BarinkEngine::Mesh ModelImporter::processMesh(aiMesh* mesh, const aiScene* scene) {
|
||||||
std::vector<glm::vec3> vertices ;
|
std::vector<unsigned int> indices;
|
||||||
std::vector<unsigned int> indices;
|
std::vector<BarinkEngine::Vertex> vertices;
|
||||||
|
|
||||||
// Process vertices
|
// Process vertices
|
||||||
for (unsigned int i = 0; i < mesh->mNumVertices; i++) {
|
for (unsigned int i = 0; i < mesh->mNumVertices; i++) {
|
||||||
glm::vec3 vector;
|
BarinkEngine::Vertex v{};
|
||||||
vector.x = mesh->mVertices[i].x;
|
glm::vec3 vector;
|
||||||
vector.y = mesh->mVertices[i].y;
|
vector.x = mesh->mVertices[i].x;
|
||||||
vector.z = mesh->mVertices[i].z;
|
vector.y = mesh->mVertices[i].y;
|
||||||
vertices.push_back(vector);
|
vector.z = mesh->mVertices[i].z;
|
||||||
}
|
|
||||||
|
v.vertices = vector;
|
||||||
// Process Indices
|
|
||||||
for (unsigned int i = 0; i < mesh->mNumFaces; i++) {
|
if (mesh->mTextureCoords[0]) {
|
||||||
aiFace face = mesh->mFaces[i];
|
|
||||||
if (face.mNumIndices < 3)
|
glm::vec2 texCoord;
|
||||||
continue;
|
|
||||||
for (unsigned int j = 0; j < face.mNumIndices; j++) {
|
texCoord.x = mesh->mTextureCoords[0][i].x;
|
||||||
indices.push_back(face.mIndices[j]);
|
texCoord.y = mesh->mTextureCoords[0][i].y;
|
||||||
}
|
|
||||||
}
|
v.uv = texCoord;
|
||||||
|
|
||||||
BarinkEngine::Mesh result;
|
}
|
||||||
|
|
||||||
|
vertices.push_back(v);
|
||||||
result.vertices = vertices;
|
}
|
||||||
result.elements = indices;
|
|
||||||
|
// Process Indices
|
||||||
return result;
|
for (unsigned int i = 0; i < mesh->mNumFaces; i++) {
|
||||||
|
aiFace face = mesh->mFaces[i];
|
||||||
|
if (face.mNumIndices < 3)
|
||||||
|
continue;
|
||||||
|
for (unsigned int j = 0; j < face.mNumIndices; j++) {
|
||||||
|
indices.push_back(face.mIndices[j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
BarinkEngine::Mesh result;
|
||||||
|
|
||||||
|
|
||||||
|
result.vertices = vertices;
|
||||||
|
result.elements = indices;
|
||||||
|
|
||||||
|
|
||||||
|
return result;
|
||||||
|
|
||||||
}
|
}
|
@ -1,55 +1,62 @@
|
|||||||
#include "Graphics/Renderable.h"
|
#include "Graphics/Renderable.h"
|
||||||
#include "AssetManager/ModelImporter.h"
|
#include "AssetManager/ModelImporter.h"
|
||||||
#include "PerfCounter.h"
|
#include "PerfCounter.h"
|
||||||
|
|
||||||
|
|
||||||
Renderable* Renderable::Load()
|
Renderable* Renderable::Load()
|
||||||
{
|
{
|
||||||
return new Renderable();
|
return new Renderable();
|
||||||
}
|
}
|
||||||
|
|
||||||
Renderable::Renderable()
|
Renderable::Renderable()
|
||||||
{
|
{
|
||||||
|
meshes = ModelImporter::Test();
|
||||||
meshes = ModelImporter::Test();
|
|
||||||
|
transform.Scale = glm::vec3(1.0f);
|
||||||
transform.Scale = glm::vec3(1.0f);
|
transform.Rotation = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||||
transform.Rotation = glm::vec3(0.0f, 90.0f, 0.0f);
|
transform.Position = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||||
transform.Position = glm::vec3(0.0f, 0.0f, -10.0f);
|
|
||||||
|
VAO.Create();
|
||||||
|
VAO.Bind();
|
||||||
VAO.Create();
|
|
||||||
VAO.Bind();
|
|
||||||
|
vertexBuffer.createBuffer();
|
||||||
|
vertexBuffer.Bind(false);
|
||||||
vertexBuffer.createBuffer();
|
vertexBuffer.setBufferData(&meshes[0].vertices[0], meshes[0].vertices.size() * sizeof(BarinkEngine::Vertex), false);
|
||||||
vertexBuffer.Bind(false);
|
|
||||||
vertexBuffer.setBufferData(&meshes[0].vertices[0], meshes[0].vertices.size() * sizeof(glm::vec3), false);
|
elementBuffer.createBuffer();
|
||||||
|
elementBuffer.Bind(true);
|
||||||
|
elementBuffer.setBufferData(&meshes[0].elements[0], meshes[0].elements.size() * sizeof(unsigned int), true);
|
||||||
elementBuffer.createBuffer();
|
|
||||||
elementBuffer.Bind(true);
|
VAO.AttachAttribute(0, 3, sizeof(BarinkEngine::Vertex));
|
||||||
elementBuffer.setBufferData(&meshes[0].elements[0], meshes[0].elements.size() * sizeof(unsigned int), true);
|
|
||||||
|
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(BarinkEngine::Vertex),(void*) offsetof(BarinkEngine::Vertex, vertices));
|
||||||
VAO.AttachAttribute(0, 3, 0);
|
glEnableVertexAttribArray(1);
|
||||||
|
|
||||||
vertexBuffer.Unbind(false);
|
vertexBuffer.Unbind(false);
|
||||||
VAO.Unbind();
|
|
||||||
|
VAO.Unbind();
|
||||||
|
|
||||||
}
|
|
||||||
|
}
|
||||||
Renderable::~Renderable()
|
|
||||||
{
|
Renderable::~Renderable()
|
||||||
}
|
{
|
||||||
|
glDeleteBuffers(1, &UV_id);
|
||||||
void Renderable::Draw()
|
}
|
||||||
{
|
|
||||||
VAO.Bind();
|
void Renderable::Draw()
|
||||||
elementBuffer.Bind(true);
|
{
|
||||||
ES->verts = meshes[0].vertices.size();
|
VAO.Bind();
|
||||||
ES->DC++;
|
elementBuffer.Bind(true);
|
||||||
glDrawElements(GL_TRIANGLES, static_cast<unsigned int>(meshes[0].elements.size()), GL_UNSIGNED_INT, NULL);
|
|
||||||
VAO.Unbind();
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glUniform1i(glGetUniformLocation(shader->id, "Texture"), GL_TEXTURE0);
|
||||||
}
|
texture->Bind();
|
||||||
|
|
||||||
|
ES->verts = meshes[0].vertices.size();
|
||||||
|
ES->DC++;
|
||||||
|
glDrawElements(GL_TRIANGLES, static_cast<unsigned int>(meshes[0].elements.size()), GL_UNSIGNED_INT, NULL);
|
||||||
|
VAO.Unbind();
|
||||||
|
|
||||||
|
}
|
||||||
|
40
BarinkEngine/graphics/Texture.cpp
Normal file
40
BarinkEngine/graphics/Texture.cpp
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#include "../Include/Graphics/Texture.h"
|
||||||
|
#include <glad/glad.h>
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
|
#include "Graphics/stb_image.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
Texture::Texture(const std::string texturePath) {
|
||||||
|
|
||||||
|
int width, height, channels;
|
||||||
|
unsigned char* data = stbi_load(texturePath.c_str(), &width, &height, &channels, 0);
|
||||||
|
std::cout << channels << std::endl;
|
||||||
|
|
||||||
|
if (data) {
|
||||||
|
glGenTextures(1, &Id);
|
||||||
|
|
||||||
|
glBindTexture(GL_TEXTURE_2D, Id);
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
|
||||||
|
glGenerateMipmap(GL_TEXTURE_2D);
|
||||||
|
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
spdlog::error("Failed to load image (%s)", texturePath );
|
||||||
|
}
|
||||||
|
stbi_image_free(data);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Texture::Bind() {
|
||||||
|
glBindTexture(GL_TEXTURE_2D, Id);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Texture::Unbind() {
|
||||||
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
}
|
@ -1,25 +1,25 @@
|
|||||||
#include "Graphics/VertexArray.h"
|
#include "Graphics/VertexArray.h"
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
|
|
||||||
void VertexArray::Create(){
|
void VertexArray::Create(){
|
||||||
glGenVertexArrays(1, &id);
|
glGenVertexArrays(1, &id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VertexArray::Bind(){
|
void VertexArray::Bind(){
|
||||||
glBindVertexArray(id);
|
glBindVertexArray(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VertexArray::Unbind(){
|
void VertexArray::Unbind(){
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VertexArray::Delete() {
|
void VertexArray::Delete() {
|
||||||
glDeleteVertexArrays(1, &id);
|
glDeleteVertexArrays(1, &id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void VertexArray::AttachAttribute(unsigned int index , int size, int stride ){
|
void VertexArray::AttachAttribute(unsigned int index , int size, int stride ){
|
||||||
glVertexAttribPointer(index, size, GL_FLOAT, GL_FALSE, stride, 0);
|
glVertexAttribPointer(index, size, GL_FLOAT, GL_FALSE, stride, 0);
|
||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,14 @@
|
|||||||
#version 440 core
|
#version 440 core
|
||||||
|
|
||||||
out vec4 FragColor;
|
out vec4 FragColor;
|
||||||
|
|
||||||
uniform vec3 MatColour;
|
uniform vec3 Color;
|
||||||
|
|
||||||
void main(){
|
in vec2 TexCoord;
|
||||||
FragColor = vec4(MatColour, 1.0f);
|
|
||||||
|
uniform sampler2D Texture;
|
||||||
|
|
||||||
|
|
||||||
|
void main(){
|
||||||
|
FragColor = mix ( texture(Texture, TexCoord), vec4(Color, 1.0f));
|
||||||
}
|
}
|
@ -1,10 +1,15 @@
|
|||||||
#version 440 core
|
#version 440 core
|
||||||
in layout(location=0) vec3 aPos;
|
in layout(location=0) vec3 aPos;
|
||||||
|
in layout(location=1) vec2 uv;
|
||||||
|
|
||||||
uniform mat4 M;
|
uniform mat4 M;
|
||||||
uniform mat4 V;
|
uniform mat4 V;
|
||||||
uniform mat4 P;
|
uniform mat4 P;
|
||||||
|
|
||||||
|
out vec2 TexCoord;
|
||||||
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
TexCoord = uv;
|
||||||
gl_Position = P * V * M * vec4(aPos.x, aPos.y, aPos.z, 1.0);
|
gl_Position = P * V * M * vec4(aPos.x, aPos.y, aPos.z, 1.0);
|
||||||
}
|
}
|
@ -16,7 +16,7 @@ project "BarinkEngine"
|
|||||||
"../libs/assimp/include",
|
"../libs/assimp/include",
|
||||||
"../libs/glad/include",
|
"../libs/glad/include",
|
||||||
"../libs/glfw/include",
|
"../libs/glfw/include",
|
||||||
"../libs/tinygltf",
|
-- "../libs/tinygltf",
|
||||||
"../libs/glew/include",
|
"../libs/glew/include",
|
||||||
"../libs/glm",
|
"../libs/glm",
|
||||||
"../libs/ImGui",
|
"../libs/ImGui",
|
||||||
|
@ -32,4 +32,10 @@ void transformWindow(Transform& transform, std::string PanelName) {
|
|||||||
ImGui::InputFloat3("Scale:", (float*)&transform.Scale[0]);
|
ImGui::InputFloat3("Scale:", (float*)&transform.Scale[0]);
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void materialWindow(Material& material, std::string PanelName) {
|
||||||
|
ImGui::Begin(PanelName.c_str());
|
||||||
|
ImGui::ColorPicker3("Color:", &material.Color[0]);
|
||||||
|
ImGui::End();
|
||||||
}
|
}
|
@ -1,7 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
#include <BarinkEngine.h>
|
#include <BarinkEngine.h>
|
||||||
|
|
||||||
void CameraTool(Camera* camera);
|
void CameraTool(Camera* camera);
|
||||||
void ScriptingTool(char* code);
|
void ScriptingTool(char* code);
|
||||||
void transformWindow(Transform& transform, std::string PanelName);
|
void transformWindow(Transform& transform, std::string PanelName);
|
||||||
|
void materialWindow(Material& material, std::string PanelName);
|
@ -7,11 +7,15 @@
|
|||||||
* Define globals
|
* Define globals
|
||||||
*/
|
*/
|
||||||
Camera* cam;
|
Camera* cam;
|
||||||
Renderable* Cube;
|
|
||||||
Renderable* Cube2;
|
|
||||||
|
|
||||||
Shader* shader;
|
Shader* shader;
|
||||||
|
|
||||||
|
Renderable* Cube;
|
||||||
Material* matCube;
|
Material* matCube;
|
||||||
|
Texture* textureCube;
|
||||||
|
|
||||||
|
Renderable* Cube2;
|
||||||
Material* matCube2;
|
Material* matCube2;
|
||||||
|
|
||||||
char* code = new char[254];
|
char* code = new char[254];
|
||||||
@ -54,6 +58,8 @@ void Start() {
|
|||||||
|
|
||||||
shader = new Shader(vertexShaderSource, fragmentShaderSource);
|
shader = new Shader(vertexShaderSource, fragmentShaderSource);
|
||||||
|
|
||||||
|
textureCube = new Texture("build/SandboxApplication/Debug/die.jpg");
|
||||||
|
|
||||||
matCube = new Material(*shader);
|
matCube = new Material(*shader);
|
||||||
matCube->Color = glm::vec3(1.0, 0.0, 0.0);
|
matCube->Color = glm::vec3(1.0, 0.0, 0.0);
|
||||||
|
|
||||||
@ -67,7 +73,17 @@ void Start() {
|
|||||||
Cube2 = Renderable::Load();
|
Cube2 = Renderable::Load();
|
||||||
Cube->addChild(*Cube2);
|
Cube->addChild(*Cube2);
|
||||||
|
|
||||||
cam = new Camera(glm::vec3(0.0f, 1.5f, -10.0f), glm::vec3(0.0f, 0.0f, 0.0f), 90.0f);
|
Cube->shader = shader;
|
||||||
|
Cube2->shader = shader;
|
||||||
|
|
||||||
|
Cube->texture = textureCube;
|
||||||
|
Cube2->texture = textureCube;
|
||||||
|
|
||||||
|
Cube2->transform.Position = glm::vec3(-9.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
|
Cube->transform.Position = glm::vec3(-8.0f, 0.0f, -2.0f);
|
||||||
|
|
||||||
|
cam = new Camera(glm::vec3(0.0f, 1.5f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), 90.0f);
|
||||||
|
|
||||||
memset(code, '\0', 254);
|
memset(code, '\0', 254);
|
||||||
|
|
||||||
@ -98,6 +114,9 @@ void ImmediateGraphicsDraw() {
|
|||||||
|
|
||||||
transformWindow(Cube2->transform, "Transform (Cube2)");
|
transformWindow(Cube2->transform, "Transform (Cube2)");
|
||||||
|
|
||||||
|
materialWindow(*matCube, "Material Cube");
|
||||||
|
materialWindow(*matCube2, "Material Cube2");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user