Target most Windows versions for a 2D game? - windows

If one were to code a game for most versions of Windows, which API should be used?
I know DirectDraw works from NT4 and up (although DirectDraw is emulated on NT4 with GDI). However, I am told DirectDraw is deprecated in newer versions of Windows?
I could revert to just GDI, but then it is hard to completely eliminate flicker and tearing, since there is no double buffering with flipping between buffers.
Should I go for Direct3D or DirectDraw? Or is there some way of completely eliminating flicker in GDI?
If Direct3D is the answer, which version of it is supported on most platforms?

Unless you are sure you will never want to port your game to any non-Windows platform, I would recommend OpenGL. It should work on all versions from 2000 upwards, and some lucky NT4 or Win98 users may be able to run it (but don't advertise those versions as "supported.") Hardware acceleration won't always work, but the impact on performance won't be noticeable for a simple 2D game. And you will be able to port it reasonably cheaply to other platforms (e.g. iPhone) if necessary.

Related

Any downsides of moving from GDI+ to OpenGL?

I recently moved the rendering part of a program of mine from GDI+ to OpenGL.
Now I'm wondering: are there any downsides to doing so?
For example, are there any versions of Windows (XP or later) that support GDI+ but not OpenGL?
Or, for example, is it possible for a lack of drivers (or poor drivers), or a lack of a graphics card, etc. to make OpenGL rendering impossible on a system on which GDI+ works fine?
(I understand the OpenGL might need to resort to software rendering on less capable systems, but aside from slowness, I'm wondering if it would ever simply not work correctly in a situation in which GDI+ would.)
It depends on the OpenGL version/profile you're using. Up to, inclusing Windows XP OpenGL-1.1 is available by default without additional drivers. Since Windows Vista the minimum available OpenGL version is OpenGL-1.4.
However if you need anything more than that, you're relying on the user installing the drivers that come from the GPU vendor; the drivers installed by default in a standard Windows installation don't cover OpenGL (for not perfectly sane reasons).
Programs and libraries that strongly depend on OpenGL-ES have resorted to incorporate fallbacks like ANGLE.
There are some idiosyncrasies, as for example: you cannot create a transparent OpenGL window, if transparency is disabled (which means, not at all, under XP). Otherwise, as datenwolf notes, there's ANGLE, but even that does not always work. Another option might be mesa3d compiled for the windows target, with software rendering enabled. This option might be the safest one and faster than the software OpenGL 1.1 implementation from Microsoft.

Are GDI, GDI+ and OpenGL really obsolete/deprecated? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
If you open the page "Graphics and Gaming (Windows)" on microsoft.com
the last category is described as
Legacy Graphics: Technologies that are obsolete and should not be used in new
applications.
This category includes (among others) the following APIs:
GDI
GDI+
OpenGL
What's your opinion? If i want to roll out a new software today it must support Windows XP (still about 50% of all installed systems). Direct2D requires Windows 7/Vista. What else should be used?
I suspect that Microsoft's definition of "legacy" has little to do with what any sensible developer should do, and is instead based on some Grand Rewrite of the Windows API.
Starting at around Windows Vista, Microsoft has been redesigning many of their API's. We now have MMDevAPI as the One True Sound API, WIC is the One True Image File API, etc. From what I've seen/heard, these new API's are much better than the old ones, and the "legacy" systems all work based on the new ones. In Windows Vista and later, DirectSound is entirely based on MMDevAPI, and components that need to read image files do it via WIC.
Windows 8 will have an ARM version, which it appears will support only a subset of the current Windows API. We won't know for sure until Windows on ARM is released, but, based on the libraries included for the ARM platform in Visual Studio 11 (ref: http://www.winehq.org/pipermail/wine-devel/2012-March/094559.html), it's looking like GDI+ and OpenGL will not be available. GDI is available for linking, but that doesn't necessarily mean it's intact.
This new API's from Vista and later roughly correspond to the libraries in the VS11 ARM target. I'm guessing that anything on that list is there because it's either the latest and greatest way to do what it does, or it's too technically important to discard (for now). Thus, "legacy" is anything that's not the latest and greatest way to do at least one thing.
I'm not sure what is the One True Graphics API. Already we have Direct2D, Direct3D, DirectComposition (which, by the way, is not available until Windows 8), DirectWrite, and DXGI. DXGI seems the closest, but I don't have a deep enough understanding of the graphics API's to say. I suspect gdi32 is technically very difficult to get rid of. How are non-legacy applications meant to find out when part of a window has been revealed and therefore must be painted, without using WM_PAINT, which involves an HDC, and how could a library do that on an application's behalf without replacing its window procedure? How are we meant to make semi-transparent windows without using UpdateLayeredWindow, which takes an HDC? How much does user32 depend on gdi32, and can they really be separated?
From a technical standpoint, Windows can easily get rid of GDI+ and OpenGL, but I'm not convinced that getting rid of OpenGL will work out, even on a new platform that doesn't promise any backward compatibility. It seems too valuable to developers. GDI+ isn't so important, but it's very easy for a third party to provide a replacement.
I would say use any of the API's you listed, and the worst that's likely to happen is that you have to rewrite your UI if you want to port your app to metro or Windows on ARM. GDI is a fine choice if your needs are simple and you'll be coding directly for the Windows API. There aren't many situations where I'd recommend GDI+ over OpenGL as a drawing API. GDI+ is slow, limited, and only available on Windows. The GDI+ API is simpler because it's 2D, so maybe it's worthwhile if you need to do something very simple but with anti-aliasing.
OpenGL isn't deprecated, Microsoft's implementation of it is. Microsoft's implementation is stuck at version 1.1, which is old. The current version of the standard is past version 4. If you want to use OpenGL, it is fully supported by NVidia, ATI, and Intel graphics cards on the Windows desktop, but not in Metro Windows Modern UI apps, is an industry standard, and also works on Mac and Linux. If you need a software fallback implementation, Mesa has got you covered, and it even works on DOS. (Since Mesa can render into memory buffers, there's no reason it won't work in Modern UI apps, but you probably don't want to do this because it can be slow.) One thing of note is that WGL, the API for accessing OpenGL functionality on the Windows desktop, depends on GDI (which is deprecated) so you probably want to use something like FreeGLUT or SDL instead if you want to future-proof your application, which also nets you platform independence.
OpenGL ES is a variant of OpenGL which works on Android and Apple iOS. It is also accessible in JavaScript via WebGL, which Internet Explorer 11 will support (and pretty much every other browser already does.) ANGLE provides a hardware-accelerated implementation of GLES for Windows which piggybacks off of DirectX (version 9 or 11) and thus should work in Modern UI apps as well. Once again, Mesa's got the software implementation covered.
TL;DR: OpenGL is not only not deprecated, it is cross-platform, standard, and has tremendous momentum in the industry. GDI and GDI+, well, not so much.
If you want to support Windows XP, then you're supporting a "legacy" operating system, and as such, using a "legacy" graphics framework is the logical choice.
Even if that weren't true, let's just say that I disagree with the advice given by the linked MSDN article. The "legacy" status here has more to do with which technology the Windows team thinks is cool this week. The status designation of "obsolete" just means that the group responsible is no longer accepting or fulfilling bug reports (except for critical security issues). Not too big of a deal—these technologies have been around long enough that they're fairly feature-complete and stable.
GDI isn't going anywhere, so if you need something rock-solid that is guaranteed to be supported anywhere and everywhere, that's what I would go with.
If you need a bit more 2D capabilities than GDI offers (e.g., alpha channel transparency), then you could consider using GDI+. It's nearly an order of magnitude slower than GDI, but that's not too big of an issue on modern machines with more power than you could ever want. This, too, is going to be supported for a very long time to come.
That said, if I were writing a new app today, I probably wouldn't bother with OpenGL. There's very little that it offers in benefits over Direct2D and DirectWrite, which are both what Microsoft is pushing as the replacements for GDI/GDI+. There might be some benefit to using OpenGL if you absolutely must target Windows XP because as far as I can tell, Direct2D/DirectWrite are only supported on Vista and later, but that's because (as I mentioned originally), Windows XP falls squarely into the "legacy" or "obsolete" camp itself. Alternatively, if you already know OpenGL well and don't have time or the desire to learn Direct2D/DirectWrite, then it might make sense to continue using it in a new application.
Don't let the verbiage of the MSDN article scare you. Choose whatever technology makes the most sense for your specific use case given all of the available information. By the time any of these technologies go away completely, you'll have to re-write the app completely for a dozen other reasons.
Edit: Hmm, it looks like DirectWrite has also been declared (by some people at least) "obsolete" as well, having been replaced by Direct2D. That's funny, it hasn't even been around long enough for me to bother learning it. I guess that only goes to support my earlier argument that "obsolete" simply designates that a particular technology is not what is currently considered to be in vogue by the Microsoft devs.
I'm personally waiting until all the bugs get worked out of this stuff (and we decide on a semi-permanent standard) before I make the switch for any of my applications. Everything I've seen written in DirectDraw or Direct2D has had serious rendering bugs and is a performance nightmare, even on reasonably competent machines. Sure, they only show up sometimes, under the right conditions, but that's too much for me. And I swear, the blurry text shows up all the time. Not being able to read what's on screen is a deal-killer for me and my users. GDI doesn't have this problem, and it's not going anywhere.
Are GDI, GDI+ and OpenGL really obsolete/deprecated?
This is not true for OpenGL. OpenGL 4 allows you to use geometry shaders on winxp. Which isn't possible with DirectX (DirectX 10 and up isn't supported on WInXP). It is also one of the only cross-platform 3D APIs out there.
From a business point of view MS is interested in promoting DirectX since it is their technology that lock Developer into windows platform (they're also interested in making DirectX more attractive for developer, but that's another story). So it makes sense that they aren't keen on promoting OpenGL.
What else should be used?
I'd advise to stop using platform-specific tecnologies when possible. Grab cross-platform framework and use it for your application. There's Qt, GTK, wxWidgets and other toolkits for GUI apps, and SDL(and alternatives) for games. This way when platform developer decide to make ridiculous decision (like not supporting DX10 on WinXP) you dislike, you'll be able to move elsewhere with minimum development cost. Qt is also ridiculously powerful and at the moment I have no reason to use something else for GUI development. Still, situation can change in the future.
In short, while developing for certain platform you should keep in mind that platform developer might have their goals that are not compatible with your wishes. Discovering that your source has become locked into single platform isn't very pleasant experience. Your own goals should be the first priority, and if os developer tries to make you use certain technology you don't like, then you shouldn't support that technology.
Because OpenGL is a standard, it should be considered equally deprecated as C or C++ so it is a matter of time before the entire Windows API -- which today has become a compile once run on every x86 machine API thanks to Wine -- is considered deprecated in favour of .NET and C#.
I use GDI for simple graphics and OpenGL, when I need accelerated 3d.
Another aspect is that Microsoft's build-in implementation of OpenGL is definitely to be considered as deprecated since it is just version 1.1 or something, but that has been for a long time.
Yeah, about OpenGL, it actually outperforms DirectX in many ways both resource and display wise. It will never be promoted by Microsoft because it can't own OpenGL, not to mention most people don't do their research and Microsoft can claim it is old. Truth is opengl is opensource standard and evolves at a much faster rate than closed does because it is more than 1 room of developers paid to work on it. Also Microsoft has contracts with many companies to release using only Microsoft's software, this causes more business for Microsoft and less to use the more advanced OpenGL standard. It is a interesting lock up if you will, Microsoft creates these contracts so that many programs are written in DirectX to keep business for Microsoft, and no company will refuse it because Microsoft has about 80%+ home user market.

