小弟刚学OpenGL,环境也配置好了,也运行过示例代码。现在编译Sierpinski垫片问题时遇到如下错误
#include <windows.h> // Header File For Windows
#include <gl\gl.h> // Header File For The OpenGL32 Library
#include <gl\glu.h> // Header File For The GLu32 Library
#include <gl\glut.h> // Header File For The Glaux Library
#include <math.h>
#include<time.h>
struct GLpoint {
GLfloat a,b;
};
void DrawDot(GLint a,GLint b){
glBegin(GL_POINTS);
glVertex2i(a,b);
glEnd();
}
void MyInit(){
glClearColor(1.0,0.0,1.0,0.0);
glColor3f(0.0f,0.0f,0.0f);
glPointSize(2.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,640.0,0.0,480.0);
}
void MyDisplay(){
glClear(GL_COLOR_BUFFER_BIT);
GLpoint P[3]= {{10.0,10.0},{600.0,10.0},{300.0,600.0}};
int index = random()%3;
GLpoint point = P[index];
DrawDot(point.a,point.b);
for(int i=0;i<55000;i++){
index = random()%3;
point.a = (point.a + P[index].a)/2;
point.b = (point.b + P[index].b)/2;
DrawDot(point.a,point.b);
}
glFlush();
}
void main(int argc,char **argv){
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(640,480);
glutInitWindowPosition(100,150);
glutCreateWindow("My Window");
glutDisplayFunc(MyDisplay);
MyInit();
glutMainLoop();
}
错误:
1>e:\opengl\first\first\opengl.c(29) : error C2065: “GLpoint”: 未声明的标识符
1>e:\opengl\first\first\opengl.c(29) : error C2146: 语法错误 : 缺少“;”(在标识符“P”的前面)
1>e:\opengl\first\first\opengl.c(29) : error C2065: “P”: 未声明的标识符
1>e:\opengl\first\first\opengl.c(29) : error C2109: 下标要求数组或指针类型
1>e:\opengl\first\first\opengl.c(29) : error C2059: 语法错误 : “{”
1>e:\opengl\first\first\opengl.c(30) : error C2143: 语法错误 : 缺少“;”(在“类型”的前面)
1>e:\opengl\first\first\opengl.c(31) : error C2146: 语法错误 : 缺少“;”(在标识符“point”的前面)
1>e:\opengl\first\first\opengl.c(31) : error C2065: “point”: 未声明的标识符
1>e:\opengl\first\first\opengl.c(31) : error C2065: “index”: 未声明的标识符
1>e:\opengl\first\first\opengl.c(31) : error C2109: 下标要求数组或指针类型
1>e:\opengl\first\first\opengl.c(32) : error C2224: “.a”的左侧必须具有结构/联合类型
1>e:\opengl\first\first\opengl.c(32) : error C2224: “.b”的左侧必须具有结构/联合类型
1>e:\opengl\first\first\opengl.c(32) : error C2198: “DrawDot”: 用于调用的参数太少
1>e:\opengl\first\first\opengl.c(33) : error C2143: 语法错误 : 缺少“;”(在“类型”的前面)
1>e:\opengl\first\first\opengl.c(33) : error C2143: 语法错误 : 缺少“;”(在“类型”的前面)
1>e:\opengl\first\first\opengl.c(33) : error C2143: 语法错误 : 缺少“)”(在“类型”的前面)
1>e:\opengl\first\first\opengl.c(33) : error C2143: 语法错误 : 缺少“;”(在“类型”的前面)
1>e:\opengl\first\first\opengl.c(33) : error C2065: “i”: 未声明的标识符
1>e:\opengl\first\first\opengl.c(33) : warning C4552: “<”: 运算符不起任何作用;应输入带副作用的运算符
1>e:\opengl\first\first\opengl.c(33) : error C2059: 语法错误 : “)”
1>e:\opengl\first\first\opengl.c(33) : error C2143: 语法错误 : 缺少“;”(在“{”的前面)
1>e:\opengl\first\first\opengl.c(34) : warning C4013: “random”未定义;假设外部返回 int
1>e:\opengl\first\first\opengl.c(35) : error C2224: “.a”的左侧必须具有结构/联合类型
1>e:\opengl\first\first\opengl.c(35) : error C2224: “.a”的左侧必须具有结构/联合类型
1>e:\opengl\first\first\opengl.c(35) : error C2109: 下标要求数组或指针类型
1>e:\opengl\first\first\opengl.c(36) : error C2224: “.b”的左侧必须具有结构/联合类型
1>e:\opengl\first\first\opengl.c(36) : error C2224: “.b”的左侧必须具有结构/联合类型
1>e:\opengl\first\first\opengl.c(36) : error C2109: 下标要求数组或指针类型
1>e:\opengl\first\first\opengl.c(37) : error C2224: “.a”的左侧必须具有结构/联合类型
1>e:\opengl\first\first\opengl.c(37) : error C2224: “.b”的左侧必须具有结构/联合类型
1>e:\opengl\first\first\opengl.c(37) : error C2198: “DrawDot”: 用于调用的参数太少
1>e:\opengl\first\first\opengl.c(51) : warning C4113: “void (__cdecl *)()”和“void (__cdecl *)(void)”的参数列表不同
1>生成日志保存在“file://e:\openGL\first\first\Debug\BuildLog.htm”
1>first - 29 个错误,3 个警告