OSDN Git Service

29698e37718ef9aba5d288b0c8f351b88ac59ffb
[meshio/pymeshio.git] / examples / opengl / material.py
1 #!/usr/bin/pyhthon
2 # coding: utf-8
3
4 from OpenGL.GL import *
5 from . import texture
6
7 '''
8 Material
9
10 * 色
11 '''
12 class Material(object):
13     def __init__(self, r, g, b, a):
14         self.r=r
15         self.g=g
16         self.b=b
17         self.a=a
18
19     def begin(self):
20         glColor4f(self.r, self.g, self.b, self.a)
21
22     def end(self):
23         pass
24
25     def onInitialize(self):
26         pass
27
28     @staticmethod
29     def create(src):
30         m=material.Material(*src.col)
31         return m
32
33
34 '''
35 Material
36
37 * 色
38 * テクスチャー
39 '''
40 class MQOMaterial(object):
41     def __init__(self, rgba):
42         self.rgba=rgba
43         self.texture=None
44
45     def begin(self):
46         glColor4f(self.rgba.r, self.rgba.g, self.rgba.b, self.rgba.a)
47         if self.texture:
48             self.texture.begin()
49
50         # backface culling
51         glEnable(GL_CULL_FACE)
52         glFrontFace(GL_CW)
53         glCullFace(GL_BACK)
54         # alpha test
55         glEnable(GL_ALPHA_TEST);
56         glAlphaFunc(GL_GREATER, 0.5);
57
58     def end(self):
59         if self.texture:
60             self.texture.end()
61
62     def onInitialize(self):
63         if self.texture:
64             self.texture.onInitialize()
65
66     @staticmethod
67     def create(src, basedir):
68         m=MQOMaterial(src.color)
69         if src.tex:
70             m.texture=texture.Texture((basedir+'/'+src.tex).replace('\\', '/'))
71         return m
72