diff --git a/Debug/Window_practice.exe b/Debug/Window_practice.exe index ca32b66..fdc54b4 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 31d9684..7e260ea 100644 Binary files a/Debug/Window_practice.pdb and b/Debug/Window_practice.pdb differ diff --git a/Window_practice/Debug/Main.obj b/Window_practice/Debug/Main.obj index 80b5237..072cbd9 100644 Binary files a/Window_practice/Debug/Main.obj and b/Window_practice/Debug/Main.obj differ diff --git a/Window_practice/Debug/Window_practice.ilk b/Window_practice/Debug/Window_practice.ilk index 6642736..5e2b014 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.tlog/CL.read.1.tlog b/Window_practice/Debug/Window_practice.tlog/CL.read.1.tlog index c343dc5..982d0cf 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/vc142.idb b/Window_practice/Debug/vc142.idb index bf69fe7..30e8081 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 f17e1ba..5654d6e 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 dadc122..39d4a4c 100644 --- a/Window_practice/Window_practice.vcxproj +++ b/Window_practice/Window_practice.vcxproj @@ -150,6 +150,9 @@ + + + diff --git a/Window_practice/Window_practice.vcxproj.filters b/Window_practice/Window_practice.vcxproj.filters index b79a273..6ea4cd9 100644 --- a/Window_practice/Window_practice.vcxproj.filters +++ b/Window_practice/Window_practice.vcxproj.filters @@ -24,4 +24,7 @@ Header Files + + + \ No newline at end of file diff --git a/Window_practice/src/Main.cpp b/Window_practice/src/Main.cpp index f290d48..5d85638 100644 --- a/Window_practice/src/Main.cpp +++ b/Window_practice/src/Main.cpp @@ -1,6 +1,44 @@ #include #include #include +#include +#include +#include + +struct ShaderProgramSource { + std::string VertexSource; + std::string FragmentSource; +}; + +static ShaderProgramSource ParseShader(const std::string& filepath) { + std::ifstream stream(filepath); + + enum class ShaderType { + NONE = -1, VERTEX = 0, FRAGMENT = 1 + }; + + std::string line; + std::stringstream ss[2]; //one is the vertex other is the fragment shader + ShaderType type = ShaderType::NONE; + + while (getline(stream, line)) { + if (line.find("#shader") != std::string::npos) { + if (line.find("vertex") != std::string::npos) { + //set mode to vertex + type = ShaderType::VERTEX; + } + else if (line.find("fragment") != std::string::npos) { + //set mode to fragment + type = ShaderType::FRAGMENT; + } + } + else { + ss[(int)type] << line << "\n"; + } + } + + return { ss[0].str(), ss[1].str() }; +} static unsigned int CompileShader(unsigned int type, const std::string& source) { unsigned int id = glCreateShader(type); @@ -89,26 +127,13 @@ int main(void){ glEnableVertexAttribArray(0); glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, 0); - std::string vertexShader = - "#version 330 core\n" - "\n" - "layout(location = 0) in vec4 position;\n" - "\n" - "void main(){\n" - " gl_Position = position;\n" - "}\n"; + ShaderProgramSource source = ParseShader("res/shaders/Basic.shader"); + std::cout << "VERTEX" << std::endl; + std::cout << source.VertexSource << std::endl; + std::cout << "FRAGMENT" << std::endl; + std::cout << source.FragmentSource << std::endl; - std::string fragmentShader = - "#version 330 core\n" - "\n" - "layout(location = 0) out vec4 color;\n" - "\n" - "void main(){\n" - " color = vec4(1.0, 0.0, 0.0, 1.0);\n" - "}\n"; - - - unsigned int shader = CreateShader(vertexShader, fragmentShader); + unsigned int shader = CreateShader(source.VertexSource, source.FragmentSource); glUseProgram(shader); glBindBuffer(GL_ARRAY_BUFFER, 0); //unbinding the buffer