diff --git a/Debug/Window_practice.exe b/Debug/Window_practice.exe
index 1d658c3..0ee55bd 100644
Binary files a/Debug/Window_practice.exe and b/Debug/Window_practice.exe differ
diff --git a/Debug/Window_practice.pdb b/Debug/Window_practice.pdb
index 4709e0c..498880f 100644
Binary files a/Debug/Window_practice.pdb and b/Debug/Window_practice.pdb differ
diff --git a/Window_practice/Debug/Window_practice.ilk b/Window_practice/Debug/Window_practice.ilk
index 22a9aa5..b982a1e 100644
Binary files a/Window_practice/Debug/Window_practice.ilk and b/Window_practice/Debug/Window_practice.ilk differ
diff --git a/Window_practice/Debug/Window_practice.log b/Window_practice/Debug/Window_practice.log
index 2226f79..5bc142a 100644
--- a/Window_practice/Debug/Window_practice.log
+++ b/Window_practice/Debug/Window_practice.log
@@ -1,9 +1,4 @@
- Main.cpp
-C:\dev\Glfw_Practice\c++\Window_practice\Window_practice\src\VertexBufferLayout.h(5,10): warning C4067: unexpected tokens following preprocessor directive - expected a newline
- Rernderer.cpp
- VertexArray.cpp
-C:\dev\Glfw_Practice\c++\Window_practice\Window_practice\src\VertexBufferLayout.h(5,10): warning C4067: unexpected tokens following preprocessor directive - expected a newline
- Generating Code...
+ Renderer.cpp
LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
glew32s.lib(glew.obj) : warning LNK4099: PDB 'vc120.pdb' was not found with 'glew32s.lib(glew.obj)' or at 'C:\dev\Glfw_Practice\c++\Window_practice\Debug\vc120.pdb'; linking object as if no debug info
diff --git a/Window_practice/Debug/Window_practice.tlog/CL.command.1.tlog b/Window_practice/Debug/Window_practice.tlog/CL.command.1.tlog
index 30e312e..9a15e9c 100644
Binary files a/Window_practice/Debug/Window_practice.tlog/CL.command.1.tlog and b/Window_practice/Debug/Window_practice.tlog/CL.command.1.tlog differ
diff --git a/Window_practice/Debug/Window_practice.tlog/CL.read.1.tlog b/Window_practice/Debug/Window_practice.tlog/CL.read.1.tlog
index 830722c..fe1ff2c 100644
Binary files a/Window_practice/Debug/Window_practice.tlog/CL.read.1.tlog and b/Window_practice/Debug/Window_practice.tlog/CL.read.1.tlog differ
diff --git a/Window_practice/Debug/Window_practice.tlog/CL.write.1.tlog b/Window_practice/Debug/Window_practice.tlog/CL.write.1.tlog
index 746aeb1..4d818d5 100644
Binary files a/Window_practice/Debug/Window_practice.tlog/CL.write.1.tlog and b/Window_practice/Debug/Window_practice.tlog/CL.write.1.tlog differ
diff --git a/Window_practice/Debug/Window_practice.tlog/link.command.1.tlog b/Window_practice/Debug/Window_practice.tlog/link.command.1.tlog
index 9e14e8d..cf75eae 100644
Binary files a/Window_practice/Debug/Window_practice.tlog/link.command.1.tlog and b/Window_practice/Debug/Window_practice.tlog/link.command.1.tlog differ
diff --git a/Window_practice/Debug/Window_practice.tlog/link.read.1.tlog b/Window_practice/Debug/Window_practice.tlog/link.read.1.tlog
index 8ab241a..f917328 100644
Binary files a/Window_practice/Debug/Window_practice.tlog/link.read.1.tlog and b/Window_practice/Debug/Window_practice.tlog/link.read.1.tlog differ
diff --git a/Window_practice/Debug/Window_practice.tlog/link.write.1.tlog b/Window_practice/Debug/Window_practice.tlog/link.write.1.tlog
index e5f7702..3f1abdc 100644
Binary files a/Window_practice/Debug/Window_practice.tlog/link.write.1.tlog and b/Window_practice/Debug/Window_practice.tlog/link.write.1.tlog differ
diff --git a/Window_practice/Debug/vc142.idb b/Window_practice/Debug/vc142.idb
index b15abdc..4bca387 100644
Binary files a/Window_practice/Debug/vc142.idb and b/Window_practice/Debug/vc142.idb differ
diff --git a/Window_practice/Debug/vc142.pdb b/Window_practice/Debug/vc142.pdb
index 9845afc..6aa2de2 100644
Binary files a/Window_practice/Debug/vc142.pdb and b/Window_practice/Debug/vc142.pdb differ
diff --git a/Window_practice/Window_practice.vcxproj b/Window_practice/Window_practice.vcxproj
index d658f02..fce7361 100644
--- a/Window_practice/Window_practice.vcxproj
+++ b/Window_practice/Window_practice.vcxproj
@@ -147,7 +147,7 @@
-
+
diff --git a/Window_practice/Window_practice.vcxproj.filters b/Window_practice/Window_practice.vcxproj.filters
index 3c07f0e..6f22d3a 100644
--- a/Window_practice/Window_practice.vcxproj.filters
+++ b/Window_practice/Window_practice.vcxproj.filters
@@ -18,7 +18,7 @@
Source Files
-
+
Source Files
diff --git a/Window_practice/res/shaders/Basic.shader b/Window_practice/res/shaders/Basic.shader
new file mode 100644
index 0000000..d22f80b
--- /dev/null
+++ b/Window_practice/res/shaders/Basic.shader
@@ -0,0 +1,20 @@
+#shader vertex
+#version 330 core
+
+layout(location = 0) in vec4 position;
+
+void main() {
+ gl_Position = position;
+};
+
+
+#shader fragment
+#version 330 core
+
+layout(location = 0) out vec4 color;
+
+uniform vec4 u_Color;
+
+void main() {
+ color = u_Color;
+};
\ No newline at end of file
diff --git a/Window_practice/shader to console.txt b/Window_practice/shader to console.txt
new file mode 100644
index 0000000..19fbdf5
--- /dev/null
+++ b/Window_practice/shader to console.txt
@@ -0,0 +1,4 @@
+ /*std::cout << "VERTEX" << std::endl;
+ std::cout << source.VertexSource << std::endl; //to write shader to console
+ std::cout << "FRAGMENT" << std::endl;
+ std::cout << source.FragmentSource << std::endl;*/
\ No newline at end of file
diff --git a/Window_practice/src/IndexBuffer.cpp b/Window_practice/src/IndexBuffer.cpp
new file mode 100644
index 0000000..218993e
--- /dev/null
+++ b/Window_practice/src/IndexBuffer.cpp
@@ -0,0 +1,27 @@
+#include "IndexBuffer.h"
+#include "Renderer.h"
+
+IndexBuffer::IndexBuffer(const unsigned int* data, unsigned int count)
+ :m_Count(count)
+{
+ GLCall(glGenBuffers(1, &m_RendererID)); //number of buffer to generate
+ GLCall(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_RendererID)); //binding the buffer
+ GLCall(glBufferData(GL_ELEMENT_ARRAY_BUFFER, count * sizeof(unsigned int), data, GL_STATIC_DRAW));
+}
+
+IndexBuffer::~IndexBuffer()
+{
+ GLCall(glDeleteBuffers(1, &m_RendererID));
+}
+
+
+void IndexBuffer::Bind() const
+{
+ GLCall(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_RendererID));
+}
+
+void IndexBuffer::Unbind() const
+{
+ GLCall(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
+}
+
diff --git a/Window_practice/src/IndexBuffer.h b/Window_practice/src/IndexBuffer.h
new file mode 100644
index 0000000..847aa0d
--- /dev/null
+++ b/Window_practice/src/IndexBuffer.h
@@ -0,0 +1,15 @@
+#pragma once
+
+class IndexBuffer {
+private:
+ unsigned int m_RendererID;
+ unsigned int m_Count;
+public:
+ IndexBuffer(const unsigned int* data, unsigned int count);
+ ~IndexBuffer();
+
+ void Bind() const;
+ void Unbind() const;
+
+ inline unsigned int GetCount() const { return m_Count; }
+};
diff --git a/Window_practice/src/Renderer.cpp b/Window_practice/src/Renderer.cpp
new file mode 100644
index 0000000..739f29a
--- /dev/null
+++ b/Window_practice/src/Renderer.cpp
@@ -0,0 +1,17 @@
+#include "Renderer.h"
+
+#include
+
+void GLClearError() {
+ while (glGetError() != GL_NO_ERROR);
+}
+
+//OpenGl logging
+bool GLLogCall(const char* function, const char* file, int line) {
+ while (GLenum error = glGetError()) {
+ std::cout << "[OpenGL Error] (" << error << "): "
+ << function << " " << file << ":" << line << std::endl;
+ return false;
+ }
+ return true;
+}
\ No newline at end of file
diff --git a/Window_practice/src/Renderer.h b/Window_practice/src/Renderer.h
new file mode 100644
index 0000000..d0139c9
--- /dev/null
+++ b/Window_practice/src/Renderer.h
@@ -0,0 +1,14 @@
+#pragma once
+
+#include
+
+//Macros
+#define ASSERT(x) if(!(x)) __debugbreak();
+#define GLCall(x) GLClearError();\
+ x;\
+ ASSERT(GLLogCall(#x, __FILE__, __LINE__))
+
+//Clearing OpenGl error list
+void GLClearError();
+//OpenGl logging
+bool GLLogCall(const char* function, const char* file, int line);
\ No newline at end of file
diff --git a/Window_practice/src/VertexArray.cpp b/Window_practice/src/VertexArray.cpp
new file mode 100644
index 0000000..2396f81
--- /dev/null
+++ b/Window_practice/src/VertexArray.cpp
@@ -0,0 +1,38 @@
+#include "VertexArray.h"
+#include "Renderer.h"
+
+VertexArray::VertexArray()
+{
+ GLCall(glGenVertexArrays(1, &m_RendererID));
+}
+
+VertexArray::~VertexArray()
+{
+ GLCall(glDeleteVertexArrays(1, &m_RendererID));
+}
+
+void VertexArray::AddBuffer(const VertexBuffer& vb, const VertexBufferLayout& layout)
+{
+ Bind();
+ vb.Bind();
+ const auto& elements = layout.GetElements();
+ unsigned int offset = 0;
+
+ for (unsigned int i = 0; i < elements.size(); i++) {
+ const auto& element = elements[i];
+ GLCall(glEnableVertexAttribArray(i));
+ GLCall(glVertexAttribPointer(i, element.count, element.type, element.normalized,
+ layout.GetStride(), (const void*)offset));
+ offset += element.count * VertexBufferElement::GetSizeOfType(element.type);
+ }
+}
+
+void VertexArray::Bind() const
+{
+ GLCall(glBindVertexArray(m_RendererID));
+}
+
+void VertexArray::Unbind() const
+{
+ GLCall(glBindVertexArray(0));
+}
diff --git a/Window_practice/src/VertexArray.h b/Window_practice/src/VertexArray.h
new file mode 100644
index 0000000..7b57e4b
--- /dev/null
+++ b/Window_practice/src/VertexArray.h
@@ -0,0 +1,16 @@
+#pragma once
+
+#include "VertexBuffer.h"
+#include "VertexBufferLayout.h"
+
+class VertexArray {
+private:
+ unsigned int m_RendererID;
+public:
+ VertexArray();
+ ~VertexArray();
+
+ void AddBuffer(const VertexBuffer& vb, const VertexBufferLayout& layout);
+ void Bind() const;
+ void Unbind() const;
+};
diff --git a/Window_practice/src/VertexBuffer.cpp b/Window_practice/src/VertexBuffer.cpp
new file mode 100644
index 0000000..c302caa
--- /dev/null
+++ b/Window_practice/src/VertexBuffer.cpp
@@ -0,0 +1,24 @@
+#include "VertexBuffer.h"
+#include "Renderer.h"
+
+VertexBuffer::VertexBuffer(const void* data, unsigned int size)
+{
+ GLCall(glGenBuffers(1, &m_RendererID)); //number of buffer to generate
+ GLCall(glBindBuffer(GL_ARRAY_BUFFER, m_RendererID)); //binding the buffer
+ GLCall(glBufferData(GL_ARRAY_BUFFER, size, data, GL_STATIC_DRAW));
+}
+
+VertexBuffer::~VertexBuffer()
+{
+ GLCall(glDeleteBuffers(1, &m_RendererID));
+}
+
+void VertexBuffer::Bind() const
+{
+ GLCall(glBindBuffer(GL_ARRAY_BUFFER, m_RendererID));
+}
+
+void VertexBuffer::Unbind() const
+{
+ GLCall(glBindBuffer(GL_ARRAY_BUFFER, 0));
+}
diff --git a/Window_practice/src/VertexBuffer.h b/Window_practice/src/VertexBuffer.h
new file mode 100644
index 0000000..0635407
--- /dev/null
+++ b/Window_practice/src/VertexBuffer.h
@@ -0,0 +1,12 @@
+#pragma once
+
+class VertexBuffer {
+private:
+ unsigned int m_RendererID;
+public:
+ VertexBuffer(const void* data, unsigned int size);
+ ~VertexBuffer();
+
+ void Bind() const;
+ void Unbind() const;
+};
diff --git a/Window_practice/src/VertexBufferLayout.h b/Window_practice/src/VertexBufferLayout.h
new file mode 100644
index 0000000..47fedc7
--- /dev/null
+++ b/Window_practice/src/VertexBufferLayout.h
@@ -0,0 +1,57 @@
+#pragma once
+
+#include
+#include "GL\glew.h"
+#include "Renderer.h";
+
+struct VertexBufferElement {
+ unsigned int type;
+ unsigned int count;
+ unsigned char normalized;
+
+ static unsigned int GetSizeOfType(unsigned int type) {
+ switch (type)
+ {
+ case GL_FLOAT: return 4;
+ case GL_UNSIGNED_INT: return 4;
+ case GL_UNSIGNED_BYTE: return 1;
+ }
+ ASSERT(false);
+ return 0;
+ }
+};
+
+class VertexBufferLayout {
+private:
+ std::vector m_Elements;
+ unsigned int m_Stride;
+public:
+ VertexBufferLayout()
+ : m_Stride(0){}
+
+ template
+ void Push(unsigned int count) {
+ static_assert(false);
+ }
+
+ template<>
+ void Push(unsigned int count) {
+ m_Elements.push_back({ GL_FLOAT, count, GL_FALSE });
+ m_Stride += VertexBufferElement::GetSizeOfType(GL_FLOAT) * count;
+ }
+
+ template<>
+ void Push(unsigned int count) {
+ m_Elements.push_back({ GL_UNSIGNED_INT ,count, GL_FALSE });
+ m_Stride += VertexBufferElement::GetSizeOfType(GL_UNSIGNED_INT) * count;
+ }
+
+ template<>
+ void Push(unsigned int count) {
+ m_Elements.push_back({ GL_UNSIGNED_BYTE ,count, GL_TRUE });
+ m_Stride += VertexBufferElement::GetSizeOfType(GL_UNSIGNED_BYTE) * count;
+ }
+
+ inline const std::vector GetElements() const{ return m_Elements; }
+ inline unsigned int GetStride() const { return m_Stride; }
+};
\ No newline at end of file