   OpenGL versus DirectX... again (maybe different though)
  I'm not talking about which is the better engine overall, I just would like to know which is *easier to learn*.  I'm not a big Object Oriented/C++ freak, so in that respect I'm thinking OpenGL might be better for me.  However, the DirectX X Library definitely provides the beginner with some ease.I'd really like to start learning 3D, and this post will give me an idea of how to.Thanks,Steven Welch   
  OpenGL is quite a bit easier to learn in my opinion. The function calls all begin with "gl" and are named logically whereas with Direct3D it's anyone's guess. I do suggest picking up a book on both at the bookstore and simply paging through them for a while. Figure out the syntax of both APIs and decide for yourself which would be better. Some people really like OpenGL, but can't stand Direct3D and vice versa. Both have their quirks.   ;  This has been asked so many times lately, it is getting a bit ridiculous here is a thread that is still up even, Why use D3D instead of OpenGL?My from my personal experience the answer is this, either is easier to learn depending on which suites you better. The only one who can answer which one is easier is you.OpenGL is more mathematical later on in development, DirectX has functions that you can use to handle some of the more complex math for harder things. You can use both and get just about identical effects.   ;  Won't be long until this thread is closed. ;)I think @GDKnight is right on the money. Check them both out and see which suits your own programming preference.And the "easier to learn" label starts off just as many flame wars as "which one is better"...:)Good luck man and just have fun with it!   ;OpenGL:#include <windows.h>#include <GL/gl.h>HWND hWindow;HDC hDC;HGLRC hRC;struct Vertex{    float x, y, z;    float r, g, b;};LRESULT WINAPI WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ){    switch( msg )    {    case WM_CLOSE:   PostQuitMessage( 0 );   return 0;    case WM_PAINT:   ValidateRect( hWnd, NULL );   return 0;    }    return DefWindowProc( hWnd, msg, wParam, lParam );}int main(){    HINSTANCE hInstance = GetModuleHandle( NULL );    //create a window    WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, WndProc, 0, 0, hInstance, NULL, NULL, NULL, NULL, "MiniOGL", NULL };    RegisterClassEx( &wc );    hWindow = CreateWindowEx( WS_EX_APPWINDOW | WS_EX_WINDOWEDGE, "MiniOGL", "MiniOGL", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,    300, 300, NULL, NULL, hInstance, NULL );    ShowWindow( hWindow, SW_SHOW );    UpdateWindow( hWindow );    //Set up pixel format and context    hDC = GetDC( hWindow );    PIXELFORMATDESCRIPTOR pfd = {0};    pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);    pfd.nVersion = 1;    pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;    pfd.iPixelType = PFD_TYPE_RGBA;    pfd.cColorBits = 32;    pfd.cDepthBits = 16;    pfd.cStencilBits = 0;    int pixelFormat = ChoosePixelFormat( hDC, &pfd );    SetPixelFormat( hDC, pixelFormat, &pfd );    hRC = wglCreateContext( hDC );    wglMakeCurrent( hDC, hRC );    //now create our triangle    Vertex Triangle[3] ={   { 0.0f, 0.9f, 0.5f, 1.0f, 0.0f, 0.0f },   { -0.9f, -0.9f, 0.5f, 0.0f, 1.0f, 0.0f },   { 0.9f, -0.9f, 0.5f, 0.0f, 0.0f, 1.0f }    };    MSG msg;    bool RunApp = true;    while( RunApp )    {   if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )   {  if( msg.message == WM_QUIT ) RunApp = false;  TranslateMessage( &msg );  DispatchMessage( &msg );   }   //render stuff   glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );   glBegin( GL_TRIANGLES );   for( int v = 0; v < 3; ++v )   {  glColor3f( Triangle[v].r, Triangle[v].g, Triangle[v].b );  glVertex3f( Triangle[v].x, Triangle[v].y, Triangle[v].z );   }   glEnd();   SwapBuffers( hDC );    }    wglMakeCurrent( 0, 0 );    wglDeleteContext( hRC );    ReleaseDC( hWindow, hDC );    DestroyWindow( hWindow );    return 0;}Direct3D:#include <windows.h>#include <d3d9.h>HWND hWindow;IDirect3D9* D3D;IDirect3DDevice9* Device;struct Vertex{    float x, y, z, rhw;    D3DCOLOR Color;};#define FVF_VERTEX (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)LRESULT WINAPI WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ){    switch( msg )    {    case WM_CLOSE:   PostQuitMessage( 0 );   return 0;    case WM_PAINT:   ValidateRect( hWnd, NULL );   return 0;    }    return DefWindowProc( hWnd, msg, wParam, lParam );}int main(){    HINSTANCE hInstance = GetModuleHandle( NULL );    //create a window    WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, WndProc, 0, 0, hInstance, NULL, NULL, NULL, NULL, "MiniD3D", NULL };    RegisterClassEx( &wc );    hWindow = CreateWindowEx( WS_EX_APPWINDOW | WS_EX_WINDOWEDGE, "MiniD3D", "MiniD3D", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,    300, 300, NULL, NULL, hInstance, NULL );    ShowWindow( hWindow, SW_SHOW );    UpdateWindow( hWindow );    //Set up d3d    D3D = Direct3DCreate9( D3D_SDK_VERSION );    D3DPRESENT_PARAMETERS d3dpp = { 0 };    d3dpp.Windowed = TRUE;    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;    d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;    D3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWindow, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &Device );    //now create our triangle    Vertex Triangle[3] ={   { 150.0f, 50.0f, 0.5f, 1.0f, D3DCOLOR_XRGB( 255, 0, 0 ) },   { 250.0f, 250.0f, 0.5f, 1.0f, D3DCOLOR_XRGB( 0, 255, 0 ) },   { 50.0f, 250.0f, 0.5f, 1.0f, D3DCOLOR_XRGB( 0, 0, 255 ) }    };    MSG msg;    bool RunApp = true;    while( RunApp )    {   if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )   {  if( msg.message == WM_QUIT ) RunApp = false;  TranslateMessage( &msg );  DispatchMessage( &msg );   }   //render stuff   Device->Clear( 0, 0, D3DCLEAR_TARGET, D3DCOLOR_XRGB( 0, 0, 0 ), 1.0f, 0 );   Device->BeginScene();   Device->SetFVF( FVF_VERTEX );   Device->DrawPrimitiveUP( D3DPT_TRIANGLELIST, 1, Triangle, sizeof(Vertex) );   Device->EndScene();   Device->Present( 0, 0, 0, 0 );    }    Device->Release();    D3D->Release();    DestroyWindow( hWindow );    return 0;}Make your own decision.   ;  Hey,Thought I'd put in my 2 cents.I use OpenGL.  Not because it's better, but because it's what the code that I'm working on uses.  It would be relatively trivial to swap [because both systems can more or less do the same stuff in a very similar way AFAIK].GL functions are prepended with 'gl', and are C-style.  DirectX stuff is OO C++.I believe that if you are using immediate mode[?] [glBegin(GL_X); glVertex3f(); glEnd();] to draw triangles in smaller batches [<20 triangles] then GL batches faster - my first directX based test project [a scrobble clone] was initially written to draw triangles using [from memory so it's probably wrong...] d3ddevice->DrawPrimitive 2 tris a batch and the performance wasn't so hot.  a newer gl based test project did a similar thing [renderwise, not codeflow wise], and the performance still wasn't great, but it did still run on lower end machines at acceptable rates.  There's a comparison of GL vs DirectX performance [on batching] over at nVidia's developer zone IIRC.I only mention this because if the two projects were 'serious' projects, and not just demos/prototypes, then the architecture would be different.  I would assume that no serious directX engine would put all of its primitives in 2 at a time without a hardware vertex buffer.  However, for GL, if it's only for a couple of primitives, it may be the way to go.  So, I believe that there's a different coding style nessecary for both.  GL and DirectX performance differences are more or less negligable IMO when you do everything 'the best way' for that API.In my opinion, GL is easier for the beginner and harder for the more advanced programmer.  Using directX to draw a couple of triangles is IMO more difficult to do 'well'.  On the other hand, checking and using GL extensions is really quite annoying, because they may have different names [eg NV_ or ARB_ or some other start].  That said, everything is more or less possible in both at the same approximate level of performance IMO.That said, the resources available are probably more on the directX court.  Although I rarely look for tutorials, GL really only has NeHe.  DirectX has a lot more.  Microsoft's released loads of examples, there's NeXe, Drunken Hyena and a bunch of other sites.  However, both have pretty straightforward documentation [gl has it's documentation (of each function, not of a whole program structure or anything) included with the platform SDK for windows, and dx documentation with the DX SDK is relatively extensive from memory.Similarly, GL's GLUT/GLAUX libraries are pretty limited when compared to what the directX [forgotten it's name, D3DX9[?]] helper library can do.I can't tell you which is better, but as far as I know all of the statements that I've made above are true.  Read a bunch of information that you can find about both and then make up your own mind.  Though, in all honesty, for me at least, it wasn't the biggest decision I made that week.  They both do graphics.  They both do graphics in a way that's pretty easy to understand and learn.In retrospect this does look pretty ranty, but you may still find it useful.--CJM   ;  If you're looking for something that's easy to learn, then I would recommened SDL (www.libsdl.org) over either DX or OGL. It can    do everything those APIs can (look at Eternal Lands), and is much simpler.   ;  I personaly use opengl+sdl so i can port to any significant os in existance and since i think microsoft is evil and i dont want to support them, but thats a personal opinion. With opengl you can still code on mac or linux or bsd or solaris or qnx or for example in some future you can port your application to haiku or whatever os you like and not whatever os microsoft chooses for you.Also most standard extensions start with ARB so I think extensions are not that big of a problem. But since i never really used directx i am probably not qualified to answer such a question. Still i wanted to point out the issues above.   ;Quote:then I would recommened SDL (www.libsdl.org) over either DX or OGL. It can do everything those APIs can (look at Eternal Lands), and is much simpler.SDL contains functionality for input, sound and 2D graphics.  It does have some overlap with DX (namely with the input and sound components of DX) but it doesn't contain any 3D functionality which DX and GL does (indeed GL only contains 3D functionality really).Thus it is incorrect to say it can do anything DX or GL can.  It can however be used along with GL.  It can do all the window setup stuff for you (thus avoiding the win32 code or the equivilent code for your platform) as well as provide input and sound.  Also code written using SDL will compile on several platforms without needing any alterations as long as you're careful when doing certain things (i.e. being mindful of endianess issues).As for DX vs GL, it doesn't really matter.  My current preference is for DX as I like the stuff that comes with the SDK (i.e. the samples, docs and tools) and I prefer the API.  You however may find you prefer GL.  My advice would be to just choose one and start using it, if you really detest it then switch but otherwise keep with it until you're comfortable with 3D graphics in general and take a look at the other one.  Once you've got a handle on 3D graphics theory and experience with one of the APIs you'll find the other one quite easy to pick up.   