파이썬[Python]: kivy, OpenGL ES - 삼각형(단색) 그리기
kivy.graphics 모듈 - OpenGL ES
/// 설명
단색의 삼각형을 그립니다.
참고: OpenGL ES 모듈 목록
reference
https://www.youtube.com/playlist?list=PL1P11yPQAo7qEnF_EysHOBUfF0AzUz3jh
참고: OpenGL ES 모듈 목록
reference
https://www.youtube.com/playlist?list=PL1P11yPQAo7qEnF_EysHOBUfF0AzUz3jh
/// 예제 main.py
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  | import kivy kivy.require('2.0.0') from kivy.app import App from kivy.core.window import Window from kivy.resources import resource_find from kivy.graphics import * from kivy.uix.widget import Widget Window.clearcolor = (1, 1, 1, 1) Window.size = (563, 1001) Window.top, Window.left = 30, 2900 #           positions vertices = [-0.5, -0.5, 0.0,              0.5, -0.5, 0.0,              0.0,  0.5, 0.0] indices = [0, 1, 2] fmt = [(b'pos', 3, 'float')] class FantasticApp(App):     def scene(self):         PushMatrix()         Mesh(vertices=vertices, indices=indices,              mode='triangles', fmt=fmt)         PopMatrix()     def build(self):         self.w = w = Widget()         w.canvas = RenderContext()         w.canvas.shader.source = resource_find('./triangle.glsl')         with w.canvas:             self.scene()         return w FantasticApp().run()  | cs | 
/// 예제 triangle.glsl
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21  | ---VERTEX SHADER #ifdef GL_ES     precision highp float; #endif attribute vec3 pos; void main(void) {     gl_Position = vec4(pos, 1.0); } ---FRAGMENT SHADER #ifdef GL_ES     precision highp float; #endif varying vec4 newColor; void main(void) {     gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); }  | cs | 
/// 출력
* 실행환경: Microsoft Windows 10 Homes
* 인터프리터: 파이썬(Python 3.9)
– 당신을 응원합니다. –
댓글
댓글 쓰기