I am porting some legacy OpenGL code to Web Assembly (using emscripten). This is using OpenGL 1.1
I have two vertex formats, and I swap between them (depending on whether I'm doing 2D drawing or 3D drawing). Here are the two formats:
struct Vertex2DRef
{
float mX;
float mY;
float mZ;
unsigned int mDiffuse;
float mTextureU;
float mTextureV;
};
struct Vertex2DNRef
{
float mX;
float mY;
float mZ;
float mNX;
float mNY;
float mNZ;
float mTextureU;
float mTextureV;
};
This is old, legacy code, so I'm just drawing straight from memory buffers. When I'm drawing 2D, I do this (Don't mind the XGL wrapping, it's just a define to also report if the call is producing errors):
XGL(glEnableClientState(GL_VERTEX_ARRAY));
XGL(glEnableClientState(GL_COLOR_ARRAY));
XGL(glEnableClientState(GL_TEXTURE_COORD_ARRAY));
XGL(glDisableClientState(GL_NORMAL_ARRAY));
int aStride=sizeof(Vertex2DRef);
Vertex2DRef* theRef=(Vertex2DRef*)theBuffer; // <- The incoming vertices are in "theBuffer"
XGL(glVertexPointer(3,GL_FLOAT,aStride,&theRef->mX));
XGL(glNormalPointer(GL_FLOAT,aStride,NULL));
XGL(glColorPointer(4,GL_UNSIGNED_BYTE,aStride,&theRef->mDiffuse));
XGL(glTexCoordPointer(2,GL_FLOAT,aStride,&theRef->mTextureU));
XGL(glDrawArrays(GL_TRIANGLES,0,theTriangleCount*3));
So the above works... I get my render exactly as I expect them.
HOWEVER: When I try to draw the other vertex format, the one with normals, but no diffuse:
XGL(glEnableClientState(GL_VERTEX_ARRAY));
XGL(glDisableClientState(GL_COLOR_ARRAY));
XGL(glEnableClientState(GL_TEXTURE_COORD_ARRAY));
XGL(glEnableClientState(GL_NORMAL_ARRAY));
int aStride=sizeof(Vertex2DNRef);
Vertex2DNRef* theRef=(Vertex2DNRef*)theBuffer;
XGL(glVertexPointer(3,GL_FLOAT,aStride,&theRef->mX));
XGL(glNormalPointer(GL_FLOAT,aStride,&theRef->mNX) );
XGL(glColorPointer(4,GL_UNSIGNED_BYTE,aStride,NULL));
XGL(glTexCoordPointer(2,GL_FLOAT,aStride,&theRef->mTextureU));
XGL(glDrawArrays(GL_TRIANGLES,0,theTriangleCount*3))
Now, I get nothing at all. That glDrawArrays line drops two errors-- GL_INVALID_OPERATION and GL_INVALID_VALUE. The reasons the documents list for those possible errors don't even apply (confirmed that theTriangleCount is not negative, and I don't use glBegin or glEnd anywhere in the program at all.
Can anyone help?