我想在 OpenGL 中制作一個游戲,到目前為止它給了我這些錯誤。這沒有多大意義,因為我遵循了一個教程(這是一個 C 教程,但幾乎相同)
這是我的代碼:
#include <stdio.h>
#include <stdlib.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_CONTENT_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;
}
glfwMakeContentCurrent(window);
glewExperimental = true;
if(glewInit() != GLEW_OK){
printf("Failed to initilize GLEW");
return -1;
}
}
這些是錯誤:
main.c: In function ‘main’:
main.c:7:23: error: ‘true’ undeclared (first use in this function)
7 | glewExperimental = true;
| ^~~~
main.c:7:23: note: each undeclared identifier is reported only once for each function it appears in
main.c:14:19: error: ‘GLFW_CONTENT_VERSION_MINOR’ undeclared (first use in this function); did you mean ‘GLFW_CONTEXT_VERSION_MINOR’?
14 | glfwWindowHint(GLFW_CONTENT_VERSION_MINOR, 3);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
| GLFW_CONTEXT_VERSION_MINOR
main.c:25:4: warning: implicit declaration of function ‘glfwMakeContentCurrent’; did you mean ‘glfwMakeContextCurrent’? [-Wimplicit-function-declaration]
25 | glfwMakeContentCurrent(window);
| ^~~~~~~~~~~~~~~~~~~~~~
| glfwMakeContextCurrent
編輯:事實證明我有一個錯字。它必須是 GLFW_CONTEXT_VERSION_MINOR 而不是 GLFW_CONTENT_VERSION_MINOR
uj5u.com熱心網友回復:
如果編譯為 C,則必須#include <stdbool.h>訪問true,false和bool。它們只是 C 中的關鍵字,而不是 C。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/356330.html
上一篇:在C中的宏函式中使用宏陳述句
下一篇:在C中實作鏈表
