diff --git a/Debug/Window_practice.exe b/Debug/Window_practice.exe index 43f80cc..4aa9ca9 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 348f7a3..057df45 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 94555a8..e6646d7 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 ee8c681..418ac8e 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 a75dc57..7f84570 100644 --- a/Window_practice/Debug/Window_practice.log +++ b/Window_practice/Debug/Window_practice.log @@ -1,5 +1,2 @@  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 '' was not found with 'glew32s.lib(glew.obj)' or at ''; 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 aaab8f2..d98202f 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 202cb9e..36c22ed 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 faaba5c..1e30569 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 b36f5ac..9476c93 100644 --- a/Window_practice/src/Main.cpp +++ b/Window_practice/src/Main.cpp @@ -1,10 +1,30 @@ #include #include + #include #include #include #include +#define ASSERT(x) if(!(x)) __debugbreak(); +#define GLCall(x) GLClearError();\ + x;\ + ASSERT(GLLogCall(#x, __FILE__, __LINE__)) + +static void GLClearError() { + while (glGetError() != GL_NO_ERROR); +} + +static 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; +} + struct ShaderProgramSource { std::string VertexSource; std::string FragmentSource; @@ -125,22 +145,20 @@ int main(void){ 2, 3, 0 }; - - //Vertex buffer(s) unsigned int buffer; - glGenBuffers(1, &buffer); //number of buffer to generate - glBindBuffer(GL_ARRAY_BUFFER, buffer); //binding the buffer - glBufferData(GL_ARRAY_BUFFER, 6 * 2 * sizeof(float), positions, GL_STATIC_DRAW); + 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)); - glEnableVertexAttribArray(0); - glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, 0); + GLCall(glEnableVertexAttribArray(0)); + GLCall(glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, 0)); //index buffer setup unsigned int ibo; //index buffer object - glGenBuffers(1, &ibo); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo); //binding the buffer - glBufferData(GL_ELEMENT_ARRAY_BUFFER, 6 * sizeof(unsigned int), indecies, GL_STATIC_DRAW); + GLCall(glGenBuffers(1, &ibo)); + GLCall(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo)); //binding the buffer + GLCall(glBufferData(GL_ELEMENT_ARRAY_BUFFER, 6 * sizeof(unsigned int), indecies, GL_STATIC_DRAW)); ShaderProgramSource source = ParseShader("res/shaders/Basic.shader"); std::cout << "VERTEX" << std::endl; @@ -151,23 +169,23 @@ int main(void){ unsigned int shader = CreateShader(source.VertexSource, source.FragmentSource); glUseProgram(shader); - glBindBuffer(GL_ARRAY_BUFFER, 0); //unbinding the buffer + GLCall(glBindBuffer(GL_ARRAY_BUFFER, 0)); //unbinding the buffer //Main loop while (!glfwWindowShouldClose(window)){ /* Render here */ - glClear(GL_COLOR_BUFFER_BIT); + GLCall(glClear(GL_COLOR_BUFFER_BIT)); - glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, nullptr); + GLCall(glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, nullptr)); /* Swap front and back buffers */ - glfwSwapBuffers(window); + GLCall(glfwSwapBuffers(window)); /* Poll for and process events */ - glfwPollEvents(); + GLCall(glfwPollEvents()); } - glDeleteProgram(shader); + GLCall(glDeleteProgram(shader)); glfwTerminate(); return 0;