OSDN Git Service

implement pmdbuilder
[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):
42         self.rgba=(0, 0, 0, 0)
43         self.vcol=False
44         self.texture=None
45
46     def begin(self):
47         glColor4f(*self.rgba)
48         if self.texture:
49             self.texture.begin()
50
51         # backface culling
52         glEnable(GL_CULL_FACE)
53         glFrontFace(GL_CW)
54         glCullFace(GL_BACK)
55         # alpha test
56         glEnable(GL_ALPHA_TEST);
57         glAlphaFunc(GL_GREATER, 0.5);
58
59     def end(self):
60         if self.texture:
61             self.texture.end()
62
63     def onInitialize(self):
64         if self.texture:
65             self.texture.onInitialize()
66
67     @staticmethod
68     def create(src, basedir):
69         m=MQOMaterial(src.color)
70         if src.tex:
71             m.texture=texture.Texture((basedir+'/'+src.tex).replace('\\', '/'))
72         return m
73