Click here to Skip to main content
14,932,407 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]
   
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
Jochen Arndt 25-Jul-18 5:40am
   
Believe me: It does not help you to get something "working" without having at least basic knowledge about the topic. It will get back to you sooner or later.

Developing is not only (re-)using other's work. It is knowing at least the basics of topics (learning them if required) and then using this knowledge for implementation.

Also using technologies like OpenGL is not a beginner topic. If this is some kind of private / learning project, I suggest to start with something simpler.

Finally, I (and most - if not all - others here) are trying to help you understanding your problem so that you learn something. But we will not do your job for you; especiall if you are only interested to get your work done ASAP. We are all answering voluntary here and have our own jobs to do.
BerthaDusStuf 25-Jul-18 14:20pm
   
I am not trying to get you to do my work for me, I just dont know about this topic and although I know that it is probably good to read around preprocesing and compilation and things like that, but I dont have time and I think it is doable without it. If you dont want to help thats fine but Im not looking to read into preprocessing compiling and linkking right now

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