Jump to content


DirectX vs OpenGL in game engine programming


23 replies to this topic

#1 eXtreme

    New Member

  • Members
  • Pip
  • 4 posts

Posted 19 February 2006 - 01:48 PM

Okay guys, i know this question sound sucks, but i am new in Game Engine programming, so is there any difference, that i should know, before i begin creating a game engine?

#2 MJeannig

    Member

  • Members
  • PipPip
  • 29 posts

Posted 19 February 2006 - 03:28 PM

There is no real difference. OpenGL has a cleaner syntax. So it may look easier for the beginner. Doing complex thing require to use extensions.
DirectX has a crappy COM-like syntax and ugly initialization but once you get used to it the two library are similar.
Everything is 3D and algorithms after all...

#3 Axel

    Valued Member

  • Members
  • PipPipPip
  • 119 posts

Posted 19 February 2006 - 03:29 PM

Quote

OpenGL has a cleaner syntax.
This is highly subjective aswell. For C++ coders the OOP style of Direct3D is pretty familiar and not "ugly".

#4 Ed Mack

    Senior Member

  • Members
  • PipPipPipPip
  • 1239 posts

Posted 19 February 2006 - 05:51 PM

They are two apis that do the same thing. One is more portable, that's about it.

#5 TheNut

    Senior Member

  • Moderators
  • 1473 posts
  • LocationThornhill, ON

Posted 19 February 2006 - 06:36 PM

Does a painter require a specific brush to paint? Does an artist require a specific pen to draw?

Games and graphics share a very basic commonality. They all operate on the basis of geometry and material properties. Regardless of the API you chose, it should not affect the design and operation of your engine, just like using a 10 cent pen from Staples won’t affect the quality of an artist’s drawing. Learn how to use data structures and abstraction to organize yourself an engine capable of maintaining polygons and materials. Combine the two later into your renderer component to actually draw the objects on the screen. With this approach, you open your engine up to countless other ways to render your scenes. Software, ray tracing, Direct3D, OpenGL, who cares. They all do the same thing in the end.
http://www.nutty.ca - Being a nut has its advantages.

#6 geon

    Senior Member

  • Members
  • PipPipPipPip
  • 893 posts

Posted 19 February 2006 - 06:58 PM

You could also use EaseWrapper and forget about the whole gl/dx issue.

#7 karligula

    Valued Member

  • Members
  • PipPipPip
  • 180 posts

Posted 20 February 2006 - 07:27 PM

Just try each one for a week and then use whichever one floats your boat highest...

#8 kusma

    Valued Member

  • Members
  • PipPipPip
  • 163 posts

Posted 22 February 2006 - 01:13 PM

i second karigula's suggestion. both apis expose more or less the same functionality. try both out and decide for yourself.

#9 mysticman

    Member

  • Members
  • PipPip
  • 95 posts

Posted 22 February 2006 - 01:55 PM

D3D is a pig to set-up (while OpenGL is a piece of cake):no:

#10 Axel

    Valued Member

  • Members
  • PipPipPip
  • 119 posts

Posted 22 February 2006 - 05:43 PM

Direct3D is not a pig to setup since DirectX 8. Its about the same amount of code you would have to setup your OpenGL context.

#11 SamuraiCrow

    Senior Member

  • Members
  • PipPipPipPip
  • 459 posts

Posted 22 February 2006 - 06:45 PM

I recommend OpenGL due to its portablilty. As for setting up an OpenGL context, use SDL or GLFW to set up the context. Otherwise you're still writing Windows-specific code and it won't be as portable. (Need I mention that I don't develop for Windows if I can avoid it?)

#12 kusma

    Valued Member

  • Members
  • PipPipPip
  • 163 posts

Posted 22 February 2006 - 06:55 PM

d3d is more pain to setup?


IDirect3D9 *direct3d = Direct3DCreate9(D3D_SDK_VERSION);

HWND window = CreateWindowEx(0, "static", "BIG", WS_POPUP | WS_VISIBLE, 0, 0, WIDTH, HEIGHT, 0, 0, GetModuleHandle(0), 0);

static D3DPRESENT_PARAMETERS present_parameters = { WIDTH, HEIGHT, D3DFMT_X8R8G8B8, 3, D3DMULTISAMPLE_NONE, 0, D3DSWAPEFFECT_DISCARD, 0, FALSE, 1, D3DFMT_D24S8, 0, D3DPRESENT_RATE_DEFAULT, 0 };

direct3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window, D3DCREATE_HARDWARE_VERTEXPROCESSING, &present_parameters, &device);

versus

DEVMODE devmode = { {0}, 0, 0, sizeof(DEVMODE), 0, DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT, {0}, 0,0,0,0,0,{0},0, BPP, WIDTH, HEIGHT, 0, 0 };

ChangeDisplaySettings((LPDEVMODE)&devmode, CDS_FULLSCREEN);

ShowCursor(FALSE);

win = CreateWindowEx(0, "static", "static", WS_POPUP | WS_VISIBLE, 0, 0, WIDTH, HEIGHT, 0, 0, GetModuleHandle(0), 0);

