Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Application Programming › DirectX 9 Tutorials #1: Initializing DirectX 9 in C++ (non-OOP)
New Posts  All Forums:Forum Nav:

DirectX 9 Tutorials #1: Initializing DirectX 9 in C++ (non-OOP)

post #1 of 7
Thread Starter 

FiX's DirectX 9 Tutorial #1: Initializing DirectX 9 in C++ (non-OOP)

A lot of people seem to want to get into game design and the game industry, or just play around with the basics of game development.
DirectX may not be the easiest or simplest way of doing this, but is the back-bone of a lot of games.
Out of boredom on a Saturday morning, I've decided to contribute to OCN and shed some light on where to start with programming in DirectX 9.
This is the non-OOP version, as it is easiest to understand, and I will write a future version in OOP instead. I recommend using OOP over non-OOP (procedural) for DirectX.
I will go into as much depth as I deem required. Further information can be found on the MSDN.

Some of the pre-requisites you will need:
  • Being able to program proficiently in C++
  • Visual Studio 2010 (you won't necessarily need this, but I will be using this as part of the guide)
  • The DirectX SDK (can be downloaded from Microsoft here)

Onto the actual tutorial now:
  1. Once you have all of the software installed, go ahead and fire up Visual Studio.
    You will need to create a New Project. Select Visual C++ -> Empty Project. Name the project whatever you want.
    I do recommend making a dedicated projects folder.
  2. The next step is to set the project up to link with the DirectX SDK.
    Right click on the Project you just created, and select Properties.
    Under Configuration Properties, select VC++ Directories.

    Reference:
    1.png

    Under 'Include Directories' you want to specify where the DirectX Headers are stored.
    For me, this is:
    Code:
    G:\Program Files (x86)\Microsoft (DirectX SDK June 2010)\Include
    

    Under 'Library Directories' you want to specify where the DirectX Libraries are stored.
    For me, this is:
    Code:
    G:\Program Files (x86)\Microsoft (DirectX SDK June 2010)\Lib\x86
    
    I would recommend compiling with the x86 libraries.

    Reference:
    2.PNG
  3. The next step is to add the required DirectX libaries to the Linker.
    Under the Linker menu, select the Input sub-tab.
    Edit the 'Additional Dependencies' box to look like:
    Code:
    d3d9.lib;%(AdditionalDependencies)
    

    Reference:
    3.PNG
  4. Now onto the actual C++ code.
    Close the Properties window and right click on 'Source Code' in the Solution Explorer.
    Add -> New Item and select C++ File (.cpp) from under the Visual C++ template section.
    Name it Main.cpp and click 'Add'. This is the entry point of the program, and where DirectX will be initialized.
    I will keep this tutorial to use this file only for simplicity sake.

    Reference:
    4.PNG
  5. Filling in the C++ code.
    This is where the tough parts really begin - setting up DirectX and its huge list of properties.

    Firstly, include the header files needed:
    Code:
    /* Header files required for DirectX */
    #include <windows.h>
    #include <windowsx.h>
    #include <d3d9.h>
    

    Now we set some constants:
    Code:
    /* Constants                                          */
    #define SCREEN_WIDTH 1024
    #define SCREEN_HEIGHT 768
    
    You can change those as you like.

    Now we add some Globals:
    Code:
    /* Globals                                                    */
    LPDIRECT3D9 d3d = NULL;
    LPDIRECT3DDEVICE9 d3ddev = NULL;
    
    Out of habit, I define all my variables to NULL or 0. This should always be done with pointers that aren't instantly being referenced.

    LPDIRECT3D9 is defined as a pointer to the IDirect3D9 interface.
    LPDIRECT3DDEVICE9 is (yet again) defined as a pointer to the IDirect3DDevice9 interface.

    Now we define some function prototypes:
    Code:
    /* Function Prototypes */
    void initialiseDirect3D(HWND hWnd);
    void renderFrame();
    void cleanDirect3D();
    
    LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
    

    The function 'initliaseDirect3D(HWND hWnd)' will initialize Direct3D for us (setup the device).
    'renderFrame()' will render the frame on call.
    'cleanDirect3D()' will clean up all of the resources that we have initialized. This is called right before we close the application.
    Lastly, the WindowProc function will handle all of the Windows System messages that may be passed to it.

    Reference:
    5.PNG
  6. Onto our first function - the entry point.
    Our entry point is defined like this:
    Code:
    /* The entry point */
    int WINAPI WinMain(HINSTANCE hInstance,
                       HINSTANCE hPrevInstance,
                       LPSTR lpCmdLine,
                       int nCmdShow)
    {
    
    }
    
    MSDN link for WinMain.
    Lets analyse this function:
    • WINAPI
      This is required by Windows as part of the entry point description. It is defined as '__stdcall' in the file 'WinDef.h', meaning it will call Win32 functions.
    • HINSTANCE hInstance
      HINSTANCE is an abbreviated way of saying Handle of an Instance. This is the instance handle defined by Windows for your current application.
      It is used by Windows to keep track of applications.
      It is a 32-bit integer (for any of you interested).
    • HINSTANCE hPrevInstance
      This parameter is a handle to to the previous instance. If there are multiple copies of this application open, this will theoretically contain the handle to that instance of the application.
      Theoretically, you can use it to stop people launching multiple copies of your application, but I have not tested this theory yet.
    • LPSTR lpCmdLine
      This is a long pointer to a string containing parameters passed to the application. You can use this to launch your application with special options.
      Example uses of this could be people passing 'myapp.exe -windowed' to your application to make it launch in windowed mode, or some other parameter based options like that.
      It can contain multiple parameters.
    • int nCmdShow
      This parameter is used to indicate how the window should appear on creation, E.G. minimized, maximized, normal, etc.
      You usually don't need to use this.
      Some of the enumerations that could be passed through it can be seen here (under the nCmdShow section).
  7. Fleshing out the WinMain entry point.
    Code:
    HWND hWnd;
    WNDCLASSEX wc;
    
    ZeroMemory(&wc, sizeof(WNDCLASSEX));
    
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = WindowProc;
    wc.hInstance = hInstance;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
    wc.lpszClassName = "WindowClass";
    
    RegisterClassEx(&wc);
    

    Lets analyse:
    • HWND hWnd;
      Just a Window Handle, nothing new.
    • WNDCLASSEX wc;
      WNDCLASSEX is a structure superseding the WNDCLASS structure.
      It is used to create the window we're going to be using with DirectX.
    • ZeroMemory(&wc, sizeof(WNDCLASSEX));
      This is used to fill the 'wc' variables structure with 0's, so any parameter we do not specify when setting it up will automatically be set to 0 (aka NULL).
      The 'sizeof(WNDCLASSEX)' is so that the function knows how many 0's it needs to write to the position in the memory that 'wc' is at.
      The ZeroMemory macro is documented here.
    • wc.cbSize = sizeof(WNDCLASSEX);
      cbSize is the size in bytes of the structure.
      Make sure you set this to 'sizeof(WNDCLASSEX)' before calling GetClassInfoEx()!
    • wc.style = CS_HREDRAW | CS_VREDRAW;
      This is the Windows Class Style bits. It is set to redraw the window here if a movement or size adjustment changes the width of height of the client area.
      See here.
    • wc.lpfnWndProc = WindowProc;
      This is a pointer to the window procedure (remember the WindowProc function we defined earlier?) to pass messages to our WindowProc function.
    • wc.hInstance = hInstance;
      This sets the class instance to be the window handle instance passed to us by Windows.
    • wc.hCursor = LoadCursor(NULL, IDC_ARROW);
      This sets the cursor that is displayed over the window to be the regular Windows Arrow cursor.
      See here for the LoadCursor function and available cursors.
    • wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
      This sets the handle to the brush background to the COLOR_WINDOW type.
      See the hbrBackground section here for more information.
    • wc.lpszClassName = "WindowClass";
      This sets the class name of the window to be 'WindowClass'. It is used later in the CreateWindowEx function to let it know which window we are talking about.
      See the lpszClassName section here for more information.
    • RegisterClassEx(&wc);
      This function registers a window for use with CreateWindowEx (for later).
      See here for more information.
  8. Continuing to flesh out the entry point function
    Now we create and show the window:
    Code:
    hWnd = CreateWindowEx(NULL,
         "WindowClass",
         "DirectX Tutorial #1 - No OOP",
         WS_OVERLAPPEDWINDOW,
         300, 300,
         SCREEN_WIDTH, SCREEN_HEIGHT,
         NULL,
         NULL,
         hInstance,
         NULL);
    
    ShowWindow(hWnd, nCmdShow);
    

    Analysis:

    • hWnd = CreateWindowEx
      Here we're defining the window handle to be a new window we're creating.
    • The paramaters
      1. Parameter 1 is the dwExStyle (a DWORD) that defines the extended window styles. We don't need this so we set it to NULL.
        See here for more information on this parameter.
      2. This is the window class name, here we refer back to the class name we registered earlier. It is an optional value.
      3. This is the window name / title. You can set it to whatever you like.
      4. This is the window style being passed in. Here we use 'WS_OVERLAPPEDWINDOW' - a window that looks close to normal.
        You can use 'WS_EX_TOPMOST | WS_POPUP' if you want to use full screen.
        See here for more styles that you can use.
      5. This is the original X position on the screen.
      6. This is the original Y position on the screen.
      7. This is the window width.
      8. This is the window height.
      9. This is the parent window handle, we don't need this so we've set it to NULL.
      10. This is a handle to a menu (or it can be used to specify a child-window identifier, depending on the window style). We don't need this so we set it to NULL.
        It is an optional parameter.
      11. This is the handle to the window instance to be associated. Here, we use hInstance.
      12. This is an optional parameter to pass a pointer to a value to the window through the CREATESTRUCT structure. It is not needed and so we set it to NULL.
      See here for more information on the CreateWindowEx function.
    • ShowWindow(hWnd, nCmdShow);
      This function sets the window state of our new window to be shown.
      See here for more information on this function.
    Your entry point function should look like this now:
    6.PNG

    Continued in next post.

Edited by FiX - 6/10/13 at 12:17am
    
CPUMotherboardGraphicsGraphics
FX-8350 Asus Crosshair V MSI GTX460 Hawk 1gb MSI GTX460 Hawk 1gb 
RAMHard DriveHard DriveHard Drive
Kingston HyperX 8gb (2x4gb) Crucial M4 64GB Samsung F3 1TB Western Digital 320GB 
CoolingOSMonitorMonitor
Custom WC Windows 7 Ultimate X64 Dell E2311H Dell E2311H 
MonitorKeyboardPowerCase
LH 23EN43 Ducky Year of the Dragon 2012 SilverStone Strider 1000W-P Corsair 800D 
Audio
Asus Xonar Essence STX 
  hide details  
Reply
    
CPUMotherboardGraphicsGraphics
FX-8350 Asus Crosshair V MSI GTX460 Hawk 1gb MSI GTX460 Hawk 1gb 
RAMHard DriveHard DriveHard Drive
Kingston HyperX 8gb (2x4gb) Crucial M4 64GB Samsung F3 1TB Western Digital 320GB 
CoolingOSMonitorMonitor
Custom WC Windows 7 Ultimate X64 Dell E2311H Dell E2311H 
MonitorKeyboardPowerCase
LH 23EN43 Ducky Year of the Dragon 2012 SilverStone Strider 1000W-P Corsair 800D 
Audio
Asus Xonar Essence STX 
  hide details  
Reply
post #2 of 7
Thread Starter 
Back here to Part 2 - finishing the rest of the basic window.
Honestly, setting up the window is a lot of the code, from then on doing things like drawing planes to the window and all that are a lot easier (and a lot less coding too).

Onwards:
  1. Finishing off the entry point function:
    It's easier from now on (to the end of this function anyway tongue.gif).
    Code:
    // Initialise Direct3D
    initialiseDirect3D(hWnd);
    
    // Main app loop
    MSG msg;
    
    while(TRUE)
    {
        while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    
        if(msg.message == WM_QUIT)
            break;
    
        renderFrame();
    }
    
    // Clean Up DirectX (and in turn, COM)
    cleanDirect3D();
    

    Fairly easy.
    Firstly, we call the function we defined earlier called initialiseDirect3D(), passing the handle to it.

    We then setup a MSG (message) variable.

    And now we start the main application loop with a while(TRUE) loop.
    This loop will encompass every single frame that the app will display.

    We now call the PeekMessage function to dispatch any sent messages, check the thread message queue for a new posted message and then retrieves it, if there is one.
    If there is one, we now handle it with TranslateMessage and DispatchMessage.
    The message is then pulled into the 'msg' variable we defined earlier.

    If the message is telling us to close, we need to break out of the while(true) loop, and then close down the app.

    We then render the frame.
    Simple.

    Outside of the while(true) loop, we clean up Direct3D and release anything we've stored in the RAM or VRAM.

    One last bit of code for this function:
    Code:
    return msg.wParam;
    }
    
    This returns the reason we're closing from the 'msg' variable to Windows.
  2. The WindowProc function
    Code:
    // Message handler for our application
    LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        switch(message)
        {
            case WM_DESTROY:
                {
                    PostQuitMessage(0);
                    return 0;
                } 
                break;
        }
    
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    
    This is a fairly simple function. We check if the message is a 'WM_DESTROY' message, and if it is, post the quit message to our message handler in our while(TRUE) loop.
  3. Initialize Direct3D for use
    Code:
    // Initialise Direct3D for use
    void initialiseDirect3D(HWND hWnd)
    {
            // Create our d3d interface
        d3d = Direct3DCreate9(D3D_SDK_VERSION);
    
            // A presentation parameter struct
        D3DPRESENT_PARAMETERS d3dpp;
    
            // Clear it out to 0s
        ZeroMemory(&d3dpp, sizeof(d3dpp));
    
            // Set our display mode to Windowed
        d3dpp.Windowed = TRUE;
            // Discard old frames
        d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
            // Set the device window to our window pointer passed as a parameter
        d3dpp.hDeviceWindow = hWnd;
    
    
        // create a device class using this information and the info from the d3dpp stuct
        d3d->CreateDevice(D3DADAPTER_DEFAULT,
                          D3DDEVTYPE_HAL,
                          hWnd,
                          D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                          &d3dpp,
                          &d3ddev);
    }
    

    We start off by allocating 'd3d' to as a new Direct3D9 interface using the function Direct3DCreate9. It takes the parameter of the current DirectX SDK version.

    We then define a new presentation parameters variable called 'd3dpp' and zero it out using the ZeroMemory macro.

    We set Windowed mode to true and the Swap Effect to D3DSWAPEFFECT_DISCARD.
    See here for more information on what swap effects can be used.
    We also set the device window to the window pointer passed to us.

    By default, VSync is enabled. If you want to disable it, add this:
    Code:
    d3dpp.PresentationInterval = D3DPRESENT_DONOTWAIT;
    
    For more presentation interval parameters, see here.

    We then tell Direct3D to create our device using the CreateDevice function.

    The parameters are as follow:
    1. This is the Adapter number to be used. We use 'D3DADAPTER_DEFAULT' to set the default display adapter. The parameter type is UINT.
    2. This parameter is the device type to be used, we use 'D3DDEVTYPE_HAL' which enabled hardware rasterization.
      See here for more device types that can be used.
    3. This is the window for the device to render to, here we pass 'hWnd'.
    4. This specifies the behavior flags to be used. We want software vertex processing, so we use 'D3DCREATE_SOFTWARE_VERTEXPROCESSING'.
      See here for other flags you can use.
    5. This is the presentation parameters to use, so we pass the 'd3dpp' struct we created earlier.
    6. This is the device interface returned (our new Direct3D Device) for us to use, so we pass 'd3ddev'.
  4. The frame rendering function
    Code:
    // Renders a single frame
    void renderFrame()
    {
        // Clear out the buffers to a blue colour
        d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 45, 100), 1.0f, 0);
    
            // Begin our scene
        d3ddev->BeginScene();
    
        // Do our rendering to our backbuffer here
    
            // End our scene
        d3ddev->EndScene();
    
            // Display our scene
        d3ddev->Present(NULL, NULL, NULL, NULL);
    }
    

    This function is called once per frame, and renders a frame.

    We start by clearing out the target buffer using the d3ddev->Clear() function.
    The first parameter is 0 as pRects is set to NULL.
    The second parameter is the pRects, which we don't need, and so is set to NULL.
    The third parameter is the D3DCLEAR flags. We want to clear the Target buffer to we set it to 'D3DCLEAR_TARGET'. Some of the other values that can be passed can be seen here.
    The fourth parameter is the colour we want to clear the window to. It is of the type 'D3DCOLOR' so we use 'D3DCOLOR_XRGB()' which take 3 values (0-255 Red, 0-255 Green, 0-255 Blue).
    The fifth parameter is the Z value we want to clear to. It clears the depth buffer to this new value. This can only be in the range of 0-1.
    The final parameter is a DWORD of what we want to clear the stencil buffer to. The values that can be used range from 0 to 2^n-1.

    We then tell the device to begin our scene.
    Inside the BeginScene / EndScene area, we render our content to our backbuffer.
    Finally, we tell the device to end our scene, and then present the scene.

    The 'd3ddev->Present()' function takes the following arguments:
    First parameter is a source Rect to present. We don't need this so we set it to NULL. To use this, the swap chain must have been created using 'D3DSWAPEFFECT_COPY'.
    The second parameter is a destination Rect to present to. Yet again, we don't need this and can't use it for the same reason as above.
    The third parameter is a HWND that can be used to override the destination window to render to. We set it to NULL as we're rendering to our regular window.
    The fourth parameter is a pointer to a RGNDATA struct specifying the area that needs to be re-rendered. This is outside the scope of this tutorial so we set it to NULL.
  5. The clean up function
    We're nearly there!

    Here's the final bit of code:
    Code:
    // Cleans up Direct3D and releases any RAM / VRAM in use
    void cleanDirect3D()
    {
        d3ddev->Release();
        d3ddev = NULL;
    
        d3d->Release();
        d3d = NULL;
    }
    

    This final bit of code releases our device and interface handles, freeing up the RAM and VRAM for us to close the application.
    It is quite simple, so doesn't need much explaining.
  6. The End!
    Well, there goes my whole Saturday writing this tutorial biggrin.gif
    Here is a Pastebin of all the code, and here is the whole project uploaded onto my server.
    With any luck, you should end up with a window looking like this:
    7.PNG

    Next on my to-do list is write a OOP based version of this, and then onto the basics like rendering triangles biggrin.gif
    Hope you enjoy reading this and found it useful.

    FiX

