opengl用顶点数组和索引数组信息绘制一个二十面体,写的代码如下,怎么改正才能得到结果?
#include<GL/glut.h>#pragmacomment(lib,"glut.lib")#pragmacomment(lib,"glu32.lib")#prag...
#include <GL/glut.h>
#pragma comment( lib, "glut.lib" )
#pragma comment( lib, "glu32.lib" )
#pragma comment( lib, "OpenGL32.lib" )
#define Glcount 100
#define Glsize 3
#define X 0.52573
#define Z 0.85065
static GLfloat vertexs []={ -X,0.0,Z,
X,0.0,Z,
-X,0.0,-Z,
X,0.0,-Z,
0.0,Z,X,
0.0,Z,-X,
0.0,-Z,X,
0.0,-Z,-X,
Z,X,0.0,
-Z,X,0.0,
Z,-X,0.0,
-Z,-X,0.0
};
static GLfloat colors[]={0.0,0.0,0.0,
1.0,0.0,0.0,
1.0,1.0,0.0,
0.0,1.0,0.0,
0.0,0.0,1.0,
1.0,0.0,1.0,
1.0,1.0,1.0,
0.0,1.0,1.0,
1.0,0.0,0.0,
1.0,1.0,0.0,
};
static GLint index[] ={
1,4,0,
4,9,0,
4,5,9,
8,5,4,
1,8,4,
1,10,8,
10,3,8,
8,3,5,
3,2,5,
3,7,2,
3,10,7,
10,6,7,
6,11,7,
6,0,11,
6,1,0,
10,1,6,
11,0,9,
2,11,9,
5,2,9,
11,2,7};
void display(void)
{glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glClear (GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, 1, 1.0f, 100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0, 2.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glColor3f (1.0, 0.0, 0.0);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glVertexPointer(Glsize,GL_FLOAT,0,vertexs);
glColorPointer(Glsize,GL_FLOAT,0,colors);
glDrawElements(GL_QUADS,Glcount,GL_UNSIGNED_INT,index);
glFlush();
}
int main(int argc, char** argv)
{glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]);
glutDisplayFunc(&display);
glutMainLoop();
return 0;} 展开
#pragma comment( lib, "glut.lib" )
#pragma comment( lib, "glu32.lib" )
#pragma comment( lib, "OpenGL32.lib" )
#define Glcount 100
#define Glsize 3
#define X 0.52573
#define Z 0.85065
static GLfloat vertexs []={ -X,0.0,Z,
X,0.0,Z,
-X,0.0,-Z,
X,0.0,-Z,
0.0,Z,X,
0.0,Z,-X,
0.0,-Z,X,
0.0,-Z,-X,
Z,X,0.0,
-Z,X,0.0,
Z,-X,0.0,
-Z,-X,0.0
};
static GLfloat colors[]={0.0,0.0,0.0,
1.0,0.0,0.0,
1.0,1.0,0.0,
0.0,1.0,0.0,
0.0,0.0,1.0,
1.0,0.0,1.0,
1.0,1.0,1.0,
0.0,1.0,1.0,
1.0,0.0,0.0,
1.0,1.0,0.0,
};
static GLint index[] ={
1,4,0,
4,9,0,
4,5,9,
8,5,4,
1,8,4,
1,10,8,
10,3,8,
8,3,5,
3,2,5,
3,7,2,
3,10,7,
10,6,7,
6,11,7,
6,0,11,
6,1,0,
10,1,6,
11,0,9,
2,11,9,
5,2,9,
11,2,7};
void display(void)
{glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glClear (GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, 1, 1.0f, 100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0, 2.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glColor3f (1.0, 0.0, 0.0);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glVertexPointer(Glsize,GL_FLOAT,0,vertexs);
glColorPointer(Glsize,GL_FLOAT,0,colors);
glDrawElements(GL_QUADS,Glcount,GL_UNSIGNED_INT,index);
glFlush();
}
int main(int argc, char** argv)
{glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]);
glutDisplayFunc(&display);
glutMainLoop();
return 0;} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询