OpenGL的范围问题

Scope troubles with OpenGL

本文关键字:问题 范围 OpenGL      更新时间:2023-10-16

今天尝试在CodeBlocks中编译这个简单的程序时遇到了困难:

// Include standard headers
#include <stdio.h>
#include <stdlib.h>
// Include GLEW. Always include it before gl.h and glfw.h, since it's a bit magic.
#include <GL/glew.h>
// Include GLFW
#include <GL/glfw.h>
// Include GLM
#include <glm/glm.hpp>
using namespace glm;
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); // We want OpenGL 3.3
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3);
    glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);    
    // 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, see you in tutorial 2 !
        // 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 ) );
}

此代码来自教程 http://www.opengl-tutorial.org/beginners-tutorials/tutorial-1-opening-a-window/

我认为问题可能是由于我无法让 CMake 正常工作而引起的,所以我只是将依赖项复制到 CodeBlocks 目录中。

这些错误都涉及 glfw 的范围...

In function 'int main()':
|23|error: 'GLFW_FSAA_SAMPLES' was not declared in this scope
|24|error: 'GLFW_OPENGL_VERSION_MAJOR' was not declared in this scope
|25|error: 'GLFW_OPENGL_VERSION_MINOR' was not declared in this scope
|26|error: 'GLFW_OPENGL_PROFILE' was not declared in this scope
|26|error: 'GLFW_OPENGL_CORE_PROFILE' was not declared in this scope

您正在阅读的教程使用 Glfw 2,您可能下载了 GLFW 3.0降级 glfw 或按照本指南进行版本迁移:http://www.glfw.org/docs/3.0/moving.html