Originally posted by BigShooter:
One more thing Jwatte (I’m kind of beginner in game programming With regards to your above code, just wanted to ask you a few questions:
IANAJW, but since he doesn’t seem to be around I’ll take a stab at this.
enum {
kPos = 1, kColor = 2, kNormal = 4, kUV = 8
};
whhat is this enumeration specifying? For instance, why is kNormal 4 and kUV = 8?
The enum defines flags that specify what kind of data is contained in the vertex array; vertex positions, colours, normals, texcoords etc. The values chosen correspond to particular bits (1 = bit0, 2 = bit1, 4 = bit3 etc), so they can be ORed together with the ‘|’ operator .
glTexCoordPointer( 2, GL_FLOAT, sizeof( MyType ), base+24 );
With this part, not sure why there’s base+ 24, that is why 24?
The +12 and +24 are offsets from the start of the interleaved data. A MyVertexTypePosNormUV contains positions, normals and texcoords. Positions come first and so start at base+0. Normals come right after that and so start at the base address plus the size of the position data; a position is 3 floats, hence 12 bytes. Similarly, texcoords come after normals and so start at the base address, plus the size of the position, plus the size of the normal. (Writing this as base+(sizeof(GLfloat)*3) etc would have been just as efficient and might make the intent clearer.)
return kPos | kNormal | kUV;
Not sure how is this part working…
This just tells the caller of specify() what kinds of data the vertex array contains, so that it (“it” being the SpecifyVertexArray function here) knows which arrays to enable. It’s necessary because SpecifyVertexArray doesn’t know exactly what it’s dealing with; it gets passed a pointer to the base class, MyVertexType. Read up on virtual functions and polymorphism if this bit is confusing you. I’d probably make the flags-accessor a separate method, but that’s just me.
HTH,
Mike
(I’ve also got some templated vertex format deduction code kicking about, but IIRC I’d been overdosing on Alexandrescu when I wrote it, and probably shouldn’t inflict it on an unsuspecting world…)
{EDIT:typo}
[This message has been edited by MikeC (edited 11-02-2003).]