diff --git a/Debug/Window_practice.exe b/Debug/Window_practice.exe index 60f6fff..3bdfcc2 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 fff6533..08a9717 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 8565a4a..3f6e3a8 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 d1f377a..1606bb4 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 7f84570..8fa17b8 100644 --- a/Window_practice/Debug/Window_practice.log +++ b/Window_practice/Debug/Window_practice.log @@ -1,2 +1,5 @@  Main.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 Window_practice.vcxproj -> C:\dev\Glfw_Practice\c++\Window_practice\Debug\Window_practice.exe 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 d98202f..d727625 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/vc142.idb b/Window_practice/Debug/vc142.idb index 08b7222..132ac97 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 ab9c5d6..262b107 100644 Binary files a/Window_practice/Debug/vc142.pdb and b/Window_practice/Debug/vc142.pdb differ diff --git a/Window_practice/src/Main.cpp b/Window_practice/src/Main.cpp index 862fadf..2fc2ce7 100644 --- a/Window_practice/src/Main.cpp +++ b/Window_practice/src/Main.cpp @@ -6,15 +6,18 @@ #include #include +//Macros #define ASSERT(x) if(!(x)) __debugbreak(); #define GLCall(x) GLClearError();\ x;\ ASSERT(GLLogCall(#x, __FILE__, __LINE__)) +//Clearing OpenGl error list static void GLClearError() { while (glGetError() != GL_NO_ERROR); } +//OpenGl logging static bool GLLogCall(const char* function, const char* file, int line) { while (GLenum error = glGetError()) { std::cout << "[OpenGL Error] (" << error << "): " @@ -30,6 +33,7 @@ struct ShaderProgramSource { std::string FragmentSource; }; +//For reading in the shader from file static ShaderProgramSource ParseShader(const std::string& filepath) { std::ifstream stream(filepath); @@ -60,6 +64,7 @@ static ShaderProgramSource ParseShader(const std::string& filepath) { return { ss[0].str(), ss[1].str() }; } +//Shader compiler static unsigned int CompileShader(unsigned int type, const std::string& source) { unsigned int id = glCreateShader(type); const char* src = source.c_str(); @@ -93,13 +98,12 @@ static unsigned int CreateShader(const std::string& vertexShader, const std::str unsigned int vs = CompileShader(GL_VERTEX_SHADER, vertexShader); unsigned int fs = CompileShader(GL_FRAGMENT_SHADER, fragmentShader); - glAttachShader(program, vs); - glAttachShader(program, fs); - glLinkProgram(program); - glValidateProgram(program); - - glDeleteShader(vs); - glDeleteShader(fs); + GLCall(glAttachShader(program, vs)); + GLCall(glAttachShader(program, fs)); + GLCall(glLinkProgram(program)); + GLCall(glValidateProgram(program)); + GLCall(glDeleteShader(vs)); + GLCall(glDeleteShader(fs)); return program; } @@ -111,6 +115,11 @@ int main(void){ return -1; } + //OpenGL version and profile + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); + glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); + //Main window creation GLFWwindow* window = glfwCreateWindow(640, 480, "OpenGl practice", NULL, NULL); if (!window){ @@ -120,7 +129,6 @@ int main(void){ } glfwMakeContextCurrent(window); - glfwSwapInterval(1); //v-sync //GLEW init @@ -145,11 +153,16 @@ int main(void){ 2, 3, 0 }; + //creating vertex array object and bindig it + unsigned int vao; + GLCall(glGenVertexArrays(1, &vao)); + GLCall(glBindVertexArray(vao)); + //Vertex buffer(s) unsigned int buffer; GLCall(glGenBuffers(1, &buffer)); //number of buffer to generate GLCall(glBindBuffer(GL_ARRAY_BUFFER, buffer)); //binding the buffer - GLCall(glBufferData(GL_ARRAY_BUFFER, 6 * 2 * sizeof(float), positions, GL_STATIC_DRAW)); + GLCall(glBufferData(GL_ARRAY_BUFFER, 4 * 2 * sizeof(float), positions, GL_STATIC_DRAW)); GLCall(glEnableVertexAttribArray(0)); GLCall(glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, 0)); @@ -160,30 +173,44 @@ int main(void){ GLCall(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo)); //binding the buffer GLCall(glBufferData(GL_ELEMENT_ARRAY_BUFFER, 6 * sizeof(unsigned int), indecies, GL_STATIC_DRAW)); + //Shader to console 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; + //Creating the shader unsigned int shader = CreateShader(source.VertexSource, source.FragmentSource); glUseProgram(shader); + //Shader Uniform //need to bound a shader before this GLCall(int location = glGetUniformLocation(shader, "u_Color")); //finding u_Color location ASSERT(location != -1); GLCall(glUniform4f(location, 0.8f, 0.3f, 0.8f, 1.0f)); - GLCall(glBindBuffer(GL_ARRAY_BUFFER, 0)); //unbinding the buffer + //unbinding the buffers + GLCall(glBindVertexArray(0)); + GLCall(glUseProgram(0)); + GLCall(glBindBuffer(GL_ARRAY_BUFFER, 0)); + GLCall(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); + //for animation float r = 0.0f; float increment = 0.05f; + //Main loop while (!glfwWindowShouldClose(window)){ /* Render here */ GLCall(glClear(GL_COLOR_BUFFER_BIT)); + GLCall(glUseProgram(shader)); GLCall(glUniform4f(location, r, 0.3f, 0.8f, 1.0f)); + + GLCall(glBindVertexArray(vao)); + GLCall(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo)); + GLCall(glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, nullptr)); if (r > 1.0f)