glfwOpenWindowHint未在此范围内声明GLFW3& GLEW

时间:2013-08-21 16:38:24

标签: 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

1 个答案:

答案 0 :(得分:8)

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

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

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