#include #include #include #pragma comment(lib,"d3d9.lib")
#pragma comment(lib,"d3dx9.lib")
#pragma comment(lib,"winmm.lib")
#define keydown(vk_code) ((getasynckeystate(vk_code) & 0x8000) ? 1 : 0)
#define msg(info) messagebox(null,info,"message",mb_ok)
#define errormsg(info) messagebox(null,info,"error",mb_iconstop)
#define safe_release_obj(pobject) if(pobject)
#define wnd_class "wndclass"
#define wnd_width 400
#define wnd_height 300
hwnd g_hwnd;
hinstance g_hinst;
lpdirect3d9 g_d3d;
lpdirect3ddevice9 g_device;
lpdirect3dvertexbuffer9 g_vb;
lpdirect3dtexture9 g_texture;
#define d3dfvf_custom (d3dfvf_xyz|d3dfvf_tex1)
struct customvertex
;class ctexture
~ctexture()
bool load(lpdirect3ddevice9 device, const char * imgpath)
return true; }
lpdirect3dtexture9 gettexture()const
private:
lpdirect3dtexture9 m_ptexture;
};ctexture g_tex1;
ctexture g_tex2;
lpdirect3dtexture9 g_pshowtexture;
bool initgeometry();
if(failed(g_device->createvertexbuffer(sizeof(square), 0, d3dfvf_custom, d3dpool_default, &g_vb, null)))
return false;
void * paddr;
if(failed(g_vb->lock(0, 0, (void**)&paddr, 0)))
return false;
memcpy(paddr, square, sizeof(square));
g_vb->unlock();
if(!g_tex1.load(g_device, "tex.bmp") ||
!g_tex2.load(g_device, "tex2.bmp"))
g_pshowtexture = g_tex1.gettexture();
g_device->setsamplerstate(0, d3dsamp_magfilter, d3dtexf_linear);
g_device->setsamplerstate(0, d3dsamp_minfilter, d3dtexf_linear);
g_device->setsamplerstate(0, d3dsamp_mipfilter, d3dtexf_point);
return true;
}bool initd3d()
void setupmatices()
void render()
lresult callback msgproc(hwnd hwnd, uint msg, wparam wparam, lparam lparam)
return defwindowproc(hwnd, msg, wparam, lparam);
}int winapi winmain(hinstance hinst,hinstance hprevinst, lpstr cmdlint, int show)
cw_usedefault, cw_usedefault, wnd_width, wnd_height,
null, null, hinst, null);
if(!g_hwnd)
return 0;
showwindow(g_hwnd, sw_shownormal);
updatewindow(g_hwnd);
msg msg=;
if(!initd3d())
else if(!initgeometry())
while(msg.message != wm_quit)
render(); }
unregisterclass(wnd_class, wcex.hinstance);
return 0;
}
不要為3d而3d
和以前的幾個朋友聊天,也有做game的。發現大家對3d技術都非常熱衷,但是這種熱衷顯得刻意的 為3d而3d,就有點捨本逐末。1 遊戲最重要的是策劃,需要具體的滿足人心底的某種需求,2 3d需要 好顯示卡的支援,這樣就將一部分使用者排斥在外面了。3 現在3d engine已經 很成熟了,通過這些上面的...
3d程式設計的無敵組合
發現有了irrlicht irrnewt irrklang 3d程式設計就無敵了。簡介一下 irrlicht在開源3d引擎裡算很好的乙個,而且它是lgpl lesser general public license 協議的,你可以隨意使用它。主頁 http irrlicht.sourceforge....
3D程式設計的深度資訊
深度資訊在不同的階段其意義是不同的,不同的3d介面對這個深度資訊的理解也有區別。本文僅僅討論位於ndc空間的深度資訊,其取值範圍通常是 0,1.0 或者 1.0,1.0 opengl預設是gl negative one to one,即 1.0,1.0 通過glclipcontrol gl zero...