DirectX sample code c++ - directx-11

I'm looking for source code (as I bet a lot of others are / were and will) for learning purposes of DirectX. I would like something similar to the vs2013 Graphics Editor when dealing with *.fbx files, etc. Every thing I find is old and outdated, or way to simple and does not show the basics like transformation cursor, picking objects or points on objects. I'm just looking for something basic.
many thanks in advance

The DirectX Tool Kit is a good place to start and includes some tutorial content as well. It supports loading models using the VS 2013 content pipeline that produces CMOs from FBX files.
You didn't state if you were looking to write a Windows desktop application (aka a Win32 application) or if you were looking to write for Windows Store / Windows phone. DirectX Tool Kit supports either, although the tutorial is written using a Windows desktop application template so that developers using Windows 7 could also utilize it.
You should also refer to the DirectX SDK Samples Catalog for locations of updated versions of the legacy DirectX SDK samples that build fine using VS 2013 only.

Related

DirectX 11 & Windows SDK: any modern project setup tutorials for Windows 7?

Note: I just wanna say at first that I tried literally everything I could find about the subject (MSDN, Stack Overflow, D3DCoder, etc.) without any success (after solving one, another error was waiting for me). So I am posting here by pure demotivation (there are similar posts already, yes, but none of them actually helped me out).
Here is how it goes:
A few months ago, I decided to start learning modern OpenGL by pure curiosity, and finally decided to switch to DirectX after reading the downsides of OpenGL (I was also only targeting Windows platform). I think it was one of the worst move I ever made: I heard that OpenGL was lacking of documentation and everything was a mess with third party libraries, but I realized that DirectX was way worst than what it seemed to be compared to OpenGL. In fact, trying to code in modern DirectX 11 using Windows 7 and VS2013 is just a pain (especially shaders) and the time it takes to figure it all out is just a time waster. After reading a lot of porting articles on MSDN about alternative libraries, like DirectXTK, DirectXTex, DirectXMesh, Effects11 and DXUT, I still don't know what to do and how to setup a fully working modern project in Windows 7. Specifically, the 5 (/5_0) shader model (deprecated) combined with the new Effects11 library (not deprecated) is the thing that confuse me the most.
By the way, I am currently reading the latest Frank Luna book about the subject ('Introduction to 3D Game Programming with Direct3D 11') and I still can't get his samples working at all (even with DirectX SDK). Also, I don't know if what I am learning is relevant or not since he wrote it before the Windows SDK switch. For your information, the latest error I am trying to solve with his samples (for those who know the book) is a E_NOINTERFACE from D3DX11CreateEffectFromMemory function (at runtime):
HR(D3DX11CreateEffectFromMemory(compiledShader->GetBufferPointer(), compiledShader- >GetBufferSize(),
0, md3dDevice, &mFX));
// Done with compiled shader.
ReleaseCOM(compiledShader); -> crash here
All that being said, here is what I wanna know:
Are there any clear step-by-step tutorials on how to setup a modern DirectX 11 project in Windows 7 using VS2013 or it is still in pre-alpha stage (just kidding)?
What is actually going on with the shader model, the HLSL compiler, and the .fx files and what should be used (I hear everywhere that it is deprecated but no replacement seems to exist yet)?
For those who know the book, any idea on how to build the old DirectX SDK samples without getting this silly runtime error?
Thanks a lot!
E_NOINTERFACE is an usual error in that context, so likely there's something wrong with the code around it you are not showing in your question.
You can still use the legacy DirectX SDK with VS 2013, but it takes a slightly different procedure than was used with VS 2010. In VC++ Directories set Executable to $(ExecutablePath);$(DXSDK_DIR)Utilities\bin\x86 or $(ExecutablePath);$(DXSDK_DIR)Utilities\bin\x64;$(DXSDK_DIR)Utilities\bin\x86, Include to $(IncludePath);$(DXSDK_DIR)Include, and Library to $(LibraryPath);$(DXSDK_DIR)Lib\x86 or $(LibraryPath);$(DXSDK_DIR)Lib\x64. Read MSDN for some other details of doing this. I've also made some notes w.r.t. to that book here.
You actually don't need the legacy DirectX SDK, but you may find it easier to do that for now using that book. VS 2013 comes with the Windows 8.1 SDK that has all the OS headers for DirectX 11 along with D3DCompile #47.
You can use the Direct3D tutorial for a simple example of setting up a Win32 desktop app (i.e. one that works on Windows 7) with a device, swapchain, and window. This makes no use of legacy DirectX SDK.
There are some additional Effects Tutorial Win32 Sample you can use as well. Instructions on adding the Effects 11 library is on the CodePlex wiki under Documentation / Effects 11 / Adding to a VS solution.
Your questions about FX vs. not are also covered on the CodePlex: Is Effects 11 deprecated? and How do I avoid using fx_5_0?. Also on StackOverflow.
Many of the older DirectX SDK samples have been reposted to MSDN Code Gallery and do not require the legacy DirectX SDK to build. You should read these posts for the fate of various DirectX SDK things:
DirectX SDK Samples Catalog
DirectX SDK Tools Catalog
Living without D3DX
DirectX SDKs of a certain age
The story for learning DirectX 11 with Windows Store apps / Windows phone 8.x aps is a lot cleaner, and is well supported by VS templates and MSDN documentation. Win32 desktop apps are of course a completely reasonable option, but you have to distinguish between legacy and modern with a bit of research. You still start with the standard Win32 desktop app project template in VS.
Note: Windows by default only supports OpenGL v1.5 software renderer. You have to install 3rd party ICD to get anything else, and there are no OpenGL VS templates.