Edited by FiX - 8/10/12 at 9:05pm
    
CPUMotherboardGraphicsGraphics
FX-8350 Asus Crosshair V MSI GTX460 Hawk 1gb MSI GTX460 Hawk 1gb 
RAMHard DriveHard DriveHard Drive
Kingston HyperX 8gb (2x4gb) Crucial M4 64GB Samsung F3 1TB Western Digital 320GB 
CoolingOSMonitorMonitor
Custom WC Windows 7 Ultimate X64 Dell E2311H Dell E2311H 
MonitorKeyboardPowerCase
LH 23EN43 Ducky Year of the Dragon 2012 SilverStone Strider 1000W-P Corsair 800D 
Audio
Asus Xonar Essence STX 
  hide details  
Reply
    
CPUMotherboardGraphicsGraphics
FX-8350 Asus Crosshair V MSI GTX460 Hawk 1gb MSI GTX460 Hawk 1gb 
RAMHard DriveHard DriveHard Drive
Kingston HyperX 8gb (2x4gb) Crucial M4 64GB Samsung F3 1TB Western Digital 320GB 
CoolingOSMonitorMonitor
Custom WC Windows 7 Ultimate X64 Dell E2311H Dell E2311H 
MonitorKeyboardPowerCase
LH 23EN43 Ducky Year of the Dragon 2012 SilverStone Strider 1000W-P Corsair 800D 
Audio
Asus Xonar Essence STX 
  hide details  
Reply
post #3 of 7
Just a quick one, in Win32, hPrevInstance is always NULL.

Even though its sort of off topic, I want to explain anyway!

Back in 16-bit Windows they had a function called GetInstanceData - you gave it an HINSTANCE and various other things. What it did was copy a buffer from that instance into your current instance.
So your theory kind of applies to 16-bit Windows, but not Win32. If this was not NULL then you could use GetInstanceData to initialize your current instance faster. One example I can think of would be copying a window handle from the previous instance so you could talk to it (say, to load a new document into it).

But now here comes the tricky part - window class registration. So if hPrevInstance was NULL this meant you were the first copy of the program. In 16-bit Windows only this instance registered window classes. Subsequent instances just continued to use the classes already registered. So essentially every 16-bit program that was well behaved would skip over class registration if hPrevInstance was non-NULL.

Enter Win32: When the Win32 guys came to shift WinMain from Win16, they ran into the problem of what to pass for hPrevInstance. Modules and instances doesn't exist in Win32 (HMODULE and HINSTANCE are the same and are just the base address of the module in memory) and unlike Win16, Win32 has separate address spaces. So they just pass NULL, fooling each program into thinking it was the first one. Since the address spaces are separate, there's no issue with re-registering window classes. This still works today smile.gif

Nowadays, in order to turn your theory into reality most programs hold a mutex object (which has an owner and can only have one owner).

