让 VBO 发挥作用
我在使 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();
}
I have problems getting OpenGL to work, basically I am getting alternate black and grey screens. I have it working fine using the fixed function pipeline (glBegin(), glEnd() and glTexCoord...) I think I am doing something very wrong, pretty new to this stuff. Any help would be appreciated.
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();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您似乎正在尝试使用顶点数组和 VBO 的一些奇怪组合。尝试此演练。
奇怪的事情:
gl*Pointer()
调用应该使用从零开始的“指针”而不是真正的指针。你的
Quad
结构有点奇怪。我不太确定你能写可用的
stride
值。尝试使用以下数组:You seem to be trying to use some odd combination of vertex arrays and VBOs. Try this walkthrough.
Strange things:
gl*Pointer()
calls should use zero-based "pointers" instead of real pointers if you're using VBOs.Your
Quad
struct is kinda weird. I'm not quite sure you can writeusable
stride
values for it. Try an array of these: