Hello. I am trying to load a texture and display it on the screen using directx. It loads fine with no errors, but the image is way too big and it doesnt fit on the window. Both the image and the window are 800x600. I understand that the borders of the
window are included with the size, but the image is still way too big. I only get about half the image (the rest runs off the right and bottom of the screen). Could my trouble be that Im using Paint (windows 7 version)? Thank you!
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff
#define
</font></font></font><font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff
</font></font><font face="Consolas" size="2" color="#0000ff
</font>
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small VC_EXTRALEAN
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff
#include
</font></font></font><font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff
</font></font><font face="Consolas" size="2" color="#0000ff
</font>
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <Windows.h>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff
#include
</font></font></font><font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff
</font></font><font face="Consolas" size="2" color="#0000ff
</font>
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small "resource.h"
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff
#include
</font></font></font><font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff
</font></font><font face="Consolas" size="2" color="#0000ff
</font>
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <d3d9.h>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff
#include
</font></font></font><font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff
</font></font><font face="Consolas" size="2" color="#0000ff
</font>
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <d3dx9.h>
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LPDIRECT3D9 d3dObject=NULL;
LPDIRECT3DDEVICE9 d3dDevice=NULL;
LPDIRECT3DTEXTURE9 texture=NULL;
LPD3DXSPRITE sprite=NULL;
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff
int
</font></font></font><font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff
</font></font><font face="Consolas" size="2" color="#0000ff
</font>
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small int<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
nCmdShow)
{
<font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small const<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small wchar_t<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
CLASS_NAME[] = L<span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small "Sample Window Class"<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small ;<font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small int<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
screenWidth;<font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small int<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
screenHeight;
WNDCLASSEX wcex;
<font face="Consolas" size="2 <font face="Consolas" size="2
wcex.cbSize =
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small sizeof<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small (WNDCLASSEX);
wcex.style= CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc= (WNDPROC)WndProc;
wcex.cbClsExtra= 0;
wcex.cbWndExtra= 0;
wcex.hInstance= hInstance;
wcex.hIcon= 0;
wcex.hCursor= LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground= (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName= 0;
wcex.lpszClassName= CLASS_NAME;
wcex.hIconSm= 0;
RegisterClassEx(&wcex);
<font face="Consolas" size="2 <font face="Consolas" size="2
HWND hWnd=CreateWindow(L
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small "Sample Window Class"<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small ,
L<span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small "Sprite Animation Demo"<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small ,
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL, hInstance, NULL);
d3dObject = Direct3DCreate9(D3D_SDK_VERSION);
<font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small if<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
(d3dObject==NULL)<font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small return<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
FALSE;
D3DPRESENT_PARAMETERS presParams;
<font face="Consolas" size="2 <font face="Consolas" size="2
ZeroMemory(&presParams,
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small sizeof<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small (presParams));
presParams.Windowed = TRUE;
presParams.SwapEffect = D3DSWAPEFFECT_DISCARD;
presParams.BackBufferFormat = D3DFMT_UNKNOWN;
presParams.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
HRESULT hr = d3dObject-> CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &presParams, &d3dDevice);
RECT screenRect;
GetClientRect(hWnd,&screenRect);
screenWidth=screenRect.right;
screenHeight=screenRect.bottom;
D3DXCreateSprite(d3dDevice, &sprite);
<font face="Consolas" size="2 <font face="Consolas" size="2
D3DXCreateTextureFromFile(d3dDevice, L
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small "landingPad.dds"<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small ,
&texture);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
MSG msg;
<font face="Consolas" size="2 <font face="Consolas" size="2
ZeroMemory(&msg,
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small sizeof<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small (msg));<font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small while<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
(msg.message!=WM_QUIT)
{
<font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small while<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small (PeekMessage(&msg,
NULL, 0U, 0U, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
hr = d3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);
hr = d3dDevice->BeginScene();
D3DXVECTOR3 pos(0,0,0);
sprite->Begin(D3DXSPRITE_ALPHABLEND);
RECT rect;
rect.left = 0;
rect.top = 0;
rect.right = screenWidth;
rect.bottom = screenHeight;
sprite->Draw(texture, &rect, NULL, &pos, 0xFFFFFFFF);
sprite->End();
d3dDevice->EndScene();
d3dDevice->Present(NULL, NULL, NULL, NULL);
}
texture->Release();
<font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small return<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
<font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small switch<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
(message)
{
<font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small case<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
WM_COMMAND:
{
<font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small int<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
wmId = LOWORD(wParam); <font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small int<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
wmEvent = HIWORD(wParam); <font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#008000; font-size:x-small <span style="font-family:Consolas; color:#008000; font-size:x-small <span style="font-family:Consolas; color:#008000; font-size:x-small // Parse the menu selections:
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small switch<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
(wmId)
{
<font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small case<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
IDM_EXIT:
DestroyWindow(hWnd);
<font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small break<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small ;
}
<font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small break<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small ;
}
<font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small case<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
WM_DESTROY:
PostQuitMessage(0);
<font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small break<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small ;<font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small default<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small :<font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small return<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
DefWindowProc(hWnd, message, wParam, lParam);
}
<font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small return<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
0;
}
View the full article
window are included with the size, but the image is still way too big. I only get about half the image (the rest runs off the right and bottom of the screen). Could my trouble be that Im using Paint (windows 7 version)? Thank you!
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff
#define
</font></font></font><font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff
</font></font><font face="Consolas" size="2" color="#0000ff
</font>
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small VC_EXTRALEAN
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff
#include
</font></font></font><font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff
</font></font><font face="Consolas" size="2" color="#0000ff
</font>
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <Windows.h>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff
#include
</font></font></font><font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff
</font></font><font face="Consolas" size="2" color="#0000ff
</font>
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small "resource.h"
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff
#include
</font></font></font><font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff
</font></font><font face="Consolas" size="2" color="#0000ff
</font>
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <d3d9.h>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff
#include
</font></font></font><font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff
</font></font><font face="Consolas" size="2" color="#0000ff
</font>
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <d3dx9.h>
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LPDIRECT3D9 d3dObject=NULL;
LPDIRECT3DDEVICE9 d3dDevice=NULL;
LPDIRECT3DTEXTURE9 texture=NULL;
LPD3DXSPRITE sprite=NULL;
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff
int
</font></font></font><font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff
</font></font><font face="Consolas" size="2" color="#0000ff
</font>
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small int<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
nCmdShow)
{
<font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small const<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small wchar_t<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
CLASS_NAME[] = L<span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small "Sample Window Class"<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small ;<font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small int<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
screenWidth;<font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small int<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
screenHeight;
WNDCLASSEX wcex;
<font face="Consolas" size="2 <font face="Consolas" size="2
wcex.cbSize =
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small sizeof<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small (WNDCLASSEX);
wcex.style= CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc= (WNDPROC)WndProc;
wcex.cbClsExtra= 0;
wcex.cbWndExtra= 0;
wcex.hInstance= hInstance;
wcex.hIcon= 0;
wcex.hCursor= LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground= (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName= 0;
wcex.lpszClassName= CLASS_NAME;
wcex.hIconSm= 0;
RegisterClassEx(&wcex);
<font face="Consolas" size="2 <font face="Consolas" size="2
HWND hWnd=CreateWindow(L
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small "Sample Window Class"<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small ,
L<span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small "Sprite Animation Demo"<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small ,
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL, hInstance, NULL);
d3dObject = Direct3DCreate9(D3D_SDK_VERSION);
<font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small if<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
(d3dObject==NULL)<font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small return<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
FALSE;
D3DPRESENT_PARAMETERS presParams;
<font face="Consolas" size="2 <font face="Consolas" size="2
ZeroMemory(&presParams,
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small sizeof<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small (presParams));
presParams.Windowed = TRUE;
presParams.SwapEffect = D3DSWAPEFFECT_DISCARD;
presParams.BackBufferFormat = D3DFMT_UNKNOWN;
presParams.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
HRESULT hr = d3dObject-> CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &presParams, &d3dDevice);
RECT screenRect;
GetClientRect(hWnd,&screenRect);
screenWidth=screenRect.right;
screenHeight=screenRect.bottom;
D3DXCreateSprite(d3dDevice, &sprite);
<font face="Consolas" size="2 <font face="Consolas" size="2
D3DXCreateTextureFromFile(d3dDevice, L
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small "landingPad.dds"<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small ,
&texture);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
MSG msg;
<font face="Consolas" size="2 <font face="Consolas" size="2
ZeroMemory(&msg,
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small sizeof<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small (msg));<font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small while<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
(msg.message!=WM_QUIT)
{
<font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small while<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small (PeekMessage(&msg,
NULL, 0U, 0U, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
hr = d3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);
hr = d3dDevice->BeginScene();
D3DXVECTOR3 pos(0,0,0);
sprite->Begin(D3DXSPRITE_ALPHABLEND);
RECT rect;
rect.left = 0;
rect.top = 0;
rect.right = screenWidth;
rect.bottom = screenHeight;
sprite->Draw(texture, &rect, NULL, &pos, 0xFFFFFFFF);
sprite->End();
d3dDevice->EndScene();
d3dDevice->Present(NULL, NULL, NULL, NULL);
}
texture->Release();
<font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small return<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
<font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small switch<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
(message)
{
<font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small case<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
WM_COMMAND:
{
<font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small int<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
wmId = LOWORD(wParam); <font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small int<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
wmEvent = HIWORD(wParam); <font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#008000; font-size:x-small <span style="font-family:Consolas; color:#008000; font-size:x-small <span style="font-family:Consolas; color:#008000; font-size:x-small // Parse the menu selections:
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small switch<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
(wmId)
{
<font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small case<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
IDM_EXIT:
DestroyWindow(hWnd);
<font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small break<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small ;
}
<font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small break<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small ;
}
<font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small case<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
WM_DESTROY:
PostQuitMessage(0);
<font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small break<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small ;<font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small default<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small :<font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small return<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
DefWindowProc(hWnd, message, wParam, lParam);
}
<font face="Consolas" size="2 <font face="Consolas" size="2
</font></font><font face="Consolas" size="2
</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small return<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
0;
}
View the full article