Screenshot OpenGL game from DLL

I have managed to make a DLL and hook wglSwapBuffers, and also add an ImGui overlay to a game.
Now I would like to be able to take screenshots from the game by using glReadPixels or to render a simple triangle, but I don’t know how to initialize OpenGL from my DLL.

LRESULT CALLBACK WindowProcHook(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
	if (uMsg == WM_KEYDOWN && wParam == VK_F1)
		show_menu = !show_menu;
	if (show_menu) {
		ImGui_ImplWin32_WndProcHandler(hWnd, uMsg, wParam, lParam);
		ImGuiIO& io = ImGui::GetIO();
		if (io.WantCaptureMouse)
			return true; // Disable game input while menu is open
	return CallWindowProc(hGameWindowProc, hWnd, uMsg, wParam, lParam);

void Screenshot(int width, int height) {
	uint8_t* pixels = new uint8_t[width * height * 3];
	glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels);
	FlipImageVertically(width, height, pixels);
	std::string filename = "screenshot_" + std::to_string(time(NULL)) + ".png";
	stbi_write_png(filename.c_str(), width, height, 3, pixels, 3 * width);
	delete[] pixels;

BOOL wglSwapBuffersHook(HDC hDc) {
	static bool imGuiInitialized = false;
	if (!imGuiInitialized) {
		imGuiInitialized = true;
		HWND hGameWindow = WindowFromDC(hDc);
		hGameWindowProc = (WNDPROC)SetWindowLongPtr(hGameWindow, GWLP_WNDPROC, (LONG_PTR)WindowProcHook);

	if (show_menu) {

		ImGui::Begin("DLL Utils", &show_menu, ImGuiWindowFlags_MenuBar);
		// ...
	return td_wglSwapBuffers(hDc);

hook.Create(L"opengl32.dll", "wglSwapBuffers", wglSwapBuffersHook, &td_wglSwapBuffers);

Isn’t OpenGL initialized by the game your hooking into? If your GUI is working it certainly looks like ImGui is able to make OpenGL calls and render itself into the window backbuffer, no?