Compare commits
3 commits
cd906be4c9
...
4b441adff3
Author | SHA1 | Date | |
---|---|---|---|
|
4b441adff3 | ||
|
3df83a13b4 | ||
|
ddd89a2b6d |
|
@ -29,19 +29,11 @@ struct PointLight {
|
|||
float quadratic;
|
||||
};
|
||||
|
||||
const int FaceRight = 0;
|
||||
const int FaceTop = 1;
|
||||
const int FaceBack = 2;
|
||||
const int FaceLeft = 3;
|
||||
const int FaceBottom = 4;
|
||||
const int FaceFront = 5;
|
||||
|
||||
// I/O
|
||||
|
||||
in vec3 vPos;
|
||||
in vec3 vNormal;
|
||||
in vec2 vTexCoords;
|
||||
flat in int vSurfaceZ;
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
|
@ -52,7 +44,6 @@ uniform PointLight pointLights[NR_POINT_LIGHTS];
|
|||
uniform int numPointLights;
|
||||
uniform DirLight sunLight;
|
||||
uniform Material material;
|
||||
uniform sampler2DArray studs;
|
||||
|
||||
// Functions
|
||||
|
||||
|
@ -70,9 +61,8 @@ void main() {
|
|||
for (int i = 0; i < numPointLights; i++) {
|
||||
result += calculatePointLight(pointLights[i]);
|
||||
}
|
||||
|
||||
vec4 studPx = texture(studs, vec3(vTexCoords, vSurfaceZ));
|
||||
FragColor = vec4(mix(result, vec3(studPx), studPx.w), 1);
|
||||
|
||||
FragColor = vec4(result, 1.0);
|
||||
}
|
||||
|
||||
vec3 calculateDirectionalLight(DirLight light) {
|
||||
|
|
|
@ -3,60 +3,18 @@ layout (location = 0) in vec3 aPos;
|
|||
layout (location = 1) in vec3 aNormal;
|
||||
layout (location = 2) in vec2 aTexCoords;
|
||||
|
||||
const int FaceRight = 0;
|
||||
const int FaceTop = 1;
|
||||
const int FaceBack = 2;
|
||||
const int FaceLeft = 3;
|
||||
const int FaceBottom = 4;
|
||||
const int FaceFront = 5;
|
||||
|
||||
const int SurfaceSmooth = 0;
|
||||
const int SurfaceGlue = 1;
|
||||
const int SurfaceWeld = 2;
|
||||
const int SurfaceStuds = 3;
|
||||
const int SurfaceInlets = 4;
|
||||
const int SurfaceUniversal = 5;
|
||||
|
||||
out vec3 vPos;
|
||||
out vec3 vNormal;
|
||||
out vec2 vTexCoords;
|
||||
flat out int vSurfaceZ;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat3 normalMatrix;
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
uniform int surfaces[6];
|
||||
uniform vec3 texScale;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = projection * view * model * vec4(aPos, 1.0);
|
||||
vPos = vec3(model * vec4(aPos, 1.0));
|
||||
vNormal = normalMatrix * aNormal;
|
||||
int vFace = aNormal == vec3(0,1,0) ? FaceTop :
|
||||
aNormal == vec3(0, -1, 0) ? FaceBottom :
|
||||
aNormal == vec3(1, 0, 0) ? FaceRight :
|
||||
aNormal == vec3(-1, 0, 0) ? FaceLeft :
|
||||
aNormal == vec3(0, 0, 1) ? FaceFront :
|
||||
aNormal == vec3(0, 0, -1) ? FaceBack : -1;
|
||||
|
||||
vSurfaceZ = surfaces[vFace];
|
||||
// if (surfaces[vFace] > SurfaceUniversal) vSurfaceZ = 0;
|
||||
|
||||
switch (vFace) {
|
||||
case FaceTop:
|
||||
case FaceBottom:
|
||||
// vTexCoords = aTexCoords * vec2(texScale.x / 2, fract(surfaceOffset + texScale.z / 12));
|
||||
vTexCoords = aTexCoords * vec2(texScale.x, texScale.z) / 2;
|
||||
break;
|
||||
case FaceLeft:
|
||||
case FaceRight:
|
||||
vTexCoords = aTexCoords * vec2(texScale.y, texScale.z) / 2;
|
||||
break;
|
||||
case FaceFront:
|
||||
case FaceBack:
|
||||
vTexCoords = aTexCoords * vec2(texScale.x, texScale.y) / 2;
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
#version 330 core
|
||||
|
||||
uniform samplerCube skybox;
|
||||
|
||||
// in vec3 vPos;
|
||||
// in vec3 vNormal;
|
||||
in vec3 vTexCoords;
|
||||
|
||||
out vec4 fColor;
|
||||
|
||||
// Main
|
||||
|
||||
void main() {
|
||||
// fColor = texture(uTexture, vTexCoords);
|
||||
fColor = texture(skybox, vTexCoords);
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
#version 330 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec3 aNormal;
|
||||
layout (location = 2) in vec2 aTexCoords;
|
||||
|
||||
// out vec3 vPos;
|
||||
// out vec3 vNormal;
|
||||
out vec3 vTexCoords;
|
||||
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
|
||||
void main()
|
||||
{
|
||||
vTexCoords = aPos;
|
||||
gl_Position = projection * view * vec4(aPos, 1.0);
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
null_plainsky is copyright of Jauhn Dabz, jauhn@yahoo.com, https://nullpoint.fragland.net
|
Before Width: | Height: | Size: 48 KiB |
Before Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 47 KiB |
Before Width: | Height: | Size: 43 KiB |
Before Width: | Height: | Size: 49 KiB |
Before Width: | Height: | Size: 28 KiB |
Before Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 36 KiB |
Before Width: | Height: | Size: 5.9 KiB |
|
@ -18,7 +18,7 @@ public:
|
|||
|
||||
float pitch = 0., yaw = -90., roll = 0.;
|
||||
|
||||
float movementSpeed = 10.0f;
|
||||
float movementSpeed = 5.0f;
|
||||
float mouseSensitivity = 0.2f;
|
||||
|
||||
Camera(glm::vec3 initialPosition);
|
||||
|
|
20
src/core/value.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
enum ValueType {
|
||||
OB_NIL = 0,
|
||||
OB_BOOLEAN,
|
||||
OB_INTEGER,
|
||||
OB_FLOAT,
|
||||
OB_STRING,
|
||||
};
|
||||
|
||||
struct Value {
|
||||
ValueType type;
|
||||
union {
|
||||
bool b;
|
||||
int i;
|
||||
float f;
|
||||
std::string str;
|
||||
};
|
||||
};
|
53
src/datamodel/instance.cpp
Normal file
|
@ -0,0 +1,53 @@
|
|||
#include "instance.h"
|
||||
#include "instancetype.h"
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
InstanceType TYPE_INSTANCE {
|
||||
.superClass = nullptr,
|
||||
.className = "Instance",
|
||||
.flags = OB_INST_NOT_CREATABLE,
|
||||
};
|
||||
|
||||
std::optional<std::shared_ptr<Instance>> Instance::GetParent() {
|
||||
if (!this->Parent.has_value() || this->Parent.value().expired())
|
||||
return std::nullopt;
|
||||
return this->Parent.value().lock();
|
||||
}
|
||||
|
||||
void Instance::SetParent(std::optional<std::shared_ptr<Instance>> newParent) {
|
||||
// Remove this instance from the existing parent
|
||||
if (this->Parent.has_value() && !this->Parent.value().expired()) {
|
||||
std::shared_ptr<Instance> parent = this->Parent.value().lock();
|
||||
parent->children.erase(std::remove_if(parent->children.begin(), parent->children.end(), [this](std::shared_ptr<Instance> ptr) {
|
||||
return ptr.get() == this;
|
||||
}));
|
||||
}
|
||||
|
||||
// Add self to
|
||||
if (newParent.has_value()) {
|
||||
newParent.value()->children.push_back(this->shared_from_this());
|
||||
}
|
||||
|
||||
this->Parent = newParent;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<Instance>> Instance::GetChildren() {
|
||||
return this->children;
|
||||
}
|
||||
|
||||
std::unique_ptr<Instance> Instance::CloneInternal() {
|
||||
// TODO: Implement refs
|
||||
|
||||
std::unique_ptr<Instance> clone = this->__copy();
|
||||
clone->children = std::vector<std::shared_ptr<Instance>>();
|
||||
clone->children.reserve(this->children.size());
|
||||
|
||||
for (std::shared_ptr<Instance> child : this->children) {
|
||||
clone->children.push_back(child->CloneInternal());
|
||||
}
|
||||
|
||||
return clone;
|
||||
}
|
39
src/datamodel/instance.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
#pragma once
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "instancetype.h"
|
||||
|
||||
#define INSTANCE_COPY_IMPL(CLASS_NAME) std::unique_ptr<Instance> CLASS_NAME::__copy() { return std::make_unique<CLASS_NAME>(CLASS_NAME(*this)); }
|
||||
#define INSTANCE_PRELUDE(CLASS_NAME) protected: virtual std::unique_ptr<Instance> __copy() override; virtual InstanceType& GetType() const override;
|
||||
// #define INSTANCE_TYPE(CLASS_NAME, TYPE_DEFINITION) InstanceType& CLASS_NAME::GetType() const { \
|
||||
// static InstanceType type = TYPE_DEFINITION; \
|
||||
// return type; \
|
||||
// };
|
||||
#define INSTANCE_TYPE(CLASS_NAME, TYPE_CONSTANT) InstanceType& CLASS_NAME::GetType() const { return TYPE_CONSTANT; };
|
||||
|
||||
extern InstanceType TYPE_INSTANCE;
|
||||
|
||||
// The base class for all objects in the data model
|
||||
class Instance : std::enable_shared_from_this<Instance> {
|
||||
private:
|
||||
std::optional<std::weak_ptr<Instance>> Parent;
|
||||
std::vector<std::shared_ptr<Instance>> children;
|
||||
protected:
|
||||
virtual std::unique_ptr<Instance> __copy();
|
||||
public:
|
||||
std::string Name;
|
||||
std::optional<std::shared_ptr<Instance>> GetParent();
|
||||
void SetParent(std::optional<std::shared_ptr<Instance>> newParent);
|
||||
std::vector<std::shared_ptr<Instance>> GetChildren();
|
||||
|
||||
virtual void Init();
|
||||
std::unique_ptr<Instance> CloneInternal();
|
||||
virtual InstanceType& GetType() const = 0;
|
||||
|
||||
virtual Value GetProperty(std::string key);
|
||||
virtual void SetProperty(std::string key, Value newValue);
|
||||
virtual Value CallMethod(std::string key, std::vector<Value> arguments);
|
||||
};
|
39
src/datamodel/instancetype.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
#pragma once
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "../core/value.h"
|
||||
|
||||
enum PropertyFlags {
|
||||
OB_PROP_READ_ONLY = 1, // The property cannot be set
|
||||
// OB_PROP_CALLBACK = 2, // The proeprty is get/set through a function instead of directly to a field
|
||||
};
|
||||
|
||||
enum MethodFlags {
|
||||
// OB_METHOD_OVERLOADED = 1, // The method has multiple definitions with different parameters suffixed by __ followed by a number
|
||||
};
|
||||
|
||||
enum InstanceFlags {
|
||||
OB_INST_NOT_CREATABLE = 1,
|
||||
};
|
||||
|
||||
struct PropertyInfo {
|
||||
PropertyFlags flags;
|
||||
void* fieldPointer;
|
||||
ValueType valueType;
|
||||
};
|
||||
|
||||
struct MethodInfo {
|
||||
MethodFlags flags;
|
||||
void* functionPointer;
|
||||
ValueType returnType;
|
||||
std::vector<ValueType> parameterTypes;
|
||||
};
|
||||
|
||||
struct InstanceType {
|
||||
InstanceType* superClass = nullptr;
|
||||
std::string className;
|
||||
InstanceFlags flags;
|
||||
std::map<std::string, PropertyInfo> properties;
|
||||
std::map<std::string, MethodInfo> methods;
|
||||
};
|
15
src/datamodel/part.cpp
Normal file
|
@ -0,0 +1,15 @@
|
|||
#include "part.h"
|
||||
#include "instance.h"
|
||||
#include "instancetype.h"
|
||||
#include <map>
|
||||
|
||||
INSTANCE_COPY_IMPL(Part)
|
||||
|
||||
InstanceType TYPE_PART {
|
||||
.superClass = &TYPE_INSTANCE,
|
||||
.className = "Part",
|
||||
.properties = std::map<std::string, PropertyInfo>(),
|
||||
.methods = std::map<std::string, MethodInfo>(),
|
||||
};
|
||||
|
||||
INSTANCE_TYPE(Part, TYPE_PART)
|
|
@ -3,11 +3,17 @@
|
|||
#include <glm/fwd.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#include <reactphysics3d/body/RigidBody.h>
|
||||
#include "rendering/material.h"
|
||||
#include "../rendering/material.h"
|
||||
#include "instance.h"
|
||||
#include "instancetype.h"
|
||||
|
||||
namespace rp = reactphysics3d;
|
||||
|
||||
struct Part {
|
||||
extern InstanceType TYPE_PART;
|
||||
|
||||
class Part : public Instance {
|
||||
INSTANCE_PRELUDE(Part)
|
||||
public:
|
||||
glm::vec3 position;
|
||||
glm::quat rotation = glm::identity<glm::quat>();
|
||||
glm::vec3 scale;
|
10
src/main.cpp
|
@ -8,7 +8,7 @@
|
|||
#include <stdio.h>
|
||||
#include <vector>
|
||||
|
||||
#include "part.h"
|
||||
#include "datamodel/part.h"
|
||||
#include "rendering/renderer.h"
|
||||
#include "physics/simulation.h"
|
||||
#include "camera.h"
|
||||
|
@ -45,9 +45,9 @@ int main() {
|
|||
parts.push_back(Part {
|
||||
.position = glm::vec3(0, -5, 0),
|
||||
.rotation = glm::vec3(0),
|
||||
.scale = glm::vec3(512, 1.2, 512),
|
||||
.scale = glm::vec3(5, 1, 5),
|
||||
.material = Material {
|
||||
.diffuse = glm::vec3(0.388235, 0.372549, 0.384314),
|
||||
.diffuse = glm::vec3(1.0f, 0.5f, 0.31f),
|
||||
.specular = glm::vec3(0.5f, 0.5f, 0.5f),
|
||||
.shininess = 32.0f,
|
||||
},
|
||||
|
@ -58,9 +58,9 @@ int main() {
|
|||
parts.push_back(Part {
|
||||
.position = glm::vec3(0),
|
||||
.rotation = glm::vec3(0),
|
||||
.scale = glm::vec3(4, 1.2, 2),
|
||||
.scale = glm::vec3(1, 1, 1),
|
||||
.material = Material {
|
||||
.diffuse = glm::vec3(0.639216f, 0.635294f, 0.647059f),
|
||||
.diffuse = glm::vec3(1.0f, 0.5f, 0.31f),
|
||||
.specular = glm::vec3(0.5f, 0.5f, 0.5f),
|
||||
.shininess = 32.0f,
|
||||
}
|
||||
|
|
|
@ -30,7 +30,6 @@ void simulationInit() {
|
|||
rp::Quaternion orientation = rp::Quaternion::identity();
|
||||
rp::Transform transform(position, orientation);
|
||||
rp::RigidBody* body = world->createRigidBody(transform);
|
||||
world->setGravity(rp::Vector3(0, -196.2, 0));
|
||||
}
|
||||
|
||||
void syncPartPhysics(Part& part) {
|
||||
|
@ -49,14 +48,13 @@ void syncPartPhysics(Part& part) {
|
|||
part.rigidBody->removeCollider(part.rigidBody->getCollider(0));
|
||||
}
|
||||
|
||||
if (part.rigidBody->getNbColliders() == 0)
|
||||
part.rigidBody->addCollider(shape, rp::Transform());
|
||||
part.rigidBody->setType(part.anchored ? rp::BodyType::STATIC : rp::BodyType::DYNAMIC);
|
||||
}
|
||||
|
||||
void physicsStep(float deltaTime) {
|
||||
// Step the simulation a few steps
|
||||
world->update(deltaTime / 2);
|
||||
world->update(deltaTime);
|
||||
|
||||
for (Part& part : parts) {
|
||||
const rp::Transform& transform = part.rigidBody->getTransform();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "../part.h"
|
||||
#include "../datamodel/part.h"
|
||||
|
||||
void simulationInit();
|
||||
void syncPartPhysics(Part& part);
|
||||
|
|
|
@ -5,7 +5,7 @@ Mesh* CUBE_MESH;
|
|||
void initMeshes() {
|
||||
static float vertices[] = {
|
||||
// positions // normals // texture coords
|
||||
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f,
|
||||
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f,
|
||||
0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f,
|
||||
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f,
|
||||
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f,
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
#include <GL/gl.h>
|
||||
#include <cstdio>
|
||||
#include <glm/ext.hpp>
|
||||
#include <glm/ext/matrix_float4x4.hpp>
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/trigonometric.hpp>
|
||||
|
@ -13,19 +12,13 @@
|
|||
#include "mesh.h"
|
||||
#include "defaultmeshes.h"
|
||||
#include "../camera.h"
|
||||
#include "../part.h"
|
||||
#include "skybox.h"
|
||||
#include "surface.h"
|
||||
#include "texture3d.h"
|
||||
#include "../datamodel/part.h"
|
||||
|
||||
#include "renderer.h"
|
||||
|
||||
Shader *shader = NULL;
|
||||
Shader *skyboxShader = NULL;
|
||||
extern Camera camera;
|
||||
extern std::vector<Part> parts;
|
||||
Skybox* skyboxTexture = NULL;
|
||||
Texture3D* studsTexture = NULL;
|
||||
|
||||
void renderInit(GLFWwindow* window) {
|
||||
glViewport(0, 0, 1200, 900);
|
||||
|
@ -33,46 +26,31 @@ void renderInit(GLFWwindow* window) {
|
|||
initMeshes();
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
// glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
|
||||
skyboxTexture = new Skybox({
|
||||
"assets/textures/skybox/null_plainsky512_lf.jpg",
|
||||
"assets/textures/skybox/null_plainsky512_rt.jpg",
|
||||
"assets/textures/skybox/null_plainsky512_up.jpg",
|
||||
"assets/textures/skybox/null_plainsky512_dn.jpg",
|
||||
"assets/textures/skybox/null_plainsky512_ft.jpg",
|
||||
"assets/textures/skybox/null_plainsky512_bk.jpg",
|
||||
}, GL_RGB);
|
||||
|
||||
studsTexture = new Texture3D("assets/textures/studs.png", 128, 128, 6, GL_RGBA);
|
||||
|
||||
// Compile shader
|
||||
shader = new Shader("assets/shaders/phong.vs", "assets/shaders/phong.fs");
|
||||
skyboxShader = new Shader("assets/shaders/skybox.vs", "assets/shaders/skybox.fs");
|
||||
}
|
||||
|
||||
void renderParts() {
|
||||
glDepthMask(GL_TRUE);
|
||||
void render(GLFWwindow* window) {
|
||||
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// Use shader
|
||||
shader->use();
|
||||
// shader->set("objectColor", glm::vec3(1.0f, 0.5f, 0.31f));
|
||||
// shader->set("lightColor", glm::vec3(1.0f, 1.0f, 1.0f));
|
||||
shader->set("objectColor", glm::vec3(1.0f, 0.5f, 0.31f));
|
||||
shader->set("lightColor", glm::vec3(1.0f, 1.0f, 1.0f));
|
||||
|
||||
// view/projection transformations
|
||||
glm::mat4 projection = glm::perspective(glm::radians(45.f), (float)1200 / (float)900, 0.1f, 100.0f);
|
||||
glm::mat4 view = camera.getLookAt();
|
||||
shader->set("projection", projection);
|
||||
shader->set("view", view);
|
||||
// shader->set("material", Material {
|
||||
// // .ambient = glm::vec3(1.0f, 0.5f, 0.31f),
|
||||
// .diffuse = glm::vec3(0.639216f, 0.635294f, 0.647059f),
|
||||
// .specular = glm::vec3(0.5f, 0.5f, 0.5f),
|
||||
// .shininess = 16.0f,
|
||||
// });
|
||||
shader->set("material", Material {
|
||||
// .ambient = glm::vec3(1.0f, 0.5f, 0.31f),
|
||||
.diffuse = glm::vec3(1.0f, 0.5f, 0.31f),
|
||||
.specular = glm::vec3(0.5f, 0.5f, 0.5f),
|
||||
.shininess = 32.0f,
|
||||
});
|
||||
shader->set("sunLight", DirLight {
|
||||
.direction = glm::vec3(-0.2f, -1.0f, -0.3f),
|
||||
.ambient = glm::vec3(0.2f, 0.2f, 0.2f),
|
||||
|
@ -89,11 +67,6 @@ void renderParts() {
|
|||
// .linear = 0.9,
|
||||
// .quadratic = 0.32,
|
||||
// });
|
||||
studsTexture->activate(0);
|
||||
shader->set("studs", 0);
|
||||
// shader->set("surfaces[1]", SurfaceStuds);
|
||||
shader->set("surfaces[1]", SurfaceStuds);
|
||||
shader->set("surfaces[4]", SurfaceInlets);
|
||||
|
||||
// Pre-calculate the normal matrix for the shader
|
||||
|
||||
|
@ -106,38 +79,10 @@ void renderParts() {
|
|||
model = model * glm::mat4_cast(part.rotation);
|
||||
model = glm::scale(model, part.scale);
|
||||
shader->set("model", model);
|
||||
shader->set("material", part.material);
|
||||
glm::mat3 normalMatrix = glm::mat3(glm::transpose(glm::inverse(model)));
|
||||
shader->set("normalMatrix", normalMatrix);
|
||||
shader->set("texScale", part.scale);
|
||||
|
||||
CUBE_MESH->bind();
|
||||
glDrawArrays(GL_TRIANGLES, 0, 36);
|
||||
}
|
||||
}
|
||||
|
||||
void renderSkyBox() {
|
||||
glDepthMask(GL_FALSE);
|
||||
|
||||
skyboxShader->use();
|
||||
|
||||
glm::mat4 projection = glm::perspective(glm::radians(45.f), (float)1200 / (float)900, 0.1f, 100.0f);
|
||||
// Remove translation component of view, making us always at (0, 0, 0)
|
||||
glm::mat4 view = glm::mat4(glm::mat3(camera.getLookAt()));
|
||||
|
||||
skyboxShader->set("projection", projection);
|
||||
skyboxShader->set("view", view);
|
||||
|
||||
skyboxShader->set("uTexture", 0);
|
||||
|
||||
CUBE_MESH->bind();
|
||||
glDrawArrays(GL_TRIANGLES, 0, 36);
|
||||
}
|
||||
|
||||
void render(GLFWwindow* window) {
|
||||
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
renderSkyBox();
|
||||
renderParts();
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
#include <GL/glew.h>
|
||||
#include <GL/gl.h>
|
||||
#include <stb/stb_image.h>
|
||||
|
||||
#include "skybox.h"
|
||||
|
||||
Skybox::Skybox(std::array<std::string, 6> faces, unsigned int format) {
|
||||
glGenTextures(1, &this->ID);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, this->ID);
|
||||
|
||||
// stbi_set_flip_vertically_on_load(true);
|
||||
for (unsigned int i = 0; i< faces.size(); i++) {
|
||||
int width, height, nrChannels;
|
||||
unsigned char *data = stbi_load(faces[i].c_str(), &width, &height,
|
||||
&nrChannels, 0);
|
||||
|
||||
if (!data) {
|
||||
printf("Failed to load texture '%s'\n", faces[i].c_str());
|
||||
abort();
|
||||
}
|
||||
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, format, width, height, 0, format,
|
||||
GL_UNSIGNED_BYTE, data);
|
||||
stbi_image_free(data);
|
||||
}
|
||||
|
||||
// Wrapping
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
||||
|
||||
// Interpolation
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
}
|
||||
|
||||
Skybox::~Skybox() {
|
||||
glDeleteTextures(1, &this->ID);
|
||||
}
|
||||
|
||||
void Skybox::activate(unsigned int textureIdx) {
|
||||
glActiveTexture(GL_TEXTURE0 + textureIdx);
|
||||
glBindTexture(GL_TEXTURE_2D, this->ID);
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#define GL_RGB 0x1907
|
||||
|
||||
class Skybox {
|
||||
private:
|
||||
unsigned int ID;
|
||||
public:
|
||||
Skybox(std::array<std::string, 6>, unsigned format = GL_RGB);
|
||||
~Skybox();
|
||||
|
||||
void activate(unsigned int textureIdx);
|
||||
};
|
|
@ -1,10 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
enum SurfaceType {
|
||||
SurfaceSmooth = 0,
|
||||
SurfaceGlue = 1,
|
||||
SurfaceWeld = 2,
|
||||
SurfaceStuds = 3,
|
||||
SurfaceInlets = 4,
|
||||
SurfaceUniversal = 5,
|
||||
};
|
|
@ -1,43 +0,0 @@
|
|||
#include "texture.h"
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include <GL/gl.h>
|
||||
#include <stb/stb_image.h>
|
||||
|
||||
Texture::Texture(const char* texturePath, unsigned int format, bool noMipMaps) {
|
||||
glGenTextures(1, &this->ID);
|
||||
glBindTexture(GL_TEXTURE_2D, this->ID);
|
||||
|
||||
// Wrapping
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
|
||||
// Interpolation
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
|
||||
// stbi_set_flip_vertically_on_load(true);
|
||||
int width, height, nrChannels;
|
||||
unsigned char *data = stbi_load(texturePath, &width, &height,
|
||||
&nrChannels, 0);
|
||||
|
||||
if (!data) {
|
||||
printf("Failed to load texture '%s'\n", texturePath);
|
||||
abort();
|
||||
}
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format,
|
||||
GL_UNSIGNED_BYTE, data);
|
||||
if (!noMipMaps) glGenerateMipmap(GL_TEXTURE_2D);
|
||||
|
||||
stbi_image_free(data);
|
||||
}
|
||||
|
||||
Texture::~Texture() {
|
||||
glDeleteTextures(1, &this->ID);
|
||||
}
|
||||
|
||||
void Texture::activate(unsigned int textureIdx) {
|
||||
glActiveTexture(GL_TEXTURE0 + textureIdx);
|
||||
glBindTexture(GL_TEXTURE_2D, this->ID);
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#define GL_RGB 0x1907
|
||||
|
||||
class Texture {
|
||||
private:
|
||||
unsigned int ID;
|
||||
public:
|
||||
Texture(const char* texturePath, unsigned format = GL_RGB, bool noMipMaps = false);
|
||||
~Texture();
|
||||
|
||||
void activate(unsigned int textureIdx);
|
||||
};
|
|
@ -1,43 +0,0 @@
|
|||
#include "texture3d.h"
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include <GL/gl.h>
|
||||
#include <stb/stb_image.h>
|
||||
|
||||
Texture3D::Texture3D(const char* texturePath, unsigned int tileWidth, unsigned int tileHeight, unsigned int tileCount, unsigned int format) {
|
||||
glGenTextures(1, &this->ID);
|
||||
glBindTexture(GL_TEXTURE_2D_ARRAY, this->ID);
|
||||
|
||||
// Wrapping
|
||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_R, GL_REPEAT);
|
||||
|
||||
// Interpolation
|
||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
|
||||
// stbi_set_flip_vertically_on_load(true);
|
||||
int width, height, nrChannels;
|
||||
unsigned char *data = stbi_load(texturePath, &width, &height,
|
||||
&nrChannels, 0);
|
||||
|
||||
if (!data) {
|
||||
printf("Failed to load texture '%s'\n", texturePath);
|
||||
abort();
|
||||
}
|
||||
|
||||
glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, format, tileWidth, tileHeight, /* no of layers= */ tileCount, 0, format,
|
||||
GL_UNSIGNED_BYTE, data);
|
||||
|
||||
stbi_image_free(data);
|
||||
}
|
||||
|
||||
Texture3D::~Texture3D() {
|
||||
glDeleteTextures(1, &this->ID);
|
||||
}
|
||||
|
||||
void Texture3D::activate(unsigned int textureIdx) {
|
||||
glActiveTexture(GL_TEXTURE0 + textureIdx);
|
||||
glBindTexture(GL_TEXTURE_2D, this->ID);
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#define GL_RGB 0x1907
|
||||
|
||||
class Texture3D {
|
||||
private:
|
||||
unsigned int ID;
|
||||
public:
|
||||
Texture3D(const char* texturePath, unsigned int tileWidth, unsigned int tileHeight, unsigned int tileCount, unsigned format = GL_RGB);
|
||||
~Texture3D();
|
||||
|
||||
void activate(unsigned int textureIdx);
|
||||
};
|
|
@ -1,2 +0,0 @@
|
|||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include <stb/stb_image.h>
|