smile.gif

---
ANYWAY!

Back on topic - I like this tutorial, seems to explain a lot which is essential, well done thumb.gif
Also, am I seeing this right? The frame doesn't get rendered until you get WM_QUIT? This doesn't make sense to me tongue.gif
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
post #4 of 7
Thread Starter 
Tompsonn, Thanks, didn't know that smile.gif

And uhh no? It gets rendered if it doesn't see WM_QUIT tongue.gif
Code:
if(msg.message == WM_QUIT)
        break;

    renderFrame();

Only doesn't render if the message is WM_QUIT.
Edited by FiX - 8/10/12 at 10:06pm
    
CPUMotherboardGraphicsGraphics
FX-8350 Asus Crosshair V MSI GTX460 Hawk 1gb MSI GTX460 Hawk 1gb 
RAMHard DriveHard DriveHard Drive
Kingston HyperX 8gb (2x4gb) Crucial M4 64GB Samsung F3 1TB Western Digital 320GB 
CoolingOSMonitorMonitor
Custom WC Windows 7 Ultimate X64 Dell E2311H Dell E2311H 
MonitorKeyboardPowerCase
LH 23EN43 Ducky Year of the Dragon 2012 SilverStone Strider 1000W-P Corsair 800D 
Audio
Asus Xonar Essence STX 
  hide details  
