c++ - glfwOpenWindowHint 未在此范围内声明 GLFW3 和 GLEW

标签 c++ c opengl opengl-3 glfw

按照 OpenGL 3+ 的一些 OpenGL 教程,一开始我遇到了一些差异,这是我设法获得的代码,但一开始我就得到了大量的错误,没有一个说它找不到包含的头文件,而仅仅是头文件没有定义核心功能。

#include <stdio.h>
#include <stdlib.h>
#include <GL/glew.h>
#include <GL/glfw3.h>
#include <glm/glm.hpp>

int main(){

// Initialise GLFW
if( !glfwInit() )
{
    fprintf( stderr, "Failed to initialize GLFW\n" );
    return -1;
}

glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4); // 4x antialiasing
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3);
glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //I don't want the
                                                                   //old OpenGL

// Open a window and create its OpenGL context
if( !glfwOpenWindow( 1024, 768, 0,0,0,0, 32,0, GLFW_WINDOW ) )
{
    fprintf( stderr, "Failed to open GLFW window\n" );
    glfwTerminate();
    return -1;
}

// Initialize GLEW
glewExperimental=true; // Needed in core profile
if (glewInit() != GLEW_OK) {
    fprintf(stderr, "Failed to initialize GLEW\n");
    return -1;
}

glfwSetWindowTitle( "Tutorial 01" );

// Ensure we can capture the escape key being pressed below
glfwEnable( GLFW_STICKY_KEYS );

do{
    // Draw nothing

    // Swap buffers
    glfwSwapBuffers();

} // Check if the ESC key was pressed or the window was closed
while( glfwGetKey( GLFW_KEY_ESC ) != GLFW_PRESS &&
glfwGetWindowParam( GLFW_OPENED ) );

问题是 MinGW 不太喜欢这个并且已经产生了大量的 “未声明”错误,所有这些都是 OpenGL 窗口存在所必需的。除了一点点 SDL2 之外,我从未使用过任何图形库,因此您可能需要引导我完成这个……非常感谢。

SigmaGLPP\main.cpp:23:20: error: 'GLFW_FSAA_SAMPLES' was not declared in this scope
SigmaGLPP\main.cpp:23:40: error: 'glfwOpenWindowHint' was not declared in this scope
SigmaGLPP\main.cpp:24:20: error: 'GLFW_OPENGL_VERSION_MAJOR' was not declared in this
scope
SigmaGLPP\main.cpp:25:20: error: 'GLFW_OPENGL_VERSION_MINOR' was not declared in this
scope
SigmaGLPP\main.cpp:29:48: error: 'GLFW_WINDOW' was not declared in this scope
SigmaGLPP\main.cpp:29:60: error: 'glfwOpenWindow' was not declared in this scope
SigmaGLPP\main.cpp:43:35: error: cannot convert 'const char*' to 'GLFWwindow*' for
argument '1' to 'void glfwSetWindowTitle(GLFWwindow*, const char*)'
SigmaGLPP\main.cpp:46:30: error: 'glfwEnable' was not declared in this scope
SigmaGLPP\main.cpp:52:21: error: too few arguments to function 'void
glfwSwapBuffers(GLFWwindow*)'
SigmaGLPP\main.cpp:55:20: error: 'GLFW_KEY_ESC' was not declared in this scope
SigmaGLPP\main.cpp:56:21: error: 'GLFW_OPENED' was not declared in this scope
SigmaGLPP\main.cpp:56:33: error: 'glfwGetWindowParam' was not declared in this scope
SigmaGLPP\main.cpp:56:36: error: expected '}' at end of input

最佳答案

您使用 GLFW3 header ,但您编写的代码适用于 GLFW2

GLFW3 中,函数 glfwOpenWindowHint() 被重命名为 glfwWindowHint()

查看此页面以获取升级说明:http://www.glfw.org/docs/3.0/moving.htmlGLFW2 以来,发生了很多变化。

关于c++ - glfwOpenWindowHint 未在此范围内声明 GLFW3 和 GLEW,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18363093/

相关文章:

java - 什么特性对应于 Java 中的 'synchronized'?

c - 命名管道 Linux

c++ - opengl3 2 个点 vector 的颜色相同

c++ - OpenGL 黑色纹理

c++ - Directx9 : Reset Device after Ctrl+Alt+Del

c++ - 从 std::array 获取对原始数组的引用

c++ - (新手模式)调用时变量的属性

c - 为什么在将 main 声明为 `int main(void)` 时传递命令行参数时没有错误?

c - HDC 句柄对另一个进程有效吗?

c++ - OpenGL 性能随时间下降的可能原因