I'm working on a small game engine. One of the features of it is that it should support DirectX and OpenGL rendering.
I am using Vertex Buffer Objects and I have a structure to define the format of my vertices. The problem is that I would like to be able to use the same structure for both DirectX and OpenGL so that I could switch from my DirectX rendering component to the OpenGL one without changing the vertices of my objects.
Is this possible?
Currently, I am using the following structure for DirectX:
struct Vertex{
float position[3]; // x, y, z
float normal[3]; // nx, ny, nz
DWORD colour; // The vertex color
float texture[2]; // u, v
};
along with:
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_TEX1 )
as flexible vertex format.
My understanding of OpenGL tells me that when I want to draw my object, I can tell the colour with this command:
glColorPointer(4, GL_FLOAT, sizeof(Vertex), BUFFER_OFFSET24);
in the drawing routine, assuming the colour has 4 components. And indeed, this works. However I do not believe I can tell OpenGL to use an unsigned integer for this task, therefore I am using:
struct Vertex{
float position[3]; // x, y, z
float normal[3]; // nx, ny, nz
float colour[4]; // r, g, b, a
float texture[2]; // u, v
};
that struct for my OpenGL code.