Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include <d3d9.h>
- #include "SpriteBatcher.h"
- #pragma comment (lib, "d3d9.lib")
- #define SCREEN_WIDTH 800
- #define SCREEN_HEIGHT 600
- #define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)
- //Global Vars
- HINSTANCE hInstance;
- HWND winHandle;
- LPDIRECT3D9 d3d;
- LPDIRECT3DDEVICE9 device;
- //---------------------------------
- SpriteBatcher batcher;
- float x;
- //Prototypes
- LRESULT CALLBACK winProc(HWND winHandle, UINT message, WPARAM wParam, LPARAM lParam);
- bool initWindow(HINSTANCE hInstance);
- bool initDirectX();
- void render();
- void cleanUp();
- //Create the main entry point
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
- {
- //Create the window
- if(!(initWindow(hInstance)))
- return false;
- //Init Direct X
- if(!(initDirectX()))
- return false;
- //Prepare the game loop
- MSG msg;
- ZeroMemory(&msg, sizeof(MSG));
- //While there is no quit message run the game loop
- while(msg.message != WM_QUIT)
- {
- //Handle window messages
- while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- //Game Code
- render();
- }
- //Clean up clean up
- cleanUp();
- return msg.wParam;
- }
- #pragma region Window Creation and call back
- bool initWindow(HINSTANCE hInstance)
- {
- //Set up the window properties
- WNDCLASSEX wc;
- ZeroMemory(&wc, sizeof(WNDCLASSEX));
- //Window properties
- wc.cbSize = sizeof(WNDCLASSEX);
- wc.style = CS_HREDRAW | CS_VREDRAW;
- wc.lpfnWndProc = winProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = hInstance;
- wc.hIcon = 0;
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
- wc.lpszMenuName = NULL;
- wc.lpszClassName = "window";
- wc.hIconSm = 0;
- //Register the window class
- RegisterClassEx(&wc);
- //Create the window
- winHandle = CreateWindowEx(NULL,
- "window",
- "My Window",
- WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- SCREEN_WIDTH,
- SCREEN_HEIGHT,
- NULL,
- NULL,
- hInstance,
- NULL);
- if(winHandle == false)
- return false;
- //Show the window
- ShowWindow(winHandle, SW_SHOW);
- return true;
- }
- //Call back funciton for the window
- LRESULT CALLBACK winProc(HWND winHandle, UINT message, WPARAM wParam, LPARAM lParam)
- {
- switch(message)
- {
- case WM_DESTROY:
- {
- PostQuitMessage(0);
- }
- break;
- }
- return DefWindowProc(winHandle, message, wParam, lParam);
- }
- #pragma endregion
- //Setup direct x
- bool initDirectX()
- {
- //Set up all the direct x properties
- d3d = NULL;
- device = NULL;
- if(NULL == (d3d = Direct3DCreate9(D3D_SDK_VERSION)))
- return false;
- D3DPRESENT_PARAMETERS d3dpp;
- ZeroMemory(&d3dpp, sizeof(d3dpp));
- d3dpp.Windowed = true;
- d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
- d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
- d3dpp.BackBufferCount = 1;
- d3dpp.BackBufferWidth = SCREEN_WIDTH;
- d3dpp.BackBufferHeight = SCREEN_HEIGHT;
- d3dpp.hDeviceWindow = winHandle;
- //Create the direct x device
- if(FAILED(d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, winHandle, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &device)))
- return false;
- //device->SetRenderState(D3DRS_CULLMODE,D3DCULL_NONE);
- //Finalize stuff
- x = 10.0f;
- return true;
- }
- //Draw the things that need to be drawn
- void render()
- {
- x++;
- //Draw
- batcher.beginBatch();
- batcher.draw(x, 50.0f, 64.0f, 64.0f, D3DCOLOR_XRGB(0,255,255));
- batcher.endBatch(device);
- }
- //Clean up
- void cleanUp()
- {
- //Clean up the D3D device
- if(device != NULL)
- {
- device->Release();
- device = NULL;
- }
- //Clean up the D3D object
- if(d3d != NULL)
- {
- d3d->Release();
- d3d = NULL;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement