c++ - 让 IBO 工作

标签 c++ visual-studio-2010 opengl

我在让 OpenGL 工作时遇到问题,基本上我得到交替的黑色和灰色屏幕。我使用固定功能管道(glBegin()、glEnd() 和 glTexCoord...)可以正常工作 我认为我做错了一些事情,这对这些东西来说很新。任何帮助将不胜感激。

struct Quad
{
    float x0, y0, z0;   // top left corner
    float x1, y1, z1;   // top right corner
    float x2, y2, z2;   // bottom left corner
    float x3, y3, z3;   // bottom right corner
    float s0, t0;
    float s1, t1;
    float s2, t2;
    float s3, t3;
    char r, g, b, a;    // tint
    float depth;        // depth value of the Quad
};

void draw{
    glEnable(GL_TEXTURE_2D);
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    // Note: glVertexPointer is deprecated, change to glVertexAttribPointer
    glVertexPointer(3, GL_FLOAT, sizeof(Quad), &(vertexBuffer_[0].x0));
    glTexCoordPointer(2, GL_FLOAT, sizeof(Quad), &(vertexBuffer_[0].s0));
    glBindBuffer(GL_ARRAY_BUFFER, VBOs_[activeVBO_]);
    glBufferData(GL_ARRAY_BUFFER, vertexBuffer_.size() * sizeof(Quad), &(vertexBuffer_[0]), GL_STATIC_DRAW);
    glDrawArrays(GL_QUADS, 0, vertexBuffer_.size());
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    SDL_GL_SwapBuffers();
    activeVBO_ = (++activeVBO_)%NUM_VBO;
    glError();
}

最佳答案

您似乎在尝试使用顶点数组和 VBO 的一些奇怪组合。尝试 this walkthrough .

奇怪的事情:

  • gl*Pointer() 如果您使用 VBO,调用应该使用从零开始的“指针”而不是真正的指针。

  • 您的 Quad 结构有点奇怪。我不太确定你能写 可用的 stride 值。试试这些:

struct Vertex
{
    float x, y, z;
    float s, t;
    char r, g, b, a;
};

关于c++ - 让 IBO 工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7879233/

相关文章:

opengl - 用 GLFW3 编译 OpenGL 程序

java - 计算地形网格上的法线

c++ - 使用预处理器指令定义命令行选项

c++ - 如何使用回调使工作简单的按钮类?

c++ - 匿名命名空间和单一定义规则

visual-c++ - fatal error C1083 : Cannot open include file: 'boost/regex.hpp' : No such file or directory

c++ - OpenGL glGetUniformBlockIndex在nvidea GPU上返回INVALID_INDEX

c++ - DosBox 图像处理库下的 Turbo-C++?

visual-studio-2010 - 在 Microsoft 单元测试中使用配置文件

visual-studio-2010 - Test Professional 2010/Microsoft 测试管理器中的 TF30063 错误