SFML community forums

Help => General => Topic started by: yearspassby on January 26, 2010, 04:39:14 pm

Title: Draw on an exisiting window ?
Post by: yearspassby on January 26, 2010, 04:39:14 pm
Hello there. Just wondering if its possible to draw on an existing window with SFML.. For example in garrys mod, so that I can draw an ingame clock and stuff like that.

If thats possible, which functions do I need in order for being able to draw onto this window?

Thanks.
Title: Draw on an exisiting window ?
Post by: Laurent on January 26, 2010, 06:30:40 pm
It's possible, but I'm not sure if will mix well with the drawing that's already done in the window, whether it is OpenGL or not.
Title: Draw on an exisiting window ?
Post by: yearspassby on January 26, 2010, 06:52:38 pm
Ok I'll test it out by myself. But how can I draw on the window ? Didn't found a function for it yet... Just to create my own window.. Thanks again.
Title: Draw on an exisiting window ?
Post by: Laurent on January 26, 2010, 07:53:57 pm
You must first retrieve the handle of the window (which is OS specific). For example, if you know the window title, you can use FindWindow on Windows.

Then you simple create your sf::Window or sf::RenderWindow with this handle
Quote
sf::Window window(handle);
Title: Draw on an exisiting window ?
Post by: yearspassby on January 26, 2010, 08:29:20 pm
I've tried it with sf::RenderWindow cause I need the Draw function.. But the whole screen gets black and the test string is flickering like hell..
I did it like that:

Code: [Select]
sf::RenderWindow MyWindow(MyHwnd);
while (true)
{
MyWindow.Draw (sMyString);
MyWindow.Display();

Sleep (1);
}


Is there a way to get rid of it ?
Title: Draw on an exisiting window ?
Post by: Laurent on January 26, 2010, 08:33:11 pm
I don't think so. Drawing on a window without altering its contents may require more specific stuff.
Title: Draw on an exisiting window ?
Post by: yearspassby on January 26, 2010, 08:51:43 pm
But it also works with Windows GDI. sf::RenderWindow creates a new window OVER the existing game window... Is there no way to directly draw onto the game window like its possible with GDI ?
Title: Draw on an exisiting window ?
Post by: Laurent on January 26, 2010, 09:36:32 pm
Quote
sf::RenderWindow creates a new window OVER the existing game window...

No, it uses the same window. But it uses its own OpenGL backbuffer, which overwrite the contents of the window when you call Display().

It may be possible with GDI, but SFML doesn't use it at all.