파이썬[Python]: kivy - RenderContext 클래스
kivy.graphics 모듈 - RenderContext 클래스(class)
/// 설명
모든 정보를 가지고 있는 클래스입니다.
참고: graphics 모듈 목록
※ 형식
RenderContext(*args, **kwargs)
reference
https://kivy.org/doc/stable/api-kivy.graphics.html
참고: graphics 모듈 목록
※ 형식
RenderContext(*args, **kwargs)
reference
https://kivy.org/doc/stable/api-kivy.graphics.html
/// 예제
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | import kivy kivy.require('2.0.0') from kivy.app import App from kivy.base import EventLoop from kivy.core.window import Window from kivy.graphics import RenderContext, Color, Rectangle from kivy.uix.widget import Widget from kivy.uix.boxlayout import BoxLayout from kivy.uix.image import Image from kivy.uix.label import Label Window.clearcolor = (1, 1, 1, 1) Window.size = (563, 1001) Window.top, Window.left = 30, 2900 fs = ''' $HEADER$ void main(void) { gl_FragColor = vec4(1.0,0.0,1.0,1.0) * texture2D(texture0, tex_coord0); } ''' class CustomWidget(Widget): def __init__(self, **kwargs): # Before doing anything, ensure the windows exist. EventLoop.ensure_window() self.texture() # drawing self.bind(size=self.update_pos) # get real size of class CustomWidget super(CustomWidget, self).__init__(**kwargs) def update_pos(self, instance, value): # centered image self.rect.pos = ((self.size[0] - self.rect.size[0]) / 2, (self.size[1] - self.rect.size[1]) / 2) def texture(self, *args): # all the necessary information for drawing self.canvas = RenderContext() # set shader.fs self.canvas.shader.fs = fs print(self.canvas.shader.fs) with self.canvas: Color(1, 1, 1) self.rect = Rectangle(size=(200, 200), source='football.png', pos=self.center) # the default vertex shader self.canvas['projection_mat'] = Window.render_context['projection_mat'] class FantasticApp(App): def build(self): bl = BoxLayout(orientation='vertical') bl.add_widget(Image(source='./football.png')) bl.add_widget(Label(text='texture', color='black', font_size=50)) bl.add_widget(CustomWidget()) return bl FantasticApp().run() # the header for the fragment Shader # ------------ # | $HEADER$ | # ------------ # #ifdef GL_ES # precision highp float; # #endif # # /* Outputs from the vertex shader */ # varying vec4 frag_color; # varying vec2 tex_coord0; # # /* uniform texture samplers */ # uniform sampler2D texture0; # # uniform mat4 frag_modelview_mat; | cs |
/// 출력
* 실행환경: Microsoft Windows 10 Homes
* 인터프리터: 파이썬(Python 3.9)
– 당신을 응원합니다. –
댓글
댓글 쓰기