Metro style app with DirectX portion - c++

Will the Windows 8 APIs allow me to write an app that uses XAML for the UI and DirectX for rendering 3D objects? Say I am writing a 3D modeling app. There are a lot of dialogs and UI elements that I would like to make in XAML, and a single rectangular window that I would render with DirectX. I prefer using C++. Is this possible?

Good news! It seems that the release version of Windows 8 will allow Metro/XAML and DirectX Interop!
This is a common theme that we heard after we released the Developer Preview. Developers like you wanted to combine the high-performance immediate-mode rendering capabilities of DirectX with the rich interactivity, control model, and design-time experience of XAML.
We heard you. With the Consumer Preview, you can now smoothly integrate XAML and DirectX 11 in the same Metro style app to create a fast and fluid experience. For example, you can now create a DirectX game and use XAML to process input, create graphics for heads-up displays and menus, or bind to your app’s data model.
To this end, we added 3 new XAML types to support a broad range of DirectX interop scenarios, each with different capabilities:
SurfaceImageSource enables full composition of DirectX content into a XAML app. This allows drawing DirectX content into the XAML
visual tree, useful for complex image effects, data visualization,
and other immediate-mode drawing scenarios.
VirtualSurfaceImageSource is used for large-scale virtualized content. This is targeted toward apps that require panning and
zooming of large content, like maps and document viewers.
SwapChainBackgroundPanel targets full-screen, DirectX-focused scenarios. This is great for games and other low-latency, full-screen
DirectX apps with a XAML overlay.
Source
Take a look at this msdn page for more detail.
Depending on how well (or badly) this turns out, you still have the option of abandoning Metro for WPF, because WPF and Direct3D can interop.

Related

Which graphics technology does Qt uses to render its custom UI?

I inspected the Qt GUI interfaces using window spy tools and I know that it does not use windows common controls or any custom window class to create its UI elements and animation effects. I asked before here about developing a custom GUI framework using GDI/GDI+ but most people responded against these technologies, so the question remains which graphics technology Qt or any other equivalent appropriator system uses to render their UI?
I am aware of DirectX/OpenGL but isn't it overkill for simple requirements? If the answer is going to be one of the above then again I wonder how one could implement robust font rendering and vector graphics solutions with these polygon rendering technology? the full featured text editor is another huge challenge.
Also there already exists solutions based on directx/opengl like MyGUI and CEGUI but I think they look ugly and nowhere near how Qt looks.
First things first, Qt-5 introduced a new rendering model, which can (but is not required to) use OpenGL for rendering the UI elements. The upshot of this is, that one can truly mix custom OpenGL rendering with Qt widgets. The downside is, that some kind of OpenGL support is required, which not all systems have.
So Qt also has these two other drawing systems: Native, which will use the hosts systems native graphics primitives (GDI, CoreGraphics, X11/XRender) and raster which does a complete rasterization of a whole window into pixel buffers, where then only those are blitted over to the underlying graphics system. raster is the slowest of the graphics backends, but it gives consistent results for all plattforms and target systems. Hence raster is usually used for programs where consistent appearance is strictly required.

OpenGL in WPF via ActiveX?

I plan to embed an unmanaged C++ OpenGL viewer in WPF. The requirements are (apart from robustness and ease of development)
proper resizing
context menu for the OpenGL viewer area (only for viewer related actions)
events (e.g. triggered by selection of an object in the OpenGL viewer)
WPF dialogs should be drawn on top of the OpenGL space
So far I've found some blogs and discussions about using a hosted WinForm control (via C++/CLI wrapper), but it seems to be bit tricky (even a bit tinkery) to get all my above requirements done (if possible).
How about creating an ActiveX control? Despite having no experience with creating an ActiveX control, one advantage would already be that it runs in its own process.
Is it a good idea or would I run into even more tinkering?
EDIT: I should be clearer about the OpenGL viewer. It's an existing app based on an C++ 3D engine which only supports OpenGL. Porting to an DirectX capable engine is considered as last resort.
Although I didn't use ActiveX, I've accomplished what I believe you are trying to achieve. Two pieces of information helped me down this road.
Mixing Managed and Unmanaged code
It turns out, that managed C++ compiles completely differently than unmanaged C++, and data is stored on a completely different heap. Luckily you can mark sections of code as managed or unmanaged by using...
#pragma managed
#pragma unmanaged
See more info at this article
OpenGL context management
I followed a method similar to what's described in this article
wglMakeCurrent and wglShareLists will be your buddy if you need to manage multiple OpenGL windows
Good Luck!
Why you want an activex? There is some managed PInvoke based wrappers as SharpGL doing the job you need easyear.
But also, since you are using WPF and you have a Viewport3d object,why don't use it? If you are familiar with 3d engines you will appreciate the semplicity ( even if there is some drawback in term of speed).
Another point, since as per this question here I was forced to abandon WPF 3d rendering in favor of OpenGl due to the fact that Opengl can render in session 0, by using pure software mode. This is a requirement if you are planning to render something in off-screen bitmaps from a service or an asp.net application.

