Skip to content

Commit 7c6ddc5

Browse files
committed
set up project and libraries, created classes for raw models and shaders
1 parent 7c8cf34 commit 7c6ddc5

27 files changed

+722
-1
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto eol=lf whitespace=tab-in-indent,trailing-space,tabwidth=4

.gitignore

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Created by https://www.gitignore.io/api/clion
2+
3+
### CLion ###
4+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
5+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
6+
7+
# User-specific stuff:
8+
.idea/**/workspace.xml
9+
.idea/**/tasks.xml
10+
.idea/dictionaries
11+
12+
# Sensitive or high-churn files:
13+
.idea/**/dataSources/
14+
.idea/**/dataSources.ids
15+
.idea/**/dataSources.xml
16+
.idea/**/dataSources.local.xml
17+
.idea/**/sqlDataSources.xml
18+
.idea/**/dynamic.xml
19+
.idea/**/uiDesigner.xml
20+
21+
# Gradle:
22+
.idea/**/gradle.xml
23+
.idea/**/libraries
24+
25+
# CMake
26+
cmake-build-debug/
27+
cmake-build-release/
28+
cmake-build-debug-clang/
29+
cmake-build-release-clang/
30+
31+
# Mongo Explorer plugin:
32+
.idea/**/mongoSettings.xml
33+
34+
## File-based project format:
35+
*.iws
36+
37+
## Plugin-specific files:
38+
39+
# IntelliJ
40+
/out/
41+
42+
# mpeltonen/sbt-idea plugin
43+
.idea_modules/
44+
45+
# JIRA plugin
46+
atlassian-ide-plugin.xml
47+
48+
# Cursive Clojure plugin
49+
.idea/replstate.xml
50+
51+
# Ruby plugin and RubyMine
52+
/.rakeTasks
53+
54+
# Crashlytics plugin (for Android Studio and IntelliJ)
55+
com_crashlytics_export_strings.xml
56+
crashlytics.properties
57+
crashlytics-build.properties
58+
fabric.properties
59+
60+
### CLion Patch ###
61+
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
62+
63+
# *.iml
64+
# modules.xml
65+
# .idea/misc.xml
66+
# *.ipr
67+
68+
# Sonarlint plugin
69+
.idea/sonarlint
70+
71+
72+
# End of https://www.gitignore.io/api/clion

.gitmodules

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[submodule "lib/glad"]
2+
path = lib/glad
3+
url = https://github.com/Dav1dde/glad.git
4+
branch = c
5+
[submodule "lib/glfw"]
6+
path = lib/glfw
7+
url = https://github.com/glfw/glfw.git
8+
[submodule "lib/glm"]
9+
path = lib/glm
10+
url = https://github.com/g-truc/glm.git
11+
[submodule "lib/stb"]
12+
path = lib/stb
13+
url = https://github.com/nothings/stb.git

