OSHGui icon indicating copy to clipboard operation
OSHGui copied to clipboard

OSHGui with CSGO surface flickering

Open papstuc opened this issue 3 years ago • 8 comments

So I'm currently trying to implement OSHGui using CSGO's surface. I found your implemenation from some years ago. However my menu is just flickering when enabled, here is a video to show it better.

I'm initializing OSHGui like so:

std::vector<OSHGui::Drawing::FontPtr> m_fonts;

OSHGui::Application::Initialize(std::make_unique<CSGORenderer>(interfaces::surface, interfaces::engine));
this->m_fonts.resize(renderer_fonts::FONT_MAX);
this->m_fonts[verdana_7] = std::make_unique<CSGOFont>(interfaces::surface, "Verdana", 7);

To draw the GUI I hook PaintTraverse and call it in MatSystemTopPanel.

void renderer::draw()
{
	this->m_render_target = this->get_renderer().GetDefaultRenderTarget();

	if (!this->m_render_target)
	{
		return;
	}

	this->m_geometry = this->get_renderer().CreateGeometryBuffer();

	if (!this->m_geometry)
	{
		return;
	}

	this->m_render_target->Draw(*this->m_geometry);
}

I'm probably doing something wrong here and I would really appreciate help.

Kind regards.

papstuc avatar Feb 22 '22 18:02 papstuc

Did you try drawing just a square or a line as a test? Does that work?

KN4CK3R avatar Feb 22 '22 18:02 KN4CK3R

Did you try drawing just a square or a line as a test? Does that work?

Yes I did. Drawing a line, text, rectangle works completely fine.

papstuc avatar Feb 22 '22 19:02 papstuc

Did you draw these with my renderer or directly from the surface?

KN4CK3R avatar Feb 22 '22 22:02 KN4CK3R

I tried directly from the surface, which worked. I sadly can't get it working with your renderer.

Would it be possible for you to evaluate me how you have gotten it working or maybe send me the implementation source code?

papstuc avatar Feb 23 '22 11:02 papstuc

I use the CSGO renderer only for ESP and other visuals but not for the GUI. My PaintTraverse hook looks like this:

auto panelName = thisPanel->GetName(panel);
if (panelName == "MatSystemTopPanel")
{
	using namespace OSHGui;
	using namespace OSHGui::Drawing;
	
	static bool once = true;
	if (once)
	{
		once = false;

		auto surface = reinterpret_cast<IMatSystemSurface*>(...);

		module.rendererCSGO = std::make_unique<CSGORenderer>(surface, module.GetEngine());
		module.fontCSGO = std::make_shared<CSGOFont>(surface, _xor_("Arial"), 14);
	}

	module.rendererCSGO->BeginRendering();

	auto geometry = module.rendererCSGO->CreateGeometryBuffer();
	{
		Graphics g(*geometry);

		// draw stuff

		if (module.IsIngame())
		{
			// draw esp
		}
	}
	auto &renderTarget = module.rendererCSGO->GetDefaultRenderTarget();
	renderTarget->Activate();
	renderTarget->Draw(*geometry);
	renderTarget->Deactivate();

	module.rendererCSGO->EndRendering();
}

KN4CK3R avatar Feb 23 '22 11:02 KN4CK3R

Thanks for the source code!

Well my problem is that the GUI is sometimes randomly crashing due to CSGO's render multi threading, thats why I'm trying to implement it using the surface.

papstuc avatar Feb 23 '22 11:02 papstuc

I don't use it for the GUI because my GUI uses some textures and I did not implement that in the CSGO renderer. Normal stuff should just work.

KN4CK3R avatar Feb 23 '22 11:02 KN4CK3R

I'm doing the same right now. Just using OSH for the GUI. Though it's crashing the same like in #9

papstuc avatar Feb 23 '22 11:02 papstuc