Skip to content

Instantly share code, notes, and snippets.

@tito
Forked from Cheaterman/main.py
Created December 7, 2018 11:01
Show Gist options
  • Save tito/ff57f7851033b45c2d29f0a0045e4f90 to your computer and use it in GitHub Desktop.
Save tito/ff57f7851033b45c2d29f0a0045e4f90 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)
KivyWindow(
panda_app=self,
display_region=self.win.make_display_region(),
)
runTouchApp(
Builder.load_string('''
BoxLayout:
orientation: 'vertical'
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))
with self.canvas.after:
Callback(lambda _: gl.glDisableVertexAttribArray(0))
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