0

I know how to draw text to window created with sf::RenderWindow(); but I need to draw text to already existing game window. It makes it go black, I don't want to erase whole window, just update text on it. Code:

#include <SFML/Graphics.hpp>
#include <SFML/Graphics/Font.hpp>
#include <windows.h>
#include <iostream>

using namespace std;

int main()
{
    HWND hWindow = FindWindow(0, "Counter-Strike: Global Offensive");

    if(!hWindow) exit(0);
    else
    {
        int i=0;
        string tmp, str;

        sf::RenderWindow window(hWindow);

        sf::Font font;
        if(!font.loadFromFile("verdana.ttf"))
        {
            cout << "error";
        }

        sf::Text text;

        text.setFont(font);
        text.setCharacterSize(17);
        text.setColor(sf::Color::White);

        while (window.isOpen())
        {       
            i++;
            itoa(i, (char*)tmp.c_str(), 10);
            str = tmp.c_str();
            text.setString(str);

            sf::Event event;
            while (window.pollEvent(event))
            {
                if (event.type == sf::Event::Closed)
                    window.close();
            }

            Sleep(1000);
            window.clear(sf::Color::Transparent);

            window.draw(text);

            window.display();
        }

        return 0;
    }

}

Please help me do it :)

daavid245
  • 1
  • 1

1 Answers1

0

I think it won't be as easy as you might thought. Every program I know which can manipulate the backbuffer of a game hooks the API calls. That isn't very difficult. There are some good librarys out there for this. But the real problem is that nearly every game use DirectX. SFML use OpenGL. I don't think they can be mixed.

You should use Direct2D or another drawing libary based on DirectX. There are even tutorials out there which explains how to code a overlay. Just use Google.

Bass Guru
  • 26
  • 6