CEF Python + PyOpenGL Demo

307 views
Skip to first unread message

Anish Narayanan

unread,
Dec 11, 2016, 4:11:47 PM12/11/16
to CEF Python
Hi Everyone,

I have been playing around with CEF Python in order to use it to make a simple and easy-to-use UI layer for my 3d game engine. I noticed that there wasn't an example combining CEF Python + Pygame + PyOpenGL, so I thought I would create a simple example! Here is a link to a github gist that illustrates how CEF Python can be used to offscreen mode to paint on a texture overlay containing the UI for a pygame window. It also shows how mouse input (working on putting together keyboard input) can be processed from pygame events into CEF Python as well as how data from HTML input objects can be returned to python to control some properties of a "3d" model (in this case, a triangle). Let me know what you all think! I have not tested it against the latest version of CEF Python on Linux at the moment (just on Windows + CEFPython v.31.2) so let me know if there are any bugs!

Thanks,
Anish

Czarek Tomczak

unread,
Dec 12, 2016, 4:01:29 AM12/12/16
to CEF Python
Thanks for sharing!
I've added a link to this gist in api/RenderHandler.md #Examples section - will appear in the next commit.

Czarek Tomczak

unread,
Dec 14, 2016, 8:34:54 AM12/14/16
to CEF Python
Anish,

I have an off-topic question. I see that you're using javascript bindings and testing on Windows. Have you noticed UI lag/lock when calling python functions from javascript? Issue reported recently in this topic: https://groups.google.com/d/topic/cefpython/NJUDIm81D3A/discussion


On Sunday, December 11, 2016 at 9:11:47 PM UTC, Anish Narayanan wrote:

Anish Narayanan

unread,
Dec 14, 2016, 9:20:57 AM12/14/16
to CEF Python
Realized I didn't post my response here! Yes, I did have problems with the UI freezing up whenever I made callbacks to python to manipulate my 3d triangle. This was especially obvious whenever I tried adding CSS timed animations for clicking on buttons to my code. I will take a look at that group thread. Is there anything that I need to test in the meantime to help debug this?

Czarek Tomczak

unread,
Dec 14, 2016, 9:35:48 AM12/14/16
to CEF Python
My last two posts in that topic contain instructions for debugging times, Windows vs Windows multithreaded vs Linux: https://groups.google.com/d/msg/cefpython/NJUDIm81D3A/NBzXt6ilCAAJ

Anish Narayanan

unread,
Dec 19, 2016, 1:48:44 AM12/19/16
to CEF Python
Sorry it took a while to get back to you. I have created a demo that works for the regular, non-multithreaded case. It gets the time in python whenever there is a mouse click on the test button, then gets the time in javascript, then gets the time once more in python for the callback. It outputs the py->js time, the js->py time, and the total time (py->py). A gist containing this can be found here. In my testing on windows, I found the following results after 8 clicks/trials:

py->js js->py total
0.0130000114441 0.010999917984 0.0239999294281
0.0210001468658 0.00699996948242 0.0280001163483
0.0319998264313 0.00999999046326 0.0419998168945
0.0250000953674 0.010999917984 0.0360000133514
0.0199999809265 0.0119998455048 0.0319998264313
0.0280001163483 -0.00100016593933 0.0269999504089
0.0179998874664 0.00300002098083 0.0209999084473
0.0220000743866 0.0 0.0220000743866

This is definitely not perfect (the javascript time and python's time are different and can result in negative differences), but I think it is fair to say that the majority of the time spent is in going from python to javascript and not the reverse.

However, I cannot seem to get the multithreaded system working as I keep running into this error:
AssertionError: cefpython.CreateBrowserSync() may only be called on the UI thread
Any ideas to get this working? Is there a different way to create the initial browser window that I should be using instead?

Czarek Tomczak

unread,
Dec 19, 2016, 2:37:12 AM12/19/16
to CEF Python
You should have posted this in that other topic. It seems off-topic to discuss it here. These times seem small. The communication between js<> python is asynchronous using IPC inter-process communication. Python is running in the Browser process and Javascript in the Renderer process. The time it takes to communicate between two processes is expected to be about 15 ms.  So I don't see anything unusual in these times. In the topic created by Aric with the initial report of the UI freeze issue, that I referenced initially a few posts above, he pasted a link to a video where you can see that in his case the freezing takes about a second or so, so his lag is about 50x bigger than what you experience. Are you saying that these small times cause UI freeze? Have you seen the video by Aric, is it a similar experience?

It was explained in Aric's topic on how to use multi-threaded message loop. Find it in his topic, or see here: https://github.com/cztomczak/cefpython/issues/133
Reply all
Reply to author
Forward
0 new messages