# glVertexPointer Stride

hi i have this structures

typedef struct VERTEX {

float xyz[3] ; // x,y,z of the vertex (modified)
float nxyz[3] ; // x,y,z of the vertex (never modified)
float tex[2] ; // 2D texture index
int np ; // number of polygons associated with node
int plist[30] ; // list of polygons associated with node
float norm[3] ; // polygon vertex normal
float anorm[3] ; /* average vertex normal */
} VERTEX ;

typedef struct POLYGON {

VERTEX *vertex[3] ; // pointer to an array of three vertices

} POLYGON ;

and i make this

POLYGON** polygon;

and then i use it like this:

polygon = _new_array(POLYGON *, 500);

polygon[0] = p0;
polygon[1] = p1;
.
.
.
polygon[n] = pn;

but the numbers of polygons is huge, so i’d like to use the vertex array extension, but in the glVertexpointer i need to know the stride thing, how can i calculate the bytes?
thanks

Stride is usually just sizeof(VERTEX)

Yes. i’m sorry what was i thinking, i mean in the *pointer parameter, how do i put it?

glVertexPointer(3, GL_FLOAT, sizeof(VERTEX), ???);

and in the display function

gldrawArrays(GL_POLYGON,0,np); /* np = number of polys */

thanks

In order to use “glVertexPointer(…)”, you’ll need to clean-up some of your data structures. First, all your vertices must be in a single, contiguous array. Try this:

struct POLYGON{
VERTEX vertex[3];
};
POLYGON* polygon;
polygon = new POLYGON[ number_of_polys ];

Then you can call:
“glVertexPointer(3, GL_FLOAT, sizeof(VERTEX), polygon[0].vertex[0].xyz );”

If you try to use:
typedef struct POLYGON{
VERTEX* vertex[3];
};
Then each of your data elements (ie. VERTEX structures) will be allocated individually in heap memory instead of in a contiguous array.

Hi again, what BritC says make sense but somehow it doesn’t work, i’ll have to make the vertex array without the VERTEX struct. please if you figure out something, please let me know thanks for your help.