我今天在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
答案 0 :(得分:1)
您正在阅读的教程使用Glfw 2,您可能已下载了GLFW 3.0 降级glfw或遵循本指南进行版本迁移: http://www.glfw.org/docs/3.0/moving.html