我正在努力使用codeblocks设置opengl和GLAD [英] I am struggling to set up opengl and GLAD using codeblocks

查看:409
本文介绍了我正在努力使用codeblocks设置opengl和GLAD的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的代码块设置OpenGL,但我一直收到错误。以下是我到目前为止所做的事情:

我从这个网站下载了GLFW的32位二进制文​​件: GLFW - 下载 [ ^ ]

我也从这个网站下载了GLAD:http://glad.dav1d.de/

然后我将这些下载中的所有文件添加到一个包含文件夹中。在此之后,我将glad.c和glad.h添加到我的项目中。然后在代码块中,我单击了项目选项卡,构建选项,搜索目录,编译器,并添加了我从下载和src文件夹中获得的2个包含文件夹。然后在搜索目录中我去了链接器并添加了lib-mingw。



来自我用来学习openGL的书我已被指示添加此代码:

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;
}





我的问题是我一直收到错误:'GLADloadproc'未在此范围内声明'GLADLoadGLLoader'在这方面没有申明。考虑到目前为止我做了什么可能是什么问题?



我尝试过的事情:



没什么.......................................... .................



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...........................................................

推荐答案

你必须包含这些函数和类型所在的头文件声明:

You have to include the header file(s) where these functions and types are declared:
#include <glad/glad.h>

路径取决于文件的安装位置。以上假设它是源文件所在目录的高兴子目录。如果它在其他地方,则必须将路径添加到编译器搜索的包含目录列表中(使用IDE时的项目设置,使用make文件时的shell变量或编译器命令行选项或在命令行上手动编译)。





快速的网络研究显示 glad.h 必须包含在之前glfw3.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).


A quick web research revealed that glad.h must be included before glfw3.h:

#include <glad/glad.h>
#include <GLFW/glfw3.h>

[/ EDIT]


这篇关于我正在努力使用codeblocks设置opengl和GLAD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