I'm trying to build both an opengl script and a qt GUI window at the same time for a small project of mine. Even after linking the glad, glfw header files and the glfw3.lib file to my compiler settings and importing glad.c to my project. Here is the code where the error occurs
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include "shader.h"
#include <iostream>
#include <QtWidgets/QApplication>
#include "login.h"
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
void processInput(GLFWwindow* window);
// settings
const unsigned int SCR_WIDTH = 800;
const unsigned int SCR_HEIGHT = 600;
int main(int argc, char* argv[]) {
// initialize GLFW
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#ifdef __APPLE__
glfwWindowHint(GLFW_OPENGL_FOWARD_COMPAT, GL_TRUE);
#endif
// creating the glfw window
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "aprende opengl", NULL, NULL);
// if the window does not initialize
if (window == NULL) {
std::cout << "Failed to create GLFW window" << std::endl;
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
// glad: load all openGL pointers
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
std::cout << "Failed to initialize GLAD" << std::endl;
return -1;
}
//builds the shader with our header file
// you can name your shader files however you like
shader ourShader("3.3.shader.vs", "3.3.shader.fs");
// set up vertex data (and buffer(s)) and configure vertex attributes
// ------------------------------------------------------------------
float vertices[] = {
// positions // colors
0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, // bottom right
-0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, // bottom left
0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f // top
};
unsigned int VBO, VAO;
// here are the identifiers that fail to be recognized
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
// bind the Vertex Array Object first, then bind and set vertex
// buffer(s), and then configure vertex attributes(s).
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
// position attributes
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
// color attributes
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)(3 * sizeof(float)));
glEnableVertexAttribArray(1);
// You can unbind the VAO afterwards so other VAO calls won't accidentally
// modify this VAO, but this rarely happens. Modifying other VAOs
// requires a call to glBindVertexArray anyways so we generally
// don't unbind VAOs (nor VBOs) when it's not directly necessary.
// glBindVertexArray(0);
// render loop
while (!glfwWindowShouldClose(window)) {
// input
processInput(window);
// render
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
// renderiza el triangulo
ourShader.use();
glBindVertexArray(VAO);
glDrawArrays(GL_TRIANGLES, 0, 3);
// GLFW: swap buffers and poll IO events (mouse pressed, etc)
glfwSwapBuffers(window);
glfwPollEvents();
}
glDeleteVertexArrays(1, &VAO);
glDeleteBuffers(1, &VBO);
// glfw: terminate, clearing all previously allocated GLFW resources.
// ------------------------------------------------------------------
glfwTerminate();
// QT constructor stuff
QApplication a(argc, argv);
login w;
w.show();
return a.exec();
}
void processInput(GLFWwindow* window) {
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
glfwSetWindowShouldClose(window, true);
}
}
void framebuffer_size_callback(GLFWwindow* window, int width, int height) {
// make sure the viewport matches the new window dimensions; note that width and
// height will be significantly larger than specified on retina displays.
glViewport(0, 0, width, height);
}
Here is the output (my project is called "simulador_7"):
>------ Build started: Project: simulador_7, Configuration: Debug x64 ------
1>shader_class.cpp
1>C:\Users\Jose Miguel\Documents\simulador\simulador_7\simulador_7\simulador_7\shader.h(42,35): warning C4101: 'e': unreferenced local variable
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\shared\minwindef.h(130,1): warning C4005: 'APIENTRY': macro redefinition
1>C:\Users\Jose Miguel\Documents\simulador\librerias\include\glad\glad.h(32): message : see previous definition of 'APIENTRY'
1>C:\Users\Jose Miguel\Documents\simulador\simulador_7\simulador_7\simulador_7\shader_class.cpp(60,3): error C3861: 'glGenVertexArrays': identifier not found
1>C:\Users\Jose Miguel\Documents\simulador\simulador_7\simulador_7\simulador_7\shader_class.cpp(61,3): error C3861: 'glGenBuffers': identifier not found
1>C:\Users\Jose Miguel\Documents\simulador\simulador_7\simulador_7\simulador_7\shader_class.cpp(65,3): error C3861: 'glBindVertexArray': identifier not found
1>C:\Users\Jose Miguel\Documents\simulador\simulador_7\simulador_7\simulador_7\shader_class.cpp(67,3): error C3861: 'glBindBuffer': identifier not found
1>C:\Users\Jose Miguel\Documents\simulador\simulador_7\simulador_7\simulador_7\shader_class.cpp(68,3): error C3861: 'glBufferData': identifier not found
1>C:\Users\Jose Miguel\Documents\simulador\simulador_7\simulador_7\simulador_7\shader_class.cpp(71,3): error C3861: 'glVertexAttribPointer': identifier not found
1>C:\Users\Jose Miguel\Documents\simulador\simulador_7\simulador_7\simulador_7\shader_class.cpp(72,3): error C3861: 'glEnableVertexAttribArray': identifier not found
1>C:\Users\Jose Miguel\Documents\simulador\simulador_7\simulador_7\simulador_7\shader_class.cpp(75,3): error C3861: 'glVertexAttribPointer': identifier not found
1>C:\Users\Jose Miguel\Documents\simulador\simulador_7\simulador_7\simulador_7\shader_class.cpp(76,3): error C3861: 'glEnableVertexAttribArray': identifier not found
1>C:\Users\Jose Miguel\Documents\simulador\simulador_7\simulador_7\simulador_7\shader_class.cpp(90,4): error C3861: 'glClearColor': identifier not found
1>C:\Users\Jose Miguel\Documents\simulador\simulador_7\simulador_7\simulador_7\shader_class.cpp(91,4): error C3861: 'glClear': identifier not found
1>C:\Users\Jose Miguel\Documents\simulador\simulador_7\simulador_7\simulador_7\shader_class.cpp(95,4): error C3861: 'glBindVertexArray': identifier not found
1>C:\Users\Jose Miguel\Documents\simulador\simulador_7\simulador_7\simulador_7\shader_class.cpp(96,4): error C3861: 'glDrawArrays': identifier not found
1>C:\Users\Jose Miguel\Documents\simulador\simulador_7\simulador_7\simulador_7\shader_class.cpp(104,3): error C3861: 'glDeleteVertexArrays': identifier not found
1>C:\Users\Jose Miguel\Documents\simulador\simulador_7\simulador_7\simulador_7\shader_class.cpp(105,3): error C3861: 'glDeleteBuffers': identifier not found
1>C:\Users\Jose Miguel\Documents\simulador\simulador_7\simulador_7\simulador_7\shader_class.cpp(126,2): error C3861: 'glViewport': identifier not found
1>Done building project "simulador_7.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Why is this happening? I've linked the same libraries again and again with no avail, cleaned the project. My other practice projects of openGL link to their corresponding libraries/includes without problem. I have included a photo of both my libraries and include folders here[1]. As you can see, I have included both glad/glfw3 directories as well as QT corresponding directories. Could there be an overlap between these folders? Before I added the include/QTWidgets path the glad headers worked just fine.