【发布时间】: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
【问题讨论】:
-
为什么要定义
GLFW_INCLUDE_NONE?"will explicitly to prevent[sic] the GLFW header from including the OpenGL header"是定义这些符号的位置。尝试删除它。
标签: c++ opengl visual-studio-code glfw