What native API is recomended by Microsoft to render 2D graphics?

According to MSDN's listing, GDI and GDI+ are both legacy. So when writing an application using the Windows API, what should you use to render 2d graphics?
Direct2D, WIC, DirectComposition (this is new to me), GDI+, GDI?
Note: not 2d games - just 2d images.
Either GDI or GDI+ are fine choices for basic needs.
The OS still uses GDI all over the place, so I'm not really sure what they mean by "legacy". Words like that generally don't have a meaning, so you shouldn't feel too bad ignoring them. The person who labeled these APIs "legacy" is probably one of those people who tell you that all of Win32 is legacy without realizing that these "modern" GUI frameworks that they love so much are built on top of Win32 and wouldn't be able to function without it.
Use GDI+ if you need the extra features it provides (such as transparency, etc.) and/or if you're programming in C++ and prefer its class-based API to GDI's flat C-style API. But note that if your app uses GDI+, you will have to redistribute the Gdiplus.dll library to users running Windows 2000 and earlier versions. GDI-based apps will always work out of the box.
That's not to say that you shouldn't investigate the new contenders. Supposedly, Direct2D is designed to interoperate well with GDI and GDI+. Only problem is, lots of developers are not in a position to require all of their clients to upgrade to Windows Vista or later. Supporting XP still seems like a worthwhile goal (at least providing a minimal subset of functionality for those users), and that's not really possible if you write the entire UI in Direct2D or one of the new fancy frameworks. I haven't really seen the advantage of switching to Direct2D for standard, line-of-business apps (I'm sure there are advantages for games and other programs that need 3D effects). You might be interested in the following comparison between Direct2D and GDI, which are both two-dimensional, hardware-accelerated graphics APIs.
Unless you really have to support XP (let it die already!), I would highly encourage using Direct2D. There are multiple reasons why Direct2D makes sense for all new developments:
generally faster rendering (aliased and anti-aliased rendering)
since Vista was introduced, GDI is not HW accelleration is highly crippeld (due to the new drivermodel)
better integration with Direct3D (if you need it), DirectWrite, DirectComposition, etc.
better utilization of new GPU features
many bitmap effects pre-built-in
GDI is not allowed for Metro-Style apps
Therefore, I would suggest anybody, who is beginning a new application to use Direct2D instead of GDI/GDI+.

Curiosity: Background C++ windows. Difference between SFML/SDL type and Qt (GUI) type

I was wondering what is the difference between the windows that will render images on the screen (such as SDL, SFML or OpenGL) and the classic GUI window (with the gray background by default) where you can implement buttons like in Qt for C++ or AWT/Swing in Java?
What is going on in the background code? Are they the same type? Is there a rendering layer over the graphics window allowing to display such images?
Well first of all they are different APIs. SDL and SFML are libraries directed at making games and quite possibly other applications. OpenGL is a graphics API, it is not a full suite of libraries.
Note also that SFML pretty much uses OpenGL to render to the window. The actual window its self is created via platform specific functions. The Win32 API is used for windows and the X11 Window System is generally used on Linux.
The "classic GUI window" is pretty much the platform specific APIs. The differences in background code is really just defined by the purpose of the API. Note that in the end of the line Qt/SFML/SDL all go down to the platform specific API. OpenGL even requires you to interface with the platform specific API. SFML/SDL/QT essentially do the lower level work for you.
I hope I gave what you are looking for as this question really has a wide range of answers.

What are some good GUI controls for directx c++?

I need GUI controls that is simple to initialize.
I think you can use the standard WinApi controls on top of DirectX window, at least with OpenGL you can. WS_CHILD on control, WS_CLIPCHILDREN on DirectX Window. Or just use regular window and initialize DirectX scene in sub-window.
Was this what you were looking for?
From MSDN:
"The DirectX Utility Library (DXUT) is a framework used by most of the Direct3D tutorials and samples and is built on top of the Direct3D 9 and Direct3D 10 API."
and...
"DXUT also include a set of textured GUI controls, including an IME-enabled edit box, extra classes such as simple camera types, and a high-resolution timer class. DXUT is designed to be modular, so the application can use all of the DXUT features or just the parts desired."
DXUT has plenty of good UI controls to get you started. All of the code is open for modification as well, so you can copy what you need. The controls are also very easy to initialize. For example, once you have the framework set up, you simply call "AddButton()" and pass in a few parameters.
For a professional project though, I would recommend either writing your own controls or looking at some of the popular frameworks, like Crazy Eddie's GUI System.