Reputation:
I use SDL to initialize my OpenGL context:
SDL_init( SDL_INIT_VIDEO );
SDL_surface* Screen = SDL_SetVideoMode( 1600, 1200, 0, SDL_OPENGL );
And then I do:
Env = new sEnvironment;
Env->DeployDefaultEnvironment( NULL, "../../CommonMedia" );
The engine starts and opens up a new window.
How can I use the existing window?
Upvotes: 1
Views: 155
Reputation: 5015
You can use DeployEnvironment instead of DeployDefaultEnvironment DeployEnvironment requires a handle to the current window, and one of the examples shows how this can be achieved using GLUT on windows. You can get the current window handle on SDL using the following code
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
Finally the definition of DeployEnvironment looks something like this:
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);
The command line parameter is the same as for DeployDefaultEnvironment, the next 4 params are paths, but you can use the constants 'DEFAULT_ENGINE_LOG_FILE', 'DEFAULT_ENGINE_ROOT_DIR', 'DEFAULT_ENGINE_ROOT_PACK', 'DEFAULT_ENGINE_INI_FILE'. OpenViewport should be false, as should CreateRenderer, and ContextTakeover should be true. Finally set ExternalWndHandle to the window handle stored in the variable declared in the code above. Note that the example is for GLUT on windows, so I have no idea whether this will work on other OSes.
Upvotes: 1