Me with czarek.tomczak are working on CEF+panda3d example (ultimate goal is to use CEF for GUI in panda3d)
Idea is simple - CEF returns BGRA (how handy!) buffer of window and all we need to do is draw it on screen.
Now question is - what is the best way to draw pixel buffer whose dimensions are not necessarily power of 2?
my first attempt was to use makeTextureBuffer / getTexture / modifyRamImage + OnscreenImage to do all the work. Few problems with that:
- Texture dimensions have to be power of 2, however we need texture with dimensions equal to screen resolution to be able to draw GUI all over screen.
- Modifying texture somehow does not work - im sure it is just me not knowing how to do it properly so please bear with me
from p3d import *
import cefpython_py27 as cefpython
import cefwindow
import sys
from direct.gui.OnscreenImage import OnscreenImage
from pandac.PandaModules import TransparencyAttrib
from direct.gui.DirectGui import DirectFrame
import libpanda, array, math
CEF_ON = False
class MyApp(object):
def __init__(self):
sys.excepthook = cefpython.ExceptHook
screen_size = (800, 600)
cefpython.Initialize()
core.loadPrcFileData('', 'win-size %d %d' % screen_size)
if CEF_ON:
windowInfo = cefpython.CefWindowInfo()
windowInfo.SetAsOffScreen(base.win);
self._browser = cefpython.CreateBrowser(windowInfo, browserSettings={}, navigateURL="http://google.com/")
self._buf = base.win.makeTextureBuffer("My Buffer", 1024, 1024)
# texture for cef contents to render to
self._tex = self._buf.getTexture()
# image to display texture on screen
self._img = OnscreenImage(image=self._tex, pos=(0, 0, 0))
#self._img.setTransparency(TransparencyAttrib.MAlpha)
def cef_step(task):
img = self._tex.modifyRamImage()
# sample for modification of img buffer
buf = array.array('B')
buf.fromstring(img.getData())
for i in range(1024):
buf[i * 4 + 0] = 100
buf[i * 4 + 1] = 0
buf[i * 4 + 2] = 100
buf[i * 4 + 3] = 0
img.setData(buf.tostring())
#self._img.setImage(self._tex)
if CEF_ON:
cefpython.SingleMessageLoop()
return task.cont
taskMgr.add(cef_step, 'cef_step')
def __del__(self):
self._img.destroy()
cefpython.Shutdown()
app = MyApp()
run()
And for p3d: pastebox.it/file/KyOwUJQMh54BxwM … hwY/p3d.py