【问题标题】:glfwOpenWindowHint not declared in this scope GLFW3 & GLEWglfwOpenWindowHint 未在此范围内声明 GLFW3 和 GLEW
【发布时间】:2013-08-21 16:38:24
【问题描述】:

按照 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

【问题讨论】:

  • 你成功加载基本着色器了吗?

标签: c++ c opengl opengl-3 glfw


【解决方案1】:

您使用GLFW3 标头,但您编写的代码是针对GLFW2

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

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

【讨论】:

  • @JustinMeiners:查看我的回答中的升级页面链接。有很多东西你应该升级。
  • 链接帮助很大,我没有意识到从 GLFW2 到 3 的变化如此之大。而且,这个响应比我预期的要快得多,哈哈。希望能见到你!
  • @MathosNatrim:不客气!也许您可以在这里提供一些帮助:stackoverflow.com/a/11647849/1065190 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-01
  • 1970-01-01
  • 2021-09-20
  • 2016-08-09
  • 2019-02-17
相关资源
最近更新 更多