.idea/.name

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/RenderEngineCpp.iml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/codeStyles/Project.xml

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CMakeLists.txt

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#require recent cmake
2+
cmake_minimum_required(VERSION 3.9)
3+
#name of the project
4+
project(RenderEngine)
5+
6+
#set up glfw
7+
option(GLFW_BUILD_DOCS OFF)
8+
option(GLFW_BUILD_EXAMPLES OFF)
9+
option(GLFW_BUILD_TESTS OFF)
10+
add_subdirectory(lib/glfw)
11+
12+
#set compiler flags
13+
if(MSVC)
14+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
15+
else()
16+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -std=c++11")
17+
if(NOT WIN32)
18+
set(GLAD_LIBRARIES dl)
19+
endif()
20+
endif()
21+
22+
#include dirs
23+
include_directories(src/
24+
lib/glad/include/
25+
lib/glfw/include/
26+
lib/glm/
27+
lib/stb/)
28+
29+
#sources
30+
file(GLOB VENDORS_SOURCES lib/glad/src/glad.c)
31+
file(GLOB PROJECT_HEADERS src/*.h
32+
src/engine/*.h
33+
src/models/*.h
34+
src/shaders/*.h )
35+
file(GLOB PROJECT_SOURCES src/*.cpp
36+
src/engine/*.cpp
37+
src/models/*.cpp
38+
src/shaders/*.cpp )
39+
file(GLOB PROJECT_SHADERS src/Shaders/*.comp
40+
src/Shaders/*.frag
41+
src/Shaders/*.geom
42+
src/Shaders/*.vert)
43+
file(GLOB PROJECT_CONFIGS CMakeLists.txt
44+
README.md
45+
.gitattributes
46+
.gitignore
47+
.gitmodules)
48+
49+
#source groups
50+
source_group("Headers" FILES ${PROJECT_HEADERS})
51+
source_group("Shaders" FILES ${PROJECT_SHADERS})
52+
source_group("Sources" FILES ${PROJECT_SOURCES})
53+
source_group("Vendors" FILES ${VENDORS_SOURCES})
54+
55+
#target for copying resources to build dir
56+
#copies res folder in the correct location based on OS and/or compiler
57+
if(UNIX)
58+
message("Detected Linux! Copying resources to bin/build/...")
59+
add_custom_target(copy_resources ALL COMMAND ${CMAKE_COMMAND} -E copy_directory
60+
"${PROJECT_SOURCE_DIR}/res" ${CMAKE_BINARY_DIR}/${PROJECT_NAME}/res)
61+
elseif(MSVC)
62+
message("Detected MSCV! Copying resources....")
63+
add_custom_target(copy_resources ALL COMMAND ${CMAKE_COMMAND} -E copy_directory
64+
"${PROJECT_SOURCE_DIR}/res" ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$<CONFIGURATION>/res)
65+
else()
66+
message("Not Linux or MSVC! Copying resources...")
67+
add_custom_target(copy_resources ALL COMMAND ${CMAKE_COMMAND} -E copy_directory
68+
"${PROJECT_SOURCE_DIR}/res" ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PROJECT_NAME}/res)
69+
endif()
70+
71+
#executable
72+
add_definitions(-DGLFW_INCLUDE_NONE
73+
-DPROJECT_SOURCE_DIR=\"${PROJECT_SOURCE_DIR}\")
74+
add_executable(${PROJECT_NAME} ${PROJECT_SOURCES} ${PROJECT_HEADERS}
75+
${PROJECT_SHADERS} ${PROJECT_CONFIGS}
76+
${VENDORS_SOURCES})
77+
#link libraries
78+
target_link_libraries(${PROJECT_NAME} glfw
79+
${GLFW_LIBRARIES} ${GLAD_LIBRARIES})
80+
set_target_properties(${PROJECT_NAME} PROPERTIES
81+
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${PROJECT_NAME})
82+
83+
add_dependencies(${PROJECT_NAME} copy_resources)
84+

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# RenderEngineCpp
1+
# OpenGL render engine!

lib/glad

Submodule glad added at 5bf3eda

lib/glfw

Submodule glfw added at 7ef34eb

lib/glm

Submodule glm added at 024e94b

lib/stb

Submodule stb added at e6afb9c

res/shaders/basic.frag

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#version 400 core
2+
3+
out vec4 FragColor;
4+
5+
void main() {
6+
FragColor = vec4(0.1f, 0.2f, 0.3f, 1);
7+
}

res/shaders/basic.vert

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#version 400 core
2+
3+
layout (location = 0) in vec3 aPos;
4+
5+
void main() {
6+
gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);
7+
}

src/Log.h

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Simple header only Log class, thanks to https://stackoverflow.com/a/32262143
3+
*/
4+
5+
#ifndef LOG_H
6+
#define LOG_H
7+
8+
#include <iostream>
9+
10+
using namespace std;
11+
12+
enum typelog {
13+
DEBUG,
14+
INFO,
15+
WARN,
16+
ERROR
17+
};
18+
19+
struct structlog {
20+
bool headers = false;
21+
typelog level = WARN;
22+
};
23+
24+
extern structlog LOGCFG;
25+
26+
class LOG {
27+
public:
28+
LOG() {}
29+
explicit LOG(typelog type) {
30+
msglevel = type;
31+
if(LOGCFG.headers) {
32+
operator << ("["+getLabel(type)+"] ");
33+
}
34+
}
35+
~LOG() {
36+
if(opened) {
37+
cout << endl;
38+
}
39+
opened = false;
40+
}
41+
template<class T>
42+
LOG &operator<<(const T &msg) {
43+
if(msglevel >= LOGCFG.level) {
44+
cout << msg;
45+
opened = true;
46+
}
47+
return *this;
48+
}
49+
private:
50+
bool opened = false;
51+
typelog msglevel = DEBUG;
52+
inline string getLabel(typelog type) {
53+
string label;
54+
switch(type) {
55+
case DEBUG: label = "DEBUG"; break;
56+
case INFO: label = "INFO"; break;
57+
case WARN: label = "WARN"; break;
58+
case ERROR: label = "ERROR"; break;
59+
}
60+
return label;
61+
}
62+
};
63+
64+
#endif /* LOG_H */

src/engine/display_manager.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include "display_manager.h"
2+
#include <glad/glad.h>
3+
#include <string>
4+
#include <iostream>
5+
#include "Log.h"
6+
7+
void DisplayManager::create_display() {
8+
// Load GLFW and Create a Window
9+
glfwInit();
10+
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
11+
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
12+
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
13+
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
14+
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
15+
_window = glfwCreateWindow(WIDTH, HEIGHT, "Render Engine", nullptr, nullptr);
16+
17+
// Check for Valid Context
18+
if (_window == nullptr) {
19+
LOG(ERROR) << "Failed to Create OpenGL Context";
20+
return;
21+
}
22+
23+
// Create Context and Load OpenGL Functions
24+
glfwMakeContextCurrent(_window);
25+
gladLoadGL();
26+
LOG(INFO) << "OpenGL " << glGetString(GL_VERSION);
27+
}
28+
29+
void DisplayManager::update_display() {
30+
//if escape is pressed, close the window
31+
if (glfwGetKey(_window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
32+
glfwSetWindowShouldClose(_window, true);
33+
34+
// flip buffers
35+
glfwSwapBuffers(_window);
36+
glfwPollEvents();
37+
}
38+
39+
//close and destroy window
40+
void DisplayManager::close_display() {
41+
glfwSetWindowShouldClose(_window, true);
42+
glfwDestroyWindow(_window);
43+
_window = nullptr;
44+
glfwTerminate();
45+
}
46+
47+
//returns a pointer to the window
48+
GLFWwindow *DisplayManager::get_window() const {
49+
return _window;
50+
}
51+
52+
//returns whether the windows is closed
53+
int DisplayManager::should_close() {
54+
return glfwWindowShouldClose(_window);
55+
}

0 commit comments

Comments
 (0)