Most of the time I use floats for that very reason. In my current project, that is impossible since the numbers are so large (earth reference coordinates …).
Assuming that I am using floats, the question becomes similar …
struct Vertex
{
float x;
float y;
float z;
float padding; // ???
};
In another project, I use compiled vertex array such as the code snip below:
namespace
{
// The format of the functions we are going to use.
typedef void (APIENTRY *PFNGLLOCKARRAYSEXTPROC) (int first, int count);
typedef void (APIENTRY *PFNGLUNLOCKARRAYSEXTPROC) (void);
// Our two function pointers.
PFNGLLOCKARRAYSEXTPROC glLockArraysEXT = NULL;
PFNGLUNLOCKARRAYSEXTPROC glUnlockArraysEXT = NULL;
// Define a vertex structure
struct Vertex3
{
float x, y, z;
};
// Define a 2D texture coordinate structure
struct Vertex2
{
float u, v;
};
// Define the vertex array, it holds the vertices of each cube corner.
Vertex3 Vertices = { coords here };
// Define the texture coordinates, positioned exactly as the vertices above.
Vertex2 TextureCoords = { coords here };
}; // namespace
// END: Internal processing utilities
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/// Post-graphics initialization hook.
void MultiTexturedObj::Init()
{
// Init our lock function pointers.
glLockArraysEXT = (PFNGLLOCKARRAYSEXTPROC) wglGetProcAddress(“glLockArraysEXT”);
glUnlockArraysEXT = (PFNGLUNLOCKARRAYSEXTPROC) wglGetProcAddress(“glUnlockArraysEXT”);
if(glLockArraysEXT == NULL | | glUnlockArraysEXT == NULL)
{
MgWarning(
“Failed retrieving vertex array lock/unlock function addresses”,
MG_TRACEPOINT
);
exit(1);
}
stateManager().enableClient(GL_VERTEX_ARRAY);
stateManager().enableClient(GL_TEXTURE_COORD_ARRAY);
// …
glVertexPointer(3, GL_FLOAT, 0, Vertices);
glTexCoordPointer(2, GL_FLOAT, 0, TextureCoords);
glLockArraysEXT(0, 24);
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/// Display hook.
void MultiTexturedObj::Render(MgGlStateManager& sMgr)
{
// Enable Face culling.
sMgr.enable(GL_CULL_FACE);
// Cull the front faces.
glCullFace(GL_FRONT);
// First pass.
glDrawArrays(GL_QUADS,0,24);
//Cull back polygons.
glCullFace(GL_BACK);
// 2nd pass
glDrawArrays(GL_QUADS,0,24);
}
I assume that since my code is working fine that I do not have an alignment problem. However, I seek to understand alignment also … hence the posts…
I thank you all for the explainations
[This message has been edited by Iceman (edited 12-14-2001).]