本文主要是介绍Nebula2探秘11-Simple Window,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Nebula2探秘11-Simple Window
happykevins文
前面的10节主要讲的是Nebula2内核层模块的应用,所以一直在黑黑Dos控制台下工作,可能大家已经非常想念Windows窗口了:) 从本章起,我将开始介绍Nebula2的应用层模块,并以一个最简单的Windows窗口程序开始。虽然简单,但是我们可以从中了解到Nebula2启动一个Windows窗口所需要的依赖,并且也简单的勾画了一个Nebula2的游戏循环。
代码如下:
/* 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
/// ----------------------------------------------------------------------------
这篇关于Nebula2探秘11-Simple Window的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!