GCC编译OpenGL项目报错true未定义及GLFW相关标识符未声明问题
错误修复方案
true未定义错误修复
你使用GCC编译.c后缀文件时默认按C语法处理,C语言没有内置
true关键字,两种修复方式可选:
- 直接将代码中两处
true替换为1,C语言中非0值代表布尔真- 在头文件引入区域添加
#include <stdbool.h>,该头文件封装了true/false宏定义
GLFW_CONTENT_VERSION_MINOR未定义错误修复
属于拼写错误,替换为正确的宏名
GLFW_CONTEXT_VERSION_MINOR即可
glfwMakeContentCurrent隐式声明警告修复
属于拼写错误,替换为正确的函数名
glfwMakeContextCurrent即可
修复后完整代码
#include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include <GL/glew.h> #include <GL/glfw3.h> int main(){ glewExperimental = true; if(!glfwInit()){ printf("failed to initialize GLFW\n"); return -1; } glfwWindowHint(GLFW_SAMPLES, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); GLFWwindow* window; window = glfwCreateWindow(1024, 768, "Game", NULL, NULL); if(window == NULL){ printf("Sorry to say this, but your OpenGL version must be 3.3 or above! Thanks for playing, but to continue you must update your video card drivers or if you use an old GPU you may have to replace it with a new one to play this game. I will be developing my game for OpenGL 1 and 2 soon so stay on touch."); glfwTerminate(); return -1; } glfwMakeContextCurrent(window); glewExperimental = true; if(glewInit() != GLEW_OK){ printf("Failed to initilize GLEW"); return -1; } return 0; }
内容的提问来源于stack exchange,提问作者RadoslavL
相关产品推荐
相关产品推荐

