/****************************************************************************/
/* Nebula2 - Tutorial 11 */
/* Create SimpleWindow Using nD3D9Server */
/* author: happykevins */
/****************************************************************************/
///----------------------------------------------------------------------------
/// +必要头文件
// nebula2 includes
#include "kernel/nkernelserver.h"
#include "kernel/nfileserver2.h"
#include "gfx2/nd3d9server.h"
// Tutorial工具库:一些通用的宏定义
#include "../NebulaUtils/nutildefs.h"
/// -必要头文件
///----------------------------------------------------------------------------
///----------------------------------------------------------------------------
/// +链接库
#pragma comment(lib, "wsock32.lib")
#pragma comment(lib, "d_nkernel.lib")
#pragma comment(lib, "d_nnebula.lib")
#pragma comment(lib, "dxguid.lib")
#pragma comment(lib, "dxerr9.lib")
#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9d.lib")
#pragma comment(lib, "d_ndirect3d9.lib")
/// -链接库
///----------------------------------------------------------------------------
///----------------------------------------------------------------------------
/// +声明使用的Nebula2 Package&Module
nNebulaUseModule(nresource);
nNebulaUseModule(nresourceserver);
nNebulaUseModule(nfont2);
nNebulaUseModule(nmesh2);
nNebulaUseModule(nmesharray);
nNebulaUseModule(nshader2);
nNebulaUseModule(ntexture2);
nNebulaUseModule(ngfxserver2);
nNebulaUsePackage(ndirect3d9);
/// -声明使用的Nebula2 Package&Module
///----------------------------------------------------------------------------
///----------------------------------------------------------------------------
/// +Application
int main(int argc, const char** argv)
{
/// 创建KernelServer
nKernelServer* ks = n_new(nKernelServer);
///----------------------------------------------------------------------------
/// +向KernelServer中添加Package&Module
nNebulaAddModule(nresource);
nNebulaAddModule(nresourceserver);
nNebulaAddModule(nfont2);
nNebulaAddModule(nmesh2);
nNebulaAddModule(nmesharray);
nNebulaAddModule(nshader2);
nNebulaAddModule(ntexture2);
nNebulaAddModule(ngfxserver2);
ks->AddPackage(ndirect3d9);
/// +向KernelServer中添加Package&Module
///----------------------------------------------------------------------------
/// 创建D3D9Server
nD3D9Server* gfx2 = (nD3D9Server*)ks->New("nd3d9server", "/sys/servers/gfx");
/// 创建ResourceServer
nResourceServer* res = (nResourceServer*)ks->New("nresourceserver", "/sys/servers/resource");
/// 获得FileServer设置shaders的路径
nFileServer2* file = (nFileServer2*)ks->Lookup("sys/servers/file2");
/// @note:这是启动d3d9server必须的
/// 因为d3d9server在初始化时会访问"shaders:shape.fx",用它来控制绘制调试图形的渲染状态
file->SetAssign("shaders", "bin:../../datafiles/shaders/fixed");
/// 初始化显示模式
nDisplayMode2 mode;
mode.SetXPos(150);
mode.SetYPos(100);
mode.SetWidth(640);
mode.SetHeight(480);
/// 将显示模式应用到d3d9server
gfx2->SetDisplayMode(mode);
/// 启动d3d9server
gfx2->OpenDisplay();
/// 这里相当于游戏循环,gfx2->Trigger()将触发win32的消息泵
while ( gfx2->Trigger() )
{
/// 一帧开始
gfx2->BeginFrame();
/// 绘制场景开始
if ( gfx2->BeginScene() )
{
/// 设置渲染缓冲区
gfx2->Clear(nGfxServer2::AllBuffers, 0.2f, 0.2f, 0.8f, 1.0f, 0, 0);
/// 绘制场景结束
gfx2->EndScene();
/// 显示场景
gfx2->PresentScene();
}
/// 一帧结束
gfx2->EndFrame();
n_sleep(0.01f);
}
/// 关闭d3d9server
gfx2->CloseDisplay();
/// 销毁KernelServer
n_delete(ks);
return 0;
}
/// -Application
///----------------------------------------------------------------------------