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

glfwOpenWindowHint not declared in this scope GLFW3 & GLEW

本文关键字:GLFW3 GLEW 声明 范围内 glfwOpenWindowHint      更新时间:2023-10-16

根据OpenGL针对OpenGL 3+的一些教程,我一开始就遇到了一些差异,这是我设法获得的代码,但一开始,我就遇到了大量错误,没有一个说它找不到包含的头,只是头没有定义核心函数。

#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 GLFWn" );
    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 windown" );
    glfwTerminate();
    return -1;
}
// Initialize GLEW
glewExperimental=true; // Needed in core profile
if (glewInit() != GLEW_OK) {
    fprintf(stderr, "Failed to initialize GLEWn");
    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之外,我从未使用过任何图形库,所以你可能需要带我了解一下。。。非常感谢。

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

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

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

有关升级说明,请查看此页面:http://www.glfw.org/docs/3.0/moving.html自GLFW2以来,发生了很多变化。