【问题标题】:Having issues with glclear and GL_COLOR_BUFFER_BITglclear 和 GL_COLOR_BUFFER_BIT 有问题
【发布时间】:2021-02-19 18:19:31
【问题描述】:

所以我遇到了 glClear 和 GL_COLOR_BUFFER_BIT 没有被“声明”的问题。 这是错误

[build] ../src/main.cpp:27:17: error: ‘GL_COLOR_BUFFER_BIT’ was not declared in this scope
[build]    27 |         glClear(GL_COLOR_BUFFER_BIT);
[build]       |                 ^~~~~~~~~~~~~~~~~~~
[build] ../src/main.cpp:27:9: error: ‘glClear’ was not declared in this scope
[build]    27 |         glClear(GL_COLOR_BUFFER_BIT);
[build]       |         ^~~~~~~

这是代码

#define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>

int main(void)
{
GLFWwindow* window;

/* Initialize the library */
if (!glfwInit())
    return -1;

/* Create a windowed mode window and its OpenGL context */
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
if (!window)
{
    glfwTerminate();
    return -1;
}

/* Make the window's context current */
glfwMakeContextCurrent(window);

/* Loop until the user closes the window */
while (!glfwWindowShouldClose(window))
{
    /* Render here */
    glClear(GL_COLOR_BUFFER_BIT);

    /* Swap front and back buffers */
    glfwSwapBuffers(window);

    /* Poll for and process events */
    glfwPollEvents();
    }

glfwTerminate();
return 0;
}

这是 cmakelist.txt

cmake_minimum_required(VERSION 3.0.0)
project(OpenGL VERSION 0.1.0)

add_executable(OpenGL src/main.cpp)

我用的是arch Linux,我用的是vs codium

【问题讨论】:

标签: c++ opengl visual-studio-code glfw


【解决方案1】:

你告诉 GLFW #include 适当的系统 gl.h (via #define GLFW_INCLUDE_NONE) 所以你必须自己 #include 它(或删除 #define)。

【讨论】:

  • 我被告知在他们的网站上这样做并修复了其他问题,我读了一些关于它的内容,它说它应该消除任何冲突,但我会尝试编辑:我试过了这并且未能在 glfw 定义的行中包含 glfw 和错误。
  • 我还定义了 gl.h 并得到文件或目录不存在(我不认为你在谈论高兴,但我尝试通过我拥有它的目录包含它并且它没用。)
  • @MeowskiesStudia 对于它的价值,我拿走了你的代码,注释掉了 #define GLFW_INCLUDE_NONE 指令,它编译得很好(Linux + glfw 3.3)。
  • @G.M.每当我删除 #define GLFW_INCLUDE_NONE 时,它都无法包含 glfw 并给出未定义 glfw 函数的调试错误(很抱歉这么晚了)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-20
  • 1970-01-01
  • 2020-08-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多