Click here to Skip to main content
15,867,849 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to set up OpenGL for my codeblocks but I keep getting an error. Here is what I have done so far:
I downloaded the 32 bit binaries for GLFW from this website: GLFW - Download[^]
I also downloaded GLAD from this website: http://glad.dav1d.de/
I then added all the files from these downloads to an include folder. After this I added glad.c and glad.h to my project. Then in codeblocks I clicked the project tab, build options, search directories, compiler and added the 2 include folders that I got from the downloads and the src folder. then in search directories I went to linker and added lib-mingw.

from a book I am using to learn openGL I was instructed to add this code:
#include <GLFW/glfw3.h>
#include <iostream>
int main()
{
//setting the version of openGL
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
//glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);

//creating a window
GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL);
if (window = NULL)
{
    std::cout <<"Failed to create GLFW window\n";
    glfwTerminate();
    return -1;
}

glfwMakeContextCurrent(window);

if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{
std::cout << "Failed to initialize GLAD" << std::endl;
return -1;
}

glViewport(0, 0, 800, 600);

return 0;
}


My problem is I keep getting the error: 'GLADloadproc' was not declared in this scope and 'GLADLoadGLLoader' was not declared in this scope. What could be the problem considering what I have done so far?

What I have tried:

Nothing...........................................................
Posted
Updated 23-Jul-18 1:53am

1 solution

You have to include the header file(s) where these functions and types are declared:
#include <glad/glad.h>
The path depends on where the file has been installed. The above assumes that it is the glad sub directory of the directory where your source file is located. If it is somewhere else you have to add the path to the list of include directories searched by your compiler (project settings when using an IDE, shell variable or compiler command line option when using a make file or compiling manually on the command line).

[EDIT]
A quick web research revealed that glad.h must be included before glfw3.h:
#include <glad/glad.h>
#include <GLFW/glfw3.h>
[/EDIT]
 
Share this answer
 
v2
Comments
BerthaDusStuf 23-Jul-18 17:53pm    
Ok thanks I have made adjustments so that now my glad folder is part of my project folder so but I am still getting the error. I also tried putting it in quotations like this: #include "glad/glad.h" and it still hasn't worked. It is the same errors that came up though. Do you have any other suggestions?
BerthaDusStuf 23-Jul-18 18:21pm    
Also I dont actually know what I am doing by going to project, build options-search directories-compiler(or linker) and selecting files. I just followed a tutorial but could you explain abit about what I am doing there. And also what am I doing in build-options-linker settings? I dont really know much so please explain simply. thanks
BerthaDusStuf 23-Jul-18 18:21pm    
Also I dont actually know what I am doing by going to project, build options-search directories-compiler(or linker) and selecting files. I just followed a tutorial but could you explain abit about what I am doing there. And also what am I doing in build-options-linker settings? I dont really know much so please explain simply. thanks
Jochen Arndt 24-Jul-18 4:38am    
See my updated answer.

I suggest also to read about the basics of C/C++ programming tools and how they work (keywords preprocessor, compiler, and linker). It helps understanding what is going on and why specific errors might be thrown.

But explaining it here is far beyond the scope of a comment and "quick answer".
BerthaDusStuf 25-Jul-18 4:53am    
User-2223753 thanks for the suggestion but I dont havee much time to learn this so I am trying to learn to set it up as quickly as possible

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900