Compare commits
	
		
			9 Commits
		
	
	
		
			assignment
			...
			assignment
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 22c46053c0 | |||
| 41c9b68eb9 | |||
| 74a0bfca41 | |||
| 4e2c62aaf4 | |||
| f1a24f576b | |||
| f981cee4e0 | |||
| 986e31dbef | |||
| 253bc47a5f | |||
| e07cdefacc | 
							
								
								
									
										56
									
								
								.clang-format
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								.clang-format
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,56 @@ | |||||||
|  | Language: Cpp | ||||||
|  | BasedOnStyle: LLVM | ||||||
|  |  | ||||||
|  | AccessModifierOffset: -8 | ||||||
|  | AlignAfterOpenBracket: Align | ||||||
|  | AlignConsecutiveAssignments: Consecutive | ||||||
|  | AlignConsecutiveDeclarations: Consecutive | ||||||
|  | AlignConsecutiveMacros: Consecutive | ||||||
|  | AlignEscapedNewlines: Left | ||||||
|  | AlignOperands: DontAlign | ||||||
|  | AlignTrailingComments: Always | ||||||
|  | AllowShortBlocksOnASingleLine: Never | ||||||
|  | AllowShortEnumsOnASingleLine: false | ||||||
|  | AllowShortFunctionsOnASingleLine: None | ||||||
|  | AllowShortLambdasOnASingleLine: None | ||||||
|  | BraceWrapping: | ||||||
|  |   AfterCaseLabel: false | ||||||
|  |   AfterClass: false | ||||||
|  |   AfterControlStatement: false | ||||||
|  |   AfterEnum: false | ||||||
|  |   AfterFunction: true | ||||||
|  |   AfterNamespace: false | ||||||
|  |   AfterObjCDeclaration: false | ||||||
|  |   AfterStruct: false | ||||||
|  |   AfterUnion: false | ||||||
|  |   AfterExternBlock: false | ||||||
|  |   BeforeCatch: false | ||||||
|  |   BeforeElse: false | ||||||
|  |   BeforeLambdaBody: false | ||||||
|  |   BeforeWhile: false | ||||||
|  |   IndentBraces: false | ||||||
|  | BreakBeforeBinaryOperators: NonAssignment | ||||||
|  | BreakBeforeBraces: Custom | ||||||
|  | BreakInheritanceList: AfterColon | ||||||
|  | BreakBeforeTernaryOperators: true | ||||||
|  | BreakConstructorInitializers: BeforeComma | ||||||
|  | BreakStringLiterals: false | ||||||
|  | ColumnLimit: 80 | ||||||
|  | Cpp11BracedListStyle: true | ||||||
|  | EmptyLineBeforeAccessModifier: Always | ||||||
|  | IndentAccessModifiers: false | ||||||
|  | IndentCaseBlocks: false | ||||||
|  | IndentCaseLabels: false | ||||||
|  | IndentGotoLabels: false | ||||||
|  | IndentPPDirectives: None | ||||||
|  | IndentWidth: 8 | ||||||
|  | InsertNewlineAtEOF: true | ||||||
|  | InsertTrailingCommas: None | ||||||
|  | MaxEmptyLinesToKeep: 1 | ||||||
|  | NamespaceIndentation: None | ||||||
|  | PackConstructorInitializers: NextLineOnly | ||||||
|  | PointerAlignment: Left | ||||||
|  | SortIncludes: Never | ||||||
|  | SpaceBeforeCaseColon: false | ||||||
|  | TabWidth: 8 | ||||||
|  | UseTab: Always | ||||||
							
								
								
									
										64
									
								
								.clang-tidy
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										64
									
								
								.clang-tidy
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,64 @@ | |||||||
|  | --- | ||||||
|  | # C++ Core Guidelines style (CppCoreGuidelines) | ||||||
|  | Checks: > | ||||||
|  |   cppcoreguidelines-*, | ||||||
|  |   readability-identifier-naming, | ||||||
|  |   readability-*, | ||||||
|  |   modernize-*, | ||||||
|  |   performance-*, | ||||||
|  |   bugprone-*, | ||||||
|  |   -modernize-use-trailing-return-type, | ||||||
|  |   -readability-magic-numbers, | ||||||
|  |   -cppcoreguidelines-avoid-magic-numbers, | ||||||
|  |   -cppcoreguidelines-pro-bounds-pointer-arithmetic, | ||||||
|  |   -cppcoreguidelines-pro-type-reinterpret-cast | ||||||
|  |  | ||||||
|  | CheckOptions: | ||||||
|  |   # C++ Core Guidelines: Types use PascalCase | ||||||
|  |   - { key: readability-identifier-naming.ClassCase,              value: CamelCase  } | ||||||
|  |   - { key: readability-identifier-naming.StructCase,             value: CamelCase  } | ||||||
|  |   - { key: readability-identifier-naming.EnumCase,               value: CamelCase  } | ||||||
|  |   - { key: readability-identifier-naming.UnionCase,              value: CamelCase  } | ||||||
|  |  | ||||||
|  |   # C++ Core Guidelines: Functions use snake_case (STL style) | ||||||
|  |   - { key: readability-identifier-naming.FunctionCase,           value: lower_case } | ||||||
|  |   - { key: readability-identifier-naming.MethodCase,             value: lower_case } | ||||||
|  |  | ||||||
|  |   # Member variables: snake_case with trailing underscore | ||||||
|  |   - { key: readability-identifier-naming.PrivateMemberCase,      value: lower_case } | ||||||
|  |   - { key: readability-identifier-naming.PrivateMemberSuffix,    value: '_'        } | ||||||
|  |   - { key: readability-identifier-naming.ProtectedMemberCase,    value: lower_case } | ||||||
|  |   - { key: readability-identifier-naming.ProtectedMemberSuffix,  value: '_'        } | ||||||
|  |   - { key: readability-identifier-naming.PublicMemberCase,       value: lower_case } | ||||||
|  |  | ||||||
|  |   # Parameters and local variables: snake_case | ||||||
|  |   - { key: readability-identifier-naming.ParameterCase,          value: lower_case } | ||||||
|  |   - { key: readability-identifier-naming.VariableCase,           value: lower_case } | ||||||
|  |   - { key: readability-identifier-naming.LocalVariableCase,      value: lower_case } | ||||||
|  |  | ||||||
|  |   # Constants and macros: UPPER_CASE | ||||||
|  |   - { key: readability-identifier-naming.ConstantCase,           value: UPPER_CASE } | ||||||
|  |   - { key: readability-identifier-naming.ConstexprVariableCase,  value: UPPER_CASE } | ||||||
|  |   - { key: readability-identifier-naming.MacroDefinitionCase,    value: UPPER_CASE } | ||||||
|  |   - { key: readability-identifier-naming.EnumConstantCase,       value: UPPER_CASE } | ||||||
|  |  | ||||||
|  |   # Global variables: snake_case (Core Guidelines: avoid globals when possible) | ||||||
|  |   - { key: readability-identifier-naming.GlobalVariableCase,     value: lower_case } | ||||||
|  |  | ||||||
|  |   # Namespaces: snake_case | ||||||
|  |   - { key: readability-identifier-naming.NamespaceCase,          value: lower_case } | ||||||
|  |  | ||||||
|  |   # Template parameters: PascalCase (following STL conventions) | ||||||
|  |   - { key: readability-identifier-naming.TypeTemplateParameterCase, value: CamelCase } | ||||||
|  |   - { key: readability-identifier-naming.ValueTemplateParameterCase, value: lower_case } | ||||||
|  |  | ||||||
|  |   # Type aliases: PascalCase (modern C++ style with 'using') | ||||||
|  |   - { key: readability-identifier-naming.TypeAliasCase,          value: CamelCase  } | ||||||
|  |  | ||||||
|  |   # Function size limits | ||||||
|  |   - { key: readability-function-size.LineThreshold,              value: 100        } | ||||||
|  |   - { key: readability-function-size.StatementThreshold,         value: 50         } | ||||||
|  |  | ||||||
|  | WarningsAsErrors: '' | ||||||
|  | HeaderFilterRegex: 'src/.*\.h$' | ||||||
|  | FormatStyle: file | ||||||
| @@ -1,71 +0,0 @@ | |||||||
| <?xml version="1.0" encoding="utf-8"?> |  | ||||||
| <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |  | ||||||
|   <ItemGroup> |  | ||||||
|     <Filter Include="Source Files"> |  | ||||||
|       <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> |  | ||||||
|       <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions> |  | ||||||
|     </Filter> |  | ||||||
|     <Filter Include="Header Files"> |  | ||||||
|       <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> |  | ||||||
|       <Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions> |  | ||||||
|     </Filter> |  | ||||||
|     <Filter Include="Resource Files"> |  | ||||||
|       <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> |  | ||||||
|       <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> |  | ||||||
|     </Filter> |  | ||||||
|     <Filter Include="glfw"> |  | ||||||
|       <UniqueIdentifier>{422e20da-2cf0-4bda-9833-a89b7ab453a1}</UniqueIdentifier> |  | ||||||
|     </Filter> |  | ||||||
|     <Filter Include="glew"> |  | ||||||
|       <UniqueIdentifier>{296e1ba9-28bc-4e0b-8d4e-413551edca96}</UniqueIdentifier> |  | ||||||
|     </Filter> |  | ||||||
|     <Filter Include="Shaders"> |  | ||||||
|       <UniqueIdentifier>{0628083b-a31c-4825-822c-11b6f933e7bd}</UniqueIdentifier> |  | ||||||
|     </Filter> |  | ||||||
|   </ItemGroup> |  | ||||||
|   <ItemGroup> |  | ||||||
|     <ClInclude Include="..\lib\glfw\glfw3.h"> |  | ||||||
|       <Filter>glfw</Filter> |  | ||||||
|     </ClInclude> |  | ||||||
|     <ClInclude Include="..\lib\glfw\glfw3native.h"> |  | ||||||
|       <Filter>glfw</Filter> |  | ||||||
|     </ClInclude> |  | ||||||
|     <ClInclude Include="..\lib\glew\GL\glew.h"> |  | ||||||
|       <Filter>glew</Filter> |  | ||||||
|     </ClInclude> |  | ||||||
|     <ClInclude Include="..\src\vertex.h"> |  | ||||||
|       <Filter>Source Files</Filter> |  | ||||||
|     </ClInclude> |  | ||||||
|     <ClInclude Include="..\src\shader.h"> |  | ||||||
|       <Filter>Source Files</Filter> |  | ||||||
|     </ClInclude> |  | ||||||
|     <ClInclude Include="..\src\buffer.h"> |  | ||||||
|       <Filter>Source Files</Filter> |  | ||||||
|     </ClInclude> |  | ||||||
|   </ItemGroup> |  | ||||||
|   <ItemGroup> |  | ||||||
|     <ClCompile Include="..\src\main.cpp"> |  | ||||||
|       <Filter>Source Files</Filter> |  | ||||||
|     </ClCompile> |  | ||||||
|     <ClCompile Include="..\lib\glew\glew.c"> |  | ||||||
|       <Filter>glew</Filter> |  | ||||||
|     </ClCompile> |  | ||||||
|     <ClCompile Include="..\src\vertex.cpp"> |  | ||||||
|       <Filter>Source Files</Filter> |  | ||||||
|     </ClCompile> |  | ||||||
|     <ClCompile Include="..\src\shader.cpp"> |  | ||||||
|       <Filter>Source Files</Filter> |  | ||||||
|     </ClCompile> |  | ||||||
|     <ClCompile Include="..\src\buffer.cpp"> |  | ||||||
|       <Filter>Source Files</Filter> |  | ||||||
|     </ClCompile> |  | ||||||
|   </ItemGroup> |  | ||||||
|   <ItemGroup> |  | ||||||
|     <None Include="..\data\fragment.glsl"> |  | ||||||
|       <Filter>Shaders</Filter> |  | ||||||
|     </None> |  | ||||||
|     <None Include="..\data\vertex.glsl"> |  | ||||||
|       <Filter>Shaders</Filter> |  | ||||||
|     </None> |  | ||||||
|   </ItemGroup> |  | ||||||
| </Project> |  | ||||||
| @@ -1,14 +1,15 @@ | |||||||
| #include "buffer.h" | #include "buffer.h" | ||||||
|  |  | ||||||
| #include <vector> | #include <vector> | ||||||
| #include <iostream> |  | ||||||
|  |  | ||||||
| #include "../lib/glew/GL/glew.h" | #include "../lib/glew/GL/glew.h" | ||||||
| #include "../lib/glfw/glfw3.h" | #include "../lib/glfw/glfw3.h" | ||||||
|  |  | ||||||
|  | #include "logger.h" | ||||||
| #include "vertex.h" | #include "vertex.h" | ||||||
|  |  | ||||||
| Buffer::Buffer(const std::vector<Vertex>& vertices, const std::vector<uint16_t>& indices) | Buffer::Buffer(const std::vector<Vertex>&   vertices, | ||||||
|  | 	       const std::vector<uint16_t>& indices) | ||||||
| { | { | ||||||
| 	index_count_ = static_cast<GLsizei>(indices.size()); | 	index_count_ = static_cast<GLsizei>(indices.size()); | ||||||
|  |  | ||||||
| @@ -19,13 +20,19 @@ Buffer::Buffer(const std::vector<Vertex>& vertices, const std::vector<uint16_t>& | |||||||
| 	glBindVertexArray(vao_); | 	glBindVertexArray(vao_); | ||||||
|  |  | ||||||
| 	glBindBuffer(GL_ARRAY_BUFFER, vbo_); | 	glBindBuffer(GL_ARRAY_BUFFER, vbo_); | ||||||
| 	glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(Vertex), vertices.data(), GL_STATIC_DRAW); | 	glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(Vertex), | ||||||
|  | 		     vertices.data(), GL_STATIC_DRAW); | ||||||
|  |  | ||||||
| 	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo_); | 	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo_); | ||||||
| 	glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(uint16_t), indices.data(), GL_STATIC_DRAW); | 	glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(uint16_t), | ||||||
|  | 		     indices.data(), GL_STATIC_DRAW); | ||||||
|  |  | ||||||
| 	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), nullptr); | 	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), | ||||||
|  | 			      nullptr); | ||||||
| 	glEnableVertexAttribArray(0); | 	glEnableVertexAttribArray(0); | ||||||
|  |  | ||||||
|  | 	Logger::info(sstr("Buffer created with ", vertices.size(), | ||||||
|  | 			  " vertices and ", indices.size(), " indices")); | ||||||
| } | } | ||||||
|  |  | ||||||
| Buffer::~Buffer() | Buffer::~Buffer() | ||||||
| @@ -33,13 +40,14 @@ Buffer::~Buffer() | |||||||
| 	glDeleteVertexArrays(1, &vao_); | 	glDeleteVertexArrays(1, &vao_); | ||||||
| 	glDeleteBuffers(1, &vbo_); | 	glDeleteBuffers(1, &vbo_); | ||||||
| 	glDeleteBuffers(1, &ebo_); | 	glDeleteBuffers(1, &ebo_); | ||||||
|  | 	Logger::info("Buffer destroyed"); | ||||||
| } | } | ||||||
|  |  | ||||||
| void Buffer::Draw(const Shader& shader) const | void Buffer::draw(const Shader& shader) const | ||||||
| { | { | ||||||
| 	glBindVertexArray(vao_); | 	glBindVertexArray(vao_); | ||||||
| 	glBindBuffer(GL_ARRAY_BUFFER, vbo_); | 	glBindBuffer(GL_ARRAY_BUFFER, vbo_); | ||||||
| 	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo_); | 	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo_); | ||||||
| 	shader.SetupAttribs(); | 	shader.setup_attribs(); | ||||||
| 	glDrawElements(GL_TRIANGLES, index_count_, GL_UNSIGNED_SHORT, nullptr); | 	glDrawElements(GL_TRIANGLES, index_count_, GL_UNSIGNED_SHORT, nullptr); | ||||||
| } | } | ||||||
| @@ -10,10 +10,11 @@ | |||||||
|  |  | ||||||
| class Buffer { | class Buffer { | ||||||
| public: | public: | ||||||
| 	Buffer(const std::vector<Vertex>& vertices, const std::vector<uint16_t>& indices); | 	Buffer(const std::vector<Vertex>&   vertices, | ||||||
|  | 	       const std::vector<uint16_t>& indices); | ||||||
| 	~Buffer(); | 	~Buffer(); | ||||||
|  |  | ||||||
| 	void Draw(const Shader& shader) const; | 	void draw(const Shader& shader) const; | ||||||
|  |  | ||||||
| private: | private: | ||||||
| 	uint32_t vao_, vbo_, ebo_; | 	uint32_t vao_, vbo_, ebo_; | ||||||
|   | |||||||
							
								
								
									
										41
									
								
								src/camera.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								src/camera.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,41 @@ | |||||||
|  | #include "camera.h" | ||||||
|  | #include "state.h" | ||||||
|  | #include "../lib/glew/GL/glew.h" | ||||||
|  | #include "../lib/glm/gtc/matrix_transform.hpp" | ||||||
|  |  | ||||||
|  | Camera::Camera() | ||||||
|  |     : projection_(glm::mat4(1.0f)) | ||||||
|  |     , viewport_(0, 0, 800, 600) | ||||||
|  |     , clear_color_(0.0f, 0.0f, 0.0f) | ||||||
|  | { | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void Camera::prepare() | ||||||
|  | { | ||||||
|  | 	// Set projection matrix | ||||||
|  | 	state::projection_matrix = projection_; | ||||||
|  |  | ||||||
|  | 	// Calculate view matrix | ||||||
|  | 	// For a camera, we need the inverse transformation: | ||||||
|  | 	// View = inverse(Translation * Rotation) | ||||||
|  | 	// Which is: Rotation^-1 * Translation^-1 | ||||||
|  | 	glm::mat4 view = glm::mat4(1.0f); | ||||||
|  |  | ||||||
|  | 	// Inverse rotation (rotate in opposite direction) | ||||||
|  | 	view = glm::rotate(view, -rotation_.z, glm::vec3(0.0f, 0.0f, 1.0f)); | ||||||
|  | 	view = glm::rotate(view, -rotation_.y, glm::vec3(0.0f, 1.0f, 0.0f)); | ||||||
|  | 	view = glm::rotate(view, -rotation_.x, glm::vec3(1.0f, 0.0f, 0.0f)); | ||||||
|  |  | ||||||
|  | 	// Inverse translation (translate in opposite direction) | ||||||
|  | 	view = glm::translate(view, -position_); | ||||||
|  |  | ||||||
|  | 	state::view_matrix = view; | ||||||
|  |  | ||||||
|  | 	// Set viewport | ||||||
|  | 	glViewport(viewport_.x, viewport_.y, viewport_.z, viewport_.w); | ||||||
|  | 	glScissor(viewport_.x, viewport_.y, viewport_.z, viewport_.w); | ||||||
|  |  | ||||||
|  | 	// Set clear color and clear buffers | ||||||
|  | 	glClearColor(clear_color_.r, clear_color_.g, clear_color_.b, 1.0f); | ||||||
|  | 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | ||||||
|  | } | ||||||
							
								
								
									
										46
									
								
								src/camera.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								src/camera.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,46 @@ | |||||||
|  | #ifndef CAMERA_H_ | ||||||
|  | #define CAMERA_H_ | ||||||
|  |  | ||||||
|  | #include "entity.h" | ||||||
|  | #include "../lib/glm/glm.hpp" | ||||||
|  |  | ||||||
|  | class Camera : public Entity { | ||||||
|  | public: | ||||||
|  | 	Camera(); | ||||||
|  |  | ||||||
|  | 	[[nodiscard]] const glm::mat4& projection() const | ||||||
|  | 	{ | ||||||
|  | 		return projection_; | ||||||
|  | 	} | ||||||
|  | 	void set_projection(const glm::mat4& proj) | ||||||
|  | 	{ | ||||||
|  | 		projection_ = proj; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	[[nodiscard]] const glm::ivec4& viewport() const | ||||||
|  | 	{ | ||||||
|  | 		return viewport_; | ||||||
|  | 	} | ||||||
|  | 	void set_viewport(const glm::ivec4& vp) | ||||||
|  | 	{ | ||||||
|  | 		viewport_ = vp; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	[[nodiscard]] const glm::vec3& clear_color() const | ||||||
|  | 	{ | ||||||
|  | 		return clear_color_; | ||||||
|  | 	} | ||||||
|  | 	void set_clear_color(const glm::vec3& color) | ||||||
|  | 	{ | ||||||
|  | 		clear_color_ = color; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	void prepare(); | ||||||
|  |  | ||||||
|  | private: | ||||||
|  | 	glm::mat4  projection_; | ||||||
|  | 	glm::ivec4 viewport_; | ||||||
|  | 	glm::vec3  clear_color_; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | #endif // CAMERA_H_ | ||||||
							
								
								
									
										223
									
								
								src/engine.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										223
									
								
								src/engine.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,223 @@ | |||||||
|  | #include "engine.h" | ||||||
|  |  | ||||||
|  | #include <vector> | ||||||
|  |  | ||||||
|  | #include "../lib/glew/GL/glew.h" | ||||||
|  | #include "../lib/glfw/glfw3.h" | ||||||
|  | #include "../lib/glm/glm.hpp" | ||||||
|  | #include "../lib/glm/gtc/matrix_transform.hpp" | ||||||
|  |  | ||||||
|  | #include "buffer.h" | ||||||
|  | #include "camera.h" | ||||||
|  | #include "logger.h" | ||||||
|  | #include "mesh.h" | ||||||
|  | #include "model.h" | ||||||
|  | #include "shader.h" | ||||||
|  | #include "state.h" | ||||||
|  | #include "vertex.h" | ||||||
|  | #include "world.h" | ||||||
|  |  | ||||||
|  | constexpr int	 screen_width  = 800; | ||||||
|  | constexpr int	 screen_height = 600; | ||||||
|  | constexpr double fps_limit     = 1.0 / 60.0; | ||||||
|  |  | ||||||
|  | Engine::Engine() | ||||||
|  |     : window_(nullptr) | ||||||
|  |     , screen_width_(screen_width) | ||||||
|  |     , screen_height_(screen_height) | ||||||
|  |     , last_update_time_(0.0) | ||||||
|  |     , last_frame_time_(0.0) | ||||||
|  |     , angle_(0.0) | ||||||
|  | { | ||||||
|  | 	Logger::info("Engine created"); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | Engine::~Engine() | ||||||
|  | { | ||||||
|  | 	Logger::info("Engine destroyed"); | ||||||
|  | 	destroy(); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void Engine::initialize() | ||||||
|  | { | ||||||
|  | 	Logger::info("Initializing engine..."); | ||||||
|  |  | ||||||
|  | 	// Initialize GLFW | ||||||
|  | 	if (!glfwInit()) { | ||||||
|  | 		Logger::error("Failed to initialize GLFW"); | ||||||
|  | 		return; | ||||||
|  | 	} | ||||||
|  | 	Logger::info("GLFW initialized successfully"); | ||||||
|  |  | ||||||
|  | 	glfwWindowHint(GLFW_RESIZABLE, false); | ||||||
|  | 	glfwWindowHint(GLFW_SAMPLES, 8); | ||||||
|  |  | ||||||
|  | 	// Create window | ||||||
|  | 	window_ = glfwCreateWindow(screen_width_, screen_height_, | ||||||
|  | 				   "Daniel Poveda", nullptr, nullptr); | ||||||
|  | 	if (window_ == nullptr) { | ||||||
|  | 		Logger::error("Failed to create OpenGL window"); | ||||||
|  | 		glfwTerminate(); | ||||||
|  | 		return; | ||||||
|  | 	} | ||||||
|  | 	glfwMakeContextCurrent(window_); | ||||||
|  |  | ||||||
|  | 	// Enable OpenGL features | ||||||
|  | 	glEnable(GL_DEPTH_TEST); | ||||||
|  | 	glEnable(GL_SCISSOR_TEST); | ||||||
|  |  | ||||||
|  | 	Logger::info( | ||||||
|  | 	    sstr("OpenGL initialized, version: ", | ||||||
|  | 		 reinterpret_cast<const char*>(glGetString(GL_VERSION)))); | ||||||
|  |  | ||||||
|  | 	// Initialize GLEW | ||||||
|  | 	glewExperimental = GL_TRUE; | ||||||
|  | 	GLenum err	 = glewInit(); | ||||||
|  | 	if (err != GLEW_OK) { | ||||||
|  | 		Logger::error(sstr( | ||||||
|  | 		    "Failed to initialize GLEW: ", | ||||||
|  | 		    reinterpret_cast<const char*>(glewGetErrorString(err)))); | ||||||
|  | 		glfwTerminate(); | ||||||
|  | 		return; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// Initialize default shader | ||||||
|  | 	Logger::info("Loading default shaders..."); | ||||||
|  | 	state::default_shader = | ||||||
|  | 	    std::make_shared<Shader>("data/vertex.glsl", "data/fragment.glsl"); | ||||||
|  | 	if (std::strlen(state::default_shader->error()) > 0) { | ||||||
|  | 		Logger::error(sstr("Failed to initialize shaders: ", | ||||||
|  | 				   state::default_shader->error())); | ||||||
|  | 	} else { | ||||||
|  | 		Logger::info("Default shaders loaded successfully"); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	Logger::info("Engine initialization complete"); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void Engine::run() | ||||||
|  | { | ||||||
|  | 	Logger::info("Starting game loop..."); | ||||||
|  |  | ||||||
|  | 	setup(); | ||||||
|  | 	start(); | ||||||
|  |  | ||||||
|  | 	last_update_time_ = glfwGetTime(); | ||||||
|  | 	last_frame_time_  = glfwGetTime(); | ||||||
|  |  | ||||||
|  | 	while (is_running()) { | ||||||
|  | 		const double now	= glfwGetTime(); | ||||||
|  | 		const double delta_time = now - last_update_time_; | ||||||
|  |  | ||||||
|  | 		process_input(); | ||||||
|  | 		update(delta_time); | ||||||
|  |  | ||||||
|  | 		if (now - last_frame_time_ >= fps_limit) { | ||||||
|  | 			render(); | ||||||
|  | 			last_frame_time_ = now; | ||||||
|  | 		} | ||||||
|  | 		last_update_time_ = now; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	Logger::info("Game loop ended"); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void Engine::destroy() | ||||||
|  | { | ||||||
|  | 	if (window_) { | ||||||
|  | 		Logger::info("Shutting down engine..."); | ||||||
|  | 		glfwTerminate(); | ||||||
|  | 		window_ = nullptr; | ||||||
|  | 		Logger::info("Engine shutdown complete"); | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void Engine::setup() | ||||||
|  | { | ||||||
|  | 	Logger::info("Setting up scene..."); | ||||||
|  |  | ||||||
|  | 	// Create world | ||||||
|  | 	world_ = std::make_unique<World>(); | ||||||
|  | 	Logger::info("World created"); | ||||||
|  |  | ||||||
|  | 	// Create camera | ||||||
|  | 	camera_ = std::make_shared<Camera>(); | ||||||
|  | 	camera_->set_position(glm::vec3(0.0f, 0.0f, 6.0f)); | ||||||
|  | 	camera_->set_projection( | ||||||
|  | 	    glm::perspective(glm::radians(45.0f), | ||||||
|  | 			     static_cast<float>(screen_width_) | ||||||
|  | 				 / static_cast<float>(screen_height_), | ||||||
|  | 			     0.1f, 100.0f)); | ||||||
|  | 	camera_->set_viewport(glm::ivec4(0, 0, screen_width_, screen_height_)); | ||||||
|  | 	camera_->set_clear_color(glm::vec3(0.1f, 0.1f, 0.1f)); | ||||||
|  | 	world_->add_entity(camera_); | ||||||
|  | 	Logger::info("Camera created and added to world"); | ||||||
|  |  | ||||||
|  | 	// Create triangle mesh | ||||||
|  | 	std::vector<Vertex> vertices = { | ||||||
|  | 	    {{0.0f, 0.5f, 0.0f}, {0.0f, 1.0f, 0.0f}}, | ||||||
|  | 	    {{-0.5f, -0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}}, | ||||||
|  | 	    {{0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}}}; | ||||||
|  | 	std::vector<uint16_t> indices = {0, 1, 2}; | ||||||
|  |  | ||||||
|  | 	auto buffer = std::make_shared<Buffer>(vertices, indices); | ||||||
|  | 	mesh_	    = std::make_shared<Mesh>(); | ||||||
|  | 	mesh_->add_buffer(buffer); | ||||||
|  | 	Logger::info(sstr("Mesh created with ", vertices.size(), | ||||||
|  | 			  " vertices and ", indices.size(), " indices")); | ||||||
|  |  | ||||||
|  | 	// Create 9 models in a 3x3 grid | ||||||
|  | 	for (int row = 0; row < 3; ++row) { | ||||||
|  | 		for (int col = 0; col < 3; ++col) { | ||||||
|  | 			auto model = std::make_shared<Model>(mesh_); | ||||||
|  | 			model->set_position( | ||||||
|  | 			    glm::vec3(-3.0f + static_cast<float>(col) * 3.0f, | ||||||
|  | 				      0.0f, static_cast<float>(-row) * 3.0f)); | ||||||
|  | 			models_.push_back(model); | ||||||
|  | 			world_->add_entity(model); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	Logger::info(sstr("Created ", models_.size(), " models in scene")); | ||||||
|  | 	Logger::info("Scene setup complete"); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void Engine::start() | ||||||
|  | { | ||||||
|  | 	// Called once after setup, before the main loop | ||||||
|  | 	// Can be used for initialization that needs the scene to be ready | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void Engine::process_input() | ||||||
|  | { | ||||||
|  | 	glfwPollEvents(); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void Engine::update(const double delta_time) | ||||||
|  | { | ||||||
|  | 	// Update angle for rotation | ||||||
|  | 	angle_ += 32.0 * delta_time; | ||||||
|  |  | ||||||
|  | 	// Update rotation for all models | ||||||
|  | 	for (auto& model : models_) { | ||||||
|  | 		model->set_rotation(glm::vec3( | ||||||
|  | 		    0.0f, glm::radians(static_cast<float>(angle_)), 0.0f)); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// Update world | ||||||
|  | 	world_->update(static_cast<float>(delta_time)); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void Engine::render() | ||||||
|  | { | ||||||
|  | 	// Draw world | ||||||
|  | 	world_->draw(); | ||||||
|  |  | ||||||
|  | 	// Swap buffers | ||||||
|  | 	glfwSwapBuffers(window_); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | bool Engine::is_running() const | ||||||
|  | { | ||||||
|  | 	return window_ && !glfwWindowShouldClose(window_) | ||||||
|  | 	    && !glfwGetKey(window_, GLFW_KEY_ESCAPE); | ||||||
|  | } | ||||||
							
								
								
									
										51
									
								
								src/engine.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								src/engine.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,51 @@ | |||||||
|  | #ifndef ENGINE_H_ | ||||||
|  | #define ENGINE_H_ | ||||||
|  |  | ||||||
|  | #include <memory> | ||||||
|  | #include <vector> | ||||||
|  |  | ||||||
|  | #include "../lib/glew/GL/glew.h" | ||||||
|  | #include "../lib/glfw/glfw3.h" | ||||||
|  |  | ||||||
|  | class World; | ||||||
|  | class Camera; | ||||||
|  | class Model; | ||||||
|  | class Mesh; | ||||||
|  |  | ||||||
|  | class Engine { | ||||||
|  | public: | ||||||
|  | 	Engine(); | ||||||
|  | 	~Engine(); | ||||||
|  |  | ||||||
|  | 	void initialize(); | ||||||
|  | 	void run(); | ||||||
|  | 	void destroy(); | ||||||
|  |  | ||||||
|  | private: | ||||||
|  | 	// Lifecycle methods | ||||||
|  | 	void setup(); | ||||||
|  | 	void start(); | ||||||
|  | 	void process_input(); | ||||||
|  | 	void update(const double delta_time); | ||||||
|  | 	void render(); | ||||||
|  |  | ||||||
|  | 	[[nodiscard]] bool is_running() const; | ||||||
|  |  | ||||||
|  | 	// Window and OpenGL | ||||||
|  | 	GLFWwindow* window_; | ||||||
|  | 	int	    screen_width_; | ||||||
|  | 	int	    screen_height_; | ||||||
|  |  | ||||||
|  | 	// Game objects | ||||||
|  | 	std::unique_ptr<World>		    world_; | ||||||
|  | 	std::shared_ptr<Camera>		    camera_; | ||||||
|  | 	std::vector<std::shared_ptr<Model>> models_; | ||||||
|  | 	std::shared_ptr<Mesh>		    mesh_; | ||||||
|  |  | ||||||
|  | 	// Game loop timing | ||||||
|  | 	double last_update_time_; | ||||||
|  | 	double last_frame_time_; | ||||||
|  | 	double angle_; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | #endif // ENGINE_H_ | ||||||
							
								
								
									
										13
									
								
								src/entity.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								src/entity.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | |||||||
|  | #include "entity.h" | ||||||
|  |  | ||||||
|  | Entity::Entity() | ||||||
|  |     : position_(0.0f, 0.0f, 0.0f) | ||||||
|  |     , rotation_(0.0f, 0.0f, 0.0f) | ||||||
|  |     , scale_(1.0f, 1.0f, 1.0f) | ||||||
|  | { | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void Entity::move(const glm::vec3& vec) | ||||||
|  | { | ||||||
|  | 	position_ += vec; | ||||||
|  | } | ||||||
							
								
								
									
										55
									
								
								src/entity.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								src/entity.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,55 @@ | |||||||
|  | #ifndef ENTITY_H_ | ||||||
|  | #define ENTITY_H_ | ||||||
|  |  | ||||||
|  | #include "../lib/glm/glm.hpp" | ||||||
|  |  | ||||||
|  | class Entity { | ||||||
|  | public: | ||||||
|  | 	Entity(); | ||||||
|  | 	virtual ~Entity() = default; | ||||||
|  |  | ||||||
|  | 	[[nodiscard]] const glm::vec3& position() const | ||||||
|  | 	{ | ||||||
|  | 		return position_; | ||||||
|  | 	} | ||||||
|  | 	void set_position(const glm::vec3& pos) | ||||||
|  | 	{ | ||||||
|  | 		position_ = pos; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	[[nodiscard]] const glm::vec3& rotation() const | ||||||
|  | 	{ | ||||||
|  | 		return rotation_; | ||||||
|  | 	} | ||||||
|  | 	void set_rotation(const glm::vec3& rot) | ||||||
|  | 	{ | ||||||
|  | 		rotation_ = rot; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	[[nodiscard]] const glm::vec3& scale() const | ||||||
|  | 	{ | ||||||
|  | 		return scale_; | ||||||
|  | 	} | ||||||
|  | 	void set_scale(const glm::vec3& scale) | ||||||
|  | 	{ | ||||||
|  | 		scale_ = scale; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	void move(const glm::vec3& vec); | ||||||
|  |  | ||||||
|  | 	virtual void update(const float delta_time) | ||||||
|  | 	{ | ||||||
|  | 		// ... | ||||||
|  | 	} | ||||||
|  | 	virtual void draw() | ||||||
|  | 	{ | ||||||
|  | 		// ... | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | protected: | ||||||
|  | 	glm::vec3 position_; | ||||||
|  | 	glm::vec3 rotation_; | ||||||
|  | 	glm::vec3 scale_; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | #endif // ENTITY_H_ | ||||||
							
								
								
									
										57
									
								
								src/logger.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								src/logger.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,57 @@ | |||||||
|  | #include "logger.h" | ||||||
|  |  | ||||||
|  | #include <chrono> | ||||||
|  | #include <iostream> | ||||||
|  |  | ||||||
|  | namespace { | ||||||
|  |  | ||||||
|  | std::string current_datetime_string() | ||||||
|  | { | ||||||
|  | 	auto	  now	     = std::chrono::system_clock::now(); | ||||||
|  | 	auto	  now_time_t = std::chrono::system_clock::to_time_t(now); | ||||||
|  | 	struct tm now_tm {}; | ||||||
|  | #ifdef _WIN32 | ||||||
|  | 	localtime_s(&now_tm, &now_time_t); | ||||||
|  | #else | ||||||
|  | 	localtime_r(&now_time_t, &now_tm); | ||||||
|  | #endif | ||||||
|  |  | ||||||
|  | 	char buffer[30]; | ||||||
|  | 	std::strftime(buffer, sizeof(buffer) / sizeof(char), "%Y-%m-%d %H:%M:%S", | ||||||
|  | 		      &now_tm); | ||||||
|  | 	return std::string{buffer}; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | } // namespace | ||||||
|  |  | ||||||
|  | void Logger::info(const std::string& message) | ||||||
|  | { | ||||||
|  | 	LogEntry entry; | ||||||
|  | 	entry.type = LogType::info; | ||||||
|  | 	entry.message = | ||||||
|  | 	    "[" + current_datetime_string() + "] [INFO]: " + message; | ||||||
|  |  | ||||||
|  | 	std::cout << "\x1B[32m" << entry.message << "\033[0m" << std::endl; | ||||||
|  | 	messages_.push_back(entry); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void Logger::warn(const std::string& message) | ||||||
|  | { | ||||||
|  | 	LogEntry entry; | ||||||
|  | 	entry.type = LogType::warn; | ||||||
|  | 	entry.message = | ||||||
|  | 	    "[" + current_datetime_string() + "] [WARN]: " + message; | ||||||
|  |  | ||||||
|  | 	std::cout << "\x1B[93m" << entry.message << "\033[0m" << std::endl; | ||||||
|  | 	messages_.push_back(entry); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void Logger::error(const std::string& message) | ||||||
|  | { | ||||||
|  | 	LogEntry entry; | ||||||
|  | 	entry.type	= LogType::error; | ||||||
|  | 	entry.message = "[" + current_datetime_string() + "] [ERROR]: " + message; | ||||||
|  |  | ||||||
|  | 	std::cerr << "\x1B[91m" << entry.message << "\033[0m" << std::endl; | ||||||
|  | 	messages_.push_back(entry); | ||||||
|  | } | ||||||
							
								
								
									
										48
									
								
								src/logger.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								src/logger.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,48 @@ | |||||||
|  | #ifndef LOGGER_H_ | ||||||
|  | #define LOGGER_H_ | ||||||
|  |  | ||||||
|  | #include <sstream> | ||||||
|  | #include <string> | ||||||
|  | #include <vector> | ||||||
|  |  | ||||||
|  | // Utility: Concatenate any types into a string | ||||||
|  | template <typename... Args> | ||||||
|  | std::string sstr(Args&&... args) | ||||||
|  | { | ||||||
|  | 	std::ostringstream stream; | ||||||
|  | 	stream << std::dec; | ||||||
|  | 	((stream << args), ...); | ||||||
|  | 	return stream.str(); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // Log types | ||||||
|  | enum class LogType { | ||||||
|  | 	info = 0, | ||||||
|  | 	warn, | ||||||
|  | 	error | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | // Log entry structure | ||||||
|  | struct LogEntry { | ||||||
|  | 	LogType	    type{LogType::info}; | ||||||
|  | 	std::string message{}; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | // Logger class | ||||||
|  | class Logger { | ||||||
|  | public: | ||||||
|  | 	static void info(const std::string& message); | ||||||
|  | 	static void warn(const std::string& message); | ||||||
|  | 	static void error(const std::string& message); | ||||||
|  |  | ||||||
|  | 	[[nodiscard]] static const std::vector<LogEntry>& messages() | ||||||
|  | 	{ | ||||||
|  | 		return messages_; | ||||||
|  | 	} | ||||||
|  | 	static void clear() { messages_.clear(); } | ||||||
|  |  | ||||||
|  | private: | ||||||
|  | 	inline static std::vector<LogEntry> messages_{}; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | #endif // LOGGER_H_ | ||||||
							
								
								
									
										116
									
								
								src/main.cpp
									
									
									
									
									
								
							
							
						
						
									
										116
									
								
								src/main.cpp
									
									
									
									
									
								
							| @@ -2,117 +2,15 @@ | |||||||
| #pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup") | #pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup") | ||||||
| #endif*/ | #endif*/ | ||||||
|  |  | ||||||
|  | #include "engine.h" | ||||||
|  |  | ||||||
| #include <iostream> | int main() | ||||||
| #include <vector> | { | ||||||
|  | 	Engine engine; | ||||||
|  |  | ||||||
| #include "../lib/glew/GL/glew.h" | 	engine.initialize(); | ||||||
| #include "../lib/glfw/glfw3.h" | 	engine.run(); | ||||||
| #include "../lib/glm/glm.hpp" | 	engine.destroy(); | ||||||
| #include "../lib/glm/gtc/matrix_transform.hpp" |  | ||||||
|  |  | ||||||
| #include "vertex.h" |  | ||||||
| #include "shader.h" |  | ||||||
| #include "buffer.h" |  | ||||||
|  |  | ||||||
| #define SCREEN_WIDTH 800 |  | ||||||
| #define SCREEN_HEIGHT 600 |  | ||||||
|  |  | ||||||
| int main() { |  | ||||||
| 	// Initialize OpenGL |  | ||||||
| 	if (!glfwInit()) { |  | ||||||
| 		std::cerr << "Failed to initialize glfw\n"; |  | ||||||
| 		return 1; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	glfwWindowHint(GLFW_RESIZABLE, false); |  | ||||||
| 	glfwWindowHint(GLFW_SAMPLES, 8); |  | ||||||
| 	 |  | ||||||
| 	//glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); |  | ||||||
| 	//glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); |  | ||||||
| 	//glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); |  | ||||||
|  |  | ||||||
| 	GLFWwindow* win = glfwCreateWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Daniel Poveda", nullptr, nullptr); |  | ||||||
| 	if (win == nullptr) { |  | ||||||
| 		std::cerr << "Failed to create opengl window\n"; |  | ||||||
| 		glfwTerminate(); |  | ||||||
| 		return 1; |  | ||||||
| 	} |  | ||||||
| 	glfwMakeContextCurrent(win); |  | ||||||
|  |  | ||||||
| 	glEnable(GL_DEPTH_TEST); |  | ||||||
| 	glEnable(GL_SCISSOR_TEST); |  | ||||||
|  |  | ||||||
| 	std::cout << "OpenGL initialized, version: " << glGetString(GL_VERSION) << "\n"; |  | ||||||
|  |  | ||||||
| 	// Initialize GLEW |  | ||||||
| 	glewExperimental = GL_TRUE; |  | ||||||
| 	GLenum err = glewInit(); |  | ||||||
| 	if (err != GLEW_OK) { |  | ||||||
| 		std::cerr << "Failed to initialize GLEW: " << glewGetErrorString(err) << "\n"; |  | ||||||
| 		glfwTerminate(); |  | ||||||
| 		return 1; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	// Logic |  | ||||||
| 	std::vector<Vertex> vertices = { |  | ||||||
| 		{{0.0f, 0.5f, 0.0f}, {0.0f, 1.0f, 0.0f}}, |  | ||||||
| 		{{-0.5f, -0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}}, |  | ||||||
| 		{{0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}}  |  | ||||||
| 	}; |  | ||||||
| 	std::vector<uint16_t> indices = { 0, 1, 2 }; |  | ||||||
|  |  | ||||||
| 	Buffer buffer(vertices, indices); |  | ||||||
| 	Shader shader("data/vertex.glsl", "data/fragment.glsl"); |  | ||||||
| 	if (std::strlen(shader.getError()) > 0) { |  | ||||||
| 		std::cerr << "Failed to initialize shaders: " << shader.getError() << "\n"; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	glm::mat4 projection = glm::perspective(glm::radians(45.0f), static_cast<float>(SCREEN_WIDTH) / SCREEN_HEIGHT, 0.1f, 100.0f); |  | ||||||
| 	//glm::mat4 view = glm::translate(glm::mat4(1.0f), glm::vec3(0, 0, 6)); |  | ||||||
| 	glm::mat4 view = glm::lookAt(glm::vec3(0, 0, 6), glm::vec3(0, 0, 0), glm::vec3(0, 1, 0)); |  | ||||||
|  |  | ||||||
| 	// main loop |  | ||||||
| 	double angle = 0.0; |  | ||||||
| 	double lastTime = glfwGetTime(); |  | ||||||
| 	while (!glfwWindowShouldClose(win) && !glfwGetKey(win, GLFW_KEY_ESCAPE)) { |  | ||||||
| 		// Delta |  | ||||||
| 		double delta_time = glfwGetTime() - lastTime; |  | ||||||
| 		lastTime = glfwGetTime(); |  | ||||||
|  |  | ||||||
| 		// Reset window |  | ||||||
| 		int screenWidth, screenHeight; |  | ||||||
| 		glfwGetWindowSize(win, &screenWidth, &screenHeight); |  | ||||||
| 		glViewport(0, 0, screenWidth, screenHeight); |  | ||||||
|  |  | ||||||
| 		glClearColor(0.1f, 0.1f, 0.1f, 1.0f); |  | ||||||
| 		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |  | ||||||
|  |  | ||||||
| 		shader.Use(); |  | ||||||
|  |  | ||||||
| 		// Logic |  | ||||||
| 		angle += 32.0 * delta_time; |  | ||||||
|  |  | ||||||
| 		for (int row = 0; row < 3; ++row) { |  | ||||||
| 			for (int col = 0; col < 3; ++col) { |  | ||||||
| 				glm::mat4 model = glm::translate(glm::mat4(1.0), glm::vec3(-3.0f + static_cast<float>(col) * 3.0f, 0.0f, static_cast<float>(-row) * 3.0f)); |  | ||||||
| 				model = glm::rotate(model, glm::radians(static_cast<float>(angle)), glm::vec3(0, 1, 0)); |  | ||||||
|  |  | ||||||
| 				glm::mat4 mvp = projection * view * model; |  | ||||||
|  |  | ||||||
| 				Shader::setMat4(shader.getLocation("mvp"), mvp); |  | ||||||
|  |  | ||||||
| 				buffer.Draw(shader); |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
|  |  | ||||||
| 		// Refresh screen |  | ||||||
| 		glfwSwapBuffers(win); |  | ||||||
| 		glfwPollEvents(); |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	// Shutdown |  | ||||||
| 	glfwTerminate(); |  | ||||||
|  |  | ||||||
| 	return 0; | 	return 0; | ||||||
| } | } | ||||||
							
								
								
									
										33
									
								
								src/mesh.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								src/mesh.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,33 @@ | |||||||
|  | #include "mesh.h" | ||||||
|  | #include "buffer.h" | ||||||
|  | #include "shader.h" | ||||||
|  | #include "state.h" | ||||||
|  |  | ||||||
|  | void Mesh::add_buffer(const std::shared_ptr<Buffer>& buffer, | ||||||
|  | 		      const std::shared_ptr<Shader>& shader) | ||||||
|  | { | ||||||
|  | 	buffers_.push_back(buffer); | ||||||
|  | 	shaders_.push_back(shader); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void Mesh::draw() | ||||||
|  | { | ||||||
|  | 	// Calculate MVP matrix | ||||||
|  | 	glm::mat4 mvp = state::projection_matrix * state::view_matrix | ||||||
|  | 	    * state::model_matrix; | ||||||
|  |  | ||||||
|  | 	// Draw each buffer with its shader | ||||||
|  | 	for (size_t i = 0; i < buffers_.size(); ++i) { | ||||||
|  | 		// Use buffer's shader if available, otherwise use default | ||||||
|  | 		// shader | ||||||
|  | 		std::shared_ptr<Shader> shader = | ||||||
|  | 		    shaders_[i] ? shaders_[i] : state::default_shader; | ||||||
|  |  | ||||||
|  | 		if (shader) { | ||||||
|  | 			shader->use(); | ||||||
|  | 			int mvpLoc = shader->uniform_location("mvp"); | ||||||
|  | 			Shader::set_mat4(mvpLoc, mvp); | ||||||
|  | 			buffers_[i]->draw(*shader); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | } | ||||||
							
								
								
									
										38
									
								
								src/mesh.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								src/mesh.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,38 @@ | |||||||
|  | #ifndef MESH_H_ | ||||||
|  | #define MESH_H_ | ||||||
|  |  | ||||||
|  | #include <memory> | ||||||
|  | #include <vector> | ||||||
|  |  | ||||||
|  | class Buffer; | ||||||
|  | class Shader; | ||||||
|  |  | ||||||
|  | class Mesh { | ||||||
|  | public: | ||||||
|  | 	Mesh()	= default; | ||||||
|  | 	~Mesh() = default; | ||||||
|  |  | ||||||
|  | 	void add_buffer(const std::shared_ptr<Buffer>& buffer, | ||||||
|  | 			const std::shared_ptr<Shader>& shader = nullptr); | ||||||
|  |  | ||||||
|  | 	[[nodiscard]] size_t num_buffers() const | ||||||
|  | 	{ | ||||||
|  | 		return buffers_.size(); | ||||||
|  | 	} | ||||||
|  | 	[[nodiscard]] const std::shared_ptr<Buffer>& buffer(size_t index) const | ||||||
|  | 	{ | ||||||
|  | 		return buffers_[index]; | ||||||
|  | 	} | ||||||
|  | 	[[nodiscard]] std::shared_ptr<Buffer>& buffer(size_t index) | ||||||
|  | 	{ | ||||||
|  | 		return buffers_[index]; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	void draw(); | ||||||
|  |  | ||||||
|  | private: | ||||||
|  | 	std::vector<std::shared_ptr<Buffer>> buffers_; | ||||||
|  | 	std::vector<std::shared_ptr<Shader>> shaders_; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | #endif // MESH_H_ | ||||||
							
								
								
									
										35
									
								
								src/model.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								src/model.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,35 @@ | |||||||
|  | #include "model.h" | ||||||
|  | #include "mesh.h" | ||||||
|  | #include "state.h" | ||||||
|  | #include "../lib/glm/gtc/matrix_transform.hpp" | ||||||
|  |  | ||||||
|  | Model::Model(const std::shared_ptr<Mesh>& mesh) | ||||||
|  |     : mesh_(mesh) | ||||||
|  | { | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void Model::draw() | ||||||
|  | { | ||||||
|  | 	if (!mesh_) | ||||||
|  | 		return; | ||||||
|  |  | ||||||
|  | 	// Build model matrix: Translation * Rotation * Scale | ||||||
|  | 	glm::mat4 model = glm::mat4(1.0f); | ||||||
|  |  | ||||||
|  | 	// Translation | ||||||
|  | 	model = glm::translate(model, position_); | ||||||
|  |  | ||||||
|  | 	// Rotation (applying X, Y, Z rotations) | ||||||
|  | 	model = glm::rotate(model, rotation_.x, glm::vec3(1.0f, 0.0f, 0.0f)); | ||||||
|  | 	model = glm::rotate(model, rotation_.y, glm::vec3(0.0f, 1.0f, 0.0f)); | ||||||
|  | 	model = glm::rotate(model, rotation_.z, glm::vec3(0.0f, 0.0f, 1.0f)); | ||||||
|  |  | ||||||
|  | 	// Scale | ||||||
|  | 	model = glm::scale(model, scale_); | ||||||
|  |  | ||||||
|  | 	// Set the model matrix in state | ||||||
|  | 	state::model_matrix = model; | ||||||
|  |  | ||||||
|  | 	// Draw the mesh | ||||||
|  | 	mesh_->draw(); | ||||||
|  | } | ||||||
							
								
								
									
										19
									
								
								src/model.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								src/model.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,19 @@ | |||||||
|  | #ifndef MODEL_H_ | ||||||
|  | #define MODEL_H_ | ||||||
|  |  | ||||||
|  | #include "entity.h" | ||||||
|  | #include <memory> | ||||||
|  |  | ||||||
|  | class Mesh; | ||||||
|  |  | ||||||
|  | class Model : public Entity { | ||||||
|  | public: | ||||||
|  | 	Model(const std::shared_ptr<Mesh>& mesh); | ||||||
|  |  | ||||||
|  | 	virtual void draw() override; | ||||||
|  |  | ||||||
|  | private: | ||||||
|  | 	std::shared_ptr<Mesh> mesh_; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | #endif // MODEL_H_ | ||||||
| @@ -1,19 +1,20 @@ | |||||||
| #include "shader.h" | #include "shader.h" | ||||||
|  |  | ||||||
| #include <vector> |  | ||||||
| #include <fstream> | #include <fstream> | ||||||
| #include <sstream> | #include <sstream> | ||||||
| #include <iostream> | #include <vector> | ||||||
|  |  | ||||||
| #include "../lib/glew/GL/glew.h" | #include "../lib/glew/GL/glew.h" | ||||||
| #include "../lib/glfw/glfw3.h" | #include "../lib/glfw/glfw3.h" | ||||||
|  |  | ||||||
|  | #include "logger.h" | ||||||
| #include "vertex.h" | #include "vertex.h" | ||||||
|  |  | ||||||
| Shader::Shader(const std::string& vertexPath, const std::string& fragmentPath) | Shader::Shader(const std::string& vertexPath, const std::string& fragmentPath) | ||||||
| { | { | ||||||
| 	const uint32_t vshader = CompileShader(GL_VERTEX_SHADER, vertexPath); | 	const uint32_t vshader = compile_shader(GL_VERTEX_SHADER, vertexPath); | ||||||
| 	const uint32_t fshader = CompileShader(GL_FRAGMENT_SHADER, fragmentPath); | 	const uint32_t fshader = | ||||||
|  | 	    compile_shader(GL_FRAGMENT_SHADER, fragmentPath); | ||||||
|  |  | ||||||
| 	if (vshader == 0 || fshader == 0) { | 	if (vshader == 0 || fshader == 0) { | ||||||
| 		program_id_ = 0; | 		program_id_ = 0; | ||||||
| @@ -30,7 +31,8 @@ Shader::Shader(const std::string& vertexPath, const std::string& fragmentPath) | |||||||
| 	glGetProgramiv(program_id_, GL_LINK_STATUS, &ret); | 	glGetProgramiv(program_id_, GL_LINK_STATUS, &ret); | ||||||
| 	if (ret == GL_FALSE) { | 	if (ret == GL_FALSE) { | ||||||
| 		char buffer[1024]; | 		char buffer[1024]; | ||||||
| 		glGetProgramInfoLog(program_id_, sizeof(buffer), nullptr, buffer); | 		glGetProgramInfoLog(program_id_, sizeof(buffer), nullptr, | ||||||
|  | 				    buffer); | ||||||
| 		error_ = buffer; | 		error_ = buffer; | ||||||
| 		glDeleteProgram(program_id_); | 		glDeleteProgram(program_id_); | ||||||
| 		program_id_ = 0; | 		program_id_ = 0; | ||||||
| @@ -40,67 +42,72 @@ Shader::Shader(const std::string& vertexPath, const std::string& fragmentPath) | |||||||
| 	glDeleteShader(fshader); | 	glDeleteShader(fshader); | ||||||
| } | } | ||||||
|  |  | ||||||
| void Shader::Use() const | void Shader::use() const | ||||||
| { | { | ||||||
| 	if (program_id_ != 0) | 	if (program_id_ != 0) | ||||||
| 		glUseProgram(program_id_); | 		glUseProgram(program_id_); | ||||||
| } | } | ||||||
|  |  | ||||||
| void Shader::SetupAttribs() const | void Shader::setup_attribs() const | ||||||
| { | { | ||||||
| 	int loc = glGetAttribLocation(program_id_, "vpos"); | 	int loc = glGetAttribLocation(program_id_, "vpos"); | ||||||
| 	if (loc != -1) { | 	if (loc != -1) { | ||||||
| 		glEnableVertexAttribArray(loc); | 		glEnableVertexAttribArray(loc); | ||||||
| 		glVertexAttribPointer(loc, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<const void*>(offsetof(Vertex, position))); | 		glVertexAttribPointer( | ||||||
|  | 		    loc, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), | ||||||
|  | 		    reinterpret_cast<const void*>(offsetof(Vertex, position))); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	loc = glGetAttribLocation(program_id_, "vcolor"); | 	loc = glGetAttribLocation(program_id_, "vcolor"); | ||||||
| 	if (loc != -1) { | 	if (loc != -1) { | ||||||
| 		glEnableVertexAttribArray(loc); | 		glEnableVertexAttribArray(loc); | ||||||
| 		glVertexAttribPointer(loc, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<const void*>(offsetof(Vertex, color))); | 		glVertexAttribPointer( | ||||||
|  | 		    loc, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), | ||||||
|  | 		    reinterpret_cast<const void*>(offsetof(Vertex, color))); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| int Shader::getLocation(const char* key) const | int Shader::uniform_location(const char* key) const | ||||||
| { | { | ||||||
| 	return glGetUniformLocation(program_id_, key); | 	return glGetUniformLocation(program_id_, key); | ||||||
| } | } | ||||||
|  |  | ||||||
| void Shader::setInt(int loc, int value) | void Shader::set_int(int loc, int value) | ||||||
| { | { | ||||||
| 	if (loc != -1) | 	if (loc != -1) | ||||||
| 		glUniform1i(loc, value); | 		glUniform1i(loc, value); | ||||||
| } | } | ||||||
|  |  | ||||||
| void Shader::setFloat(int loc, float value) | void Shader::set_float(int loc, float value) | ||||||
| { | { | ||||||
| 	if (loc != -1) | 	if (loc != -1) | ||||||
| 		glUniform1f(loc, value); | 		glUniform1f(loc, value); | ||||||
| } | } | ||||||
|  |  | ||||||
| void Shader::setVec3(int loc, const glm::vec3& value) | void Shader::set_vec3(int loc, const glm::vec3& value) | ||||||
| { | { | ||||||
| 	if (loc != -1) | 	if (loc != -1) | ||||||
| 		glUniform3fv(loc, 1, &value[0]); | 		glUniform3fv(loc, 1, &value[0]); | ||||||
| } | } | ||||||
|  |  | ||||||
| void Shader::setVec4(int loc, const glm::vec4& value) | void Shader::set_vec4(int loc, const glm::vec4& value) | ||||||
| { | { | ||||||
| 	if (loc != -1) | 	if (loc != -1) | ||||||
| 		glUniform4fv(loc, 1, &value[0]); | 		glUniform4fv(loc, 1, &value[0]); | ||||||
| } | } | ||||||
|  |  | ||||||
| void Shader::setMat4(int loc, const glm::mat4& value) | void Shader::set_mat4(int loc, const glm::mat4& value) | ||||||
| { | { | ||||||
| 	if (loc != -1) | 	if (loc != -1) | ||||||
| 		glUniformMatrix4fv(loc, 1, GL_FALSE, &value[0][0]); | 		glUniformMatrix4fv(loc, 1, GL_FALSE, &value[0][0]); | ||||||
| } | } | ||||||
|  |  | ||||||
| std::string Shader::ReadShaderFile(const std::string& filename) | std::string Shader::read_shader_file(const std::string& filename) | ||||||
| { | { | ||||||
| 	std::ifstream file(filename); | 	std::ifstream file(filename); | ||||||
| 	if (!file) { | 	if (!file) { | ||||||
| 		error_ = "Failed to open shader file: " + filename + "\n"; | 		error_ = "Failed to open shader file: " + filename; | ||||||
|  | 		Logger::error(sstr("Failed to open shader file: ", filename)); | ||||||
| 		return std::string{0}; | 		return std::string{0}; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -109,13 +116,18 @@ std::string Shader::ReadShaderFile(const std::string& filename) | |||||||
| 	return buffer.str(); | 	return buffer.str(); | ||||||
| } | } | ||||||
|  |  | ||||||
| uint32_t Shader::CompileShader(uint32_t type, const std::string& source_path) | uint32_t Shader::compile_shader(uint32_t type, const std::string& source_path) | ||||||
| { | { | ||||||
| 	std::string source = ReadShaderFile(source_path); | 	const char* shader_type_name = | ||||||
| 	//std::cout << "SHADER FILE: " << source << "\n"; | 	    (type == GL_VERTEX_SHADER) ? "vertex" : "fragment"; | ||||||
|  |  | ||||||
|  | 	std::string source = read_shader_file(source_path); | ||||||
| 	if (source.empty()) | 	if (source.empty()) | ||||||
| 		return 0; | 		return 0; | ||||||
|  |  | ||||||
|  | 	Logger::info( | ||||||
|  | 	    sstr("Compiling ", shader_type_name, " shader: ", source_path)); | ||||||
|  |  | ||||||
| 	const uint32_t shader	   = glCreateShader(type); | 	const uint32_t shader	   = glCreateShader(type); | ||||||
| 	const char*    shader_code = source.c_str(); | 	const char*    shader_code = source.c_str(); | ||||||
|  |  | ||||||
| @@ -129,9 +141,13 @@ uint32_t Shader::CompileShader(uint32_t type, const std::string& source_path) | |||||||
| 		char buffer[1024]; | 		char buffer[1024]; | ||||||
| 		glGetShaderInfoLog(shader, sizeof(buffer), nullptr, buffer); | 		glGetShaderInfoLog(shader, sizeof(buffer), nullptr, buffer); | ||||||
| 		error_ = buffer; | 		error_ = buffer; | ||||||
|  | 		Logger::error( | ||||||
|  | 		    sstr("Shader compilation failed (", shader_type_name, "): ", | ||||||
|  | 			 buffer)); | ||||||
| 		glDeleteShader(shader); | 		glDeleteShader(shader); | ||||||
| 		return 0; | 		return 0; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	Logger::info(sstr(shader_type_name, " shader compiled successfully")); | ||||||
| 	return shader; | 	return shader; | ||||||
| } | } | ||||||
|   | |||||||
							
								
								
									
										34
									
								
								src/shader.h
									
									
									
									
									
								
							
							
						
						
									
										34
									
								
								src/shader.h
									
									
									
									
									
								
							| @@ -9,29 +9,35 @@ | |||||||
|  |  | ||||||
| class Shader { | class Shader { | ||||||
| public: | public: | ||||||
| 	Shader(const std::string& vertex_path, const std::string& fragment_path); | 	Shader(const std::string& vertex_path, | ||||||
|  | 	       const std::string& fragment_path); | ||||||
|  |  | ||||||
| 	void Use() const; | 	void use() const; | ||||||
| 	void SetupAttribs() const; | 	void setup_attribs() const; | ||||||
|  |  | ||||||
| 	uint32_t getId() const { return program_id_; } | 	[[nodiscard]] uint32_t id() const | ||||||
| 	const char* getError() const { return error_.c_str(); } | 	{ | ||||||
|  | 		return program_id_; | ||||||
|  | 	} | ||||||
|  | 	[[nodiscard]] const char* error() const | ||||||
|  | 	{ | ||||||
|  | 		return error_.c_str(); | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	int getLocation(const char* key) const; | 	[[nodiscard]] int uniform_location(const char* key) const; | ||||||
|  |  | ||||||
| 	static void setInt(int loc, int value); | 	static void set_int(int loc, int value); | ||||||
| 	static void setFloat(int loc, float value); | 	static void set_float(int loc, float value); | ||||||
| 	static void setVec3(int loc, const glm::vec3& value); | 	static void set_vec3(int loc, const glm::vec3& value); | ||||||
| 	static void setVec4(int loc, const glm::vec4& value); | 	static void set_vec4(int loc, const glm::vec4& value); | ||||||
| 	static void setMat4(int loc, const glm::mat4& value); | 	static void set_mat4(int loc, const glm::mat4& value); | ||||||
|  |  | ||||||
| private: | private: | ||||||
| 	uint32_t    program_id_; | 	uint32_t    program_id_; | ||||||
| 	std::string error_; | 	std::string error_; | ||||||
|  |  | ||||||
| 	std::string ReadShaderFile(const std::string& filename); | 	std::string read_shader_file(const std::string& filename); | ||||||
| 	uint32_t CompileShader(uint32_t type, const std::string& source_path); | 	uint32_t compile_shader(uint32_t type, const std::string& source_path); | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  |  | ||||||
| #endif // SHADER_H_ | #endif // SHADER_H_ | ||||||
							
								
								
									
										18
									
								
								src/state.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								src/state.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,18 @@ | |||||||
|  | #ifndef STATE_H_ | ||||||
|  | #define STATE_H_ | ||||||
|  |  | ||||||
|  | #include <memory> | ||||||
|  | #include "../lib/glm/glm.hpp" | ||||||
|  |  | ||||||
|  | class Shader; | ||||||
|  |  | ||||||
|  | namespace state { | ||||||
|  |  | ||||||
|  | inline std::shared_ptr<Shader> default_shader	 = nullptr; | ||||||
|  | inline glm::mat4	       projection_matrix = glm::mat4(1.0f); | ||||||
|  | inline glm::mat4	       view_matrix	 = glm::mat4(1.0f); | ||||||
|  | inline glm::mat4	       model_matrix	 = glm::mat4(1.0f); | ||||||
|  |  | ||||||
|  | } // namespace state | ||||||
|  |  | ||||||
|  | #endif // STATE_H_ | ||||||
| @@ -4,8 +4,8 @@ | |||||||
| #include "../lib/glm/glm.hpp" | #include "../lib/glm/glm.hpp" | ||||||
|  |  | ||||||
| struct Vertex { | struct Vertex { | ||||||
| 	glm::vec3 position{ 0.0f, 0.0f, 0.0f }; | 	glm::vec3 position{0.0f, 0.0f, 0.0f}; | ||||||
| 	glm::vec3 color{ 0.0f, 0.0f, 0.0f }; | 	glm::vec3 color{0.0f, 0.0f, 0.0f}; | ||||||
| }; | }; | ||||||
|  |  | ||||||
| #endif // VERTEX_H_ | #endif // VERTEX_H_ | ||||||
							
								
								
									
										68
									
								
								src/world.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										68
									
								
								src/world.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,68 @@ | |||||||
|  | #include "world.h" | ||||||
|  |  | ||||||
|  | #include <algorithm> | ||||||
|  |  | ||||||
|  | #include "camera.h" | ||||||
|  | #include "entity.h" | ||||||
|  | #include "logger.h" | ||||||
|  |  | ||||||
|  | void World::add_entity(const std::shared_ptr<Entity>& entity) | ||||||
|  | { | ||||||
|  | 	entities_.push_back(entity); | ||||||
|  |  | ||||||
|  | 	// Check if entity is a camera | ||||||
|  | 	std::shared_ptr<Camera> camera = | ||||||
|  | 	    std::dynamic_pointer_cast<Camera>(entity); | ||||||
|  | 	if (camera) { | ||||||
|  | 		cameras_.push_back(camera); | ||||||
|  | 		Logger::info(sstr("Camera added to world (total cameras: ", | ||||||
|  | 				  cameras_.size(), ")")); | ||||||
|  | 	} else { | ||||||
|  | 		Logger::info(sstr("Entity added to world (total entities: ", | ||||||
|  | 				  entities_.size(), ")")); | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void World::remove_entity(const std::shared_ptr<Entity>& entity) | ||||||
|  | { | ||||||
|  | 	// Remove from entities list | ||||||
|  | 	auto it = std::find(entities_.begin(), entities_.end(), entity); | ||||||
|  | 	if (it != entities_.end()) { | ||||||
|  | 		entities_.erase(it); | ||||||
|  | 		Logger::info("Entity removed from world"); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// Check if entity is a camera and remove from cameras list | ||||||
|  | 	std::shared_ptr<Camera> camera = | ||||||
|  | 	    std::dynamic_pointer_cast<Camera>(entity); | ||||||
|  | 	if (camera) { | ||||||
|  | 		auto camIt = | ||||||
|  | 		    std::find(cameras_.begin(), cameras_.end(), camera); | ||||||
|  | 		if (camIt != cameras_.end()) { | ||||||
|  | 			cameras_.erase(camIt); | ||||||
|  | 			Logger::info("Camera removed from world"); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void World::update(float delta_time) | ||||||
|  | { | ||||||
|  | 	for (auto& entity : entities_) { | ||||||
|  | 		entity->update(delta_time); | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void World::draw() | ||||||
|  | { | ||||||
|  | 	// Draw for each camera | ||||||
|  | 	for (auto& camera : cameras_) { | ||||||
|  | 		// Prepare the camera (sets viewport, projection, view, clears | ||||||
|  | 		// screen) | ||||||
|  | 		camera->prepare(); | ||||||
|  |  | ||||||
|  | 		// Draw all entities | ||||||
|  | 		for (auto& entity : entities_) { | ||||||
|  | 			entity->draw(); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | } | ||||||
							
								
								
									
										38
									
								
								src/world.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								src/world.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,38 @@ | |||||||
|  | #ifndef WORLD_H_ | ||||||
|  | #define WORLD_H_ | ||||||
|  |  | ||||||
|  | #include <memory> | ||||||
|  | #include <vector> | ||||||
|  |  | ||||||
|  | class Entity; | ||||||
|  | class Camera; | ||||||
|  |  | ||||||
|  | class World { | ||||||
|  | public: | ||||||
|  | 	World() = default; | ||||||
|  |  | ||||||
|  | 	void add_entity(const std::shared_ptr<Entity>& entity); | ||||||
|  | 	void remove_entity(const std::shared_ptr<Entity>& entity); | ||||||
|  |  | ||||||
|  | 	[[nodiscard]] size_t num_entities() const | ||||||
|  | 	{ | ||||||
|  | 		return entities_.size(); | ||||||
|  | 	} | ||||||
|  | 	[[nodiscard]] const std::shared_ptr<Entity>& entity(size_t index) const | ||||||
|  | 	{ | ||||||
|  | 		return entities_[index]; | ||||||
|  | 	} | ||||||
|  | 	[[nodiscard]] std::shared_ptr<Entity>& entity(size_t index) | ||||||
|  | 	{ | ||||||
|  | 		return entities_[index]; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	void update(float delta_time); | ||||||
|  | 	void draw(); | ||||||
|  |  | ||||||
|  | private: | ||||||
|  | 	std::vector<std::shared_ptr<Entity>> entities_; | ||||||
|  | 	std::vector<std::shared_ptr<Camera>> cameras_; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | #endif // WORLD_H_ | ||||||
| @@ -72,20 +72,20 @@ | |||||||
|   <PropertyGroup Label="UserMacros" /> |   <PropertyGroup Label="UserMacros" /> | ||||||
|   <PropertyGroup /> |   <PropertyGroup /> | ||||||
|   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> |   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||||||
|     <OutDir>$(SolutionDir)Build\$(Platform)\$(Configuration)\</OutDir> |     <OutDir>$(SolutionDir)build\$(Platform)\$(Configuration)\</OutDir> | ||||||
|     <IntDir>$(SolutionDir)Build\obj\$(Platform)\$(Configuration)\</IntDir> |     <IntDir>$(SolutionDir)build\obj\$(Platform)\$(Configuration)\</IntDir> | ||||||
|   </PropertyGroup> |   </PropertyGroup> | ||||||
|   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> |   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||||||
|     <OutDir>$(SolutionDir)Build\$(Platform)\$(Configuration)\</OutDir> |     <OutDir>$(SolutionDir)build\$(Platform)\$(Configuration)\</OutDir> | ||||||
|     <IntDir>$(SolutionDir)Build\obj\$(Platform)\$(Configuration)\</IntDir> |     <IntDir>$(SolutionDir)build\obj\$(Platform)\$(Configuration)\</IntDir> | ||||||
|   </PropertyGroup> |   </PropertyGroup> | ||||||
|   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> |   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||||||
|     <OutDir>$(SolutionDir)Build\$(Platform)\$(Configuration)\</OutDir> |     <OutDir>$(SolutionDir)build\$(Platform)\$(Configuration)\</OutDir> | ||||||
|     <IntDir>$(SolutionDir)Build\obj\$(Platform)\$(Configuration)\</IntDir> |     <IntDir>$(SolutionDir)build\obj\$(Platform)\$(Configuration)\</IntDir> | ||||||
|   </PropertyGroup> |   </PropertyGroup> | ||||||
|   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> |   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||||||
|     <OutDir>$(SolutionDir)Build\$(Platform)\$(Configuration)\</OutDir> |     <OutDir>$(SolutionDir)build\$(Platform)\$(Configuration)\</OutDir> | ||||||
|     <IntDir>$(SolutionDir)Build\obj\$(Platform)\$(Configuration)\</IntDir> |     <IntDir>$(SolutionDir)build\obj\$(Platform)\$(Configuration)\</IntDir> | ||||||
|   </PropertyGroup> |   </PropertyGroup> | ||||||
|   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> |   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||||||
|     <ClCompile> |     <ClCompile> | ||||||
| @@ -93,12 +93,12 @@ | |||||||
|       <Optimization>Disabled</Optimization> |       <Optimization>Disabled</Optimization> | ||||||
|       <SDLCheck>true</SDLCheck> |       <SDLCheck>true</SDLCheck> | ||||||
|       <ConformanceMode>true</ConformanceMode> |       <ConformanceMode>true</ConformanceMode> | ||||||
|       <AdditionalIncludeDirectories>../lib/glew</AdditionalIncludeDirectories> |       <AdditionalIncludeDirectories>lib/glew</AdditionalIncludeDirectories> | ||||||
|       <PreprocessorDefinitions>GLEW_STATIC;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions> |       <PreprocessorDefinitions>GLEW_STATIC;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||||||
|       <LanguageStandard>stdcpp20</LanguageStandard> |       <LanguageStandard>stdcpp20</LanguageStandard> | ||||||
|     </ClCompile> |     </ClCompile> | ||||||
|     <Link> |     <Link> | ||||||
|       <AdditionalLibraryDirectories>../lib/glfw</AdditionalLibraryDirectories> |       <AdditionalLibraryDirectories>lib/glfw</AdditionalLibraryDirectories> | ||||||
|       <AdditionalDependencies>glfw3.win32.lib;opengl32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies> |       <AdditionalDependencies>glfw3.win32.lib;opengl32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||||||
|     </Link> |     </Link> | ||||||
|   </ItemDefinitionGroup> |   </ItemDefinitionGroup> | ||||||
| @@ -108,12 +108,12 @@ | |||||||
|       <Optimization>Disabled</Optimization> |       <Optimization>Disabled</Optimization> | ||||||
|       <SDLCheck>true</SDLCheck> |       <SDLCheck>true</SDLCheck> | ||||||
|       <ConformanceMode>true</ConformanceMode> |       <ConformanceMode>true</ConformanceMode> | ||||||
|       <AdditionalIncludeDirectories>../lib/glew</AdditionalIncludeDirectories> |       <AdditionalIncludeDirectories>lib/glew</AdditionalIncludeDirectories> | ||||||
|       <PreprocessorDefinitions>GLEW_STATIC;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions> |       <PreprocessorDefinitions>GLEW_STATIC;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||||||
|       <LanguageStandard>stdcpp20</LanguageStandard> |       <LanguageStandard>stdcpp20</LanguageStandard> | ||||||
|     </ClCompile> |     </ClCompile> | ||||||
|     <Link> |     <Link> | ||||||
|       <AdditionalLibraryDirectories>../lib/glfw</AdditionalLibraryDirectories> |       <AdditionalLibraryDirectories>lib/glfw</AdditionalLibraryDirectories> | ||||||
|       <AdditionalDependencies>glfw3.win64.lib;opengl32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies> |       <AdditionalDependencies>glfw3.win64.lib;opengl32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||||||
|     </Link> |     </Link> | ||||||
|   </ItemDefinitionGroup> |   </ItemDefinitionGroup> | ||||||
| @@ -125,14 +125,14 @@ | |||||||
|       <IntrinsicFunctions>true</IntrinsicFunctions> |       <IntrinsicFunctions>true</IntrinsicFunctions> | ||||||
|       <SDLCheck>true</SDLCheck> |       <SDLCheck>true</SDLCheck> | ||||||
|       <ConformanceMode>true</ConformanceMode> |       <ConformanceMode>true</ConformanceMode> | ||||||
|       <AdditionalIncludeDirectories>../lib/glew</AdditionalIncludeDirectories> |       <AdditionalIncludeDirectories>lib/glew</AdditionalIncludeDirectories> | ||||||
|       <PreprocessorDefinitions>GLEW_STATIC;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions> |       <PreprocessorDefinitions>GLEW_STATIC;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||||||
|       <LanguageStandard>stdcpp20</LanguageStandard> |       <LanguageStandard>stdcpp20</LanguageStandard> | ||||||
|     </ClCompile> |     </ClCompile> | ||||||
|     <Link> |     <Link> | ||||||
|       <EnableCOMDATFolding>true</EnableCOMDATFolding> |       <EnableCOMDATFolding>true</EnableCOMDATFolding> | ||||||
|       <OptimizeReferences>true</OptimizeReferences> |       <OptimizeReferences>true</OptimizeReferences> | ||||||
|       <AdditionalLibraryDirectories>../lib/glfw</AdditionalLibraryDirectories> |       <AdditionalLibraryDirectories>lib/glfw</AdditionalLibraryDirectories> | ||||||
|       <AdditionalDependencies>glfw3.win32.lib;opengl32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies> |       <AdditionalDependencies>glfw3.win32.lib;opengl32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||||||
|     </Link> |     </Link> | ||||||
|   </ItemDefinitionGroup> |   </ItemDefinitionGroup> | ||||||
| @@ -144,35 +144,50 @@ | |||||||
|       <IntrinsicFunctions>true</IntrinsicFunctions> |       <IntrinsicFunctions>true</IntrinsicFunctions> | ||||||
|       <SDLCheck>true</SDLCheck> |       <SDLCheck>true</SDLCheck> | ||||||
|       <ConformanceMode>true</ConformanceMode> |       <ConformanceMode>true</ConformanceMode> | ||||||
|       <AdditionalIncludeDirectories>../lib/glew</AdditionalIncludeDirectories> |       <AdditionalIncludeDirectories>lib/glew</AdditionalIncludeDirectories> | ||||||
|       <PreprocessorDefinitions>GLEW_STATIC;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions> |       <PreprocessorDefinitions>GLEW_STATIC;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||||||
|       <LanguageStandard>stdcpp20</LanguageStandard> |       <LanguageStandard>stdcpp20</LanguageStandard> | ||||||
|     </ClCompile> |     </ClCompile> | ||||||
|     <Link> |     <Link> | ||||||
|       <EnableCOMDATFolding>true</EnableCOMDATFolding> |       <EnableCOMDATFolding>true</EnableCOMDATFolding> | ||||||
|       <OptimizeReferences>true</OptimizeReferences> |       <OptimizeReferences>true</OptimizeReferences> | ||||||
|       <AdditionalLibraryDirectories>../lib/glfw</AdditionalLibraryDirectories> |       <AdditionalLibraryDirectories>lib/glfw</AdditionalLibraryDirectories> | ||||||
|       <AdditionalDependencies>glfw3.win64.lib;opengl32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies> |       <AdditionalDependencies>glfw3.win64.lib;opengl32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||||||
|     </Link> |     </Link> | ||||||
|   </ItemDefinitionGroup> |   </ItemDefinitionGroup> | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <ClInclude Include="..\lib\glew\GL\glew.h" /> |     <ClInclude Include="lib\glew\GL\glew.h" /> | ||||||
|     <ClInclude Include="..\lib\glfw\glfw3.h" /> |     <ClInclude Include="lib\glfw\glfw3.h" /> | ||||||
|     <ClInclude Include="..\lib\glfw\glfw3native.h" /> |     <ClInclude Include="lib\glfw\glfw3native.h" /> | ||||||
|     <ClInclude Include="..\src\buffer.h" /> |     <ClInclude Include="src\buffer.h" /> | ||||||
|     <ClInclude Include="..\src\shader.h" /> |     <ClInclude Include="src\camera.h" /> | ||||||
|     <ClInclude Include="..\src\vertex.h" /> |     <ClInclude Include="src\engine.h" /> | ||||||
|  |     <ClInclude Include="src\entity.h" /> | ||||||
|  |     <ClInclude Include="src\logger.h" /> | ||||||
|  |     <ClInclude Include="src\mesh.h" /> | ||||||
|  |     <ClInclude Include="src\model.h" /> | ||||||
|  |     <ClInclude Include="src\shader.h" /> | ||||||
|  |     <ClInclude Include="src\state.h" /> | ||||||
|  |     <ClInclude Include="src\vertex.h" /> | ||||||
|  |     <ClInclude Include="src\world.h" /> | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <ClCompile Include="..\lib\glew\glew.c" /> |     <ClCompile Include="lib\glew\glew.c" /> | ||||||
|     <ClCompile Include="..\src\buffer.cpp" /> |     <ClCompile Include="src\buffer.cpp" /> | ||||||
|     <ClCompile Include="..\src\main.cpp" /> |     <ClCompile Include="src\camera.cpp" /> | ||||||
|     <ClCompile Include="..\src\shader.cpp" /> |     <ClCompile Include="src\engine.cpp" /> | ||||||
|     <ClCompile Include="..\src\vertex.cpp" /> |     <ClCompile Include="src\entity.cpp" /> | ||||||
|  |     <ClCompile Include="src\logger.cpp" /> | ||||||
|  |     <ClCompile Include="src\main.cpp" /> | ||||||
|  |     <ClCompile Include="src\mesh.cpp" /> | ||||||
|  |     <ClCompile Include="src\model.cpp" /> | ||||||
|  |     <ClCompile Include="src\shader.cpp" /> | ||||||
|  |     <ClCompile Include="src\vertex.cpp" /> | ||||||
|  |     <ClCompile Include="src\world.cpp" /> | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <None Include="..\data\fragment.glsl" /> |     <None Include="data\fragment.glsl" /> | ||||||
|     <None Include="..\data\vertex.glsl" /> |     <None Include="data\vertex.glsl" /> | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
|   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> |   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | ||||||
|   <ImportGroup Label="ExtensionTargets"> |   <ImportGroup Label="ExtensionTargets"> | ||||||
							
								
								
									
										116
									
								
								ugine3d.vcxproj.filters
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										116
									
								
								ugine3d.vcxproj.filters
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,116 @@ | |||||||
|  | <?xml version="1.0" encoding="utf-8"?> | ||||||
|  | <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||||||
|  |   <ItemGroup> | ||||||
|  |     <Filter Include="Source Files"> | ||||||
|  |       <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> | ||||||
|  |       <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions> | ||||||
|  |     </Filter> | ||||||
|  |     <Filter Include="Header Files"> | ||||||
|  |       <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> | ||||||
|  |       <Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions> | ||||||
|  |     </Filter> | ||||||
|  |     <Filter Include="Resource Files"> | ||||||
|  |       <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> | ||||||
|  |       <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> | ||||||
|  |     </Filter> | ||||||
|  |     <Filter Include="glfw"> | ||||||
|  |       <UniqueIdentifier>{422e20da-2cf0-4bda-9833-a89b7ab453a1}</UniqueIdentifier> | ||||||
|  |     </Filter> | ||||||
|  |     <Filter Include="glew"> | ||||||
|  |       <UniqueIdentifier>{296e1ba9-28bc-4e0b-8d4e-413551edca96}</UniqueIdentifier> | ||||||
|  |     </Filter> | ||||||
|  |     <Filter Include="Shaders"> | ||||||
|  |       <UniqueIdentifier>{0628083b-a31c-4825-822c-11b6f933e7bd}</UniqueIdentifier> | ||||||
|  |     </Filter> | ||||||
|  |   </ItemGroup> | ||||||
|  |   <ItemGroup> | ||||||
|  |     <ClInclude Include="lib\glfw\glfw3.h"> | ||||||
|  |       <Filter>glfw</Filter> | ||||||
|  |     </ClInclude> | ||||||
|  |     <ClInclude Include="lib\glfw\glfw3native.h"> | ||||||
|  |       <Filter>glfw</Filter> | ||||||
|  |     </ClInclude> | ||||||
|  |     <ClInclude Include="lib\glew\GL\glew.h"> | ||||||
|  |       <Filter>glew</Filter> | ||||||
|  |     </ClInclude> | ||||||
|  |     <ClInclude Include="src\vertex.h"> | ||||||
|  |       <Filter>Source Files</Filter> | ||||||
|  |     </ClInclude> | ||||||
|  |     <ClInclude Include="src\shader.h"> | ||||||
|  |       <Filter>Source Files</Filter> | ||||||
|  |     </ClInclude> | ||||||
|  |     <ClInclude Include="src\buffer.h"> | ||||||
|  |       <Filter>Source Files</Filter> | ||||||
|  |     </ClInclude> | ||||||
|  |     <ClInclude Include="src\state.h"> | ||||||
|  |       <Filter>Source Files</Filter> | ||||||
|  |     </ClInclude> | ||||||
|  |     <ClInclude Include="src\mesh.h"> | ||||||
|  |       <Filter>Source Files</Filter> | ||||||
|  |     </ClInclude> | ||||||
|  |     <ClInclude Include="src\entity.h"> | ||||||
|  |       <Filter>Source Files</Filter> | ||||||
|  |     </ClInclude> | ||||||
|  |     <ClInclude Include="src\model.h"> | ||||||
|  |       <Filter>Source Files</Filter> | ||||||
|  |     </ClInclude> | ||||||
|  |     <ClInclude Include="src\camera.h"> | ||||||
|  |       <Filter>Source Files</Filter> | ||||||
|  |     </ClInclude> | ||||||
|  |     <ClInclude Include="src\world.h"> | ||||||
|  |       <Filter>Source Files</Filter> | ||||||
|  |     </ClInclude> | ||||||
|  |     <ClInclude Include="src\engine.h"> | ||||||
|  |       <Filter>Source Files</Filter> | ||||||
|  |     </ClInclude> | ||||||
|  |     <ClInclude Include="src\logger.h"> | ||||||
|  |       <Filter>Source Files</Filter> | ||||||
|  |     </ClInclude> | ||||||
|  |   </ItemGroup> | ||||||
|  |   <ItemGroup> | ||||||
|  |     <ClCompile Include="src\main.cpp"> | ||||||
|  |       <Filter>Source Files</Filter> | ||||||
|  |     </ClCompile> | ||||||
|  |     <ClCompile Include="lib\glew\glew.c"> | ||||||
|  |       <Filter>glew</Filter> | ||||||
|  |     </ClCompile> | ||||||
|  |     <ClCompile Include="src\vertex.cpp"> | ||||||
|  |       <Filter>Source Files</Filter> | ||||||
|  |     </ClCompile> | ||||||
|  |     <ClCompile Include="src\shader.cpp"> | ||||||
|  |       <Filter>Source Files</Filter> | ||||||
|  |     </ClCompile> | ||||||
|  |     <ClCompile Include="src\buffer.cpp"> | ||||||
|  |       <Filter>Source Files</Filter> | ||||||
|  |     </ClCompile> | ||||||
|  |     <ClCompile Include="src\mesh.cpp"> | ||||||
|  |       <Filter>Source Files</Filter> | ||||||
|  |     </ClCompile> | ||||||
|  |     <ClCompile Include="src\entity.cpp"> | ||||||
|  |       <Filter>Source Files</Filter> | ||||||
|  |     </ClCompile> | ||||||
|  |     <ClCompile Include="src\model.cpp"> | ||||||
|  |       <Filter>Source Files</Filter> | ||||||
|  |     </ClCompile> | ||||||
|  |     <ClCompile Include="src\camera.cpp"> | ||||||
|  |       <Filter>Source Files</Filter> | ||||||
|  |     </ClCompile> | ||||||
|  |     <ClCompile Include="src\world.cpp"> | ||||||
|  |       <Filter>Source Files</Filter> | ||||||
|  |     </ClCompile> | ||||||
|  |     <ClCompile Include="src\engine.cpp"> | ||||||
|  |       <Filter>Source Files</Filter> | ||||||
|  |     </ClCompile> | ||||||
|  |     <ClCompile Include="src\logger.cpp"> | ||||||
|  |       <Filter>Source Files</Filter> | ||||||
|  |     </ClCompile> | ||||||
|  |   </ItemGroup> | ||||||
|  |   <ItemGroup> | ||||||
|  |     <None Include="data\fragment.glsl"> | ||||||
|  |       <Filter>Shaders</Filter> | ||||||
|  |     </None> | ||||||
|  |     <None Include="data\vertex.glsl"> | ||||||
|  |       <Filter>Shaders</Filter> | ||||||
|  |     </None> | ||||||
|  |   </ItemGroup> | ||||||
|  | </Project> | ||||||
| @@ -1,19 +1,19 @@ | |||||||
| <?xml version="1.0" encoding="utf-8"?> | <?xml version="1.0" encoding="utf-8"?> | ||||||
| <Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | <Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||||||
|   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> |   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||||||
|     <LocalDebuggerWorkingDirectory>..</LocalDebuggerWorkingDirectory> |     <LocalDebuggerWorkingDirectory>$(ProjectDir)</LocalDebuggerWorkingDirectory> | ||||||
|     <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor> |     <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor> | ||||||
|   </PropertyGroup> |   </PropertyGroup> | ||||||
|   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> |   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||||||
|     <LocalDebuggerWorkingDirectory>..</LocalDebuggerWorkingDirectory> |     <LocalDebuggerWorkingDirectory>$(ProjectDir)</LocalDebuggerWorkingDirectory> | ||||||
|     <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor> |     <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor> | ||||||
|   </PropertyGroup> |   </PropertyGroup> | ||||||
|   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> |   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||||||
|     <LocalDebuggerWorkingDirectory>..</LocalDebuggerWorkingDirectory> |     <LocalDebuggerWorkingDirectory>$(ProjectDir)</LocalDebuggerWorkingDirectory> | ||||||
|     <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor> |     <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor> | ||||||
|   </PropertyGroup> |   </PropertyGroup> | ||||||
|   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> |   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||||||
|     <LocalDebuggerWorkingDirectory>..</LocalDebuggerWorkingDirectory> |     <LocalDebuggerWorkingDirectory>$(ProjectDir)</LocalDebuggerWorkingDirectory> | ||||||
|     <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor> |     <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor> | ||||||
|   </PropertyGroup> |   </PropertyGroup> | ||||||
| </Project> | </Project> | ||||||
		Reference in New Issue
	
	Block a user