Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

things (Check readme changes!) #5

Merged
merged 7 commits into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,14 @@ Pull requests are welcome. For major changes, please open an issue first to disc
- [x] Materials
- [x] Render System
- [x] Multiple Objects rendering at the same time
- [ ] Lights
- [ ] Skybox
- [ ] Mesh Importing
- [ ] Full UV mapping support
- [ ] Full vertex color support
- [ ] Multiple texture materials
- [ ] Normals
- [ ] Normal maps
- [ ] Skybox
- [ ] Lights
- [ ] Input System
- [ ] Events System
- [ ] Collision
Expand All @@ -93,4 +98,4 @@ Pull requests are welcome. For major changes, please open an issue first to disc
- [ ] Scene Graph
- [ ] XML based scene graph import
- [ ] Test ON Windows
- [ ] Port to Emscripten
- [ ] Port to Emscripten
93 changes: 47 additions & 46 deletions engine/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,30 @@
#include "ce_render_fundementals.h"
#include "rendering/camera.h"
#include "rendering/material.h"
#include "rendering/rendering_engine.h"
#include "rendering/render_engine.h"

/*
* Vertices
*/
// clang-format off
ce::Vertex cubeVertices[] = {
//<POS> <COLOR> <TEX COORD>
ce::Vertex cubeVerts[] = {
// Position Color Texture coord
glm::vec3( 0.5f, 0.5f, -0.5f), glm::vec4(0.0f, 0.0f, 0.0f, 1.0f), glm::vec2(1.0f, 1.0f),// 0
glm::vec3( 0.5f, -0.5f, -0.5f), glm::vec4(0.0f, 0.0f, 1.0f, 1.0f), glm::vec2(1.0f, 0.0f),// 1
glm::vec3(-0.5f, -0.5f, -0.5f), glm::vec4(0.0f, 1.0f, 1.0f, 1.0f), glm::vec2(0.0f, 0.0f),// 2
glm::vec3(-0.5f, 0.5f, -0.5f), glm::vec4(0.0f, 1.0f, 0.0f, 1.0f), glm::vec2(0.0f, 1.0f),// 3

glm::vec3( 0.5f, 0.5f, 0.5f), glm::vec4(1.0f, 0.0f, 0.0f, 1.0f), glm::vec2(1.0f, 1.0f),// 4
glm::vec3( 0.5f, -0.5f, 0.5f), glm::vec4(1.0f, 1.0f, 0.0f, 1.0f), glm::vec2(1.0f, 0.0f),// 5
glm::vec3(-0.5f, -0.5f, 0.5f), glm::vec4(1.0f, 0.0f, 1.0f, 1.0f), glm::vec2(0.0f, 0.0f),// 6
glm::vec3(-0.5f, 0.5f, 0.5f), glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), glm::vec2(0.0f, 1.0f),// 7
glm::vec3( 0.5f, 0.5f, 0.5f), glm::vec4(1.0f, 0.0f, 0.0f, 1.0f), glm::vec2(1.0f, 1.0f),// 4
glm::vec3( 0.5f, -0.5f, 0.5f), glm::vec4(1.0f, 1.0f, 0.0f, 1.0f), glm::vec2(1.0f, 0.0f),// 5
glm::vec3(-0.5f, -0.5f, 0.5f), glm::vec4(1.0f, 0.0f, 1.0f, 1.0f), glm::vec2(0.0f, 0.0f),// 6
glm::vec3(-0.5f, 0.5f, 0.5f), glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), glm::vec2(0.0f, 1.0f),// 7
};
ce::Vertex planeVertices[] = {
//<POS> <COLOR> <TEX COORD>
glm::vec3( 1.0f, 0.0f, 1.0f), glm::vec4(0.0f, 1.0f, 0.0f, 1.0f), glm::vec2(1.0f, 1.0f),// 0
glm::vec3( 1.0f, 0.0f, -1.0f), glm::vec4(0.0f, 1.0f, 0.0f, 1.0f), glm::vec2(1.0f, 0.0f),// 1
glm::vec3(-1.0f, 0.0f, -1.0f), glm::vec4(0.0f, 1.0f, 0.0f, 1.0f), glm::vec2(0.0f, 0.0f),// 2
glm::vec3(-1.0f, 0.0f, 1.0f), glm::vec4(0.0f, 1.0f, 0.0f, 1.0f), glm::vec2(0.0f, 1.0f)// 3
ce::Vertex planeVerts[] = {
// Position Color Texture coord
glm::vec3( 1.0f, 0.0f, 1.0f), glm::vec4(0.0f, 1.0f, 0.0f, 1.0f), glm::vec2(1.0f, 1.0f),// 0
glm::vec3( 1.0f, 0.0f, -1.0f), glm::vec4(0.0f, 1.0f, 0.0f, 1.0f), glm::vec2(1.0f, 0.0f),// 1
glm::vec3(-1.0f, 0.0f, -1.0f), glm::vec4(0.0f, 1.0f, 0.0f, 1.0f), glm::vec2(0.0f, 0.0f),// 2
glm::vec3(-1.0f, 0.0f, 1.0f), glm::vec4(0.0f, 1.0f, 0.0f, 1.0f), glm::vec2(0.0f, 1.0f),// 3
};


Expand All @@ -53,8 +53,8 @@ ce::Vertex planeVertices[] = {
2-1/
*/
// clang-format on
unsigned cubeVertexCount = sizeof(cubeVertices) / sizeof(ce::Vertex);
unsigned planeVertexCount = sizeof(planeVertices) / sizeof(ce::Vertex);
unsigned cubeVertCount = sizeof(cubeVerts) / sizeof(ce::Vertex);
unsigned planeVertCount = sizeof(planeVerts) / sizeof(ce::Vertex);
// 7<=>5
// clang-format off
GLuint cubeIndices [] = {
Expand All @@ -80,7 +80,7 @@ GLuint cubeIndices [] = {

GLuint planeIndices[] = {
0, 1, 3,
1, 2, 3
1, 2, 3,
};
// clang-format on
unsigned cubeIndexCount = sizeof(cubeIndices) / sizeof(GLuint);
Expand All @@ -92,31 +92,32 @@ int main(int argc, char* argv[]) {
ce::Time* time = new ce::Time();

ce::Window* window = new ce::Window("Cinnabar");
ce::RenderingEngine* renderingEngine = new ce::RenderingEngine();
renderingEngine->setFOV(75.0f);
renderingEngine->setSize(window->getWindowSize());
renderingEngine->setClipRange(0.1f, 100.0f);

//Cube
ce::Transform* cubeTransform = new ce::Transform();
ce::Mesh* cubeMesh = new ce::Mesh(cubeVertices, cubeVertexCount, cubeIndices, cubeIndexCount);

ce::RenderEngine* renderEngine = new ce::RenderEngine();
renderEngine->setFOV(75.0f);
renderEngine->setSize(window->getWindowSize());
renderEngine->setClipRange(0.1f, 100.0f);

// Cube
ce::Mesh* cubeMesh = new ce::Mesh(cubeVerts, cubeVertCount, cubeIndices, cubeIndexCount);
ce::Transform* cubePos = new ce::Transform();
ce::Material* cubeMaterial = new ce::Material("basic");
cubeMaterial->setTexture("uv-map.png");

//Plane
// Plane
ce::Mesh* planeMesh = new ce::Mesh(planeVerts, planeIndexCount, planeIndices, planeVertCount);
ce::Transform* planePos = new ce::Transform();
ce::Material* planeMaterial = new ce::Material("color");
ce::Mesh* planeMesh = new ce::Mesh(planeVertices, planeIndexCount, planeIndices, planeVertexCount);
ce::Transform* planeTransform = new ce::Transform();
planeTransform->setPosition(0.0f,-1.0f,0.0f);
planeTransform->scale(10.0f,1.0f,10.0f);
planePos->setPosition(0.0f, -1.0f, 0.0f);
planePos->scale(10.0f, 1.0f, 10.0f);

float mouseSensitivity = 0.1f;
float mouseSens = 0.1f;
ce::Camera* camera = new ce::Camera();
// Seperate so i can put in a player class later
// TODO: Seperate so i can put in a player class later
glm::vec3 cameraVelocity(0.0f);
camera->getTransform()->setPosition(0.0f, 0.0f, 1.5f);
camera->getTransform()->setYaw(-90.0f);
renderingEngine->setCamera(camera);
renderEngine->setCamera(camera);
/*
* Game Loop
*/
Expand All @@ -131,7 +132,7 @@ int main(int argc, char* argv[]) {
if (window->mouseVisible())
break;
glm::vec2 mouseDelta(event.motion.xrel, event.motion.yrel);
mouseDelta *= mouseSensitivity;
mouseDelta *= mouseSens;
camera->getTransform()->yaw(mouseDelta.x);
camera->getTransform()->pitch(-mouseDelta.y);
break;
Expand Down Expand Up @@ -176,17 +177,17 @@ int main(int argc, char* argv[]) {
break;
}
case SDL_WINDOWEVENT: {
renderingEngine->setSize(window->getWindowSize());
renderEngine->setSize(window->getWindowSize());
break;
}
}
}
// Transform
cubeTransform->roll(25.0f * time->getDeltaTime());
cubeTransform->yaw(50.0f * time->getDeltaTime());
cubeTransform->pitch(100.0f * time->getDeltaTime());
// Rotate cube
cubePos->roll(25.0f * time->getDeltaTime());
cubePos->yaw(50.0f * time->getDeltaTime());
cubePos->pitch(100.0f * time->getDeltaTime());

// Camera
// Move camera
glm::vec3
cameraFront = camera->getTransform()->getForward(),
cameraRight = camera->getRight(),
Expand All @@ -196,18 +197,18 @@ int main(int argc, char* argv[]) {
(cameraRight * cameraVelocity.x) +
(cameraUp * cameraVelocity.y));

/* Render */
renderingEngine->registerCommand({cubeTransform, cubeMaterial, cubeMesh, cubeMesh->GetIndexCount()});
renderingEngine->registerCommand({planeTransform, planeMaterial, planeMesh, planeMesh->GetIndexCount()});
renderingEngine->render();
// Render
renderEngine->registerCommand({cubePos, cubeMaterial, cubeMesh, cubeMesh->GetIndexCount()});
renderEngine->registerCommand({planePos, planeMaterial, planeMesh, planeMesh->GetIndexCount()});
renderEngine->render();

window->swapBuffers();
}
delete cubeMesh;
delete cubeMaterial;
delete cubeTransform;
delete cubePos;

delete renderingEngine;
delete renderEngine;
delete window;
return 0;
}
}
4 changes: 2 additions & 2 deletions engine/rendering/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include "vertex.h"

ce::Mesh::Mesh(Vertex* vertexArray, const unsigned vertexCount,
GLuint* indexArray, const unsigned indexCount)
: m_vertexCount(vertexCount), m_indexCount(indexCount), m_VAO(0), m_VBO(0), m_EBO(0) {
GLuint* indexArray, const unsigned cubeIndexCount)
: m_vertexCount(vertexCount), m_indexCount(cubeIndexCount), m_VAO(0), m_VBO(0), m_EBO(0) {
glGenVertexArrays(1, &m_VAO);
glBindVertexArray(m_VAO);
initVAO(vertexArray, indexArray);
Expand Down
2 changes: 1 addition & 1 deletion engine/rendering/mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace ce {

public:
Mesh(Vertex* vertexArray, const unsigned vertexCount,
GLuint* indexArray = NULL, const unsigned indexCount = 0);
GLuint* indexArray = NULL, const unsigned cubeIndexCount = 0);
~Mesh();
void sendToShader(class Shader* shader, bool bind = true);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#include "rendering_engine.h"
#include "render_engine.h"
#include <core/tpnt_log.h>

void ce::RenderingEngine::clear() {
void ce::RenderEngine::clear() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}

void ce::RenderingEngine::render(unsigned count) {
void ce::RenderEngine::render(unsigned count) {
glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_INT, 0);
}

void ce::RenderingEngine::bind(RenderCommand command) {
void ce::RenderEngine::bind(RenderCommand command) {
// Update Shader Values TODO: shouldn't this be somewhere else instead of the bind command?
command.material->update();

Expand All @@ -24,12 +24,12 @@ void ce::RenderingEngine::bind(RenderCommand command) {
command.material->bind();
}

void ce::RenderingEngine::unbind(RenderCommand command) {
void ce::RenderEngine::unbind(RenderCommand command) {
command.mesh->unbind();
command.material->unbind();
}

ce::RenderingEngine::RenderingEngine()
ce::RenderEngine::RenderEngine()
: m_aspectRatio(0),
m_fov(0),
m_near(0),
Expand Down Expand Up @@ -57,22 +57,22 @@ ce::RenderingEngine::RenderingEngine()
setClearColor(glm::vec4());
}

ce::RenderingEngine::~RenderingEngine() {}
ce::RenderEngine::~RenderEngine() {}

void ce::RenderingEngine::setClearColor(glm::vec4 color) {
void ce::RenderEngine::setClearColor(glm::vec4 color) {
glClearColor(color.r, color.g, color.b, color.a);
}

void ce::RenderingEngine::setSize(glm::vec2 size) {
void ce::RenderEngine::setSize(glm::vec2 size) {
glViewport(0, 0, size.x, size.y);
m_aspectRatio = size.x / size.y;
}

glm::mat4 ce::RenderingEngine::getProjection() {
glm::mat4 ce::RenderEngine::getProjection() {
return glm::perspective(m_fov, m_aspectRatio, m_near, m_far);
}

void ce::RenderingEngine::render() {
void ce::RenderEngine::render() {
clear();
for (int i = 0; i < m_commands.size(); i++) {
RenderCommand command = m_commands[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace ce {
unsigned points;
};

class RenderingEngine {
class RenderEngine {
private:
float m_aspectRatio, m_fov, m_near, m_far;

Expand All @@ -29,8 +29,8 @@ namespace ce {
void unbind(RenderCommand command);

public:
RenderingEngine();
~RenderingEngine();
RenderEngine();
~RenderEngine();

void setFOV(float fov) { m_fov = glm::radians(fov); };
void setClipRange(float near, float far) {
Expand Down
2 changes: 1 addition & 1 deletion res/shaders/basic.frag
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ out vec4 fColor;

void main() {
fColor = texture(material.texture,vTexCoord) * vColor;
}
}
2 changes: 1 addition & 1 deletion res/shaders/basic.vert
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ void main() {
vTexCoord = aTexCoord;

gl_Position = transform.proj * transform.view * transform.model * vec4(aPos, 1.0f);
}
}
2 changes: 1 addition & 1 deletion res/shaders/color.frag
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ out vec4 fColor;

void main() {
fColor = vColor;
}
}
2 changes: 1 addition & 1 deletion res/shaders/color.vert
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ void main() {
vTexCoord = aTexCoord;

gl_Position = transform.proj * transform.view * transform.model * vec4(aPos, 1.0f);
}
}