游戏开发论坛

 找回密码
 立即注册
搜索
查看: 3141|回复: 2

关于函数glMultiDrawElements

[复制链接]

7

主题

20

帖子

20

积分

注册会员

Rank: 2

积分
20
发表于 2006-6-21 10:07:00 | 显示全部楼层 |阅读模式
我在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]

0

主题

2

帖子

0

积分

新手上路

Rank: 1

积分
0
发表于 2011-8-22 23:58:00 | 显示全部楼层

Re:关于函数glMultiDrawElements

glMultiDrawElements:

http://www.glforum.glx.me/viewtopic.php?f=6&t=114

2万

主题

2万

帖子

6万

积分

论坛元老

Rank: 8Rank: 8

积分
66489
QQ
发表于 2011-8-23 11:21:00 | 显示全部楼层

Re:关于函数glMultiDrawElements

glMultiDrawElements属于扩展,所以:

一、标准SDK里没有。推荐你使用GLEW

二、显卡不一定支持,所以你需要处理不支持的情况
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-6-8 21:34

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表