Skip to content

Instantly share code, notes, and snippets.

@Cheaterman
Created January 30, 2020 09:57
Show Gist options
  • Save Cheaterman/34a609de7fd9c4409ab75075590a4a15 to your computer and use it in GitHub Desktop.
Save Cheaterman/34a609de7fd9c4409ab75075590a4a15 to your computer and use it in GitHub Desktop.
main.py
import os
os.environ['KIVY_WINDOW'] = '' # noqa
from kivy.base import EventLoop, runTouchApp
from kivy.core.window import WindowBase
from kivy.graphics import Callback, opengl as gl
from kivy.lang import Builder
from kivy.properties import ObjectProperty
from direct.showbase.ShowBase import ShowBase
from panda3d.core import CallbackNode, Camera, NodePath, OrthographicLens
def reset_gl_context():
gl.glEnable(gl.GL_BLEND)
gl.glDisable(gl.GL_DEPTH_TEST)
gl.glEnable(gl.GL_STENCIL_TEST)
gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
gl.glBlendFuncSeparate(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA, gl.GL_ONE, gl.GL_ONE)
gl.glActiveTexture(gl.GL_TEXTURE0)
gl.glPixelStorei(gl.GL_UNPACK_ALIGNMENT, 1)
class PandaApp(ShowBase):
def __init__(self):
ShowBase.__init__(self)
display_region = self.win.make_display_region()
display_region.set_sort(30)
KivyWindow(
panda_app=self,
display_region=display_region,
)
runTouchApp(
Builder.load_string('''
BoxLayout:
orientation: 'vertical'
opacity: .5
Label:
text: 'Hello, world!'
Button:
text: 'Owi'
'''),
slave=True
)
scene = self.loader.loadModel('models/environment')
scene.reparentTo(self.render)
scene.setScale(0.25, 0.25, 0.25)
class KivyWindow(WindowBase):
_clearcolor = ObjectProperty()
def __init__(self, panda_app, display_region, **kwargs):
self.panda_app = panda_app
display_region.set_draw_callback(self.on_draw)
super().__init__(**kwargs)
with self.canvas.before:
Callback(lambda _: reset_gl_context())
Callback(lambda _: gl.glEnableVertexAttribArray(0))
Callback(lambda _: gl.glEnableVertexAttribArray(1))
with self.canvas.after:
Callback(lambda _: gl.glDisableVertexAttribArray(0))
Callback(lambda _: gl.glDisableVertexAttribArray(1))
def on_draw(self, data=None):
if data:
self.size = self.panda_app.win.get_size()
EventLoop.idle()
else:
super().on_draw()
PandaApp().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment