glfwOpenWindowHint在此作用域中未声明 GLFW3和GLEW

9

开始学习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

1
你成功加载了基本着色器吗? - user868935
1个回答

11
您正在使用GLFW3的头文件,但您编写的代码是针对GLFW2的。
GLFW3中,函数glfwOpenWindowHint()被重命名为glfwWindowHint()
请查看此页面以获取升级说明:http://www.glfw.org/docs/3.0/moving.htmlGLFW2以来发生了很多变化。

@JustinMeiners:请查看我的回答中的升级页面链接。有很多东西需要升级。 - Sergey K.
这个链接帮了我很多,我没有意识到从GLFW2到3有这么多变化。另外,你的回复比我预期的要快得多,哈哈。希望能再次见到你! - Mathos Natrim
@MathosNatrim:不用谢!也许你可以在这里帮个忙:https://dev59.com/jWgu5IYBdhLWcg3wAigi#11647849 :) - Sergey K.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接