View Full Version : glInterleavedArray with Struct Arrays?
Statix
02-25-2003, 11:33 AM
I currently have a struct array which holds all of the data required for a point of a triangle.
struct TriangleSurfaceArray{
float u, v, nx, ny, nz, x, y, n
};
After putting the data into the struct array. I cnn't figure out how to make glInterleavedArray accept the struct as an array and parse the data correctly.
Using a direct rendering approach this code works fine:
glBegin(GL_TRIANGLES);
for(int i=0; i < TriSurfaceCount*3; i++) //*3
{
//glColor3f(TriangleSurfaceStructUV[i].x,TriangleSurfaceStructUV[i].y,TriangleSurfaceStructUV[i].z);
glTexCoord2f(TriangleSurfaceStructUV[i].u,TriangleSurfaceStructUV[i].v);
glNormal3f(TriangleSurfaceStructUV[i].nx,TriangleSurfaceStructUV[i].ny,TriangleSurfaceStructUV[i].nz);
glVertex3f(TriangleSurfaceStructUV[i].x,TriangleSurfaceStructUV[i].y,TriangleSurfaceStructUV[i].z);
}
glEnd();
But as for the interleaved array version i have no idea how to make it work correctly =(
Any help would be greatly appreciated.
Statix
02-25-2003, 11:35 AM
typo on the struct format btw
struct TriangleSurfaceArray{
float u, v, nx, ny, nz, x, y, z
};
n->z :P
OneSadCookie
02-25-2003, 11:38 AM
Does glInterleavedArrays(GL_T2F_N3F_V3F, sizeof(TriangleSurfaceArray) - 8 * sizeof(float), pointer); not work?
Statix
02-25-2003, 11:45 AM
haha that made it render atleast now, but in actuality i have 2 structs, one for triangles and one for quads, both setup the same way
glInterleavedArrays(GL_T2F_N3F_V3F, sizeof(InterleavedTriangleArrayUV)-8 * sizeof(float), TriangleSurfaceStructUV);
glDrawArrays(GL_TRIANGLES, 0, TriSurfaceCount);
//glInterleavedArrays(GL_T2F_N3F_V3F, sizeof(InterleavedTriangleArrayUV), TriangleSurfaceStructUV);
glInterleavedArrays(GL_T2F_N3F_V3F, sizeof(InterleavedQuadArrayUV)-8 * sizeof(float), QuadSurfaceStructUV);
glDrawArrays(GL_QUADS, 0, QuadSurfaceCount);
appears that only one of the arrays is rendering via that code
Statix
02-25-2003, 11:58 AM
for a better example heres what the correct rendering looks like via the direct render method in the first post.
Direct Render (http://www.machin-shin.net/temp/direct.gif)
and heres one using the interleaved array code above. interleaved struct (http://www.machin-shin.net/temp/interleaved.gif)
Catman
02-25-2003, 12:25 PM
I think you should try
glInterleavedArrays(GL_T2F_N3F_V3F, 0, TriangleSurfaceStructUV);
because the second parameter (stride) is the size of unuseful data between array elements... At least I use the function this way in my program...
Humus
02-25-2003, 12:47 PM
I think you should scrap the glInterleavedArrays and move over to glVertexPointer/glNormalPointer/glTexCoordPointer etc.
bakery2k
02-25-2003, 12:48 PM
In here:
glInterleavedArrays(GL_T2F_N3F_V3F, sizeof(TriangleSurfaceArray) - 8 * sizeof(float), pointer);
What is the "- 8 * sizeof(float)" for? Surely you just want a stride of sizeof(TriangleSurfaceArray).
Remember that the stride is the offset between the BEGINNING of two successive elements. Stride=0 is a special case, which means that the arrays are tightly packed. All other values give the distance between the beginnings of vertices.
OneSadCookie
02-25-2003, 12:56 PM
Heh, whoops. Should be sizeof(TriangleSurfaceArray).
Catman
02-25-2003, 01:20 PM
Originally posted by bakery2k:
Remember that the stride is the offset between the BEGINNING of two successive elements. Stride=0 is a special case, which means that the arrays are tightly packed. All other values give the distance between the beginnings of vertices.
Yes, so in this case stride=0 should work...
Statix
02-25-2003, 04:13 PM
glInterleavedArrays(GL_T2F_N3F_V3F, 0, TriangleSurfaceStructUV);
glDrawArrays(GL_TRIANGLES, 0, TriSurfaceCount);
//glInterleavedArrays(GL_T2F_N3F_V3F, sizeof(InterleavedTriangleArrayUV), TriangleSurfaceStructUV);
glInterleavedArrays(GL_T2F_N3F_V3F, 0, QuadSurfaceStructUV);
glDrawArrays(GL_QUADS, 0, QuadSurfaceCount);
still has the same rendering output as the interleaved array imaged posted up in this thread a bit
Statix
02-25-2003, 04:18 PM
haha got it working wasn't rendering the full surface array size
this code = working render:
glInterleavedArrays(GL_T2F_N3F_V3F, 0, TriangleSurfaceStructUV);
glDrawArrays(GL_TRIANGLES, 0, TriSurfaceCount*3);
glInterleavedArrays(GL_T2F_N3F_V3F, 0, QuadSurfaceStructUV);
glDrawArrays(GL_QUADS, 0, QuadSurfaceCount*4);
Catman
02-25-2003, 11:52 PM
Well, yes. I think nobody has noticed that... http://www.opengl.org/discussion_boards/ubb/smile.gif You have to specify the number of vertices in glDrawArrays() not the number of polygons...
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.