• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Spykam22

Supporting both DirectX & OpenGL

8 posts in this topic

Hello!  I re-writing my game engine from scratch and was trying to decide whether I should support DirectX & OpenGL or just DirectX?  I understand that OpenGL is cross-platform while DirectX is restricted to Windows & the Xbox.  I also have a couple more questions:

 

  1. I am developing on Windows using Visual Studio 2013 Ultimate.  If I were to implement OpenGL,  how would I build for different platforms? Example: If I wanted to build on maybe, Linux or Mac.  Would I have to build my project on that operating system?
  2. If I do develop for both API's, how should I setup my project? Should I create two separate projects? Or keep them both separated in one project using enums, and interfaces? Example: 
    enum NXAPIChoice
    {
        NXAPI_DirectX,
        NXAPI_OpenGL,
    }
    
    NXAPIChoice NXGame::DefaultAPI = NXAPIChoice::NXAPI_DirectX;
    
    void NXGame::FinalInitialize()
    {
        int sWidth = 0, sHeight = 0;
    			InitializeWindows(sWidth, sHeight);
    			SetupGPU(sWidth, sHeight);
    
    			//TODO: [HIGH PRIORITY] Initialize Input
    			//TODO: [HIGH PRIORITY] Initialize Audio
    
    			Initialize();
    
    			//TODO: [HIGH PRIORITY] Create & Start GameTime
    }
    
    void NXGame::SetupGPU(int width, int height)
    {
        //stuff...
        NXGPU::Initialize(DefaultAPI, width, height, ...other);
    }
    
    void NXGPU::Initialize(NXAPIChoice choice, int width, int height, ...other)
    {
        if (choice == NXAPIChoice::NXAPI_DirectX)
           InitializeDirect3D(width, height, D3D_FEATURE_LEVEL_11_0, ...other);
        else
           InitializeOpenGL(width, height, GL_VERSION, ...other)
    }
    

    Also if I were to develop for both, and I do have to compile my code on other platforms (linux or mac), will I be able to skip my DirectX code (assuming it would cause errors because DX is not available) and just compile GL code? Is it even worth adding support for both? Thanks! smile.png

[EDIT: Or perhaps, shall I finish my engine with DirectX first (creating empty methods for GL in the process) and just start working on GL support (fill in the empty methods) after DirectX is fully implemented?]

Edited by KamRandle
2

Share this post


Link to post
Share on other sites

If I was new to this stuff I would finish the engine with one, then make it again with the other, then I feel like I'd truly know how to make it the 3rd time with both. This would be if you are trying to use this as a learning experience of course. If you already know how both work well enough then this wouldn't be the way to go about it.

0

Share this post


Link to post
Share on other sites

I'd honestly recommend switching to OpenGL if you feel comfortable with the idea. Choosing DirectX means you either choose to limit your audience or you choose to limit your graphics options. Even if your game isn't coming out for 5 years, the same situation that exists today with Windows XP not supporting DX11 will exist with Windows 7 not supporting DX13 or whatever. OpenGL doesn't have that problem since driver manufacturers control support levels. And if there's any chance your game would sell in China or other countries that lag further behind on OS adoption, the impact of using DirectX will really, really hurt. Even in America, you're still talking about a larger group than all Mac and Linux users combined.

 

Is there a reason you're hesitant to use OpenGL? If you have tools that only work with DirectX and make your life insanely easier, obviously you should stick with DirectX. But if you're just worried OpenGL is slower or harder to use or something, just jump in and you'll find out all the FUD is unjustified.

-2

Share this post


Link to post
Share on other sites

Yes. The days of a virtual interface and run-time selectable graphics API are long gone.

Maybe I'm just being stupid but what is the reasoning behind that?
2

Share this post


Link to post
Share on other sites

That's what i did in my 3d engine in my signature, have a look at it if you wish (Camera.h and Camera.cpp are good example). If i want to use opengl, i simply declalre

a macro COMPILE_FOR_OPENGL, if i want dx9, COMPILE_FOR_DIRECTX9 and so on. It's a bit of pain to write at first, but it had the advantage of being

extremly simple to switch between apis. The other solution would be separate interfaces in dlls i guess.

 

Both have advantages and inconveniances, it's a double edged sword kinda deal.

Edited by Vortez
0

Share this post


Link to post
Share on other sites

Yes. The days of a virtual interface and run-time selectable graphics API are long gone.

Maybe I'm just being stupid but what is the reasoning behind that?

  • Performance: Reducing virtual calls is usually a micro-optimization but when it’s virtual for every SetTexture(), SetBlendMode(), etc. it can add up. Plus other locations in code that have to become run-time if/else’s instead of just macro-excluded lines of code. With other options readily available there is just no need for the overhead.
  • Code maintenance: But you still need macros around the Direct3D parts for your ports for Linux and OS X, so the macro spaghetti still exists to some degree.  On some platforms it is both and on some platforms it is only one.  It is easier to just make it, “On some platforms it is this and on others that—no cross-overs.”
  • OpenGL on Windows is generally just not a good idea.  OpenGL hasn’t had any form of consistency standards by which vendors are required to adhere until very recently, meaning it may run as expected on some cards and not on others.  Again from #2, it is just best to use Direct3D on Windows and OpenGL on everything else.
#3 is the main reason.  Direct3D is near 100% consistent on all Windows machines and OpenGL more like 80%.  On Mac OS X OpenGL is near 100% consistent.  Linux OpenGL is somewhere between.  So you always want to use Direct3D on Windows; there is never really any reason for overlapping builds.
 
 
 
L. Spiro Edited by L. Spiro
2

Share this post


Link to post
Share on other sites
Hello everyone! Thanks for the answers. I think I may just write my DirectX version first. It is being developed alongside a game that I am using it for. It will be my first game to be released. After I am finished, then I'll focus on GL versions. How many people do you guys think use Bootcamp on OS X? Thanks! :)
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0