Sign in to follow this  
Wurmknight

OpenGL Direct3D or DirectDraw

Recommended Posts

I'm sure this question has been asked elsewhere..but for the life of me, I cannot find it. My dilemma is: Me and a co-worker are planning on making an RPG and chose DirectX as our API-of-choice. We are both fluent C# programmers (which is the language we plan on writing this) and i've done some OpenGL stuff in the past. So my question is, is it more efficient with todays graphic card capabilities to use Direct3D or use the DirectDraw method for our graphics? Not sure if I mentioned it, but we our aiming our first game to be a single-player 2D RPG. I know there is probably no definitive answer, but i'm hoping for any opinions here. Thanks, Dustin

Share this post


Link to post
Share on other sites
Can't comment on speed, but DirectDraw was in fact dropped (back in DX8 I think?) from the API a while ago. Add advances in 3d accelerated hardware into the mix, and I'll dare go out on a leg here and say that D3D ought to be faster (this constitues subjective opinion not backed up by any benchmarks). Another plus is that you already know OGL so you'll probably find D3D more intuitive.

Share this post


Link to post
Share on other sites
I recommend using Direct3D. You will have a lot more options as far as scaling/rotating/alpha blending your sprites for some pretty cool effects. You'll also learn about the Direct3D interface in case you want to make a 3D project at a later date.

I recommends taking a look at the Direct3DX Sprite class. It will be handling the bulk of your work and is a good place to start.

Share this post


Link to post
Share on other sites
Quote:
Original post by Etherstar
I recommends taking a look at the Direct3DX Sprite class. It will be handling the bulk of your work and is a good place to start.


