iphone - 开放式GL-ES 2.0 : Drawing a simple line

标签 iphone opengl-es line-drawing

我花了相当多的时间和精力试图弄清楚如何在 iPhone 上的 opneGL es 中画一条线。这是我的代码

 myMagicVertices[0] = -0.5;
    myMagicVertices[1] = -0.5;
    myMagicVertices[2] = 2.0;
    myMagicVertices[3] = 2.0;

    glDrawElements(GL_LINE_STRIP, 2, GL_UNSIGNED_BYTE, myMagicVertices);

但我在屏幕上看到的只是空白屏幕。我不知道该怎么做。谁能给我指出正确的方向

最佳答案

glDrawElements() 的最后一个参数应该是顶点列表中的索引列表,而不是顶点本身。您还需要告诉 OpenGL 您的顶点列表。

代码应如下所示:

float vertices[] = {-0.5f, -0.5f, 0.5f, 0.5f};
unsigned int indices[] = {0, 1};

glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, vertices);
glDrawElements(GL_LINES, 2, GL_UNSIGNED_INT, indices);

编辑:我认为这也可行:

float vertices[] = {-0.5f, -0.5f, 0.5f, 0.5f};

glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, vertices);

glDrawArrays(GL_LINES, 0, 2);

关于iphone - 开放式GL-ES 2.0 : Drawing a simple line,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9217702/

相关文章:

iphone - 如何禁用/启用 UISearchBar 键盘的搜索按钮?

css - iPhone 4 移动网络应用程序像素缩放问题

iphone - 使用 `CVImageBufferRef` 将 `glTexImage2D` 转换为 OpenGL ES 纹理时如何消除伪影?

java - Swing:我通过鼠标拖动绘制的任何线仅在下次拖动鼠标时显示

ios - 画线 + 该线与自身的交点,并检测该画线内的 CCSprite

ios - 以编程方式为给定 iTunes ID 的所有地区构建 iTunes URL?

iphone - ABPeoplePickerNavigationController 内存泄漏?

android - glDepthMask(GL_FALSE) 破坏某些 GPU 上的帧缓冲区

java - 为什么 Sprite 大小会影响 OpenGL ES 2.0/3.0 中的性能?