Reply
    
CPUMotherboardGraphicsGraphics
FX-8350 Asus Crosshair V MSI GTX460 Hawk 1gb MSI GTX460 Hawk 1gb 
RAMHard DriveHard DriveHard Drive
Kingston HyperX 8gb (2x4gb) Crucial M4 64GB Samsung F3 1TB Western Digital 320GB 
CoolingOSMonitorMonitor
Custom WC Windows 7 Ultimate X64 Dell E2311H Dell E2311H 
MonitorKeyboardPowerCase
LH 23EN43 Ducky Year of the Dragon 2012 SilverStone Strider 1000W-P Corsair 800D 
Audio
Asus Xonar Essence STX 
  hide details  
Reply
post #5 of 7
Quote:
Originally Posted by FiX View Post

Tompsonn, Thanks, didn't know that smile.gif
And uhh no? It gets rendered if it doesn't see WM_QUIT tongue.gif
Code:
if(msg.message == WM_QUIT)
        break;
    renderFrame();
Only doesn't render if the message is WM_QUIT.

doh.gif
I should stop writing (and reading) code while drinking....
Also do we not need CoInitialize and CoUnInitialize or do the D3D APIs implicitly do this?
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
post #6 of 7
Thread Starter 
Quote:
Originally Posted by tompsonn View Post

