2
我是新来openGLES(和OpenGL的太),我有一个问题...openGLES顶点指针问题
我有一个struct条:
struct Vertex2F
{
GLfloat x;
GLfloat y;
};
struct Vertex3F
{
GLfloat x;
GLfloat y;
GLfloat z;
};
struct Color4UB
{
GLubyte r;
GLubyte g;
GLubyte b;
GLubyte a;
};
struct Vertex
{
Vertex3F pos;
Color4UB color;
Vertex2F tex;
};
struct Strip
{
Strip() {vertices = 0; count = 0;}
Strip(int cnt);
~Strip();
void allocate(int cnt);
void draw();
Vertex *vertices;
int count;
};
,我想也呈现GL_TRIANGLE_STRIP 。这里是代码:
const int size = sizeof(Vertex);
long stripOffset = (long) &strip_;
int diff = offsetof(Vertex, pos); //diff = 0
glVertexPointer(3, GL_FLOAT, size, (void*)(stripOffset + diff));
它显示了一些奇怪的事情后呈现与glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
如果显示在所有。但是,此代码按预期工作:
GLfloat ar[4*3];
for (int i = 0; i < 4; ++i)
{
ar[3*i + 0] = strip_.vertices[i].pos.x;
ar[3*i + 1] = strip_.vertices[i].pos.y;
ar[3*i + 2] = strip_.vertices[i].pos.z;
}
glVertexPointer(3, GL_FLOAT, 0, (void*)(ar));
请解释我在第一种情况下做错了什么?
非常感谢!感觉自己很愚蠢( – Andrew