VBO什么都没画 [英] VBO doesn't draw anything
问题描述
我试图在我的本机Blackberry 10应用程序中使用VBO绘制一个正方形.我的实现是,
I am trying to draw a square with VBO in my native blackberry 10 application. My implementation is,
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glGenBuffers(1,&decompressTileImage->VBOId);
glBindBuffer(GL_ARRAY_BUFFER,decompressTileImage->VBOId);
glBufferData(GL_ARRAY_BUFFER,sizeof(tileCoordList)+sizeof(tileTextureCoordList),0,GL_STATIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER,0,sizeof(tileCoordList),tileCoordList);
glBufferSubData(GL_ARRAY_BUFFER,sizeof(tileCoordList),sizeof(tileTextureCoordList),tileTextureCoordList);
glTexCoordPointer(3, GL_FLOAT, sizeof(tileTextureCoordList), (void*)sizeof(this->tileCoordList));
glVertexPointer(3, GL_FLOAT, sizeof(tileCoordList), 0);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glDisable(GL_BLEND);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisable(GL_TEXTURE_2D);
swapBuffers();
此处tileCoordList包含正方形的坐标,而tileTextureCoordList包含相应的纹理. tileCoordList
是Square3D
类型的结构.
Here tileCoordList contains the co-ordinates for the square and tileTextureCoordList contains the corresponding texture. tileCoordList
is a Square3D
type structure.
typedef struct
{
Vertex3D lowerLeft;
Vertex3D lowerRight;
Vertex3D upperLeft;
Vertex3D upperRight;
}Square3D;
typedef struct
{
GLfloat x;
GLfloat y;
GLfloat z;
} Vertex3D;
4 Vertex3D
表示tileCoordList中的正方形. tileTextureCoordList
也是如此.我可以在没有VBO的情况下进行罚款.我正在使用opengl-es 1.1
4 Vertex3D
represents a square in tileCoordList. Same goes for tileTextureCoordList
. I can draw fine without the VBO though. I am using opengl-es 1.1
另一个问题.
如果我创建两个VBO.假设我用它的ID绑定了第一个,并复制了数据并绘制了它.然后是第二个,我也将其绑定并复制数据并绘制它.现在,如果我想再次绘制第一个,是否需要再次绑定它?如果我需要再次绑定,是否还需要再次将数据复制到该VBO的缓冲区中?
If I create two VBOs. Suppose I bound the first one with its id and copied the data and drew it. And then comes the second one and I also bind it and copy the data and draw it. Now if I want to draw the first one again do I need to bind it again? If I need to bind again do I need to copy the data to buffer for that VBO again also?
推荐答案
注释中已经表明tileCoordList
和tileTextureCoordList
是指向Square3D
结构的指针.
It has transpired in the comments that tileCoordList
and tileTextureCoordList
are pointers to Square3D
structures.
这意味着sizeof
运算符将为您提供指针的大小,而不是结构的大小.
This means that the sizeof
operator will give you the size of a pointer, not the size of the struct.
您可以使用例如
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(*tileCoordList), tileCoordList);
相反.
这篇关于VBO什么都没画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!