Jump to content
  • Advertisement
Sign in to follow this  
Kackurot

OpenGL DirectX + OpenGL engine

This topic is 5202 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm making a 3d rendering engine that use's opengl and directx. I have a little problem trying to make a standard vertex structure. I know directx likes to have its color format compressed to one bgra format while opengl likes it in a three component format. Does any one here have any ideas on how to make a standard vertex format so opengl or dx can use it without modifications? By the way, I'm using C and assembly, no C++ for the engine. -Kackurot

Share this post


Link to post
Share on other sites
Advertisement
Not really sure, in OpenGL, if using vertex arrays, you use arrays of floats for vertices, normals and colors (colors can be integer values too I think). Maybe you just have to initialize the color array according to the rendering library the user will use?

Share this post


Link to post
Share on other sites
Opengl can use Unsigned Bytes as colors, ie: each component is stored as a value [0, 255].

So something just like this should work:
struct APIColor
{
unsigned char R, G, B, A;
}

and I believe Direct3D has a macro D3DCOLOR_ARGB(a, r, g, b) that converts 4 unsigned char's into a D3D Color.

So simply use the normal RGBA unsigned byte colors for opengl, and feed those same values into that Macro when using D3D.


EDIT:

I don't know in what order D3D stores the RGBA values internally, but you might even be able to get away with this:

struct APIColor
{
union
{
unsigned int Color;
unsigned char R, G, B, A;
}
}

Thinking about it more, I'm sure Opengl allows you to specify the order of the color components (GL_RGBA, GL_ARGB, GL_BGRA, etc).

so that union trick should work regardless, just re-order the bytes to match D3D's representation, and then send the appropriate GL_xxxx flag to Opengl.

Share this post


Link to post
Share on other sites
Quote:
Original post by Kackurot
I'm making a 3d rendering engine that use's opengl and directx.


Just wondering... why do people do this??

Why not just write it in OpenGL? You get everything (shaders, VBOs, etc) anywhere there is an OpenGL implementation (Linux, Windows, Mac). Then why go through the hassle of writing it with DirectX and duplicate all the work??

Share this post


Link to post
Share on other sites
It's for the convience of the user...

Some people prefer a certain api or can only use a certain api for ex. GL programs can run no faster than 4 fps on my computer, probably due to the dack of drivers or such, and i am to lazy to download them.

If there was someone like me, but had less knowledge of computers, this could lead to excessive frustration, and so on...

Share this post


Link to post
Share on other sites
imho the user shouldn't have to worry about the API, that's the programmer's job. However, it is the job of the user to keep their computer updated and virus free, although half the users don't do this.

Share this post


Link to post
Share on other sites
WarAmp, Your union suggestion will do the the trick. Thanks man, should of thought of that sooner. Theres only one thing though, dx likes to use DWORDs ( unsined long ), but I'm sure I can make dx shut up about that thing.

Share this post


Link to post
Share on other sites
Quote:
Original post by ngill
Quote:
Original post by Kackurot
I'm making a 3d rendering engine that use's opengl and directx.


Just wondering... why do people do this??

Why not just write it in OpenGL? You get everything (shaders, VBOs, etc) anywhere there is an OpenGL implementation (Linux, Windows, Mac). Then why go through the hassle of writing it with DirectX and duplicate all the work??


IMO it's just good practice in general to not tie your software down to one particular API or platform.

Share this post


Link to post
Share on other sites
Why expose your vertex structure to API-independent code at all?

Begin your design with two entirely seperate graphics systems, and then identify areas of common functionality between them (refactoring those out) - not the other way around.

For instance, I might have an API-independent LoadModel function which will load a model file and extract vertex and face data from it - but I could pass that data off to an API-dependent PackForUse function which rearranges the data into a structure most suited to that API.

Admittedly it's a more useful technique when the renderers are substantially different (say, PS2 and Xbox), but it works.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!