|
|
- //////////////////////////////////////////////////////////////////////////////////////////////////
- //
- // File: d3dinit.cpp
- //
- // Author: Frank Luna (C) All Rights Reserved
- //
- // System: AMD Athlon 1800+ XP, 512 DDR, Geforce 3, Windows XP, MSVC++ 7.0
- //
- // Desc: Demonstrates how to initialize Direct3D, how to use the book's framework
- // functions, and how to clear the screen to black. Note that the Direct3D
- // initialization code is in the d3dUtility.h/.cpp files.
- //
- //////////////////////////////////////////////////////////////////////////////////////////////////
- #include "d3dUtility.h"
- #include <strstream>
- /*#include <d3dx9tex.h>
- #include <d3dx9core.h>
- */
- //
- // Globals
- //
- IDirect3DDevice9* Device = 0;
- IDirect3DTexture9* Tex1 = 0;
- IDirect3DTexture9* Tex2 = 0;
- ID3DXSprite* Spr = 0;
- //
- // Framework Functions
- //
- bool Setup()
- {
- // Nothing to setup in this sample.
- D3DXCreateSprite(Device,&Spr);
- Device->SetSamplerState(0,D3DSAMP_MIPFILTER,D3DTEXF_NONE);
- D3DXCreateTextureFromFileEx(Device,".\\DATA\\1.tga",0,0,0,0,D3DFMT_A8R8G8B8,D3DPOOL_DEFAULT,D3DX_FILTER_BOX,D3DX_DEFAULT,0xFF000000,0,0,&Tex1);
- //D3DXCreateTextureFromFile(Device,".\\DATA\\1.tga",&Tex1);
- //D3DXCreateTextureFromFileEx(Device,"1.tga",0,0,0,0,D3DFMT_A8R8G8B8,D3DPOOL_DEFAULT,D3DX_FILTER_BOX,D3DX_DEFAULT,0xFFffffff,0,0,&Tex1);
- D3DSURFACE_DESC desc;
- Tex1->GetLevelDesc(0,&desc);
-
-
- int height = desc.Height;
- int width = desc.Width;
- return true;
- }
- void Cleanup()
- {
- // Nothing to cleanup in this sample.
- }
- bool Display(float timeDelta)
- {
- if( Device ) // Only use Device methods if we have a valid device.
- {
- // Instruct the device to set each pixel on the back buffer black -
- // D3DCLEAR_TARGET: 0x00000000 (black) - and to set each pixel on
- // the depth buffer to a value of 1.0 - D3DCLEAR_ZBUFFER: 1.0f.
- static float lastTime;
- static int fps = 0;
- lastTime += timeDelta;
- if( lastTime > 1.0 )
- {
- std::ostrstream oss;
- oss << fps << "\n" << '\0' ;
- OutputDebugString( oss.str() );
- lastTime -= 1.0;
- fps = 0.0;
- }
- else
- ++fps;
- Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00ffffff, 1.0f, 0);
- Device->BeginScene();
- Spr->Begin(D3DXSPRITE_ALPHABLEND);
- Spr->Draw(Tex1,0,0,0,0xffffffff);
- Spr->End();
- Device->EndScene();
- // Swap the back and front buffers.
- Device->Present(0, 0, 0, 0);
- }
- return true;
- }
- //
- // WndProc
- //
- LRESULT CALLBACK d3d::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
- {
- switch( msg )
- {
- case WM_CREATE:
- SetTimer(hwnd,1,100,0);
- break;
- case WM_DESTROY:
- ::PostQuitMessage(0);
- break;
-
- case WM_KEYDOWN:
- if( wParam == VK_ESCAPE )
- ::DestroyWindow(hwnd);
- break;
- case WM_TIMER:
- int i = 1;
- break;
- }
- return ::DefWindowProc(hwnd, msg, wParam, lParam);
- }
- //
- // WinMain
- //
- int WINAPI WinMain(HINSTANCE hinstance,
- HINSTANCE prevInstance,
- PSTR cmdLine,
- int showCmd)
- {
- if(!d3d::InitD3D(hinstance,
- 640, 480, true, D3DDEVTYPE_HAL, &Device))
- {
- ::MessageBox(0, "InitD3D() - FAILED", 0, 0);
- return 0;
- }
-
- if(!Setup())
- {
- ::MessageBox(0, "Setup() - FAILED", 0, 0);
- return 0;
- }
- d3d::EnterMsgLoop( Display );
- Cleanup();
- Device->Release();
- return 0;
- }
复制代码 |
|