Last time I tried to work with Direct3DX sprite class, it all ended in disaster. You can only use images that size is in power of two and images will be resized for some weird reason (and thus it looks blurred and different). I wasn't able to render my 64x64 bitmap file into the screen as 64x64 image that looks the same as the original. And did I mention it was slow? My engine slowed already below 20fps when I rendered 20x10 tilemap on the screen. That's hardly enough for a decent RPG which I tried to create (so I went for DirectDraw, and it's way faster).

Share this post


Link to post
Share on other sites
D3DX Sprite class is quite slow. If you implement it by yourself, it will be way faster. DirectDraw of course works on non-3d-accelerated graphics cards, but if you don't need such backward-compatibility, you should use D3D instead.

Share this post


Link to post
Share on other sites
I'd go with Direct3D any day. Setting up and using D3D isn't harder than using DD and you get lots of cool effects for free. If you use D3DXSprite it's easy as cake. I don't believe D3DXSprite is slow at all. It was before, but MS have fixed it.

Share this post


Link to post
Share on other sites
I just recently dipped my toe into Managed Direct3D recently. I admit I ran into a few issues while getting the code to do what I wanted. Most of these issues were caused by my preconcieved notions about how to do 2D Graphics. Once I got passed that, and coded my application in a more appropriate way, I found that not only was Managed Direct3D easier, but also that the scene rendered faster. I know some other posters say that DirectDraw is faster, but I have a feeling that this is mostly cause by trying to use Direct3D incorrectly.

For example my first draft of my code tried to create a vertex buffer, set the texture and draw primatives each time I wanted to draw 1 tile. This seemed like the normal way to do it given past expirence with DirectDraw, but it was really slow. what I didn't know is the correct way to do it in direct3d, is to create a big list of points in 3D space that describe all the places you want 1 texture, and call DrawPrimitives once for each texture. Changing my code to work in this manner made all the difference in the world. I now render a 24x12 space of tiles with 48x48 tiles in about 35 milliseconds using Direct3D. So the myth about Direct3D being slow for 2D is untrue.

The real challenge I was facing is that most of the resources you will find for Direct3D are C++ and are for unmanaged code. I was looking primarily for VB.Net code which I was unable to find. I ended up translating a lot of C# and unamaged C++ examples to get what I needed.

Rather than say use Direct3D, but it will be hard, I'll do you one better than that. I wrote up my expirences as they happened to create working tutorial on 2D in Direct3D that does the most common things people do with 2D graphics. It focuses on windowed mode, but it could be applied to full screen. It uses colorkey transparency since that seems to be more common in 2D land. It also is geared towards the "take a rectangle from here and draw it there" line of thinking by providing some fucntions to convert source and destination rectangles into Vertices for Direct3D to use. The only thing you might not like about it is the sample code is in vb.net but I find translating vb.net to c# and vice versa is pretty easy. I am also very anxious to get some feedback on it.

If your still interested check it out at http://www.k2wrpg.org/wiki/index.php?Direct3DVbDotNet

Share this post


Link to post
Share on other sites
I have a similar question.

I'm working on a system in c# where I need to construct sharp 2d images (a combination of pictures and text) using managed directx, store them as a texture/surface and then display them on the screen, either as flat 2d quads or as part of a 3d object.

Unfortunately my boss wants the system to be easily upgradable in the future, so deprecated parts of directX, i.e. directdraw, aren't really acceptable.

I've been trying to get the system working using Direct3dx's sprite system and textures, but I'm left with slightly blurred images when loading simple images from disk and displaying them.

I've turned off the filtering for the TextureLoader, but the problems persist.
Is this a problem with the D3DX sprite system? Do I somehow have to disable filtering for the entire system, and if so can anyone give me a pointer?

If it is a problem with D3DX sprites, then can anyone tell me any ways to quickly load and display images with the same sharpness as the original image?
Or do I have to go back to my boss and tell him it's DirectDraw or nothing? :)

Share this post


Link to post
Share on other sites
Thanks everyone for the replies. I have chosen Direct3D over DirectDraw after reading everyones opinions and searching around, I really think D3D will allow me to use features I might find much harder to do with DirectDraw surfaces.

@Zangetsu:
I appreciate the link and I plan on looking over the site better when I get home (at work right now). I am curious though, and this is directed at anyone who can answer this. On your tutorial, you have a function (sub-routine i guess in VB) that disposes the D3D device.. In managed C#, wouldn't it dispose itself when the 'form' was destroyed/closed, because it is a member variable of that class. I could be thinking wrong, so that is why i'm so curious about this. I'm sure disposing it really doesn't hinder anything but I am curious if this step even needs to be called.

Share this post


Link to post
Share on other sites
Quote:
Original post by Habba
Quote:
Original post by Etherstar
I recommends taking a look at the Direct3DX Sprite class. It will be handling the bulk of your work and is a good place to start.


Last time I tried to work with Direct3DX sprite class, it all ended in disaster. You can only use images that size is in power of two and images will be resized for some weird reason (and thus it looks blurred and different). I wasn't able to render my 64x64 bitmap file into the screen as 64x64 image that looks the same as the original. And did I mention it was slow? My engine slowed already below 20fps when I rendered 20x10 tilemap on the screen. That's hardly enough for a decent RPG which I tried to create (so I went for DirectDraw, and it's way faster).


Quote:
Original post by Joni-Matti
D3DX Sprite class is quite slow. If you implement it by yourself, it will be way faster. DirectDraw of course works on non-3d-accelerated graphics cards, but if you don't need such backward-compatibility, you should use D3D instead.


Funny, I don't seem to have that problem.



6 different sprites, none of them having power of 2 dimensions (all loaded with the straight forward TextureLoader.FromFile method), being randomly placed on the screen every frame (when running it just looks like a flashy blob of color), with alpha blending used (50%), and the sprites are being placed out of order (instead of 6 loops, there is one loop that draws one instance of each per iteration) to avoid texture optimization. Properly ordered (draw all of one sprite first, then the next), the framerate more then doubles to 560 fps. Written in Visual C# Express, Managed DirectX 9, using the Sprite class.

Share this post


Link to post
Share on other sites
For a fair comparison I did up something similar in Managed DirectDraw on the same machine (Radeon X800 Pro) just to see how much the video card was playing into it.

Fullscreen 640x480x32, drawing the first of the 6 (100x101, the smallest sprite) without alpha blending 256 times per frame, gives 550 fps. Conclusion: Modern video cards are not optimized (or rather the drivers are not) for fast DirectDraw. Unless you are targeting much earlier hardware, Direct3D to display 2D would be the best choice.

Share this post


Link to post
Share on other sites
To the people who have said that it's quite slow and or shows graphical artifacts, that was quite a while ago when that truely was the case. I've been using the Sprite class a lot lately, and can say it is far from slow, and doesn't show artifacts. Infact, it's less prone to texture artifacts than manually doing it yourself. I know if I used very small textures and stretched them horizontally a lot when I used to use my own textured quads, the texture could lose alignment slightly and really throw off the look of say a window border for a UI, etc.

In short, the sprite class is quite fast now.

Share this post


Link to post
Share on other sites
Quote:
Original post by Wurmknight
@Zangetsu:
I appreciate the link and I plan on looking over the site better when I get home (at work right now). I am curious though, and this is directed at anyone who can answer this. On your tutorial, you have a function (sub-routine i guess in VB) that disposes the D3D device.. In managed C#, wouldn't it dispose itself when the 'form' was destroyed/closed, because it is a member variable of that class. I could be thinking wrong, so that is why i'm so curious about this. I'm sure disposing it really doesn't hinder anything but I am curious if this step even needs to be called.


Well I won't claim to be an expert, but I suspect that even though the code uses "Managed" DirectX, that somewhere underneath it all, it calls Bill only knows what unmanaged code. The other thing that is curious is that the objects even have a dispose method. You right that in theory when the garbage collector clears the object it should dispose itself. If it does dispose itself, why go through the trouble to add the dispose method to this implementation? I also suspect that the garbage collector may not be able to recover video memory like it does system memory. I think for the real answer we would need to consult the DirectX Docs, and if the answer isn't there, then ask the DX dev team itself. As for me until I get a better answer; If it has a Dispose method, I call it when I am done.

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  

  • Announcements

  • Forum Statistics

    • Total Topics
      628345
    • Total Posts
      2982200
  • Similar Content

    • By test opty
      Hi all,
       
      I'm starting OpenGL using a tut on the Web. But at this point I would like to know the primitives needed for creating a window using OpenGL. So on Windows and using MS VS 2017, what is the simplest code required to render a window with the title of "First Rectangle", please?
       
       
    • By DejayHextrix
      Hi, New here. 
      I need some help. My fiance and I like to play this mobile game online that goes by real time. Her and I are always working but when we have free time we like to play this game. We don't always got time throughout the day to Queue Buildings, troops, Upgrades....etc.... 
      I was told to look into DLL Injection and OpenGL/DirectX Hooking. Is this true? Is this what I need to learn? 
      How do I read the Android files, or modify the files, or get the in-game tags/variables for the game I want? 
      Any assistance on this would be most appreciated. I been everywhere and seems no one knows or is to lazy to help me out. It would be nice to have assistance for once. I don't know what I need to learn. 
      So links of topics I need to learn within the comment section would be SOOOOO.....Helpful. Anything to just get me started. 
      Thanks, 
      Dejay Hextrix 
    • By mellinoe
      Hi all,
      First time poster here, although I've been reading posts here for quite a while. This place has been invaluable for learning graphics programming -- thanks for a great resource!
      Right now, I'm working on a graphics abstraction layer for .NET which supports D3D11, Vulkan, and OpenGL at the moment. I have implemented most of my planned features already, and things are working well. Some remaining features that I am planning are Compute Shaders, and some flavor of read-write shader resources. At the moment, my shaders can just get simple read-only access to a uniform (or constant) buffer, a texture, or a sampler. Unfortunately, I'm having a tough time grasping the distinctions between all of the different kinds of read-write resources that are available. In D3D alone, there seem to be 5 or 6 different kinds of resources with similar but different characteristics. On top of that, I get the impression that some of them are more or less "obsoleted" by the newer kinds, and don't have much of a place in modern code. There seem to be a few pivots:
      The data source/destination (buffer or texture) Read-write or read-only Structured or unstructured (?) Ordered vs unordered (?) These are just my observations based on a lot of MSDN and OpenGL doc reading. For my library, I'm not interested in exposing every possibility to the user -- just trying to find a good "middle-ground" that can be represented cleanly across API's which is good enough for common scenarios.
      Can anyone give a sort of "overview" of the different options, and perhaps compare/contrast the concepts between Direct3D, OpenGL, and Vulkan? I'd also be very interested in hearing how other folks have abstracted these concepts in their libraries.
    • By aejt
      I recently started getting into graphics programming (2nd try, first try was many years ago) and I'm working on a 3d rendering engine which I hope to be able to make a 3D game with sooner or later. I have plenty of C++ experience, but not a lot when it comes to graphics, and while it's definitely going much better this time, I'm having trouble figuring out how assets are usually handled by engines.
      I'm not having trouble with handling the GPU resources, but more so with how the resources should be defined and used in the system (materials, models, etc).
      This is my plan now, I've implemented most of it except for the XML parts and factories and those are the ones I'm not sure of at all:
      I have these classes:
      For GPU resources:
      Geometry: holds and manages everything needed to render a geometry: VAO, VBO, EBO. Texture: holds and manages a texture which is loaded into the GPU. Shader: holds and manages a shader which is loaded into the GPU. For assets relying on GPU resources:
      Material: holds a shader resource, multiple texture resources, as well as uniform settings. Mesh: holds a geometry and a material. Model: holds multiple meshes, possibly in a tree structure to more easily support skinning later on? For handling GPU resources:
      ResourceCache<T>: T can be any resource loaded into the GPU. It owns these resources and only hands out handles to them on request (currently string identifiers are used when requesting handles, but all resources are stored in a vector and each handle only contains resource's index in that vector) Resource<T>: The handles given out from ResourceCache. The handles are reference counted and to get the underlying resource you simply deference like with pointers (*handle).  
      And my plan is to define everything into these XML documents to abstract away files:
      Resources.xml for ref-counted GPU resources (geometry, shaders, textures) Resources are assigned names/ids and resource files, and possibly some attributes (what vertex attributes does this geometry have? what vertex attributes does this shader expect? what uniforms does this shader use? and so on) Are reference counted using ResourceCache<T> Assets.xml for assets using the GPU resources (materials, meshes, models) Assets are not reference counted, but they hold handles to ref-counted resources. References the resources defined in Resources.xml by names/ids. The XMLs are loaded into some structure in memory which is then used for loading the resources/assets using factory classes:
      Factory classes for resources:
      For example, a texture factory could contain the texture definitions from the XML containing data about textures in the game, as well as a cache containing all loaded textures. This means it has mappings from each name/id to a file and when asked to load a texture with a name/id, it can look up its path and use a "BinaryLoader" to either load the file and create the resource directly, or asynchronously load the file's data into a queue which then can be read from later to create the resources synchronously in the GL context. These factories only return handles.
      Factory classes for assets:
      Much like for resources, these classes contain the definitions for the assets they can load. For example, with the definition the MaterialFactory will know which shader, textures and possibly uniform a certain material has, and with the help of TextureFactory and ShaderFactory, it can retrieve handles to the resources it needs (Shader + Textures), setup itself from XML data (uniform values), and return a created instance of requested material. These factories return actual instances, not handles (but the instances contain handles).
       
       
      Is this a good or commonly used approach? Is this going to bite me in the ass later on? Are there other more preferable approaches? Is this outside of the scope of a 3d renderer and should be on the engine side? I'd love to receive and kind of advice or suggestions!
      Thanks!
    • By nedondev
      I 'm learning how to create game by using opengl with c/c++ coding, so here is my fist game. In video description also have game contain in Dropbox. May be I will make it better in future.
      Thanks.
  • Popular Now