如何将Linderdaum引擎与现有的OpenGL上下文一起使用



我使用SDL初始化OpenGL上下文:

SDL_init( SDL_INIT_VIDEO );
SDL_surface* Screen = SDL_SetVideoMode( 1600, 1200, 0, SDL_OPENGL );

然后我做:

Env = new sEnvironment;
Env->DeployDefaultEnvironment( NULL, "../../CommonMedia" );

发动机启动并打开一个新窗口。

如何使用现有窗口?

您可以使用DeployEnvironment而不是DeployDefaultEnvironmentDeployEnvironment需要一个当前窗口的句柄,其中一个示例展示了如何在窗口上使用GLUT来实现这一点。您可以使用以下代码获得SDL上的当前窗口句柄

SDL_SysWMinfo SysInfo; //Will hold our Window information
SDL_VERSION(&SysInfo.version); //Set SDL version
if(SDL_GetWMInfo(&SysInfo) <= 0) {
    printf("%s : %dn", SDL_GetError(), SysInfo.window); 
    return; //or throw exception or whatever       
}
#ifdef __WIN32__
HWND WindowHandle = SysInfo.window; //Win32 window handle
#else
Window WindowHandle = SysInfo.window; //X11 window handle
#endif

最后,DeployEnvironment的定义如下:

DeployEnvironment   (const std::vector< std::string > * CommandLine,
const std::string & LogFileName,
const std::string & RootDir,
const std::string & CommonMediaDir,
const std::string & ConfigFile,
const bool          OpenViewport,
const bool          CreateRenderer,
const bool          ContextTakeover,
void *          ExternalWndHandle);

命令行参数与DeployDefaultEnvironment的参数相同,接下来的4个参数是路径,但您可以使用常量"DEFAULT_ENGINE_LOG_FILE"、"DEFAULT _ENGINE_ROOT_DIR"、"AULT_ENGINE_ROOT_PACK"one_answers"DEFAULT_ENGINE_INI_FILE。OpenViewport和CreateRenderer应为false,ContextTakeover应为true。最后,将ExternalWndHandle设置为存储在上面代码中声明的变量中的窗口句柄。注意,这个例子是针对windows上的GLUT,所以我不知道这是否适用于其他操作系统。

最新更新