我使用SDL来初始化我的OpenGL上下文:
SDL_init( SDL_INIT_VIDEO );
SDL_surface* Screen = SDL_SetVideoMode( 1600, 1200, 0, SDL_OPENGL );然后我就做了:
Env = new sEnvironment;
Env->DeployDefaultEnvironment( NULL, "../../CommonMedia" );引擎启动并打开一个新窗口。
如何使用现有窗口?
发布于 2013-07-15 20:52:54
您可以使用DeployEnvironment而不是DeployDefaultEnvironment DeployEnvironment需要当前窗口的句柄,其中一个示例展示了如何在窗口上使用GLUT来实现这一点。您可以使用以下代码获取SDL上的当前窗口句柄
SDL_SysWMinfo SysInfo; //Will hold our Window information
SDL_VERSION(&SysInfo.version); //Set SDL version
if(SDL_GetWMInfo(&SysInfo) <= 0) {
printf("%s : %d\n", 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’、'DEFAULT_ENGINE_ROOT_PACK‘、'DEFAULT_ENGINE_INI_FILE’。OpenViewport应为false,CreateRenderer也应为false,ContextTakeover应为true。最后,将ExternalWndHandle设置为存储在上面代码中声明的变量中的窗口句柄。请注意,该示例是针对windows上的GLUT的,因此我不知道这是否适用于其他OSes。
https://stackoverflow.com/questions/17591558
复制相似问题