What's the main developing framework for the next Windows?

Some articles point to Windows 8 development being HTML-based instead of primarily using native code like C or C++ (as it has been until now) or .NET (as now, or even more so as it would have been in Longhorn, but never was.)
Is this true? Will the core APIs be accessible from Javascript then? What is the primary API / framework for Windows 8?
This is worth asking. When Windows 8 was demonstrated in June, a couple of comments by the presenter scared quite a few developers - or at least turned the Internet into panic mode. I'm surprised this question hasn't been asked here before.
The best article on the topic I have found is Windows 8 for Software Developers on Ars Technica.
The short answer is: it will remain the same.
The long answer is: it will remain the same, but several things will be added. You may want to pursue using those if you're willing to bet on new Microsoft technologies. One particularly interesting one is WinRT, which is a new object-oriented native code API exposed through COM, which is supposed to be a new version of the old flat Win32 API. Details are in the linked article.
It is very, very, very, very unlikely that anything that already exists, especially based on Win32 or .Net, would be removed. That means your existing programs written in .Net or native C++ or Delphi will continue to work fine. It is also unlikely that the primary development platform will be HTML. More likely is that HTML applications will be encourage for specific scenarios - perhaps touchscreen, kiosks and tablets.
I'd encourage you to read the article I linked to above - it covers this in far more detail than any answer here can.
There are three ways to develop for Windows 8, and they all access the same underlying API, the Windows Runtime.
Use C++ and call WinRT functions much like calling Win32 APIs back in the day (you know, yesterday)
Use C# or VB and call what appear to be .NET methods (but aren't)
Use Javascript and call WinRT functions
The UI is built with XAML using a pretty reasonable designer. More details are still coming out: check http://channel9.msdn.com/Events/BUILD/BUILD2011 for videos with detailed coding demos. http://channel9.msdn.com/Events/BUILD/BUILD2011/BPS-1005 is not a bad starting point.
There are 3 language/framework combinations that are all equally supported:
C++ and XAML
C#/VB and XAML
JavaScript and CSS/HTML
All are first class ways to write Windows 8 Metro style applications. Windows Runtime provides direct access to each of these languages and so choice of development environment can be based on familiarity or feature set of the language and not on restricted availability.
Update: I forgot one: C++/Direct3D (for games).
The original quote, in the context of writing a tablet desktop weather gadget application, is that the application uses "our new developer platform, which is, uhh, it's based on HTML5 and JavaScript."
The demonstrator never said a gadget is the preferred type for applications (How many Vista sidebar gadget or Windows 7 desktop gadget have you written in your life? Even when you can write them in simple HTML!), or the platform is the preferred platform for desktop weather gadget applications (How many animation control have you add to your application with video playing requirement? It is THE control used by Windows Explorer to display video!).
Today, after spending a few minutes playing with Windows 8 developer preview, I found that you can use Expression Blend 5 to easily auto-generate metro-styled applications in HTML and Javascript. Also in Visual Studio you can create exactly looking applications in Silverlight. :)
I am very excited!!! Go Windows 8! :)

MS Windows Programming advice for Mac/Unix developer

