aCu*_*ria 1 c++ opengl visual-studio-2010
我有问题让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();
}
Run Code Online (Sandbox Code Playgroud)
您似乎试图使用顶点数组和VBO的奇数组合.试试这个演练.
奇怪的事情:
gl*Pointer()
如果你正在使用VBO,调用应该使用从零开始的"指针"而不是真正的指针.
你的Quad
结构有点怪异.我不太确定你能stride
为它写出可用的值.尝试以下数组:
Run Code Online (Sandbox Code Playgroud)struct Vertex { float x, y, z; float s, t; char r, g, b, a; };
归档时间: |
|
查看次数: |
77 次 |
最近记录: |