Basic Error Checking
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -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
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,10 +1,30 @@
|
||||
#include <GL/glew.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
#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;
|
||||
|
||||
Reference in New Issue
Block a user