Basic Error Checking
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,5 +1,2 @@
|
|||||||
Main.cpp
|
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
|
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 <GL/glew.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#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 {
|
struct ShaderProgramSource {
|
||||||
std::string VertexSource;
|
std::string VertexSource;
|
||||||
std::string FragmentSource;
|
std::string FragmentSource;
|
||||||
@@ -125,22 +145,20 @@ int main(void){
|
|||||||
2, 3, 0
|
2, 3, 0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Vertex buffer(s)
|
//Vertex buffer(s)
|
||||||
unsigned int buffer;
|
unsigned int buffer;
|
||||||
glGenBuffers(1, &buffer); //number of buffer to generate
|
GLCall(glGenBuffers(1, &buffer)); //number of buffer to generate
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, buffer); //binding the buffer
|
GLCall(glBindBuffer(GL_ARRAY_BUFFER, buffer)); //binding the buffer
|
||||||
glBufferData(GL_ARRAY_BUFFER, 6 * 2 * sizeof(float), positions, GL_STATIC_DRAW);
|
GLCall(glBufferData(GL_ARRAY_BUFFER, 6 * 2 * sizeof(float), positions, GL_STATIC_DRAW));
|
||||||
|
|
||||||
glEnableVertexAttribArray(0);
|
GLCall(glEnableVertexAttribArray(0));
|
||||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, 0);
|
GLCall(glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, 0));
|
||||||
|
|
||||||
//index buffer setup
|
//index buffer setup
|
||||||
unsigned int ibo; //index buffer object
|
unsigned int ibo; //index buffer object
|
||||||
glGenBuffers(1, &ibo);
|
GLCall(glGenBuffers(1, &ibo));
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo); //binding the buffer
|
GLCall(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo)); //binding the buffer
|
||||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, 6 * sizeof(unsigned int), indecies, GL_STATIC_DRAW);
|
GLCall(glBufferData(GL_ELEMENT_ARRAY_BUFFER, 6 * sizeof(unsigned int), indecies, GL_STATIC_DRAW));
|
||||||
|
|
||||||
ShaderProgramSource source = ParseShader("res/shaders/Basic.shader");
|
ShaderProgramSource source = ParseShader("res/shaders/Basic.shader");
|
||||||
std::cout << "VERTEX" << std::endl;
|
std::cout << "VERTEX" << std::endl;
|
||||||
@@ -151,23 +169,23 @@ int main(void){
|
|||||||
unsigned int shader = CreateShader(source.VertexSource, source.FragmentSource);
|
unsigned int shader = CreateShader(source.VertexSource, source.FragmentSource);
|
||||||
glUseProgram(shader);
|
glUseProgram(shader);
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0); //unbinding the buffer
|
GLCall(glBindBuffer(GL_ARRAY_BUFFER, 0)); //unbinding the buffer
|
||||||
|
|
||||||
//Main loop
|
//Main loop
|
||||||
while (!glfwWindowShouldClose(window)){
|
while (!glfwWindowShouldClose(window)){
|
||||||
/* Render here */
|
/* 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 */
|
/* Swap front and back buffers */
|
||||||
glfwSwapBuffers(window);
|
GLCall(glfwSwapBuffers(window));
|
||||||
|
|
||||||
/* Poll for and process events */
|
/* Poll for and process events */
|
||||||
glfwPollEvents();
|
GLCall(glfwPollEvents());
|
||||||
}
|
}
|
||||||
|
|
||||||
glDeleteProgram(shader);
|
GLCall(glDeleteProgram(shader));
|
||||||
|
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user