我知道如何将文本绘制到使用sf::RenderWindow();
创建的窗口,但我需要在已有的游戏窗口中绘制文本。它让它变黑了,我不想删除整个窗口,只是更新它上面的文字。代码:
#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;
}
}
请帮我做:)
答案 0 :(得分:0)
我认为这不会像你想象的那么容易。 我所知道的每个可以操作游戏后台的程序都会挂钩API调用。这不是很困难。这里有一些很好的图书馆。但真正的问题是几乎每个游戏都使用DirectX。 SFML使用OpenGL。我不认为他们可以混在一起。
您应该使用Direct2D或基于DirectX的其他绘图库。 甚至还有教程解释了如何编写叠加层。只需使用Google。