nvidia 的 nview 工具可把畫面轉90度(1024*768), 所有的程式輸出都可左轉90度, 但為何碰上 d3d9 的全螢幕模式下程式輸出就完全不轉了? 以下附上我的程式碼, 請先進們指教! 如何用最有效率的方法將之左轉90度! 還有為何這支程式為何 nview 無法控制它轉90度? #include
#pragma hdrstop #include "Unit1.h"
//#include <Math.hpp> HDC hDC = 0; // Handle Device Context
TCanvas* cv = 0; // Pointer to Canvas //---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "AIRLib_OCX"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Screen->Cursor=crNone;
SetBounds((Screen->Width-nWidth)/2, (Screen->Height-nHeight)/2,
nWidth,nHeight);
bool bOk = true;
if(!InitD3D(Handle, nWidth, nHeight, false, D3DDEVTYPE_HAL, &Device))
{
ShowMessage("InitD3D() FAILED!");
bOk = false;
} Application->OnIdle = idle;
//Display(0.4);
} bool Display(float timeDelta)
{
// GetFlyValues(); if( Device ) // Only use Device methods if we have a valid device.
{
Device->BeginScene(); pBackSurf->GetDC(&hDC);
cv = new TCanvas;
cv->Handle = hDC;
cv->Font->Name = "Arial";
cv->Font->Style = TFontStyles() << fsBold;
cv->Font->Size = 12; cv->Brush->Color = clBlack;
cv->Pen->Color = clRed;
cv->Rectangle(0, 0, (nWidth), (nHeight));
Form1->Button1->PaintTo(cv, 100.0, 200.0); /* if(Form1->bBack)
BitBlt(cv->Handle, 0, 0, nWidth, nHeight,
bmBack->Canvas->Handle, 0, 0, SRCCOPY); */ // DrawRadar();
// DrawVel();
// DrawAOA();
// DrawHel();
// DrawROC();
// SetGMS();
// DrawROC1();
// DrawHel1();
// DrawVel1();
// DrawAOA1();
// DrawHeading(); // DrawTexts(); // if(Form1->bRef)
// {
// 十字線
cv->Pen->Color = clGray;
int i, x, y; for(i=0; (iMoveTo(x, 0);
cv->LineTo(x, nHeight);
} for(i=0; (iMoveTo(0, y);
cv->LineTo(nWidth, y);
} cv->Pen->Color = clRed;
cv->MoveTo((nWidth/2), 0);
cv->LineTo((nWidth/2), nHeight);
cv->Pen->Color =clYellow;
cv->MoveTo(0, (nHeight/2));
cv->LineTo(nWidth, (nHeight/2));
cv->Font->Color = clWhite;
cv->Brush->Style= bsClear; cv->TextOutA(2, 18, "test");
cv->Brush->Color = clBlack;
cv->Pen->Color = clRed;
cv->Brush->Style= bsClear; // } // CalcFPS(timeDelta); delete cv; pBackSurf->ReleaseDC(hDC);
Device->EndScene();
Device->Present(0, 0, 0, 0);
} return true;
}
void Cleanup()
{
Release(pBackSurf);
Release(Device); // CloseShareMemory(); } void __fastcall TForm1::FormDestroy(TObject *Sender)
{
Cleanup();
Screen->Cursor=crDefault;
} void __fastcall TForm1::idle(TObject* Sender,bool &Done)
{
static float lastTime=timeGetTime();
float currTime=timeGetTime();
float timeDelta=(currTime-lastTime)*0.001f;
Display(timeDelta);
lastTime=currTime; Done=false;
} bool InitD3D(HWND hwnd,
int width, int height,
bool windowed,
D3DDEVTYPE deviceType,
IDirect3DDevice9** device)
{
HRESULT hr = 0; // Step 1: Create the IDirect3D9 object. IDirect3D9* d3d9 = 0;
d3d9 = Direct3DCreate9(D3D_SDK_VERSION); if( !d3d9 )
{
::MessageBox(0, "Direct3DCreate9() - FAILED", 0, 0);
return false;
} // Step 2: Check for hardware vp. D3DCAPS9 caps;
d3d9->GetDeviceCaps(D3DADAPTER_DEFAULT, deviceType, &caps); int vp = 0;
if( caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT )
vp = D3DCREATE_HARDWARE_VERTEXPROCESSING;
else
vp = D3DCREATE_SOFTWARE_VERTEXPROCESSING; // Step 3: Fill out the D3DPRESENT_PARAMETERS structure.
D3DPRESENT_PARAMETERS d3dpp;
d3dpp.BackBufferWidth = width ;
d3dpp.BackBufferHeight = height;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
d3dpp.BackBufferCount = 1;
d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
d3dpp.MultiSampleQuality = 0;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = hwnd;
d3dpp.Windowed = windowed;
// d3dpp.EnableAutoDepthStencil = false;
// d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
d3dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; // Step 4: Create the device. hr = d3d9->CreateDevice(
D3DADAPTER_DEFAULT, // primary adapter
deviceType, // device type
hwnd, // window associated with device
vp, // vertex processing
&d3dpp, // present parameters
device); // return created device if( FAILED(hr) )
{
// try again using a 16-bit depth buffer
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
hr = d3d9->CreateDevice(
D3DADAPTER_DEFAULT,
deviceType,
hwnd,
vp,
&d3dpp,
device); if( FAILED(hr) )
{
d3d9->Release(); // done with d3d9 object
::MessageBox(0, "CreateDevice() - FAILED", 0, 0);
return false;
}
}
hr=Device->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackSurf ); d3d9->Release(); // done with d3d9 object
if( FAILED(hr) ){
d3d9->Release(); // done with d3d9 object
::MessageBox(0, "GetBackBuffer() - FAILED", 0, 0);
return false;
} return true;
} //---------------------------------------------------------------------------