diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..e888fab --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "engine"] + path = engine + url = git@github.com:mohlek/opengl_engine.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b04296..0013466 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,90 +1,11 @@ -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 3.5) PROJECT(MEDIEVAL_SOMETHING) -set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules") +file(GLOB_RECURSE src_medieval "src/*.cpp") -set(SOURCE - src/engine/Window.cpp - src/engine/Buffer.cpp - src/engine/VertexArrayObject.cpp - src/engine/Object.cpp - src/engine/Camera.cpp - src/engine/shader/ShaderLoader.cpp - src/engine/shader/Shader.cpp - src/engine/shader/ShaderProgram.cpp - src/engine/model/3ds/Model3DS.cpp - src/shader/MainShader.cpp - src/main.cpp -) +add_subdirectory(engine/) -set(SHADERS - src/shader/main.frag - src/shader/main.vert -) +add_executable(medievalSomething ${src_medieval}) -set(RESOURCES - resource/dragon.3ds -) - -######################################################### -# FIND OpenGL -######################################################### -find_package(OpenGL REQUIRED) -include_directories(${OPENGL_INCLUDE_DIRS}) -link_directories(${OPENGL_LIBRARY_DIRS}) -add_definitions(${OPENGL_DEFINITIONS}) -if(NOT OPENGL_FOUND) - message(ERROR " OpenGL not found!") -endif(NOT OPENGL_FOUND) - -######################################################### -# FIND GLEW -######################################################### -find_package(GLEW REQUIRED) -include_directories(${GLEW_INCLUDE_DIRS}) -link_directories(${GLEW_LIBRARY_DIRS}) -add_definitions(${GLEW_DEFINITIONS}) -if(NOT GLEW_FOUND) - message(ERROR " GLEW not found!") -endif(NOT GLEW_FOUND) - -######################################################### -# FIND GLFW -######################################################### -find_package(PkgConfig REQUIRED) -pkg_search_module(GLFW REQUIRED glfw3) -# find_package(glfw3 3.2 REQUIRED) -include_directories(${GLFW_INCLUDE_DIRS}) -link_directories(${GLFW_LIBRARY_DIRS}) -add_definitions(${GLDFW_DEFINITIONS}) -if(NOT GLFW_FOUND) - message(ERROR " GLFW not found!") -endif(NOT GLFW_FOUND) - -######################################################## -# FIND LIB3DS -######################################################## -find_package(Lib3ds) -include_directories(${LIB3DS_INCLUDE_DIRS}) -link_directories(${LIB3DS_LIBRARY_DIRS}) -if(NOT LIB3DS_FOUND) - message(ERROR " LIB3DS not found!") -endif(NOT LIB3DS_FOUND) - - -######################################################## -# COPY SHADER -######################################################## - -foreach(SHADER ${SHADERS}) - message(STATUS "copy shader " ${SHADER}) - file(COPY ${SHADER} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/shader/) -endforeach(SHADER) - -message(STATUS "copy resources") -file(COPY ${RESOURCES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/resource/) - -add_executable(medievalSomething ${SOURCE}) - -target_link_libraries(medievalSomething ${OPENGL_LIBRARIES} ${GLEW_LIBRARIES} ${GLFW_LIBRARIES} ${LIB3DS_LIBRARY}) +target_link_libraries(medievalSomething engine) diff --git a/cmake/modules/FindLib3ds.cmake b/cmake/modules/FindLib3ds.cmake deleted file mode 100644 index 60383d6..0000000 --- a/cmake/modules/FindLib3ds.cmake +++ /dev/null @@ -1,37 +0,0 @@ -# find lib3ds includes and library -# -# LIB3DS_INCLUDE_DIR - where the lib3ds directory containing the headers can be -# found -# LIB3DS_LIBRARY - full path to the lib3ds library -# LIB3DS_FOUND - TRUE if lib3ds was found - -FIND_PATH(LIB3DS_INCLUDE_DIR lib3ds/file.h - /usr/include - /usr/local/include - $ENV{INCLUDE} -) -FIND_LIBRARY(LIB3DS_LIBRARY NAMES 3ds lib3ds) - -IF(LIB3DS_INCLUDE_DIR) - MESSAGE(STATUS "Found lib3ds include dir: ${LIB3DS_INCLUDE_DIR}") -ELSE(LIB3DS_INCLUDE_DIR) - MESSAGE(STATUS "Could NOT find lib3ds headers.") -ENDIF(LIB3DS_INCLUDE_DIR) - -IF(LIB3DS_LIBRARY) - MESSAGE(STATUS "Found lib3ds library: ${LIB3DS_LIBRARY}") -ELSE(LIB3DS_LIBRARY) - MESSAGE(STATUS "Could NOT find lib3ds library.") -ENDIF(LIB3DS_LIBRARY) - - -IF(LIB3DS_INCLUDE_DIR AND LIB3DS_LIBRARY) - SET(LIB3DS_FOUND TRUE) -ELSE(LIB3DS_INCLUDE_DIR AND LIB3DS_LIBRARY) - SET(LIB3DS_FOUND FALSE) - IF(Lib3ds_FIND_REQUIRED) - MESSAGE(FATAL_ERROR "Could not find lib3ds. Please install lib3ds (http://lib3ds.sourceforge.net)") - ENDIF(Lib3ds_FIND_REQUIRED) -ENDIF(LIB3DS_INCLUDE_DIR AND LIB3DS_LIBRARY) - -# vim: et sw=4 ts=4 diff --git a/engine b/engine new file mode 160000 index 0000000..1d49b83 --- /dev/null +++ b/engine @@ -0,0 +1 @@ +Subproject commit 1d49b83488399bea4a7bc7a707d91e74715be68d diff --git a/resource/dragon.3ds b/resource/dragon.3ds deleted file mode 100644 index b435408..0000000 Binary files a/resource/dragon.3ds and /dev/null differ diff --git a/resource/textures/Ani_Fire_A.png b/resource/textures/Ani_Fire_A.png deleted file mode 100644 index 60dbd97..0000000 Binary files a/resource/textures/Ani_Fire_A.png and /dev/null differ diff --git a/resource/textures/Dragon_Bump_Col2.jpg b/resource/textures/Dragon_Bump_Col2.jpg deleted file mode 100644 index 81f70e5..0000000 Binary files a/resource/textures/Dragon_Bump_Col2.jpg and /dev/null differ diff --git a/resource/textures/Dragon_Nor.jpg b/resource/textures/Dragon_Nor.jpg deleted file mode 100644 index 56a2c10..0000000 Binary files a/resource/textures/Dragon_Nor.jpg and /dev/null differ diff --git a/resource/textures/Dragon_Nor_mirror2.jpg b/resource/textures/Dragon_Nor_mirror2.jpg deleted file mode 100644 index 1c1ada9..0000000 Binary files a/resource/textures/Dragon_Nor_mirror2.jpg and /dev/null differ diff --git a/resource/textures/Dragon_ground_color.jpg b/resource/textures/Dragon_ground_color.jpg deleted file mode 100644 index 800cc9b..0000000 Binary files a/resource/textures/Dragon_ground_color.jpg and /dev/null differ diff --git a/resource/textures/Fire_A_2.png b/resource/textures/Fire_A_2.png deleted file mode 100644 index c272c6d..0000000 Binary files a/resource/textures/Fire_A_2.png and /dev/null differ diff --git a/resource/textures/Floor_C.jpg b/resource/textures/Floor_C.jpg deleted file mode 100644 index f31c16b..0000000 Binary files a/resource/textures/Floor_C.jpg and /dev/null differ diff --git a/resource/textures/Floor_N.jpg b/resource/textures/Floor_N.jpg deleted file mode 100644 index 47d205c..0000000 Binary files a/resource/textures/Floor_N.jpg and /dev/null differ diff --git a/resource/textures/Floor_S.jpg b/resource/textures/Floor_S.jpg deleted file mode 100644 index 79b19e5..0000000 Binary files a/resource/textures/Floor_S.jpg and /dev/null differ diff --git a/src/engine/Buffer.cpp b/src/engine/Buffer.cpp deleted file mode 100644 index 527a0b0..0000000 --- a/src/engine/Buffer.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#include "Buffer.h" - -#include - -#define MEMCPY - -using namespace Engine; - -Buffer::Buffer(GLenum bufferType) : bufferType(bufferType) { - glCreateBuffers(1, &this->bufferId); -} - -Buffer::~Buffer() { - glDeleteBuffers(1, &this->bufferId); -} - -void Buffer::bind() { - glBindBuffer(this->bufferType, this->bufferId); -} - -void Buffer::unbind() { - glBindBuffer(this->bufferType, 0); -} - -void* Buffer::map(GLenum access = GL_READ_WRITE) { - if (glMapNamedBuffer) { - if (access != GL_READ_ONLY) { - glNamedBufferData(this->bufferId, this->size, NULL, GL_STATIC_DRAW); - } - return glMapNamedBuffer(this->bufferId, access); - } - - bind(); - if (access != GL_READ_ONLY) { - glBufferData(this->bufferType, this->size, NULL, GL_STATIC_DRAW); - } - return glMapBuffer(this->bufferType, access); -} - -void Buffer::pushData(void* data, int size) { - this->size = size; - - #ifdef MEMCPY - void* addr = map(GL_WRITE_ONLY); - std::memcpy(addr, data, this->size); - unmap(); - #else - if (glNamedBufferSubData) { - glNamedBufferSubData(this->bufferId, 0, size, data); - } - - bind(); - glBufferSubData(this->bufferType, 0, size, data); - #endif - -} - -bool Buffer::unmap() { - if (glUnmapNamedBuffer) { - return glUnmapNamedBuffer(this->bufferId); - } - - bind(); - return glUnmapBuffer(this->bufferId); -} diff --git a/src/engine/Buffer.h b/src/engine/Buffer.h deleted file mode 100644 index f685296..0000000 --- a/src/engine/Buffer.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef BUFFER_H -#define BUFFER_H - -#include - -namespace Engine { - - class Buffer { - private: - GLuint bufferId = 0; - public: - const GLenum bufferType; - - GLint size; - GLenum dataType = GL_FLOAT; - GLsizei stride; - GLenum valuesPerIndex = 3; - - Buffer(GLenum bufferType); - Buffer() : Buffer(GL_ARRAY_BUFFER) {}; - virtual ~Buffer(); - - void bind(); - void unbind(); - - void pushData(void* data, int size); - - void* map(GLenum access); - bool unmap(); - - GLuint getId() { return bufferId; } - - }; -} - -#endif diff --git a/src/engine/Camera.cpp b/src/engine/Camera.cpp deleted file mode 100644 index eeb0dbf..0000000 --- a/src/engine/Camera.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "Camera.h" - -using namespace Engine; - -Camera::Camera() { - glGenBuffers(1, &this->cameraBuffer); -} - -Camera::~Camera() { - glBindBuffer(GL_UNIFORM_BUFFER, this->cameraBuffer); - glDeleteBuffers(1, &this->cameraBuffer); -} - -void Camera::setCamera(glm::vec3 cameraPos, glm::vec3 lookAt) { - if (!this->cameraBuffer) { - return; - } - - float realMatrix[] = {cameraPos.x, cameraPos.y, cameraPos.z, 0.0f, - lookAt.x, lookAt.y, lookAt.z, 0.0f}; - - glBindBuffer(GL_UNIFORM_BUFFER, this->cameraBuffer); - glBufferData(GL_UNIFORM_BUFFER, sizeof(float) * 8, realMatrix, GL_DYNAMIC_DRAW); - glBindBuffer(GL_UNIFORM_BUFFER, 0); -} diff --git a/src/engine/Camera.h b/src/engine/Camera.h deleted file mode 100644 index 0348d18..0000000 --- a/src/engine/Camera.h +++ /dev/null @@ -1,16 +0,0 @@ -#include - -#include - -namespace Engine { - - class Camera { - private: - GLuint cameraBuffer; - public: - Camera(); - ~Camera(); - - void setCamera(glm::vec3 cameraPos, glm::vec3 lookAt); - }; -} diff --git a/src/engine/Object.cpp b/src/engine/Object.cpp deleted file mode 100644 index c8d3e2c..0000000 --- a/src/engine/Object.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "Object.h" - -using namespace Engine; - -Object::Object() { -} - -Object::~Object() { -} diff --git a/src/engine/Object.h b/src/engine/Object.h deleted file mode 100644 index 65a3f10..0000000 --- a/src/engine/Object.h +++ /dev/null @@ -1,17 +0,0 @@ -#include - -#include -#include - -#include "Buffer.h" - -namespace Engine { - - class Object { - private: - Buffer buffer; - public: - Object(); - virtual ~Object(); - }; -}; diff --git a/src/engine/VertexArrayObject.cpp b/src/engine/VertexArrayObject.cpp deleted file mode 100644 index 30d8f9c..0000000 --- a/src/engine/VertexArrayObject.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include "VertexArrayObject.h" - -using namespace Engine; - -VertexArrayObject::VertexArrayObject() { - if (glCreateVertexArrays) { - glCreateVertexArrays(1, &this->vaoId); - return; - } - glGenVertexArrays(1, &this->vaoId); -} - -VertexArrayObject::~VertexArrayObject() { - this->buffers.clear(); - glDeleteVertexArrays(1, &this->vaoId); -} - -void VertexArrayObject::addBuffer(std::shared_ptr& buffer) { - const int index = this->buffers.size(); - - if (glEnableVertexArrayAttrib) { - glEnableVertexArrayAttrib(this->vaoId, index); - glVertexArrayVertexBuffer(this->vaoId, index, buffer->getId(), 0, buffer->stride); - glVertexArrayAttribFormat(this->vaoId, index, buffer->valuesPerIndex, GL_FLOAT, GL_FALSE, 0); - } else { - glEnableVertexAttribArray(index); - buffer->bind(); - bind(); - glVertexAttribPointer(index, buffer->valuesPerIndex, buffer->dataType, GL_FALSE, buffer->stride, 0); - } - - this->buffers.push_back(buffer); -} - -void VertexArrayObject::bind() { - glBindVertexArray(this->vaoId); -} diff --git a/src/engine/VertexArrayObject.h b/src/engine/VertexArrayObject.h deleted file mode 100644 index 6cdd8fa..0000000 --- a/src/engine/VertexArrayObject.h +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include -#include - -#include "Buffer.h" - -namespace Engine { - - class VertexArrayObject { - private: - GLuint vaoId = 0; - - std::vector> buffers; - public: - VertexArrayObject(); - virtual ~VertexArrayObject(); - - void addBuffer(std::shared_ptr& buffer); - - void bind(); - }; -} diff --git a/src/engine/Window.cpp b/src/engine/Window.cpp deleted file mode 100644 index 2db54e0..0000000 --- a/src/engine/Window.cpp +++ /dev/null @@ -1,189 +0,0 @@ -#include "Window.h" -#include - -#include -#include -#include - -using namespace Engine; - -Window::Window() { - if (!glfwInit()) { - fprintf(stderr, "Error: could not init GLFW\n"); - return; - } - - glfwSetErrorCallback(errorCallback); - - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5); - glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); - glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); - - - this->monitor = glfwGetPrimaryMonitor(); - if (!monitor) { - throw "Could not get primary monitor"; - } - - this->mode = glfwGetVideoMode(this->monitor); - - if (!this->mode) { - throw "Could not get videomode"; - } - - glfwWindowHint(GLFW_RED_BITS, this->mode->redBits); - glfwWindowHint(GLFW_GREEN_BITS, this->mode->greenBits); - glfwWindowHint(GLFW_BLUE_BITS, this->mode->blueBits); - glfwWindowHint(GLFW_REFRESH_RATE, this->mode->refreshRate); - - glfwWindowHint(GLFW_SAMPLES, 8); -} - -void Window::create() { - - if (!monitor) { - fprintf(stderr, "monitor not initialized"); - } - - int width = this->mode->width; - int height = this->mode->height; - - this->window = glfwCreateWindow(width, height - 15, "Medieval something", NULL, NULL); - if (!this->window) { - fprintf(stderr, "Could not create window"); - glfwTerminate(); - return; - } - - glfwMakeContextCurrent(this->window); - - glfwMaximizeWindow(this->window); - //glfwSetWindowMonitor(this->window, this->monitor, 0, 0, this->mode->width, this->mode->height, this->mode->refreshRate); - - glfwSwapInterval(1); - - glewExperimental = GL_TRUE; - glewInit(); - - glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB); - glDebugMessageControlARB(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE); - glDebugMessageCallbackARB(openGLDebugOutput, NULL); - - const GLubyte* renderer = glGetString(GL_RENDERER); // get renderer string - const GLubyte* version = glGetString(GL_VERSION); // version as a string - printf("Renderer: %s\n", renderer); - printf("OpenGL version supported %s\n", version); - - glEnable(GL_DEPTH_TEST); // enable depth-testing - glDepthFunc(GL_LESS); // depth-testing interprets a smaller value as "closer" - - glEnable(GL_MULTISAMPLE); - - glfwSetKeyCallback(this->window, keyCallback); -} - -bool Window::loop() { - glfwSwapBuffers(this->window); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glfwPollEvents(); - - return !glfwWindowShouldClose(this->window); -} - -void Window::close() { - if (this->window) { - glfwDestroyWindow(window); - window = NULL; - } - glfwTerminate(); -} - -void Window::keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods) { - fprintf(stdout, "Key %s\n", glfwGetKeyName(key, 0)); -} - -void Window::errorCallback(int error, const char* desc) { - fprintf(stderr, "Error: %s\n", desc); - return; -} - -void Window::openGLDebugOutput(unsigned int source, unsigned int type, unsigned int id, unsigned int severity, int length, const char* message, const void* userParam) { - - // Thanks to Luca :) - - /*if (std::string(message, std::string("Buffer detailed info").size()) == "Buffer detailed info") - { - //filter it - return; - } - - std::string error_source, error_type, error_severity; - switch(source) { - case GL_DEBUG_SOURCE_API_ARB: - error_source = "OpenGL"; - break; - case GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB: - error_source = "Windows"; - break; - case GL_DEBUG_SOURCE_SHADER_COMPILER_ARB: - error_source = "Shader Compiler"; - break; - case GL_DEBUG_SOURCE_THIRD_PARTY_ARB: - error_source = "Third Party"; - break; - case GL_DEBUG_SOURCE_APPLICATION_ARB: - error_source = "Application"; - break; - case GL_DEBUG_SOURCE_OTHER_ARB: - error_source = "Other"; - break; - default: - error_source = "UNKNOW"; - break; - } - - switch (type) { - case GL_DEBUG_TYPE_ERROR_ARB: - error_type = "Error"; - break; - case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB: - error_type = "Deprecated behavior"; - break; - case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB: - error_type = "Undefined behavior"; - break; - case GL_DEBUG_TYPE_PORTABILITY_ARB: - error_type = "Portability"; - break; - case GL_DEBUG_TYPE_PERFORMANCE_ARB: - error_type = "Performance"; - break; - case GL_DEBUG_TYPE_OTHER_ARB: - error_type = "Other"; - default: - error_type = "UNKNOW"; - break; - } - - switch (severity) { - case GL_DEBUG_SEVERITY_HIGH_ARB: - error_severity = "High"; - break; - case GL_DEBUG_SEVERITY_MEDIUM_ARB: - error_severity = "Medium"; - break; - case GL_DEBUG_SEVERITY_LOW_ARB: - error_severity = "Low"; - break; - default: - error_severity = "UNKNOW"; - break; - } - - std::cout << "Source: " << error_source << " Type: " << error_type << " Severity: " << error_severity << " Message: " << message << std::endl; - - if (severity == GL_DEBUG_SEVERITY_HIGH_ARB) { - raise(SIGTRAP); - }*/ -} diff --git a/src/engine/Window.h b/src/engine/Window.h deleted file mode 100644 index baf602a..0000000 --- a/src/engine/Window.h +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include - -#include -#include - -namespace Engine { - - class Window { - private: - GLFWwindow* window; - GLFWmonitor* monitor; - const GLFWvidmode* mode; - - static void errorCallback(int error, const char* desc); - static void keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods); - - static void openGLDebugOutput(unsigned int source, unsigned int type, unsigned int id, unsigned int severity, int length, const char* message, const void* userParam); - public: - void create(); - bool loop(); - void close(); - - Window(); - }; -} diff --git a/src/engine/model/3ds/Model3DS.cpp b/src/engine/model/3ds/Model3DS.cpp deleted file mode 100644 index ec5d3db..0000000 --- a/src/engine/model/3ds/Model3DS.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include "Model3DS.h" - -#include -#include - -#include -#include - -using namespace Engine; - -Model3DS::Model3DS(std::string&& filename) { - this->vertexVBO = std::make_shared(Buffer()); - this->normalsVBO = std::make_shared(Buffer()); - this->model = lib3ds_file_load(filename.c_str()); - - if (!model) { - throw "Unable to load model"; - } -} - -Model3DS::~Model3DS() { - -} - -unsigned int Model3DS::getTotalFaces() { - assert(model != NULL); - - unsigned int totalFaces = 0; - Lib3dsMesh* mesh; - for (mesh = this->model->meshes; mesh != NULL; mesh = mesh->next) { - totalFaces += mesh->faces; - } - - return totalFaces; -} - -void Model3DS::createVBO() { - unsigned int totalFaces = getTotalFaces(); - - Lib3dsVector* vertices = new Lib3dsVector[totalFaces * 3]; - Lib3dsVector* normals = new Lib3dsVector[totalFaces * 3]; - Lib3dsMesh* mesh; - - unsigned int finishedFaces = 0; - - for (mesh = this->model->meshes; mesh != NULL; mesh = mesh->next) { - lib3ds_mesh_calculate_normals(mesh, &normals[finishedFaces * 3]); - - for (unsigned int curFace = 0; curFace < mesh->faces; ++curFace) { - Lib3dsFace* face = &mesh->faceL[curFace]; - - for (unsigned int i = 0; i < 3; ++i) { - std::memcpy(&vertices[finishedFaces * 3 + 1], mesh->pointL[face->points[i]].pos, sizeof(Lib3dsVector)); - } - finishedFaces++; - } - } - - unsigned int size = sizeof(Lib3dsVector) * 3 * totalFaces; - - this->vertexVBO->stride = sizeof(Lib3dsVector) * 3; - this->vertexVBO->pushData(vertices, size); - - this->normalsVBO->stride = sizeof(Lib3dsVector) * 3; - this->normalsVBO->pushData(normals, size); - - delete vertices; - delete normals; - - lib3ds_file_free(this->model); - this->model = NULL; -} - -void Model3DS::render() { -} - diff --git a/src/engine/model/3ds/Model3DS.h b/src/engine/model/3ds/Model3DS.h deleted file mode 100644 index 9c28e43..0000000 --- a/src/engine/model/3ds/Model3DS.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef MODEL3DS_H -#define MODEL3DS_H - -#include -#include - -#include -#include - -#include "../../Buffer.h" - -namespace Engine { - class Model3DS { - private: - Lib3dsFile* model; - - unsigned int getTotalFaces(); - public: - std::shared_ptr vertexVBO; - std::shared_ptr normalsVBO; - - Model3DS(std::string&& filename); - ~Model3DS(); - void render(); - void createVBO(); - }; -} - -#endif diff --git a/src/engine/model/milkshape/MS3DSpec.h b/src/engine/model/milkshape/MS3DSpec.h deleted file mode 100644 index 2a0aee1..0000000 --- a/src/engine/model/milkshape/MS3DSpec.h +++ /dev/null @@ -1,168 +0,0 @@ -// -// MilkShape 3D 1.4.0 File Format Specification -// -// This specifcation is written in C style. -// -// The data structures are defined in the order as they appear in the .ms3d file. -// - -// -// max values -// -#define MAX_VERTICES 8192 -#define MAX_TRIANGLES 16384 -#define MAX_GROUPS 128 -#define MAX_MATERIALS 128 -#define MAX_JOINTS 128 -#define MAX_KEYFRAMES 216 // increase when needed - -// -// flags -// -#define SELECTED 1 -#define HIDDEN 2 -#define SELECTED2 4 -#define DIRTY 8 - -// -// types -// -#ifndef byte -typedef unsigned char byte; -#endif // byte - -#ifndef word -typedef unsigned short word; -#endif // word - -// -// First comes the header. -// -typdef struct { - char id[10]; // always "MS3D000000" - int version; // 3 -} ms3d_header_t; - -// -// Then comes the number of vertices -// -word nNumVertices; - -// -// Then comes nNumVertices * sizeof (ms3d_vertex_t) -// -typedef struct { - byte flags; // SELECTED | SELECTED2 | HIDDEN - float vertex[3]; // - char boneId; // -1 = no bone - byte referenceCount; -} ms3d_vertex_t; - -// -// number of triangles -// -word nNumTriangles; - -// -// nNumTriangles * sizeof (ms3d_triangle_t) -// -typedef struct { - word flags; // SELECTED | SELECTED2 | HIDDEN - word vertexIndices[3]; // - float vertexNormals[3][3]; // - float s[3]; // - float t[3]; // - byte smoothingGroup; // 1 - 32 - byte groupIndex; // -} ms3d_triangle_t; - -// -// number of groups -// -word nNumGroups; - -// -// nNumGroups * sizeof (ms3d_group_t) -// -typedef struct { - byte flags; // SELECTED | HIDDEN - char name[32]; // - word numtriangles; // - word triangleIndices[numtriangles]; // the groups group the triangles - char materialIndex; // -1 = no material -} ms3d_group_t; - -// -// number of materials -// -word nNumMaterials; - -// -// nNumMaterials * sizeof (ms3d_material_t) -// -typedef struct { - char name[32]; // - float ambient[4]; // - float diffuse[4]; // - float specular[4]; // - float emissive[4]; // - float shininess; // 0.0f - 128.0f - float transparency; // 0.0f - 1.0f - char mode; // 0, 1, 2 is unused now - char texture[128]; // texture.bmp - char alphamap[128]; // alpha.bmp -} ms3d_material_t; - -// -// save some keyframer data -// -float fAnimationFPS; -float fCurrentTime; -int iTotalFrames; - -// -// number of joints -// -word nNumJoints; - -// -// nNumJoints * sizeof (ms3d_joint_t) -// -typedef struct { - float time; // time in seconds - float rotation[3]; // x, y, z angles -} ms3d_keyframe_rot_t; - -typedef struct { - float time; // time in seconds - float position[3]; // local position -} ms3d_keyframe_pos_t; - -typedef struct { - byte flags; // SELECTED | DIRTY - char name[32]; // - char parentName[32]; // - float rotation[3]; // local reference matrix - float position[3]; - - word numKeyFramesRot; // - word numKeyFramesTrans; // - - ms3d_keyframe_rot_t keyFramesRot[numKeyFramesRot]; // local animation matrices - ms3d_keyframe_pos_t keyFramesTrans[numKeyFramesTrans]; // local animation matrices -} ms3d_joint_t; - -// -// Mesh Transformation: -// -// 0. Build the transformation matrices from the rotation and position -// 1. Multiply the vertices by the inverse of local reference matrix (lmatrix0) -// 2. then translate the result by (lmatrix0 * keyFramesTrans) -// 3. then multiply the result by (lmatrix0 * keyFramesRot) -// -// For normals skip step 2. -// -// NOTE: this file format may change in future versions! -// -// - Mete Ciragan -// diff --git a/src/engine/shader/Shader.cpp b/src/engine/shader/Shader.cpp deleted file mode 100644 index d55dfb2..0000000 --- a/src/engine/shader/Shader.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include "Shader.h" - -using namespace Engine; - -Shader::~Shader() { - glDeleteShader(this->shaderId); -} - -void Shader::compile() { - if (shaderId) { - return; - } - - this->shaderId = glCreateShader(this->shaderType); - const char* s = this->source.c_str(); - glShaderSource(this->shaderId, 1, &s, 0); - glCompileShader(this->shaderId); -} diff --git a/src/engine/shader/Shader.h b/src/engine/shader/Shader.h deleted file mode 100644 index e785214..0000000 --- a/src/engine/shader/Shader.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef SHADER_H -#define SHADER_H - -#include - -#include - -#include "ShaderLoader.h" - -namespace Engine { - - class Shader { - private: - GLuint shaderId = 0; - public: - const GLenum shaderType; - const std::string source; - - Shader(ShaderLoader& loader) : Shader(loader.shaderType, loader.source) {}; - - Shader(const GLenum shaderType, const std::string& source) : shaderType(shaderType), source(source) {}; - Shader(const GLenum shaderType, const std::string&& source): shaderType(shaderType), source(std::move(source)) {}; - virtual ~Shader(); - - void compile(); - - GLuint getShaderId() { return this->shaderId; } - }; -} - -#endif diff --git a/src/engine/shader/ShaderLoader.cpp b/src/engine/shader/ShaderLoader.cpp deleted file mode 100644 index 359b3a6..0000000 --- a/src/engine/shader/ShaderLoader.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "ShaderLoader.h" - -#include -#include - -using namespace Engine; - -ShaderLoader::ShaderLoader(GLenum shaderType, std::string&& path) : shaderType(shaderType) { - - std::ifstream fileStream(path.c_str(), std::ios::in); - - if (!fileStream.is_open()) { - std::cerr << "Could not read shader " << path << std::endl; - return; - } - - std::string line; - while (!fileStream.eof()) { - std::getline(fileStream, line); - this->source.append(line + "\n"); - } - - fileStream.close(); -} diff --git a/src/engine/shader/ShaderLoader.h b/src/engine/shader/ShaderLoader.h deleted file mode 100644 index 08c1d57..0000000 --- a/src/engine/shader/ShaderLoader.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef SHADERLOADER_H -#define SHADERLOADER_H - -#include -#include -#include - -namespace Engine { - - class ShaderLoader { - private: - public: - const GLenum shaderType; - std::string source; - - ShaderLoader(GLenum shaderType, std::string&& path); - }; -} - -#endif diff --git a/src/engine/shader/ShaderProgram.cpp b/src/engine/shader/ShaderProgram.cpp deleted file mode 100644 index 91e5c7c..0000000 --- a/src/engine/shader/ShaderProgram.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include "ShaderProgram.h" - -#include - -using namespace Engine; - -ShaderProgram::ShaderProgram() { -} - -ShaderProgram::~ShaderProgram() { - this->shaders.clear(); - glDeleteProgram(this->programId); -} - -void printProgramInfoLog(GLuint obj) { - if (obj == -1) return; - int infologLength = 0; - int charsWritten = 0; - char *infoLog; - - glGetProgramiv(obj, GL_INFO_LOG_LENGTH,&infologLength); - - if (infologLength > 0) { - infoLog = (char *)malloc(infologLength); - glGetProgramInfoLog(obj, infologLength, &charsWritten, infoLog); - std::cout << infoLog << std::endl; - free(infoLog); - } -} - -GLint ShaderProgram::getUniformLocation(std::string&& name) { - return glGetUniformLocation(this->programId, name.c_str()); -} - -void ShaderProgram::link() { - this->programId = glCreateProgram(); - - for (auto& s : this->shaders) { - s->compile(); - glAttachShader(this->programId, s->getShaderId()); - } - - glLinkProgram(this->programId); - printProgramInfoLog(this->programId); -} - -void ShaderProgram::use() { - glUseProgram(this->programId); -} - -void ShaderProgram::end() { - glUseProgram(0); -} diff --git a/src/engine/shader/ShaderProgram.h b/src/engine/shader/ShaderProgram.h deleted file mode 100644 index e0656a6..0000000 --- a/src/engine/shader/ShaderProgram.h +++ /dev/null @@ -1,29 +0,0 @@ -#include - -#include -#include -#include -#include - -#include "Shader.h" - -namespace Engine { - - class ShaderProgram { - private: - GLuint programId = 0; - - public: - std::vector> shaders; - std::map uniforms; - - ShaderProgram(); - virtual ~ShaderProgram(); - - GLint getUniformLocation(std::string&& name); - - void link(); - void use(); - void end(); - }; -} diff --git a/src/main.cpp b/src/main.cpp index 6503f42..efc8bf3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,53 +1,17 @@ #include -#include -#include -#include - -#include "engine/Window.h" -#include "engine/Camera.h" - -#include "engine/model/3ds/Model3DS.h" -#include "engine/VertexArrayObject.h" - -#include "shader/MainShader.h" - -using namespace Engine; +#include int main(int argc, char** argv) { + Engine::Window* win = new Engine::Window("Medieval something", 800, 600); - Window* win = new Window(); - - win->create(); - - Game::Shader::MainShader mainShader; - - mainShader.link(); - - Model3DS dragon("resource/dragon.3ds"); - - float points[] = { - 0.0f, 0.5f, 0.0f, - 0.5f, -0.5f, 0.0f, - -0.5f, -0.5f, 0.0f - }; - - VertexArrayObject vao; - std::shared_ptr vbo = std::make_shared(); - vbo->pushData(points, 9 * sizeof(float)); - vbo->stride = 3 * sizeof(float); - - //vao.addBuffer(dragon.vertexVBO); - vao.addBuffer(vbo); - - while (win->loop()) { - mainShader.use(); - - vao.bind(); - glDrawArrays(GL_TRIANGLES, 0, 3); + if (!win->create()) { + return 1; } - win->close(); + do { + + } while (win->loop()); return 0; } diff --git a/src/shader/MainShader.cpp b/src/shader/MainShader.cpp deleted file mode 100644 index 74529e0..0000000 --- a/src/shader/MainShader.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "MainShader.h" - -#include -#include "../engine/shader/Shader.h" -#include "../engine/shader/ShaderLoader.h" - -using namespace Game::Shader; - -MainShader::MainShader() { - Engine::ShaderLoader loadMainFragment(GL_FRAGMENT_SHADER, "shader/main.frag"); - std::shared_ptr mainFragment = std::make_shared(Engine::Shader(loadMainFragment)); - this->shaders.push_back(mainFragment); - - Engine::ShaderLoader loadMainVertex(GL_VERTEX_SHADER, "shader/main.vert"); - std::shared_ptr mainVertex = std::make_shared(Engine::Shader(loadMainVertex)); - this->shaders.push_back(mainVertex); -} diff --git a/src/shader/MainShader.h b/src/shader/MainShader.h deleted file mode 100644 index 3e4b84f..0000000 --- a/src/shader/MainShader.h +++ /dev/null @@ -1,15 +0,0 @@ -#include "../engine/shader/ShaderProgram.h" - -#include - -namespace Game { - namespace Shader { - class MainShader : public Engine::ShaderProgram { - - public: - GLint positionLocation = getUniformLocation("position"); - - MainShader(); - }; - } -} diff --git a/src/shader/main.frag b/src/shader/main.frag deleted file mode 100644 index c48aa27..0000000 --- a/src/shader/main.frag +++ /dev/null @@ -1,7 +0,0 @@ -#version 450 core - -out vec4 color; - -void main() { - color = vec4(0.5, 0.0, 0.0, 1.0); -} diff --git a/src/shader/main.vert b/src/shader/main.vert deleted file mode 100644 index a611a69..0000000 --- a/src/shader/main.vert +++ /dev/null @@ -1,7 +0,0 @@ -#version 450 core - -in vec3 aPos; - -void main() { - gl_Position = vec4(aPos, 1.0); -}