Common interface to d3d and ogl

Started by
2 comments, last by cow_in_the_well 22 years ago
Hey all, I'm making a class which will act as a common interface to opengl and d3d8. Ive got init, frame management (clearing, begin, endframe) and renderstates working so far. Now I would like to make vertex buffer functionality. I've been trying to work out how to make a vertex class that will be compatible with both opengl and direct3d (i don't want the d3d and ogl implementations to convert the common vertex type to their own type, that would be too slow). it would basically be something like this:
    
class CommonVertex3D
{
float x,y,z;
float u,v;
DWORD color;

};
    
My main wondererment is that D3D uses 32bit packed colour values, but i'm pretty sure OpenGL doesn't (anyone? i've only learnt D3D really ^_^). I'm also not exactly sure how OpenGL vertex buffers work, so if anyone could fill me in a bit at all, that would be good. Any info/ideas on how to implement this would be welcome . Thanks.... [edited by - cow_in_the_well on April 18, 2002 4:05:58 AM]

- Thomas Cowellwebsite | journal | engine video

Advertisement
Don''t worry, OGL can use packed 32-bit colours.

I use a similar thing in my work, and I''ve found that it''s a lot easier to make OGL take D3D-formatted vertex data than the other way round.

Basically set up your vertex structure like one of the D3D FVFs then you can use the gl*Pointer functions to tell OGL where each component is in the structure.

Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions
Thank you! You are the bringer of good news !

Does anyone else who has done this sort of thing have any suggestions/cautions for me?

Thanks.

- Thomas Cowellwebsite | journal | engine video

I ended up writing a vertex buffer class that was pretty much a mirror of the D3D one, with some extra bits that I needed as I went along.

This way, you could in fact make it an abstract base class, and when you go to create one, have your renderer create an appropriate one instead, depending on if the user has various vendor-specific extensions that would boost performance.

Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions

This topic is closed to new replies.

Advertisement