我不知道那个device->Clear(...)为什么不能实现
// 3D.cpp : Defines the entry point for the application.
//#include "stdafx.h"
IDirect3D9 *d3d9=0;
IDirect3DDevice9 *device=0;
bool SetUp()
{ return true;
}
bool Display(float timeDelta)
{
if(device->Clear(0,0,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,0xff000f00,1.0f,0)!=D3D_OK)
{
::MessageBox(0,"","",MB_OK);//////////////////////////////////////////////////////////////
}
device->Present(0,0,0,0);
return true;
}
bool ClearUp()
{ if(d3d9!=0)
d3d9->Release();
if(device!=0)
device->Release();
return true;
}void EnterMsgLoop(bool (* p)(float timeDelta))
{
MSG msg;
::memset(&msg,0,sizeof(msg));
static float latm=(float)timeGetTime();
while(msg.message!=WM_QUIT)
{
if(::PeekMessage(&msg,0,0,0,PM_REMOVE))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
else
{
float curtm=(float)timeGetTime();
float timeDelta = (curtm-latm)*0.002f;
p(timeDelta);
latm=curtm;
}
}}LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
switch( msg )
{
case WM_DESTROY:
::PostQuitMessage(0);
break;
case WM_KEYDOWN:
if( wparam == VK_ESCAPE )
::DestroyWindow(hwnd);
break;
}
return ::DefWindowProc(hwnd,msg,wparam,lparam);
} void IniTD3D(HWND *phwnd)
{
d3d9=Direct3DCreate9(D3D_SDK_VERSION);
D3DPRESENT_PARAMETERS d3dpp;
d3dpp.BackBufferWidth=640;
d3dpp.BackBufferHeight=480;
d3dpp.BackBufferFormat=D3DFMT_A8R8G8B8;
d3dpp.BackBufferCount=1;
d3dpp.MultiSampleType=D3DMULTISAMPLE_NONE;
d3dpp.MultiSampleQuality=0;
d3dpp.SwapEffect=D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow=*phwnd;
d3dpp.Windowed =true;
d3dpp.EnableAutoDepthStencil = false;
d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
d3dpp.Flags = 0;
d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
d3d9->CreateDevice(
D3DADAPTER_DEFAULT, // primary adapter
D3DDEVTYPE_REF, // device type
*phwnd, // window associated with device
D3DCREATE_SOFTWARE_VERTEXPROCESSING, // vertex processing
&d3dpp, // present parameters
&device);
}int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASS wc;
memset(&wc,0,sizeof(wc));
wc.lpfnWndProc=(WNDPROC)WndProc;
wc.style=CS_HREDRAW|CS_VREDRAW;
wc.hInstance=hInstance;
wc.hCursor=::LoadCursor(0,IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszClassName = "Direct3D9App"; ::RegisterClass(&wc); HWND hwnd;
hwnd=::CreateWindow("Direct3D9App","D3DTest",WS_EX_TOPMOST,
0, 0, 640,480,0 , 0 , hInstance, 0 );
::ShowWindow(hwnd,SW_SHOW);
::UpdateWindow(hwnd); IniTD3D(&hwnd); SetUp(); EnterMsgLoop(Display); ClearUp();
return 0;
}
// stdafx.h : #if !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_)
#define AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif #define WIN32_LEAN_AND_MEAN #include <windows.h>
#include"mmsystem.h"
#pragma comment(lib,"winmm.lib")
#include"d3d9.h"
#pragma comment(lib,"d3d9.lib")#endif
// 3D.cpp : Defines the entry point for the application.
//#include "stdafx.h"
IDirect3D9 *d3d9=0;
IDirect3DDevice9 *device=0;
bool SetUp()
{ return true;
}
bool Display(float timeDelta)
{
if(device->Clear(0,0,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,0xff000f00,1.0f,0)!=D3D_OK)
{
::MessageBox(0,"","",MB_OK);//////////////////////////////////////////////////////////////
}
device->Present(0,0,0,0);
return true;
}
bool ClearUp()
{ if(d3d9!=0)
d3d9->Release();
if(device!=0)
device->Release();
return true;
}void EnterMsgLoop(bool (* p)(float timeDelta))
{
MSG msg;
::memset(&msg,0,sizeof(msg));
static float latm=(float)timeGetTime();
while(msg.message!=WM_QUIT)
{
if(::PeekMessage(&msg,0,0,0,PM_REMOVE))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
else
{
float curtm=(float)timeGetTime();
float timeDelta = (curtm-latm)*0.002f;
p(timeDelta);
latm=curtm;
}
}}LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
switch( msg )
{
case WM_DESTROY:
::PostQuitMessage(0);
break;
case WM_KEYDOWN:
if( wparam == VK_ESCAPE )
::DestroyWindow(hwnd);
break;
}
return ::DefWindowProc(hwnd,msg,wparam,lparam);
} void IniTD3D(HWND *phwnd)
{
d3d9=Direct3DCreate9(D3D_SDK_VERSION);
D3DPRESENT_PARAMETERS d3dpp;
d3dpp.BackBufferWidth=640;
d3dpp.BackBufferHeight=480;
d3dpp.BackBufferFormat=D3DFMT_A8R8G8B8;
d3dpp.BackBufferCount=1;
d3dpp.MultiSampleType=D3DMULTISAMPLE_NONE;
d3dpp.MultiSampleQuality=0;
d3dpp.SwapEffect=D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow=*phwnd;
d3dpp.Windowed =true;
d3dpp.EnableAutoDepthStencil = false;
d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
d3dpp.Flags = 0;
d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
d3d9->CreateDevice(
D3DADAPTER_DEFAULT, // primary adapter
D3DDEVTYPE_REF, // device type
*phwnd, // window associated with device
D3DCREATE_SOFTWARE_VERTEXPROCESSING, // vertex processing
&d3dpp, // present parameters
&device);
}int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASS wc;
memset(&wc,0,sizeof(wc));
wc.lpfnWndProc=(WNDPROC)WndProc;
wc.style=CS_HREDRAW|CS_VREDRAW;
wc.hInstance=hInstance;
wc.hCursor=::LoadCursor(0,IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszClassName = "Direct3D9App"; ::RegisterClass(&wc); HWND hwnd;
hwnd=::CreateWindow("Direct3D9App","D3DTest",WS_EX_TOPMOST,
0, 0, 640,480,0 , 0 , hInstance, 0 );
::ShowWindow(hwnd,SW_SHOW);
::UpdateWindow(hwnd); IniTD3D(&hwnd); SetUp(); EnterMsgLoop(Display); ClearUp();
return 0;
}
// stdafx.h : #if !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_)
#define AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif #define WIN32_LEAN_AND_MEAN #include <windows.h>
#include"mmsystem.h"
#pragma comment(lib,"winmm.lib")
#include"d3d9.h"
#pragma comment(lib,"d3d9.lib")#endif
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货