Direct3D in Windows 8, extremely seriously simple code

See my blog at: List of 6 things that can get you started with Game Design to get some ideas on how to get started with the DirectX 11 changes in Windows 8.  Also see Frank Luna’s book: 3D Game Programming with DirectX 11, with some changes using the links from that blog you should be able to work through the issues you might be facing with getting up to speed.  And I think that the big opportunity to make some bucks is coming.  I could be wrong, it has been a depressing month for me, so maybe I am just full of it, or as some might say full of sh.

Let’s take a look at an extremely simple piece of code, which if you look at the templates included with the Visual Studio 11 versions, you might be confused on how to get started.  So let’s get started with the most simple and boring code possible.  In the following code I show two things: The use of the console windows (thanks to Frank Luna) and some lightly modified code from his book (please order it if you are going to get rich with Windows 8).

First off, Frank Luna used the ostream to allow the vector operations to show up using the cout process, pretty cool. 

To get more information about the XMStoreFloat4, see:

https://msdn.microsoft.com/en-us/library/microsoft.directx_sdk.storing.xmstorefloat4(v=vs.85).aspx

Then in the main component, the XMVectorPow sets the left matrix elements to the power of matching elements of the right matrix.

clip_image001

Which operationally is the same as: 3^1, 3^1, 2^3, 2^7, or you could write:

Result.x = pow(V1.x, V2.x);

Result.y = pow(V1.y, V2.y);

Result.z = pow(V1.z, V2.z);

Result.w = pow(V1.w, V2.w);

And in the case of my program below, you will get the output, which is console and not where I would like to get to, but it proves that a DirectX example can be done in just a few lines of code (Thanks to Frank Luna and his excellent book):

image

 

 

 

  1.  //Tested on Windows 8 with VS 11 Beta
    
     #include <algorithm>
    
     #include <iostream>
    
     #include <vector>
    
     #include "DirectXMath.h"
    
     #include "DirectXPackedVector.h"
    
     using namespace DirectX; 
    
     using namespace DirectX::PackedVector;
    
      
    
     using namespace std;
    
     // Consider buying Frank Luna's book: 3D Game Programming with DirectX 11, dedcoder.net
    
     // You will need to do some tweaking to use the book
    
     // Overload the  "<<" operators use cout to 
    
     // output XMVECTOR objects
    
     ostream& operator<<(ostream& os, FXMVECTOR v)
    
     {
    
          XMFLOAT4 dest;
    
          XMStoreFloat4(&dest, v);
    
      
    
          os << "(" << dest.x<< ", " << dest.y << ", " << dest.z <<  ", " << dest.w << ")";
    
          return os;
    
     }
    
    
    
      
    
     int main()
    
     {
    
           XMVECTOR aVector = XMVectorSet(3.0f, 3.0f, 2.0f, 2.0f);
    
           XMVECTOR bVector = XMVectorSet(1.0f, 1.0f, 3.0f, 7.0f);
    
           cout<<"Left vector (aVector) contains (3,3,2,2) "            <<endl;
    
           cout<<"Right vector (bVector) contains (1,1,3,7)"            <<endl;
    
      
    
           cout << "XMVectorPow(aVector, bVector) = " << XMVectorPow(aVector, bVector) << endl;
    
           system("PAUSE");
    
           return 0;
    
     }
    

Oh, oh, this wasn’t very complicated.  Sorry.