【问题标题】:Scope troubles with OpenGLOpenGL 的范围问题
【发布时间】:2013-12-29 06:36:44
【问题描述】:

我今天尝试在 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 GLFW\n" );
        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 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, 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?
  • 为什么glfw.hGL.h在同一个系统目录下?它们根本不相关,应该位于不同的位置。 GLEW 也是如此。
  • @AndonM.Coleman:这就是库的打包方式。它的头文件放在库目录内的GL 子目录中。
  • @sftrabbit API 版本:2.5
  • @legends2k:那么不要使用 ,即系统头文件。你想要“GL/glfw.h”

标签: c++ opengl scope


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2014-12-28
    • 2014-01-28
    • 2021-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-04
    • 2010-11-09
    相关资源
    最近更新 更多