hdc = GetDC(win);

GLuint pixelformat = ChoosePixelFormat(hdc, &pfd);

SetPixelFormat(hdc, pixelformat, &pfd);

hrc = wglCreateContext(hdc);

wglMakeCurrent(hdc, hrc);


...

#13 kusma

    Valued Member

  • Members
  • PipPipPip
  • 163 posts

Posted 22 February 2006 - 06:57 PM

setup-code should in general not count when choosing api anyway, since it's code you write once. general usage of the api is more relevant.

#14 CobraLionz

    Member

  • Members
  • PipPip
  • 54 posts

Posted 22 February 2006 - 09:15 PM

Forgive the children who are still on nehe tutorial #3

#15 mysticman

    Member

  • Members
  • PipPip
  • 95 posts

Posted 24 February 2006 - 06:10 PM

kusma said:

d3d is more pain to setup?


IDirect3D9 *direct3d = Direct3DCreate9(D3D_SDK_VERSION);

HWND window = CreateWindowEx(0, "static", "BIG", WS_POPUP | WS_VISIBLE, 0, 0, WIDTH, HEIGHT, 0, 0, GetModuleHandle(0), 0);

static D3DPRESENT_PARAMETERS present_parameters = { WIDTH, HEIGHT, D3DFMT_X8R8G8B8, 3, D3DMULTISAMPLE_NONE, 0, D3DSWAPEFFECT_DISCARD, 0, FALSE, 1, D3DFMT_D24S8, 0, D3DPRESENT_RATE_DEFAULT, 0 };

direct3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window, D3DCREATE_HARDWARE_VERTEXPROCESSING, &present_parameters, &device);

versus

DEVMODE devmode = { {0}, 0, 0, sizeof(DEVMODE), 0, DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT, {0}, 0,0,0,0,0,{0},0, BPP, WIDTH, HEIGHT, 0, 0 };

ChangeDisplaySettings((LPDEVMODE)&devmode, CDS_FULLSCREEN);

ShowCursor(FALSE);

win = CreateWindowEx(0, "static", "static", WS_POPUP | WS_VISIBLE, 0, 0, WIDTH, HEIGHT, 0, 0, GetModuleHandle(0), 0);

hdc = GetDC(win);

GLuint pixelformat = ChoosePixelFormat(hdc, &pfd);

SetPixelFormat(hdc, pixelformat, &pfd);

hrc = wglCreateContext(hdc);

wglMakeCurrent(hdc, hrc);


...


I don't see an instruction in OpenGL in both the codes. This is everything code Windoz:closedeye

I with the setup don't intend whether to open a window but as to execute the rendering of a scene....:wub:

#16 baldurk

    Senior Member

  • Members
  • PipPipPipPip
  • 1057 posts

Posted 25 February 2006 - 01:43 AM

If anyone has anything useful to say to the OP, feel free. Otherwise, stop beating a horse that died about 4 years ago. I won't say there aren't differences between the APIs, because there are, but there's no point flaming each other about it.
baldurk
He who knows not and knows that he knows not is ignorant. Teach him.
He who knows not and knows not that he knows not is a fool. Shun him.

#17 SamuraiCrow

    Senior Member

  • Members
  • PipPipPipPip
  • 459 posts

Posted 25 February 2006 - 11:04 PM

Hear here!

Put simply, if you ever want your code to run on a Mac on Linux (or anything other than Windows or XBox series) use OpenGL.

#18 kusma

    Valued Member

  • Members
  • PipPipPip
  • 163 posts

Posted 26 February 2006 - 05:51 AM

mysticman said:

I don't see an instruction in OpenGL in both the codes. This is everything code Windoz:closedeye

I with the setup don't intend whether to open a window but as to execute the rendering of a scene....:wub:

Well, that kind of code is mostly just stuff like glDrawElements() versus device->DrawIndexedPrimitives(). this is simple semantics, it is NOT where you end up spending your actual development-time.

SamuraiCode: If you're serious about portability, you don't lock your engine to one API. And in either case, the biggest issue when porting a game to another (real-world) platform is tuning assets.

#19 daktaris

    New Member

  • Members
  • Pip
  • 2 posts

Posted 28 February 2006 - 05:26 PM

SamuraiCrow said:

Hear here!

Put simply, if you ever want your code to run on a Mac on Linux (or anything other than Windows or XBox series) use OpenGL.

odd...my Unreal-based Xbox/PC game (therefore D3D) that was released last year also made it on Macs as well. Must have been emulated...

Sarcasm aside...Aspyr did the porting and they have this down to a science. Within 3 weeks they had it running on Linux and Macs including translating vertex and pixel shaders into vertex and fragment programs.

Take the advice of everyone who reiterated that it's a non-issue. Pick one and go with it. My criteria forselection is support/updates/sample code. Remember your thought process because it will serve you again once you have to pick a high level shading language :).

#20 Axel

    Valued Member

  • Members
  • PipPipPip
  • 119 posts

Posted 01 March 2006 - 07:24 AM

Doesn't Unreal have an OpenGL backend anyway?





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users