-
-
Save bANNji/24ebedaf5a72f2003d29 to your computer and use it in GitHub Desktop.
First Dx Window
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//include the basic windows header files and the Direct3dD Header file | |
#include <windows.h> | |
#include <windowsx.h> | |
#include <d3d9.h> | |
// Include the DIrect3D library file | |
#pragma comment (lib, "d3d9.lib") | |
// global declarations | |
LPDIRECT3D9 d3d; // The pointer to our Direct3D Interface | |
LPDIRECT3DDEVICE9 d3ddev; // the pointer to the device class | |
// functiuon prototypes | |
void initD3D(HWND hWnd); // Sets up and initializes Direct3D | |
void render_frame(void); // Renders a single frame | |
void cleanD3D(void); // Closes Direct3D and releases memory | |
// The window proc function prototype | |
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); | |
// this function initializes and prepares direct3d for use | |
void initD3D(HWND hWnd) | |
{ | |
d3d = Direct3DCreate9(D3D_SDK_VERSION); // Create the Direct3D Interface | |
D3DPRESENT_PARAMETERS d3dpp; // create a stuct to hold verious device information | |
ZeroMemory(&d3dpp, sizeof(d3dpp)); //Clear out the stuct for usee | |
d3dpp.Windowed = TRUE; // Program windowed not full screen | |
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; // Discard old frames | |
d3dpp.hDeviceWindow = hWnd; // Set the window to be used by Direct3D | |
// Create a deviced calss using this information and information from the d3dpp stuct | |
d3d->CreateDevice(D3DADAPTER_DEFAULT, | |
D3DDEVTYPE_HAL, | |
hWnd, | |
D3DCREATE_SOFTWARE_VERTEXPROCESSING, | |
&d3dpp, | |
&d3ddev); | |
} | |
// THE FUN STUFF | |
// this is the function used to render a single frame | |
void render_frame(void) | |
{ | |
// clear the window to a deep blue | |
d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 40, 100), 1.0f, 0); | |
d3ddev->BeginScene(); // this begins the 3D Scene | |
// do 3D Rendering on the back buffer here... | |
d3ddev->EndScene(); // ends the 3D Scene | |
d3ddev->Present(NULL, NULL, NULL, NULL); // This displays the created frame | |
} | |
// THis is the function that cleans up Direct3D and COM | |
void cleanD3D(void) | |
{ | |
d3ddev->Release(); // close and release the 3D Device | |
d3d->Release(); //Close and release Direct3D | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment