繁体   English   中英

Ubuntu中的OpenGL(C语言)说事情是未宣布的

[英]OpenGL in Ubuntu (C Language) saying things are undeclared

所以我刚刚开始学习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();
}

这只是主要方法的一些代码和它之后的第一个方法,我得到了一个错误。 通过未声明我猜这意味着方法没有被声明,但我遵循他的代码,所以我不确定

在声明之前,您尝试在main函数中使用displays方法。 您需要在main函数之前移动整个函数,或者将stub添加到顶部:

void displays();

int main(int argc, char **argv){
   ...
}

void displays(){
   ...
}

C按照它看到的顺序解析所有内容 - 您不能使用尚未完整声明的方法,或者至少声明它将在某个时刻存在。

关于你的评论:你找不到-l *的东西意味着你要么没有为OpenGL安装开发库,要么让它们奇怪地设置 - 这就是说它无法找到要链接的库文件。

另外, mykey问题暗示你要么没有声明mykey函数,要么没有根据原型声明它:

void mykey(unsigned char key, int x, int y) 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM