diff --git a/NothinFancy/NothinFancy.vcxproj b/NothinFancy/NothinFancy.vcxproj index 5b63d20..895c60e 100644 --- a/NothinFancy/NothinFancy.vcxproj +++ b/NothinFancy/NothinFancy.vcxproj @@ -195,6 +195,7 @@ + @@ -208,6 +209,7 @@ + diff --git a/NothinFancy/NothinFancy.vcxproj.filters b/NothinFancy/NothinFancy.vcxproj.filters index 4692b11..8342d6f 100644 --- a/NothinFancy/NothinFancy.vcxproj.filters +++ b/NothinFancy/NothinFancy.vcxproj.filters @@ -36,6 +36,9 @@ Source Files + + Source Files + @@ -71,6 +74,9 @@ Header Files + + Header Files + diff --git a/NothinFancy/src/Renderer/Renderer.cpp b/NothinFancy/src/Renderer/Renderer.cpp index 410dcb4..db20de2 100644 --- a/NothinFancy/src/Renderer/Renderer.cpp +++ b/NothinFancy/src/Renderer/Renderer.cpp @@ -43,9 +43,6 @@ namespace nf { wglMakeCurrent(m_hdc, m_hglrc); wglSwapIntervalEXT(0); Log("OpenGL version: " + std::string((char*)glGetString(GL_VERSION))); - GLuint vao; - glGenVertexArrays(1, &vao); - glBindVertexArray(vao); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); } diff --git a/NothinFancy/src/Renderer/Shader.cpp b/NothinFancy/src/Renderer/Shader.cpp new file mode 100644 index 0000000..0f1ec8b --- /dev/null +++ b/NothinFancy/src/Renderer/Shader.cpp @@ -0,0 +1,49 @@ +#include "Shader.h" + +namespace nf { + Shader::Shader(const char* vertexSource, const char* fragmentSource) { + m_id = glCreateProgram(); + unsigned int vs = glCreateShader(GL_VERTEX_SHADER); + unsigned int fs = glCreateShader(GL_FRAGMENT_SHADER); + glShaderSource(vs, 1, &vertexSource, nullptr); + glShaderSource(fs, 1, &fragmentSource, nullptr); + glCompileShader(vs); + glCompileShader(fs); + for (int i = 0; i < 2; i++) { + unsigned int curr = (i == 0 ? vs : fs); + int result; + glGetShaderiv(curr, GL_COMPILE_STATUS, &result); + if (result != GL_TRUE) { + int length; + glGetShaderiv(curr, GL_INFO_LOG_LENGTH, &length); + char* message = new char[length]; + glGetShaderInfoLog(curr, length, &length, message); + message[length - 2] = 0; + Error(("OpenGL Error: " + (std::string)message).c_str()); + } + } + glAttachShader(m_id, vs); + glAttachShader(m_id, fs); + glLinkProgram(m_id); + glValidateProgram(m_id); + int result; + glGetProgramiv(m_id, GL_VALIDATE_STATUS, &result); + if (result != GL_TRUE) { + int length; + glGetProgramiv(m_id, GL_INFO_LOG_LENGTH, &length); + char* message = new char[length]; + glGetProgramInfoLog(m_id, length, &length, message); + Error(("OpenGL Error: " + (std::string)message).c_str()); + } + glDeleteShader(vs); + glDeleteShader(fs); + } + + void Shader::bind() { + glUseProgram(m_id); + } + + Shader::~Shader() { + glDeleteProgram(m_id); + } +} \ No newline at end of file diff --git a/NothinFancy/src/Renderer/VertexArray.cpp b/NothinFancy/src/Renderer/VertexArray.cpp index ae5aa98..917121a 100644 --- a/NothinFancy/src/Renderer/VertexArray.cpp +++ b/NothinFancy/src/Renderer/VertexArray.cpp @@ -14,7 +14,8 @@ namespace nf { VertexArray::VertexArray(const void* bufferData, size_t bufferSize) : m_id(0), m_vb(bufferData, bufferSize), - m_hasLayout(false) + m_hasLayout(false), + m_vertexStride(0) { glGenVertexArrays(1, &m_id); } diff --git a/NothinFancy/src/include/Shader.h b/NothinFancy/src/include/Shader.h new file mode 100644 index 0000000..c715962 --- /dev/null +++ b/NothinFancy/src/include/Shader.h @@ -0,0 +1,20 @@ +#pragma once +#ifdef NFENGINE +#include "GL/glew.h" +#endif + +#include "Utility.h" + +namespace nf { + class Shader { + public: + Shader(const char* vertexSource, const char* fragmentSource); + + void bind(); + + ~Shader(); + private: + unsigned int m_id; + //Associated resource? + }; +} \ No newline at end of file