Nebula2使用音频视频接口心得

0 views
Skip to first unread message

神杀中龙

unread,
Dec 15, 2006, 1:38:27 AM12/15/06
to 用nebula2 sdk来做游戏
// 搞明白 怎么做后, Nebula2的 视频接口可以
认为是最容易使用的了。 也是对
DirectShow的二次封装。
//------------------------------------------------------------------------------
/**
@file
@ingroup Nebula2TutorialsBasic

@brief Basic Example 02 - Opening a graphics window.

This example opens a graphics window and clears it to a particular
colour. In order to open a window we need to do quite a lot more
than the previous example.

The main class we need to deal with is nGfxServer2, this is the
base
class for all the graphics implementations. Unlike the kernel
server
all other servers have to be created through the kernel server,
this
is true for any nRoot derived class and servers are always derived
from nRoot. In order to be able to create a server, or other nRoot
derived object, we have to first ensure that it has been registered

with the kernel server; this is done by adding packages. The base
gfx classes are contained in the nnebula package and the D3D9 based

graphics server is in the ndirect3d9 package. See @ref
Nebula2Packages to see the other packages. There are two steps to
adding a package, the first is to declare which packages we are
using, and then after creating the kernel server we have to add the

packages.

The 图形服务器 can now be created via nKernelServer::New(). It

is also necessary to add a resource server (nResourceServer) as the

graphics server expects one to be available.
*/

#include "kernel/nkernelserver.h"
#include "kernel/nfileserver2.h"
#include "resource/nresourceserver.h"
#include "gfx2/ngfxserver2.h"
#include "audio3/ndsoundserver3.h"
#include "audio3/ndsound3.h"
#include "video/ndshowserver.h"


// declare packages
nNebulaUsePackage(nnebula);
nNebulaUsePackage(ndirect3d9);
nNebulaUsePackage(ndsaudioserver3); //使用DirectSound
DSaudioServer
nNebulaUsePackage(ndshow);

int main(int /*argc*/, const char** /*argv*/)
{
nKernelServer* kernelServer = new nKernelServer(); //唯一对象

// all packages have to be declared and added before you use them
kernelServer->AddPackage(nnebula);
kernelServer->AddPackage(ndirect3d9);
kernelServer->AddPackage(ndsaudioserver3);
kernelServer->AddPackage(ndshow);

nRef<nResourceServer> refResourceServer;
nRef<nGfxServer2> refGfxServer;


refResourceServer =
(nResourceServer*)kernelServer->New("nresourceserver",
"/sys/servers/resource");
refGfxServer = (nGfxServer2*)kernelServer->New("nd3d9server",
"/sys/servers/gfx");


//音频对象
//音频服务器
nDSoundServer3* audioServer = NULL;
audioServer = (nDSoundServer3*)kernelServer->New("ndsoundserver3",
"/sys/servers/audio");

//使用视频对象
nDShowServer* videoServer = NULL;
videoServer =
(nDShowServer*)kernelServer->New("ndshowserver","/sys/servers/video");


// set shaders assign, needed for the gfx server,
// this means that "shaders:" can be used to refer to the given
directory.
kernelServer->GetFileServer()->SetAssign("shaders",
"home:data/shaders/fixed");

nDisplayMode2 DisplayMode(
"Nebula2: 音频啊音频",
nDisplayMode2::Windowed,
0, 0,
640, 480,
false);
DisplayMode.SetDialogBoxMode(true);
refGfxServer->SetDisplayMode(DisplayMode); //设置显示模式

bool result;
result = refGfxServer->OpenDisplay();
n_assert(result);


//使用音频接口
nDSound3 *Lsound = NULL;

Lsound = new nDSound3();
audioServer->Open(); //必须根据窗口来使用

audioServer->Create(&Lsound,
"F:\\LoLLay.wav",DSBCAPS_CTRLFX,GUID_NULL, 2);
//Lsound->Play();

// to avoid dereferencing the nRef all the time
// get a pointer to the gfx server.
nGfxServer2* gfxServer = refGfxServer.get();

videoServer->Open();

videoServer->PlayFile("F:\\backup\\Server\\video\\TombRaider7_No.1_Download.wmv");

// triggthe gfx server once every frame
// Trigger() returns false if you close the window
while (gfxServer->Trigger())
{
gfxServer->BeginScene();
gfxServer->Clear(nGfxServer2::AllBuffers, 0.0f, 0.8f, 0.6f,
0.4f, 0.0f, 0);


audioServer->BeginScene(timeGetTime());
audioServer->EndScene();


gfxServer->EndScene();
gfxServer->PresentScene();

// allow Windows to multitask
n_sleep(0.0);
}


if(Lsound != NULL)
{
delete Lsound; Lsound = NULL;
}

videoServer->Close();
audioServer->Close();
refGfxServer->CloseDisplay();
refGfxServer->Release();
refResourceServer->Release();

delete kernelServer;
return 0;
}

fatsnake

unread,
Dec 15, 2006, 1:43:12 AM12/15/06
to 用nebula2 sdk来做游戏
感谢神杀中龙发贴,希望大家踊跃一点,为死气沉沉的Nebula2爱好者论坛带来活力。
Reply all
Reply to author
Forward
0 new messages