//////////////////////////////////////////////////////////////////////////////////////////////////
//
// File: xfile.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 load and render an XFile.
//
//////////////////////////////////////////////////////////////////////////////////////////////////
#include "d3dgui.h"
#include "d3dUtility.h"
#pragma comment(lib,"d3d9.lib")
#pragma comment(lib,"d3dx9.lib")
#pragma comment(lib,"winmm.lib")
//
// Globals
//
IDirect3DDevice9* Device = 0;
CD3DGUISystem *gui=NULL;
BOOL LMBDown=FALSE;
int mouseX=0,mouseY=0;
int arialID = -1;
int timesID = -1;
#define STATIC_ID_1 1
#define STATIC_ID_2 2
#define BUTTON_ID_1 3
#define BUTTON_ID_2 4
#define BUTTON_ID_3 5
#define BUTTON_ID_4 6
const int Width = 640;
const int Height = 480;
void GUICallback(int id, int state)
{
switch(id)
{
case BUTTON_ID_1:
case BUTTON_ID_2:
case BUTTON_ID_3:
// Demonstration. No need to do anything.
break;
case BUTTON_ID_4:
// If the quit button is pressed, quit app.
if(state == UGP_BUTTON_DOWN) PostQuitMessage(0);
break;
}
}
//
// Framework functions
//
bool Setup()
{
gui = new CD3DGUISystem(Device, Width, Height);
gui->AddBackdrop("backdrop.jpg");
gui->CreateFont("Arial", 18, &arialID);
gui->CreateFont("Times New Roman", 18, ×ID);
gui->AddStaticText(STATIC_ID_1, "Main Menu Version: 1.0",
450, 100, D3DCOLOR_XRGB(0,255,0), arialID);
gui->AddStaticText(STATIC_ID_2, "Chapter 4 - GUI Demo",
450, 340, D3DCOLOR_XRGB(0,0,255), timesID);
gui->AddButton(BUTTON_ID_1, 50, 200, "startUp.png",
"StartOver.png", "startDown.png");
gui->AddButton(BUTTON_ID_2, 50, 232, "loadUp.png",
"loadOver.png", "loadDown.png");
gui->AddButton(BUTTON_ID_3, 50, 264, "optionsUp.png",
"optionsOver.png", "optionsDown.png");
gui->AddButton(BUTTON_ID_4, 50, 296, "quitUp.png",
"quitOver.png", "quitDown.png");
Device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
Device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
Device->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);
//
// Set Lights.
//
D3DXVECTOR3 dir(1.0f, -1.0f, 1.0f);
D3DXCOLOR col(1.0f, 1.0f, 1.0f, 1.0f);
D3DLIGHT9 light = d3d::InitDirectionalLight(&dir, &col);
Device->SetLight(0, &light);
Device->LightEnable(0, true);
Device->SetRenderState(D3DRS_NORMALIZENORMALS, true);
Device->SetRenderState(D3DRS_SPECULARENABLE, true);
//
// Set camera.
//
D3DXVECTOR3 pos(4.0f, 4.0f, -13.0f);
D3DXVECTOR3 target(0.0f, 0.0f, 0.0f);
D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);
D3DXMATRIX V;
D3DXMatrixLookAtLH(
&V,
&pos,
&target,
&up);
Device->SetTransform(D3DTS_VIEW, &V);
//
// Set projection matrix.
//
D3DXMATRIX proj;
D3DXMatrixPerspectiveFovLH(
&proj,
D3DX_PI * 0.5f, // 90 - degree
(float)Width / (float)Height,
1.0f,
1000.0f);
Device->SetTransform(D3DTS_PROJECTION, &proj);
return true;
}
void Cleanup()
{
gui->Shutdown();
delete gui;
gui = NULL;
}
bool Display(float timeDelta)
{
if( Device )
{
//
// Update: Rotate the mesh.
//
static float y = 0.0f;
D3DXMATRIX yRot;
D3DXMatrixRotationY(&yRot, y);
y += timeDelta;
if( y >= 6.28f )
y = 0.0f;
D3DXMATRIX World = yRot;
Device->SetTransform(D3DTS_WORLD, &World);
//
// Render
//
Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0);
Device->BeginScene();
ProcessGUI(gui, LMBDown, mouseX, mouseY, GUICallback);
Device->EndScene();
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_DESTROY:
::PostQuitMessage(0);
break;
case WM_KEYDOWN:
if( wParam == VK_ESCAPE )
::DestroyWindow(hwnd);
break;
case WM_LBUTTONDOWN:
LMBDown = true;
break;
case WM_LBUTTONUP:
LMBDown = false;
break;
case WM_MOUSEMOVE:
mouseX = LOWORD (lParam);
mouseY = HIWORD (lParam);
break;
}
return ::DefWindowProc(hwnd, msg, wParam, lParam);
}
//
// WinMain
//
int WINAPI WinMain(HINSTANCE hinstance,
HINSTANCE prevInstance,
PSTR cmdLine,
int showCmd)
{
if(!d3d::InitD3D(hinstance,
Width, Height, 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;
}
没有合适的资源?快使用搜索试试~ 我知道了~
d3d游戏编程源代码
共45个文件
cpp:20个
h:18个
txt:6个
5星 · 超过95%的资源 需积分: 9 28 下载量 165 浏览量
2010-08-25
17:10:42
上传
评论 1
收藏 69KB RAR 举报
温馨提示
这是我学习并整理的一些代码,可以直接用在程序代码中,方便大家学习!
资源推荐
资源详情
资源评论
收起资源包目录
d3dtools.rar (45个子文件)
d3dtools
粒子系统
pSystem.h 3KB
pSystem.cpp 11KB
声音
DirectMusic.cpp 8KB
DirectMusic.h 2KB
技术文档
细节纹理.txt 2KB
Desktop.ini 77B
gui图形用户界面
D3DGUI.cpp 13KB
实例.txt 5KB
D3DGUI.h 3KB
地形
terrain.cpp 13KB
terrain.h 2KB
terrainDriver.txt 4KB
模型动画
XMesh.h 2KB
XMesh.cpp 7KB
XStructures.cpp 5KB
XStructures.h 1011B
碰撞检测
compute.cpp 1KB
compute.h 331B
效果架构
效果实现例子.txt 1010B
fog.txt 1KB
框架
main.cpp 3KB
d3dUtility.cpp 10KB
d3dUtility.h 5KB
文本
d3dfont.h 2KB
dxutil.h 8KB
d3dfont.cpp 23KB
3dtext
d3dtext.cpp 1KB
d3dtext.h 187B
fps
fps.cpp 1KB
fps.h 833B
d3dutil.cpp 20KB
dxutil.cpp 35KB
d3dutil.h 6KB
cfont.cpp 3KB
摄像机
camera.h 1KB
camera.cpp 4KB
截头体
MathDefines.h 422B
Frustum.h 582B
Vector.cpp 3KB
Plane.h 1KB
Vector.h 1KB
Plane.cpp 3KB
Frustum.cpp 5KB
main.cpp 8KB
使用说明.txt 0B
共 45 条
- 1
资源评论
- yy________2013-10-19很好,很基础
abs911
- 粉丝: 1
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功