I have a few years of experience writing Unix command line tools (no GUI experience) in python, C and C++, and only recently crossed into the GUI world (Cocoa and IOS only). I've learned quite a bit of objective-C and am getting to understand how cocoa MVC works. However, one of the apps I am developing needs a Windows version and I was wondering what a good place to start would be given that I have absolutely no Windows development experience.
I was thinking about using Visual C++ 2010 Express as my development platform (because it's free and because I don't need to learn C++). My application is relatively simple, it will have only two windows and spend most of the time running in the background. It will however need to communicate with the OS (load dll's etc) and an online server (HTTP methods) and I'm not sure whether Visual C++ Express edition gives me access to the required API's. Would a Windows Forms application suffice? Am I going about this the wrong way? Do I need to learn C#? Any advice will be appreciated.
If you are already happy with proper c++, visual Studio C++ express should suit you fine. Given that you are not making a complicated GUI, you don't even need to dip into the managed code - C++ express allows you to create proper c++ console and GUI apps. You also don't need to install the platform SDK - it is part of VS C++ express.
Not being managed C++, you will be able to share source files between your various projects. managed c++, despite the c++ in the name, really is a different enough language that it will be annoying to work with if you simultaneously have to deal with iso C++.
--
Note: The native windows API is a C api, not a C++ framework. So it does not provide a rich set of classes in a coherent framework to deal with. On the other hand, while, large, it is actually quite simple to work with.
Also: Given that you are already familiar with Mac development, there is a LGPL (iirc) package called CFLite that builds on windows and that implements the C api that underlays the Objective-C Cocoa API.
If you use its abstratcions you can share a greater part of code between windows and Mac (and other platforms).
Other C++ IDE's you might want to consider:
Code::Blocks
QT Creator
both of which can be configured to use the MINGW port of GCC to windows.
you'll be better off with c++ than c# if you need more "low-level" stuff. Loading dlls (that is, libs) is simple (pragma comment lib...), as is pure HTTP transfer and communication.
So, VC++ with windows form will suffice, and it is "very c++".
You have access to all global APIs, and loading specific apis like http requires only two lines: one to include wininet header, and other lib (libs are actually "references" to dlls).
If you go the C++ Express way then you need to install Windows SDK separately, and set it up for Visual Studio to use it. And you can't use MFC.
I would however, suggest C#, because it feels like putting little toy bricks together. Easier to debug and maintain. Problem with C# is that it has so many library functions that you can not possibly know if what you want is already made to a function. But that's why we are here :-) If you feel that something you want to do should already exist then ask a question about it. One notable feature that C# lacks is zip archives (it has something similar, but not quite). For zips you can use public libraries, like SharpZipLib or DotNetZip.
If I were you, I wouldn't jump into a whole new API so quickly. Have you considered using Python on Windows? Most of the Python packages I've seen are also available for Windows, so you'll feel at home. And if you need some GUI, you can opt for wxPython, pyGTK or something similar.
For Windows specific things, you can always use ctypes. Especially if they're as simple as loading a DLL.
have you considered approaching Adobe AIR? it allows you to deploy on Mac, Linux, Windows, iOS, etc. communicating with and launching native processes has been possible since 2.0 and the the latest 2.5 SDK can target Android OS and TVs. with your experience you should be able to pick up ActionScript3 / MXML in no time.
additionally, there are a handful of free IDEs you can use with the Flex and AIR SDKs. or, if you're a student or low-income developer, you can get a free copy of Flash Builder 4 from Adobe: http://www.adobe.com/devnet-archive/flex/free/
edit: i believe deploying AIR applications on iPhone requires Flash Professional CS5, which includes the packager for iPhone options. at the same time, i've read that AIR and other cross-compilers for iOS are painfully slow, so it's perhaps best to develop natively in Objective-C for iOS.

Windows Phone 7 and native C++/CLI

Microsoft recently released tools and documentation for its new Phone 7 platform, which to the dismay of those who have a big C++ codebase (like me) doesn't support native development anymore. Although I've found speculation about this decision being reversed, I doubt it. So I was thinking how viable would be to make this codebase available to Phone 7 by adapting it to compile under C++/CLI. Of course the user interface parts couldn't be ported, but I'm not sure about the rest. Anyone had a similar experience? I'm not talking about code that does heavy low-level stuff - but there's a quite frequent use of templates and smart pointers.
c++/cli can theoretically be used with WPF/Silverlight using the trick of replacing the C# generated from the XAML with a macro definition that can be used inside the main class in a code behind file. I worked out this technique but haven't had the motivation to take it beyond theory - I'm quite happy mixing languages.
As far as using c++/cli in a pure safe mode for your logic code, this may still not be possible but I'd love to hear how someone goes trying it now. Whilst researching it for Silverlight back in 2008 I found this daunting silverlight forum comment:
I just gave Silverlight&C++ it a try by compiling the MSIL from my C++ project into a Silverlight-compatible DLL. The good news: it works, and you can call this code from a Silverlight project. The bad news: The C++ compiler apparently uses MSIL instructions that Silverlight disallows.
So, if you try this, even with the simplest of programs, you'll almost immediately get the exception "Operation could destabilize the runtime." To me, this makes it seem less likely that we'll see Silverlight for C++ soon, as the compiler will need to behave quite a bit differently.
You can generate verifiable managed code in C++/CLI using the /clr:safe option. The problem is that most of your normal c++ code will not compile with that option.
C# is currently the only supported language for WinPhone7.
I fully expect that MS will add support for VB and C++/CLI in the future too, but don't expect to open up the native-code kimono anytime soon.
Native code just has too many issues to overcome, specifically around security, reliability, etc. Managed code is FAR easier to statically verify and FAR easier to control while running.
If you're upset about porting C++ code to C#, just be glad MS didn't force you to have to move to Objective-C ;)
From our own experience, the proces of porting well-written C++ to C# actually takes a lot less effort than one might at first expect. Sure, there's a learning curve, but you have that with any port. We actually got so much benefit from porting our core app and data engines to C# that we re-tooled our entire team to code in C# and port our C# back to C++ where necessary rather than the other way around! So far, we've only ported two modules back to C++ and call our C# code from our native code via interop instead.
Again, remember, WinPhone is a brand new platform using best of breed, highly-productive, next-generation development tools and platforms. It is not your father's WinMo.
If support for C++ is something you find to be crucially important, then make sure MS know - (respectfully and professionally) state your position in the MSDN forums and at developer events near you.
Update1: 2012-12-17:
While native C++ still isn't officially supported for Windows Phone 7, Windows Phone 8 now supports native C++ code so you can more easily port your existing C++ codebase(s) to Windows Phone 8 (as well as Windows 8 and Windows desktop apps).
While there isn't 100% compatibility between the Windows8/Phone8 platforms and API's right now, I expect the two platforms to become increasingly integrated over the next couple of releases.
This is especially true now that one of the key barriers to closer cooperation between Windows and other groups at Microsoft recently left the company ;)
Update2: 4/15/2014:
As per the recent announcements at //BUILD/ 2014, you can now start building "universal" apps in C++ & XAML, C#/VB & XAML or JavaScript & HTML that will run on Windows 8.1, Windows Phone 8.1 and Xbox One! For more details on building Windows Phone 8.1 Universal Apps, read this article.
The whole development idea is built on Silverlight. I think you can add your managed dll written in C++ without any problem to this Silverlight project, but it could not use native code.
I am planning to install the tools on my machine tonight and will try this out.
It is fine if MS decides to leave the path and create something new, that is MS' decision. So let's face the facts. Silverlight is no success yet. MS lost significant share due to Apple, Android and RIM. Application developers simply have to evaluate the business case for their own applications and decide if they trust in a share gain of Windows 7 phone or not. For the company that I run, we decided not to support any more MS Windows phone 7, not because of this or the other technical reason, but just because that we don't believe in the return of our investment for the port.
We start supporting Apple, Symbian, Andoid and MeeGo in the future if we see a market success of this new platform. All support C/C++ and enable us to reuse our proven application cores. So why worry at all. Personal technology preferences should not be gating. If personal preferences worry, then I would kick MS out for their to me ugly looking UI.
Thomas
It is on the horizon finally!
So a survey sent to windows phone developers about their future
development preferences and XNA isn't mentioned once in the Survey (A
survey sent to windows phone developers - did I mention that)
They do however ask:
How would you prefer to use C++ in your mobile apps/games?
Develop apps/games that are C++ from top to bottom (UI, business logic, and platform
APIs)
Use C++ for business logic and then write platform abstraction layer
Use C++ for business logic use 3rd party runtime engines
I don’t want to use C++

Windows API GUI programming

I'm working on a Project with outdated, very old looking GUI (the used GUI framework is more than 10 years old)
Since the used programming language is Eiffel, there are almost no good libraries for GUI development. Although Wrappers for C libraries exist, it's not that easy to wrap something like Qt with them.
The current GUI framework uses the Windows API to create windows, widgets and so on. But as stated - it's very old.
Now i would like to learn more about how to use the Windows API directly to create state of the art GUI's
Can someone recommend any reading material?
"Windows Programming" by Charles Petzold is an excellent start on Win32 API programming.
It won't show you how to create a WPF-grade interface but it will show you how to create a basic average application.
It doesn't take a lot of surgery to turn on Windows Visual Styles and get an instant new look. If your toolset doesn't allow creating resources then take a look at mt.exe in the Windows SDK.

Resources