Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question]CEF Off-Screen-Rendering + ImGUI #1140

Closed
Centurius123 opened this issue May 13, 2017 · 16 comments
Closed

[Question]CEF Off-Screen-Rendering + ImGUI #1140

Centurius123 opened this issue May 13, 2017 · 16 comments

Comments

@Centurius123
Copy link

Hello guys,

I have a Question. Is it possible to add CEF into a ImGUI Window?

I get on the CEF onPaint Function a buffer and can I at this buffer into a ImGUI Window?
void CEFView::OnPaint(CefRefPtr<CefBrowser> browser, CefRenderHandler::PaintElementType paintType, const CefRenderHandler::RectList& dirtyRects, const void* buffer, int width, int height)

@ocornut
Copy link
Owner

ocornut commented May 13, 2017 via email

@Centurius123
Copy link
Author

Ohh sorry!
CEF -> Chromium Embedded Framework
https://bitbucket.org/chromiumembedded/cef

I try to open a Website and draw this Website into a ImGUI Window

@ocornut
Copy link
Owner

ocornut commented May 13, 2017 via email

@Centurius123
Copy link
Author

I try to use ImGUI::Image, but my game crashs.
I can write the buffer into a bmp file, but I dont know how I create a Image with the buffer into a ImGUI Window

@ocornut
Copy link
Owner

ocornut commented May 13, 2017

If something crash please specify exactly why and in which condition.

Uploading a texture to your renderer/engine is up to you, it's generally a simple/common task. If you are using one of the stock imgui_impl_xxx.cpp examples so you can see how they upload textures. For example OpenGL uses glGenTextures+glBindTexture+glTexImage2D

@Centurius123
Copy link
Author

I use dx11
How I draw a Bitmap?

@ocornut
Copy link
Owner

ocornut commented May 13, 2017

You upload it into a texture and pass this texture pointer to AddImage().

@Centurius123
Copy link
Author

Do you have an example for addimage?

@ocornut
Copy link
Owner

ocornut commented May 13, 2017

Use
ImGui::Image(ID3D11ShaderResourceView* id, ImVec2 size);

ImTextureID = ID3D11ShaderResourceView* if you are using imgui_impl_dx11.cpp renderer.

@rafadsm
Copy link

rafadsm commented May 16, 2017

I was looking for it!
Is it possible to use ImGui to render the buffer using DX9?
I tried using ImGui :: Image and drawlist-> addimage, but crash

  • |buffer| contains the pixel data for the whole image
  • |buffer| will be width * height * 4 bytes in size and represents a BGRA image

@ocornut
Copy link
Owner

ocornut commented May 17, 2017 via email

@rafadsm
Copy link

rafadsm commented May 17, 2017

My code:

static class CefDelegate
{
public:
	void OnPaint(CefRefPtr<CefBrowser> browser,
	CefRenderHandler::PaintElementType type,
	const CefRenderHandler::RectList& dirtyRects,
	const void* buffer, int width, int height)
	{
		ImGui_ImplDX9_NewFrame();		
		ImGui::SetNextWindowSize(ImVec2(width, height), ImGuiSetCond_FirstUseEver);
		ImGui::SetNextWindowPos(ImVec2(0, 0));
		if (!ImGui::Begin("Cef Frame", 0, ImVec2(0, 0), 0.0f, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings))
		{
			ImGui::End();
			return;
		}		
		ImDrawList* draw_list = ImGui::GetWindowDrawList();
		draw_list->AddImage(&buffer, ImVec2(0, 0), ImVec2(width, height));		
		/*
		or
		ImGui::Image(&buffer, ImVec2(width, height));
		*/		
		ImGui::End();		
		RGetDevice()->SetRenderState(D3DRS_ZENABLE, false);
		RGetDevice()->SetRenderState(D3DRS_ALPHABLENDENABLE, false);
		RGetDevice()->SetRenderState(D3DRS_SCISSORTESTENABLE, false);
		ImGui::Render();
	}
};

Visual Studio ScreenShot
https://prnt.sc/f8wrod
DX9 version

I also tried to store a buffer in a texture using:

In Definitions
IDirect3DTexture9* tx;
In Init
RGetDevice()->CreateTexture(RGetScreenWidth(), RGetScreenHeight(), 1, 0, D3DFMT_A4R4G4B4, D3DPOOL_MANAGED, &tx, NULL);

In OnPaint:

D3DLOCKED_RECT d3dLockedRect;
tx->LockRect(0, &d3dLockedRect, 0, 0);
memcpy(d3dLockedRect.pBits, buffer, width *height* 4);
tx->UnlockRect(0);

In Draw Function:

draw_list->AddImage(tx, ImVec2(0, 0), ImVec2(width, height));
or
ImGui::Image(tx, ImVec2(width, height));

OnPaint API Docs: http://magpcss.org/ceforum/apidocs/projects/(default)/CefRenderHandler.html#OnPaint(CefRefPtr,PaintElementType,constRectList&,constvoid*)

@ocornut
Copy link
Owner

ocornut commented May 17, 2017

Is &buffer a LPDIRECT3DTEXTURE9, aka buffer of DIRECT3DTEXTURE9 type?
Read the rendering code ImGui_ImplDX9_RenderDrawLists to understand what is happening. Whatever you are passing to ImGui::Image or ImDrawList::AddImage() is passed to that render loop,
g_pd3dDevice->SetTexture(0, (LPDIRECT3DTEXTURE9)pcmd->TextureId);

Also this (bool*)true passed on Begin makes no sense. Pass a NULL pointer if you don't have a bool to store the state of whether the window is open or not. You are passing an invalid pointer (pointer to 0x00000001) which is going to crash whenever imgui tries to write there.

PS: When posting attachment, please use the github attachment system.

@rafadsm
Copy link

rafadsm commented May 17, 2017

  • Is &buffer a LPDIRECT3DTEXTURE9, aka buffer of DIRECT3DTEXTURE9 type?
    No, the documentation says it contains pixel data for the entire image
    "|buffer| contains the pixel data for the whole image"

  • PS: When posting attachment, please use the github attachment system.
    I apologize, I did, but the attached image did not open, so I sent

Could you help me convert the buffer to an IDirect3DTexture9 texture?
I tried using:
My application freezes and crashes using this

D3DLOCKED_RECT d3dLockedRect;
tx->LockRect(0, &d3dLockedRect, 0, 0);
memcpy(d3dLockedRect.pBits, buffer, width *height* 4);
tx->UnlockRect(0);
  • Buffer Documentation:
    |buffer| will be width * height *4 bytes in size and represents a BGRA image
    |buffer| contains the pixel data for the whole image

@ocornut
Copy link
Owner

ocornut commented May 17, 2017

Could you help me convert the buffer to an IDirect3DTexture9 texture?

Sorry this question has nothing to do with imgui. Try to look up the answer elsewhere.

@Centurius123
Copy link
Author

Try to use CreateDDSTextureFromMemory()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants