I am currently working on a simple 3D wireframe renderer using openGL.
I working on Windows 10 using Visual Studio. I use glfw to manage openGL windows, glad to load the latest version of openGL and glm for various mathematical stuff. The way I integrate these libraries with Visual Studio is with vcpkg and it worked well. I was working on my wireframe renderer program and it was going well.
Recently, my previous PC stopped working though. So I had to migrate the whole project (I backed it up) to a new PC. I installed Visual Studio, used vcpkg to integrate glfw, glad and glm and got it running. However, I realized, that nothing was being rendered in the window, despite not having changed anything in the code from the last version that was running just fine on the older PC.
I rolled the project back to a version where it was much simpler and was basically just rendering a single triangle, and back on the old machine it was working, but now on the new PC, it is not working at all. I am very confused since I am not even getting any errors, the program itself runs just fine, but simply nothing is rendered.
What could be the cause of this?
Here is the code of the simple version (1 file only) of the program, on which the more complex 3D wireframe rendere was built up on. This code worked on the old PC, but now is rendering nothing on my new PC.
#define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>
#include <glad/glad.h>
#include <stdio.h>
void error_callback(int error, const char* description);
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods);
int main()
{
glfwSetErrorCallback(error_callback);
if (!glfwInit())
{
perror("glfw init failed");
return -1;
}
puts("glfw initialized");
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
GLFWwindow* window = glfwCreateWindow(640, 480, "Renderer", NULL, NULL);
if (!window)
{
perror("Window creation failed");
return -1;
}
glfwMakeContextCurrent(window);
gladLoadGL();
glfwSetKeyCallback(window, key_callback);
GLuint VAOID;
glGenVertexArrays(1, &VAOID);
glBindVertexArray(VAOID);
//Create some vertices for a triangle
GLfloat objectVertices[] =
{
-1.0f, -1.0f, 0.0f,
1.0f, -1.0f, 0.0f,
0.0f, 1.0f, 0.0f
};
GLuint VBOID;
glGenBuffers(1, &VBOID);
glBindBuffer(GL_ARRAY_BUFFER, VBOID);
glBufferData(GL_ARRAY_BUFFER, sizeof(objectVertices), objectVertices, GL_STATIC_DRAW);
//Tell openGL how our data is formatted
glVertexAttribPointer(
0,
3, //Each vertex is described by 3 values
GL_FLOAT, //data type of each value
GL_FALSE,
0,
0
);
glEnableVertexAttribArray(0);
glBindVertexArray(0);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
//The program keeps running until the hint flag for termination is set
while (!glfwWindowShouldClose(window))
{
glBindVertexArray(VAOID);
glDrawArrays(GL_TRIANGLES, 0, 3);
glBindVertexArray(0);
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwDestroyWindow(window);
glfwTerminate();
return 0;
}
/*
* This function is called when an error occurs
*/
void error_callback(int error, const char* description)
{
fprintf(stderr, "Error: %s\n", description);
}
/*
* This function is called when a keyboard key is pressed
*/
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
//Esc key pressed: set the flag to tell the program to terminate
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
{
glfwSetWindowShouldClose(window, GLFW_TRUE);
}
}
I made sure to update my Nvidia drivers prior to setting up anything in the environment of Visual Studio (both PCs had nvidia graphics cards)
Is there any reason, why this code shouldn’t work? It worked on the previous machine.