所以我刚开始学习 OpenGL,我正在用 C 语言在 Ubuntu 上学习。
我从我的讲师笔记中做了一些例子,他们工作了,但是这个给了我错误。
callbackexample.c: In function ‘main’:
callbackexample.c:17:18: error: ‘displays’ undeclared (first use in this function)
callbackexample.c:17:18: note: each undeclared identifier is reported only once for each function it appears in
依此类推,适用于我文件中的每个方法。我逐字逐句地按照他的笔记,我得到了这个,所以我不确定出了什么问题。
#include <stdlib.h>
#include <math.h>
#include <GL/glut.h>
#define DEG_TO_RAD 0.017453
int singleb, doubleb; //window ids
GLfloat theta = 0.0;
int main(int argc, char **argv){
glutInit(&argc, argv);
//create single buffered window
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
singleb = glutCreateWindow("single_buffered");
glutDisplayFunc(displays);
glutReshapeFunc(myReshape);
glutIdleFunc(spinDisplay);
glutMouseFunc(mouse);
glutKeyboardFunc(mykey);
//create double buffered window
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowPosition(400,0); //create window to the right
doubleb = glutCreateWindow("double_buffered");
glutDisplayFunc(displayd);
glutReshapeFunc(myReshape);
glutIdleFunc(spinDisplay);
glutMouseFunc(mouse);
glutCreateMenu(quit_menu);
glutAddMenuEntry("quit", 1);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutMainLoop();
}
void displays() {
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
glVertex2f ( cos(DEG_TO_RAD * theta),
sin(DEG_TO_RAD * theta));
glVertex2f ( -sin(DEG_TO_RAD * theta),
cos(DEG_TO_RAD * theta));
glVertex2f ( -cos(DEG_TO_RAD * theta),
-sin(DEG_TO_RAD * theta));
glVertex2f ( sin(DEG_TO_RAD * theta),
-cos(DEG_TO_RAD * theta));
glEnd();
glFlush();
}
这只是主要方法的一些代码,以及它之后的第一个方法,我得到了一个错误。通过未声明,我猜这意味着方法没有声明,但我遵循了他的代码,所以我不确定