Skip to content

Commit

Permalink
Original texture is displayed along with combined texture
Browse files Browse the repository at this point in the history
  • Loading branch information
Sentient07 committed Mar 10, 2015
1 parent e5022e1 commit 195cbeb
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions examples/canvas/multitexture.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from kivy.clock import Clock
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.floatlayout import FloatLayout
from kivy.lang import Builder
from kivy.core.window import Window
from kivy.graphics import RenderContext, Color, Rectangle, BindTexture

Expand All @@ -35,6 +37,27 @@
'''


kv = """
<MultitextureLayout>:
Image:
source: "mtexture1.png"
size_hint: .3,.3
id: 1
pos: 0,200
Image:
source: "mtexture2.png"
size_hint: .3,.3
id: 2
pos: 200,200
MultitextureWidget:
"""

Builder.load_string(kv)


class MultitextureWidget(Widget):

def __init__(self, **kwargs):
Expand All @@ -51,13 +74,14 @@ def __init__(self, **kwargs):
BindTexture(source='mtexture2.png', index=1)

# create a rectangle with texture (will be at index 0)
Rectangle(size=(512, 512), source='mtexture1.png')
Rectangle(size=(150, 150), source='mtexture1.png', pos=(500, 200))

# set the texture1 to use texture index 1
self.canvas['texture1'] = 1

# call the constructor of parent
# if they are any graphics objects, they will be added on our new canvas
# if they are any graphics objects, they will be added on our new
# canvas
super(MultitextureWidget, self).__init__(**kwargs)

# We'll update our glsl variables in a clock
Expand All @@ -69,10 +93,17 @@ def update_glsl(self, *largs):
self.canvas['modelview_mat'] = Window.render_context['modelview_mat']


class MultitextureLayout(FloatLayout):

def __init__(self, **kwargs):
self.size = kwargs['size']
super(MultitextureLayout, self).__init__(**kwargs)


class MultitextureApp(App):

def build(self):
return MultitextureWidget()
return MultitextureLayout(size=(600, 600))


if __name__ == '__main__':
Expand Down

0 comments on commit 195cbeb

Please sign in to comment.