doh.gif
I should stop writing (and reading) code while drinking....
Also do we not need CoInitialize and CoUnInitialize or do the D3D APIs implicitly do this?
IIRC they do it implicitly.
    
CPUMotherboardGraphicsGraphics
FX-8350 Asus Crosshair V MSI GTX460 Hawk 1gb MSI GTX460 Hawk 1gb 
RAMHard DriveHard DriveHard Drive
Kingston HyperX 8gb (2x4gb) Crucial M4 64GB Samsung F3 1TB Western Digital 320GB 
CoolingOSMonitorMonitor
Custom WC Windows 7 Ultimate X64 Dell E2311H Dell E2311H 
MonitorKeyboardPowerCase
LH 23EN43 Ducky Year of the Dragon 2012 SilverStone Strider 1000W-P Corsair 800D 
Audio
Asus Xonar Essence STX 
  hide details  
Reply
    
CPUMotherboardGraphicsGraphics
FX-8350 Asus Crosshair V MSI GTX460 Hawk 1gb MSI GTX460 Hawk 1gb 
RAMHard DriveHard DriveHard Drive
Kingston HyperX 8gb (2x4gb) Crucial M4 64GB Samsung F3 1TB Western Digital 320GB 
CoolingOSMonitorMonitor
Custom WC Windows 7 Ultimate X64 Dell E2311H Dell E2311H 
MonitorKeyboardPowerCase
LH 23EN43 Ducky Year of the Dragon 2012 SilverStone Strider 1000W-P Corsair 800D 
Audio
Asus Xonar Essence STX 
  hide details  
Reply
post #7 of 7
Quote:
Originally Posted by FiX View Post

IIRC they do it implicitly.

Ah right smile.gif Good to know. I know squat about DirectX tongue.gif
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Application Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Application Programming › DirectX 9 Tutorials #1: Initializing DirectX 9 in C++ (non-OOP)