|
我在VC编写例子时使用glMultiDrawElements函数,编译器报告没有定义这个函数,可以我按F12在glext.h中有这个函数的声明,而且我也加了#include "gl/glext.h", why?
代码如下:
#include <iostream>
#include "gl/glut.h"
#include "gl/glext.h"
#define GLMULTIDRAWELEMENTS
GLdouble vertices3d[] = {
-5, -5, 5,
5, -5, 5,
5, -5, -5,
-5, -5, -5,
-5, 5, 5,
5, 5, 5,
5, 5, -5,
-5, 5, -5
};
GLfloat colors3f[] = {
1.0, 0.0, 0.0,
1.0, 1.0, 0.0,
1.0, 0.0, 1.0,
0.0, 1.0, 0.0,
0.0, 1.0, 1.0,
0.0, 0.0, 1.0,
0.3, 1.0, 0.3,
1.0, 0.5, 0.7
};
GLubyte indices1[] = {
0, 1, 2
};
GLubyte indices2[] = {1, 5, 6, 2};
GLubyte indices3[] = {4, 0, 3, 7, 5};
//指针数组
GLubyte* pIndices[] = {
indices1,
indices2,
indices3
};
//各个索引数组的元素个数
GLint pnCountIdx[] = {3, 4, 5};
void init()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_SMOOTH);
}
void reshape(GLsizei w, GLsizei h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(w>h)
gluPerspective(45.0, (GLfloat)w/(GLfloat)h, 0.1, 40);
else
gluPerspective(45.0, (GLfloat)h/(GLfloat)w, 0.1, 40);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glColorPointer(3, GL_FLOAT, 0, colors3f);
glVertexPointer(3, GL_DOUBLE, 0, vertices3d);
gluLookAt(30, 0, 0, 0, 0, 0, 0, 1, 0);
//#undef GLMULTIDRAWELEMENTS
#ifdef GLMULTIDRAWELEMENTS
glMultiDrawElementsEXT(GL_TRIANGLES, pnCountIdx, GL_UNSIGNED_BYTE, pIndices, 3);
#else
int primcount = 3; //指针数组的元素个数
for(int i=0; i<primcount; i++)
glDrawElements(GL_TRIANGLES, pnCountIdx, GL_UNSIGNED_BYTE, pIndices);
#endif //#ifdef GLMULTIDRAWELEMENTS
glFlush();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGBA);
glutInitWindowPosition(100, 100);
glutInitWindowSize(400, 300);
glutCreateWindow("Use glMultiDrawElements()");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
[em24] [em24] [em24] [em7] [em22] [em21] [em11] |
|