Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Draw on an exisiting window ?  (Read 2494 times)

0 Members and 3 Guests are viewing this topic.

yearspassby

  • Newbie
  • *
  • Posts: 6
    • View Profile
Draw on an exisiting window ?
« 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Draw on an exisiting window ?
« Reply #1 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.
Laurent Gomila - SFML developer

yearspassby

  • Newbie
  • *
  • Posts: 6
    • View Profile
Draw on an exisiting window ?
« Reply #2 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Draw on an exisiting window ?
« Reply #3 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);
Laurent Gomila - SFML developer

yearspassby

  • Newbie
  • *
  • Posts: 6
    • View Profile
Draw on an exisiting window ?
« Reply #4 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 ?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Draw on an exisiting window ?
« Reply #5 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.
Laurent Gomila - SFML developer

yearspassby

  • Newbie
  • *
  • Posts: 6
    • View Profile
Draw on an exisiting window ?
« Reply #6 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 ?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Draw on an exisiting window ?
« Reply #7 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.
Laurent Gomila - SFML developer

 

anything