OpenGL:glDrawElements无法绘制 [英] OpenGL: glDrawElements doesn't draw

查看:79
本文介绍了OpenGL:glDrawElements无法绘制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试顶点数组"的东西,但是由于某种原因,glDrawElements命令无法为我绘制任何东西.我可以在两者之间使用glBegin/glEnd和glDrawElements进行绘制,但是glDrawElements不起作用.这是一个代码段:

I'm trying out the Vertex Arrays stuff but for some reason the glDrawElements command doesn't draw anything for me. I can draw using glBegin/glEnd and glDrawElements in between, but glDrawElements doesn't work. Here's a code snippet:

这些数组在构造函数中设置:

These arrays get set up in the constructor:

double points[100];
GLint indices[50];

for (int i=0; i < 50; i++){
    points[2*i] = radius * cos(i*2*PI/50);
    points[2*i + 1] = radius * sin(i*2*PI/50);
    indices[i] = i;
}

仅使用带有glArrayElement的points数组的工作代码:

Working code using only the points array with glArrayElement:

void GLCircle::draw()
{
    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(2, GL_DOUBLE, 0, points);

    glBegin(GL_POLYGON);
    for (int i=0; i < 50; i++){
        glArrayElement(i);
    }
    glEnd();
}

还有工作代码,使用点数组,可以通过索引数组访问特定的索引:

Also working code, using points array, specific indices accessed via indices array:

void GLCircle::draw()
{
    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(2, GL_DOUBLE, 0, points);

    glBegin(GL_POLYGON);
    for (int i=0; i < 50; i++){
        glArrayElement(indices[i]);
    }
    glEnd();
}

非工作代码,尝试使用glDrawElements:

NON-working code, attempting to use glDrawElements:

void GLCircle::draw()
{
    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(2, GL_DOUBLE, 0, points);

    glDrawElements(GL_POLYGON, 4, GL_INT, indices);
}

有什么建议吗?我现在并不需要完全使用它,但是令人不安的是它不起作用...

Any advice? It's not entirely necessary for me to use it at this point, but it's disturbing that it doesn't work...

推荐答案

glDrawElements的第二个参数是count,所以4不应该是索引数(50)吗?

The 2nd parameter of glDrawElements is count, so shouldn't 4 be the numbers of indices (50)?

这篇关于OpenGL:glDrawElements无法绘制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