Original Post
Okay, back story: I have a terrain engine, which uses a 2D heightmap and draws it with quads. This was working spectacularly. Then I wanted more speed. So I decided to restart it entirely with using an octree (well, more like a quadtree since it''s only one cube high).
So I decided I would delve into vertex arrays. I decided to make one big array of my vertices, each chunk of the terrain (16x16 chunks, if it matters) would be represented as an array of indices into the vertex array. This doesn''t work.
I''ve defined my vertex and normal arrays in 1 dimension as arrays of structs. The structs are as follows (vertex for the vertices, vector for the normals):
typedef struct vertex
{
float x;
float y;
float z;
} vertex;
typedef struct vector
{
float x;
float y;
float z;
} vector;
AFAIK this should be laid out in memory the same way as an array of floats, like {x, y, z, x, y, z, x, y, z...} etc. Am I wrong?
Because this works:
for(int j = 248; j < 267 - 1; j++)
{
glBegin(GL_QUAD_STRIP);
for(int x = 248; x < 267; x++)
{
int index = j * width + x; //indices for quad strip (vertex and the vertex below it)
int index2 = (j + 1) * width + x;
glNormal3f(normals[index].x, normals[index].y, normals[index].z);
glVertex3f(vertices[index].x, vertices[index].y, vertices[index].z);
glNormal3f(normals[index2].x, normals[index2].y, normals[index2].z);
glVertex3f(vertices[index2].x, vertices[index2].y, vertices[index2].z);
}
glEnd();
}
But this does not:
for(int j = 248; j < 267 - 1; j++)
{
glBegin(GL_QUAD_STRIP);
for(int x = 248; x < 267; x++)
{
int index = j * width + x;
int index2 = (j + 1) * width + x;
glArrayElement(index);
glArrayElement(index2);
}
glEnd();
}
Shouldn''t these be equivalent? Am I not allowed to use structs here?
BTW, I defined the arrays like this:
glVertexPointer(3, GL_FLOAT, 0, vertices); glNormalPointer(GL_FLOAT, 0, normals);Thanks, -Jeremy