#include "Core_Global.h"
#include "rmxftmpl.h"
#include "rmxfguid.h"
cGraphics::cGraphics()
{
m_hWnd = NULL;
m_pD3D = NULL;
m_pD3DDevice = NULL;
m_pSprite = NULL;
m_AmbientRed = m_AmbientGreen = m_AmbientBlue = 255;
m_Width = 0;
m_Height = 0;
m_BPP = 0;
m_Windowed = TRUE;
m_ZBuffer = FALSE;
m_HAL = FALSE;
}
cGraphics::~cGraphics()
{
Shutdown();
}
BOOL cGraphics::Init()
{
Shutdown();
if((m_pD3D = Direct3DCreate8(D3D_SDK_VERSION)) == NULL)
return FALSE;
return TRUE;
}
BOOL cGraphics::SetMode(HWND hWnd, BOOL Windowed, BOOL UseZBuffer, long Width, long Height, char BPP)
{
D3DPRESENT_PARAMETERS d3dpp;
D3DFORMAT Format, AltFormat;
RECT WndRect, ClientRect;
long WndWidth, WndHeight;
float Aspect;
// Error checking
if((m_hWnd = hWnd) == NULL)
return FALSE;
if(m_pD3D == NULL)
return FALSE;
if(FAILED(m_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &m_d3ddm)))
return FALSE;
if(!Width) {
if(Windowed == FALSE) {
m_Width = m_d3ddm.Width;
} else {
GetClientRect(m_hWnd, &ClientRect);
m_Width = ClientRect.right;
}
} else {
m_Width = Width;
}
if(!Height) {
if(Windowed == FALSE) {
m_Height = m_d3ddm.Height;
} else {
GetClientRect(m_hWnd, &ClientRect);
m_Height = ClientRect.bottom;
}
} else {
m_Height = Height;
}
if(!(m_BPP = BPP) || Windowed == TRUE) {
if(!(m_BPP = GetFormatBPP(m_d3ddm.Format)))
return FALSE;
}
if(Windowed == TRUE) {
GetWindowRect(m_hWnd, &WndRect);
GetClientRect(m_hWnd, &ClientRect);
WndWidth = (WndRect.right - (ClientRect.right - m_Width)) - WndRect.left;
WndHeight = (WndRect.bottom - (ClientRect.bottom - m_Height)) - WndRect.top;
MoveWindow(m_hWnd, WndRect.left, WndRect.top, WndWidth, WndHeight, TRUE);
}
ZeroMemory(&d3dpp, sizeof(D3DPRESENT_PARAMETERS));
m_HAL = FALSE;
if((m_Windowed = Windowed) == TRUE) {
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = m_d3ddm.Format;
if(CheckFormat(m_d3ddm.Format, TRUE, TRUE) == TRUE) {
m_HAL = TRUE;
} else {
if(CheckFormat(m_d3ddm.Format, TRUE, FALSE) == FALSE)
return FALSE;
}
} else {
d3dpp.Windowed = FALSE;
d3dpp.SwapEffect = D3DSWAPEFFECT_FLIP;
d3dpp.BackBufferWidth = m_Width;
d3dpp.BackBufferHeight = m_Height;
d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_ONE; // or D3DPRESENT_INTERVAL_DEFAULT or D3DPRESENT_INTERVAL_IMMEDIATE
if(m_BPP == 32) {
Format = D3DFMT_X8R8G8B8;
AltFormat = D3DFMT_X8R8G8B8;
}
if(m_BPP == 24) {
Format = D3DFMT_R8G8B8;
AltFormat = D3DFMT_R8G8B8;
}
if(m_BPP == 16) {
Format = D3DFMT_R5G6B5;
AltFormat = D3DFMT_X1R5G5B5;
}
if(m_BPP == 8) {
Format = D3DFMT_P8;
AltFormat = D3DFMT_P8;
}
if(CheckFormat(Format, FALSE, TRUE) == TRUE) {
m_HAL = TRUE;
} else {
if(CheckFormat(AltFormat, FALSE, TRUE) == TRUE) {
m_HAL = TRUE;
Format = AltFormat;
} else {
if(CheckFormat(Format, FALSE, FALSE) == FALSE) {
if(CheckFormat(AltFormat, FALSE, FALSE) == FALSE)
return FALSE;
else
Format = AltFormat;
}
}
}
d3dpp.BackBufferFormat = Format;
}
if((m_ZBuffer = UseZBuffer) == TRUE) {
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
} else {
d3dpp.EnableAutoDepthStencil = FALSE;
}
if(FAILED(m_pD3D->CreateDevice(D3DADAPTER_DEFAULT,
(m_HAL == TRUE) ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF,
hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &m_pD3DDevice))) {
if(m_ZBuffer == TRUE) {
m_ZBuffer = FALSE;
d3dpp.EnableAutoDepthStencil = FALSE;
if(FAILED(m_pD3D->CreateDevice(D3DADAPTER_DEFAULT,
(m_HAL == TRUE) ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF,
hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &m_pD3DDevice)))
return FALSE;
} else
return FALSE;
}
EnableLighting(FALSE);
EnableZBuffer(m_ZBuffer);
EnableAlphaBlending(FALSE);
EnableAlphaTesting(FALSE);
m_pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
m_pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
m_pD3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
m_pD3DDevice->SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);
m_pD3DDevice->SetTextureStageState(0, D3DTSS_MINFILTER, D3DTEXF_LINEAR);
SetAmbientLight(255,255,255);
Aspect = (float)m_Height / (float)m_Width;
SetPerspective(D3DX_PI/4, Aspect, 1.0f, 10000.0f);
if(FAILED(D3DXCreateSprite(m_pD3DDevice, &m_pSprite)))
return FALSE;
return TRUE;
}
BOOL cGraphics::Shutdown()
{
ReleaseCOM(m_pSprite);
ReleaseCOM(m_pD3DDevice);
ReleaseCOM(m_pD3D);
return TRUE;
}
IDirect3D8 *cGraphics::GetDirect3DCOM()
{
return m_pD3D;
}
IDirect3DDevice8 *cGraphics::GetDeviceCOM()
{
return m_pD3DDevice;
}
ID3DXSprite *cGraphics::GetSpriteCOM()
{
return m_pSprite;
}
long cGraphics::GetNumDisplayModes()
{
if(m_pD3D == NULL)
return 0;
return (long)m_pD3D->GetAdapterModeCount(D3DADAPTER_DEFAULT);
}
BOOL cGraphics::GetDisplayModeInfo(long Num, D3DDISPLAYMODE *Mode)
{
long Max;
if(m_pD3D == NULL)
return FALSE;
Max = GetNumDisplayModes();
if(Num >= Max)
return FALSE;
if(FAILED(m_pD3D->EnumAdapterModes(D3DADAPTER_DEFAULT,
Num, Mode)))
return FALSE;
return TRUE;
}
char cGraphics::GetFormatBPP(D3DFORMAT Format)
{
switch(Format) {
case D3DFMT_A8R8G8B8:
case D3DFMT_X8R8G8B8:
return 32;
break;
case D3DFMT_R8G8B8:
return 24;
break;
case D3DFMT_R5G6B5:
case D3DFMT_X1R5G5B5:
case D3DFMT_A1R5G5B5:
case D3DFMT_A4R4G4B4:
return 16;
break;
case D3DFMT_A8P8:
case D3DFMT_P8:
return 8;
break;
default:
return 0;
}
}
BOOL cGraphics::CheckFormat(D3DFORMAT Format, BOOL Windowed, BOOL HAL)
{
if(FAILED(m_pD3D->CheckDeviceType(D3DADAPTER_DEFAULT,
(HAL == TRUE) ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF,
Format, Format, Windowed)))
return FALSE;
return TRUE;
}
BOOL cGraphics::BeginScene()
{
if(m_pD3DDevice == NULL)
return FALSE;
if(FAILED(m_pD3DDevice->BeginScene()))
return FALSE;
return TRUE;
}
BOOL cGraphics::EndScene()
{
short i;
if(m_pD3DDevice == NULL)
return FALSE;
for(i=0;i<8;i++)
m_pD3DDevice->SetTexture(i, NULL);
if(FAILED(m_pD3DDevice->EndScene()))
return FALSE;
return TRUE;
}
BOOL cGraphics::BeginSprite()
{
if(m_pSprite == NULL)
return FALSE;
if(FAILED(m_pSprite->Begin()))
return FALSE;
return TRUE;
}
BOOL cGraphics::EndSprite()
{
if(m_pSprite == NULL)
return FALSE;
if(FAILED(m_pSprite->End()))
return FALSE;
return TRUE;
}
BOOL cGraphics::Display()
{
if(m_pD3DDevice == NULL)
return FALSE;
if(FAILED(m_pD3DDevice->Present(NULL, NULL, NULL, NULL)))
return FALSE;
return TRUE;
}
BOOL cGraphics::Clear(long Color, float ZBuffer)
{
if(m_pD3DDevice == NULL)
return FALSE;
if(m_ZBuffer == FALSE)
return ClearDisplay(Color
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
网络游戏开发设计VC++.rar (53个子文件)
3D引擎
Core_Global.h 398B
Core_System.h 3KB
Core_Input.h 8KB
Core_Input.cpp 13KB
Core_Sound.h 6KB
Core_Graphics.h 25KB
Core_Network.h 6KB
Core_System.cpp 8KB
Core_Graphics.cpp 63KB
Core_Sound.cpp 28KB
Core_Network.cpp 23KB
Client
Client.dsp 5KB
Client.aps 17KB
Client.ncb 65KB
Client.exe 352KB
resource.h 685B
NodeTree.h 3KB
WinMain.h 4KB
Debug
NodeTree.cpp 10KB
Frustum.cpp 5KB
WinMain.cpp 19KB
Client.dsw 535B
Client.cpp 11KB
Frustum.h 524B
Client.opt 53KB
Client.rc 2KB
Client.h 3KB
Server
resource.h 448B
Server.rc 2KB
Server.h 512B
WinMain.h 4KB
Debug
Server.dsp 5KB
WinMain.cpp 21KB
Server.opt 53KB
Server.suo 9KB
Server.exe 316KB
Server.ncb 65KB
Server.cpp 319B
Server.dsw 535B
执行程序
服务端.exe 316KB
fData
brick.bmp 48KB
Sword.x 3KB
dirt.bmp 48KB
ArenaCM.x 43KB
Sword.bmp 12KB
Pillar.bmp 192KB
Stars.bmp 192KB
Warrior.x 733KB
stone.bmp 48KB
Warrior.bmp 191KB
Arena.x 127KB
客户端.exe 352KB
论文.doc 607KB
共 53 条
- 1
资源评论
a13945149916
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功