Sign in to follow this  
Wurmknight

OpenGL Direct3D or DirectDraw

Recommended Posts

Wurmknight    122
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
Stani R    1070
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
Etherstar    200
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
Habba    122
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
Joni-Matti    138
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
DarkZoulz    106
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
zangetsu    272
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
KoalaGerch    122
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
Wurmknight    122
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
Michalson    1657
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
Michalson    1657
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
Flimflam    665
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
zangetsu    272
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  

  • Similar Content

    • By pseudomarvin
      I assumed that if a shader is computationally expensive then the execution is just slower. But running the following GLSL FS instead just crashes
      void main() { float x = 0; float y = 0; int sum = 0; for (float x = 0; x < 10; x += 0.00005) { for (float y = 0; y < 10; y += 0.00005) { sum++; } } fragColor = vec4(1, 1, 1 , 1.0); } with unhandled exception in nvoglv32.dll. Are there any hard limits on the number of steps/time that a shader can take before it is shut down? I was thinking about implementing some time intensive computation in shaders where it would take on the order of seconds to compute a frame, is that possible? Thanks.
    • By Arulbabu Donbosco
      There are studios selling applications which is just copying any 3Dgraphic content and regenerating into another new window. especially for CAVE Virtual reality experience. so that the user opens REvite or CAD or any other 3D applications and opens a model. then when the user selects the rendered window the VR application copies the 3D model information from the OpenGL window. 
      I got the clue that the VR application replaces the windows opengl32.dll file. how this is possible ... how can we copy the 3d content from the current OpenGL window.
      anyone, please help me .. how to go further... to create an application like VR CAVE. 
       
      Thanks
    • By cebugdev
      hi all,

      i am trying to build an OpenGL 2D GUI system, (yeah yeah, i know i should not be re inventing the wheel, but this is for educational and some other purpose only),
      i have built GUI system before using 2D systems such as that of HTML/JS canvas, but in 2D system, i can directly match a mouse coordinates to the actual graphic coordinates with additional computation for screen size/ratio/scale ofcourse.
      now i want to port it to OpenGL, i know that to render a 2D object in OpenGL we specify coordiantes in Clip space or use the orthographic projection, now heres what i need help about.
      1. what is the right way of rendering the GUI? is it thru drawing in clip space or switching to ortho projection?
      2. from screen coordinates (top left is 0,0 nd bottom right is width height), how can i map the mouse coordinates to OpenGL 2D so that mouse events such as button click works? In consideration ofcourse to the current screen/size dimension.
      3. when let say if the screen size/dimension is different, how to handle this? in my previous javascript 2D engine using canvas, i just have my working coordinates and then just perform the bitblk or copying my working canvas to screen canvas and scale the mouse coordinates from there, in OpenGL how to work on a multiple screen sizes (more like an OpenGL ES question).
      lastly, if you guys know any books, resources, links or tutorials that handle or discuss this, i found one with marekknows opengl game engine website but its not free,
      Just let me know. Did not have any luck finding resource in google for writing our own OpenGL GUI framework.
      IF there are no any available online, just let me know, what things do i need to look into for OpenGL and i will study them one by one to make it work.
      thank you, and looking forward to positive replies.
    • By fllwr0491
      I have a few beginner questions about tesselation that I really have no clue.
      The opengl wiki doesn't seem to talk anything about the details.
       
      What is the relationship between TCS layout out and TES layout in?
      How does the tesselator know how control points are organized?
          e.g. If TES input requests triangles, but TCS can output N vertices.
             What happens in this case?
      In this article,
      http://www.informit.com/articles/article.aspx?p=2120983
      the isoline example TCS out=4, but TES in=isoline.
      And gl_TessCoord is only a single one.
      So which ones are the control points?
      How are tesselator building primitives?
    • By Orella
      I've been developing a 2D Engine using SFML + ImGui.
      Here you can see an image
      The editor is rendered using ImGui and the scene window is a sf::RenderTexture where I draw the GameObjects and then is converted to ImGui::Image to render it in the editor.
      Now I need to create a 3D Engine during this year in my Bachelor Degree but using SDL2 + ImGui and I want to recreate what I did with the 2D Engine. 
      I've managed to render the editor like I did in the 2D Engine using this example that comes with ImGui. 
      3D Editor preview
      But I don't know how to create an equivalent of sf::RenderTexture in SDL2, so I can draw the 3D scene there and convert it to ImGui::Image to show it in the editor.
      If you can provide code will be better. And if you want me to provide any specific code tell me.
      Thanks!
  • Popular Now