What version of DirectX should I use to make a 2D desktop GUI application?

I want to make a 2D desktop GUI application with DirectX but I don't know which version to use. I initially tried Direct2D but it never really gained popularity, thus there isn't a lot of community support or documentation for it compared to the rest of DirectX, so it's not an option.
So I have three options:
DirectX 9.0c
DirectX 10
DirectX 11 (not 11.1, I'm not getting Windows 8)
A knowledgeable friend of mine strongly encouraged DirectX 9.0c saying that's all I need, but I am wary of using an 8-year old platform. Microsoft is pretty much the zenith of legacy support but I think that they must have a limit. I have no idea of the difference between DX10 and DX11.
Keep in mind that I'm very much a novice programmer so this is mostly a learning project.
Any advice is appreciated!
Edit: I'd also appreciate advice on any significant differences in functionality or programming paradigms between the versions.
What version of DirectX should I use to make a 2D desktop GUI application?
DirectX 9, because you'll get more users.
A knowledgeable friend of mine strongly encouraged DirectX 9.0c saying that's all I need, but I am wary of using an 8-year old platform.
Many DirectX 7 and DirectX 5 games still work just fine, not to mention titles that use DirectDraw. So there's no problem with 8-year old platform. Using newer (than 9) version might not even benefit you, so blindly going for higher version number isn't a good idea.
Depending on your circumstances you could also consider using OpenGL but that choice makes sense only if your app has to be cross-platform. If you know that application will be windows-only, then choosing DirectX 9 makes sense.
Microsoft's primary commitment is to its Windows customers. Who still run 15 years old games that use whatever DirectX version was in use back then. IDirectDraw is alive and well. Clearly you'll benefit from that as a developer secondarily. And sure, DX 9 is most widely supported by hardware so that's an excellent choice. Consider something higher if your game performs poorly on old hardware, the DX version is an automatic selector.
Are you writing this for work, or for fun?
If it's for work, then you have to go by the minimum system requirements that someone in business or marketing has defined. If your minimum OS can be Win7 or Vista SP2 w/ Platform Update, then Direct2D is a viable option. Otherwise, DX9 is the way you have to go.
If it's for fun on your own personal time, then do whatever you think will be the most fun :) Direct2D will certainly be MUCH easier to work with if you just want to do 2D graphics. I wouldn't worry much about the "it hasn't gained popularity/community support" angle, especially because it's being used by all the major desktop apps nowadays (Firefox, Internet Explorer, and even the next version of Paint.NET). Also, Win8 will update Direct2D with a whole bunch of interesting new features (and this update will also be available for Win7 from what I understand).
Direct2D can be clumsy to work with at first, but that's mainly due to all the COM stuff. Once you get used to it and build up your own little utilities warchest, it's really not any more complicated than GDI+. In fact, I've been able to port a bunch of old GDI+ code to using Direct2D/DirectWrite and often it's just a line-by-line substitution, e.g. SolidBrush -> SolidColorBrush (this is in the Paint.NET 4.0 code base, btw).
I used the Direct 2D to render graphs of functions and it's pretty easy to use - I'd say, as simple as GDI+. I'd guess, that level of complexity of DirectX 11 and DirectX 9 (in terms of 2D graphics) is quite similar, so don't worry about that.
DirectX 9.0 runs on (let's say) all modern computers, and 11 restricts you to Windows Vista (with platform pack) and Windows 7. Take into consideration, though, that Windows XP will eventually vanish and DirectX will evolve, so I'm not sure, is it worth investing your time into technology, which won't be developed anymore. I would suggest DirectX 11's Direct2D then.

Win32: Is there a replacement GDI32.dll that uses hardware acceleration?

Has anyone out there created a version of GDI32.dll that takes advantage of hardware acceleration available on the machine? gdiplus.dll?
Starting with Windows Vista, GDI is no longer hardware accelerated. (GDI+ was never hardware accelerated). Without Microsoft fixing GDI (and GDI+) to be able to run well on the computer: native applications (C++ MFC, Delphi, etc), and managed WinForms applications, will continue to run poorly forever.
While i could use Direct2D for business applications, i cannot control the fact that the development environment still creates controls, with decades of library support code, that assumes the presence of GDI.
Application Compatibility: Graphical Device Interface (GDI):
GDI primitives such as LineTo and
Rectangle are now rendered in software
rather than video hardware, which
greatly simplify the display drivers.
Windows And Video Memory
In XP GDI is GPU accelerated to
various degrees depending on how the
OS is configured or the device driver
(for details see Hooking Versus
Punting).
In Vista, GDI is not GPU accelerated
Comparing Direct2D and GDI
As a result, in Windows Vista, the GDI
DDI display driver was changed to be
only implemented by a Microsoft
supplied driver, the Canonical Display
Driver (CDD). GDI rendered to a system
memory bitmap. Dirty regions were used
to update the video memory texture
which the window manager uses to
composite the desktop.
It seems that Vista was a special case in the history of GDI performance.
Both articles below show that the future for GDI looks bright again.
http://msdn.microsoft.com/en-us/library/ff729480%28VS.85%29.aspx
GDI is hardware accelerated on Windows
XP, and accelerated on Windows 7 when
the Desktop Window Manager is running
and a WDDM 1.1 driver is in use.
Direct2D is hardware accelerated on
almost any WDDM driver and regardless
of whether DWM is in use. On Vista,
GDI will always render on the CPU.
http://blogs.msdn.com/b/e7/archive/2009/04/25/engineering-windows-7-for-graphics-performance.aspx
Based on real-world application
statistics, ... we worked with our
graphics IHV partners to provide
support in their drivers to accelerate
the most commonly used GDI operations.
Well, yes, GDI is the "it works anywhere anytime" API for rendering graphics. It puts very low demands on the video driver. Everybody got that right a long time ago. Which took a while, I got a distinct memory of a ATI Mach video card that gave me no end of trouble. It stopped me from buying ATI products for quite a while.
Everybody got DirectX right a lesser long time ago too. It is being taking advantage of in the WPF rendering model, it completely relies on DirectX to get the job done. Milcore is the shim name. You won't get it until you buy into the WPF programming model.
What do you mean by hardware acceleration?
I mean, GDI doesn't do a lot other than raster blits, but those were hardware accelerated. And, given that Vista and Windows 7 arn't terribly slower with desktop apps, still are.
GDI still gets the video drivers to do all the heavy lifting, so if GDI isn't hardware accelerated, then its the driver vendors fault, not GDI's.

What percentage of Windows boxes have OpenGL support [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I've been thinking about starting a new graphics project and I want to use Java. Java has wrappers for all of the relevant GL functionality but I wonder how many people, including casual users, actually have decent GL drivers installed. By decent, I mean somewhat stable and fairly new (GL 1.5 support would probably do although the GLSL support that comes with 2.0 would be great). I could DirectX, even with Java, but I pretty much hate it and this project is supposed to be 'fun'. Also, I like the at least near-cross-platformedness of GL. So, anyone know of any non-imaginary stats on what percentage of Windows users have the drivers to run a GL app?
The Steam Hardware Survey is probably the best and most detailed source for info about what gamers have. Accurate statistics for the general population will be harder to come by. Instead, you should look at this in terms of how recent you want the graphics hardware. For example, any ATI chip from the R300 series (Radeon 9550+) onward supports OpenGL 2.0. On the NVidia side, any GeForce 6000+ series chip will support OpenGL 2.0, and their predecessors, the FX series, almost supported OpenGL 2.0. The R300 series and the FX series were both introduced in 2002, so if you know what portion of your target market is using a PC from 2003 or later, you'll have a fairly good idea of how widespread OpenGL 2.0 support is among users with discrete graphics.
If you want to support integrated graphics (which are the largest segment of the market, but aren't particularly common with those who are serious about graphics of any kind) your users will need at least a GMA X3000 for hardware acceleration of OpenGL 2.0 features, which means their system has to be from 2006 or later.
If you're interested in support on other operating systems, any Intel Mac will support OpenGL 2.0 with software fallbacks, and hardware acceleration whenever the chip would support it under Windows. On Linux, any system with Mesa 7 or later (June 2007 or later) will support OpenGL 2.0 software rendering. Hardware acceleration is less reliable, but there are decent open-source drivers for ATI chips from R300 and newer.
Every modern day video card supports OpenGL ... Shouldnt you be questioning how many Windows boxes have the Java runtime?
As I recall, Windows XP comes with 1.1 support out of the box. Vista upgrades this to 1.5. So you can at least count on those as an absolute minimum.
Apart from that, the GPU drivers from pretty much any vendor gives you at least 2.0 support.
But if I were you, I'd reconsider DirectX. I don't know what you hate about it, but it does have some advantages. The tool support is vastly better (ie, there are tools available. And PIX is nothing short of amazing), the API is up to date, and well designed, rather than accumulated over 20 years of a committee working at cross purposes, and if this is limited to Windows anyway, cross-platform doesn't really matter. (On the other hand, of course, if you do need cross-platform capabilities, it doesn't really matter what else DirectX can offer, it won't deliver that one killer feature)
Nearly everybody has SOME form of OpenGL support. Experience has shown that the actual drivers involved can be quite poor when dealing with ATI and especially Intel hardware, but it will at least work, aforementioned bugs notwithstanding. If nothing else, Windows can fall back to its built in 1.1 (XP and earlier) or 1.4 (Vista and higher) implementation. It won't work well, but it will work.
Windows XP comes with OpenGL 1.1 (quite slow though). Windows Vista also comes with OpenGL 1.1 (but for some special applications it has OpenGL 1.4 emulator on top of D3D).
When you install a graphics driver on Windows, it installs a more OpenGL version. OpenGL 1.5 is roughly "DX9 shader model 2.0" capable hardware. How many machines have that kind of hardware depends on your target market. In traditional/hardcore games space, almost all will (see Steam Hardware Survey).
In more casual/small games space, quite a lot of machines have much older hardware (see Unity Hardware Stats - almost 30% in 2009 Q1 are older than "DX9 shader model 2.0"). Also, a lot of machines in that space do not have custom drivers; they use whatever display drivers are shipped in Windows (which do not provide anything more than GL 1.1). Again, see Unity Hardware Stats - the most popular driver versions are the ones that come with Windows.
Stability wise, I'd strongly suggest using D3D9 on Windows instead of OpenGL. Driver quality is much better for D3D9 (less crashes inside drivers, less incorrect rendering, better performance, ...).
I'd say that all Windows users have some support for OpenGL. The latest versions usually are reserved for Vista users, gamers, and developers.

Resources