OSDN Git Service

fix import_mqo.py
[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=(1, 1, 1, 1)
43         self.vcol=False
44         self.texture=None
45
46     def __enter__(self):
47         self.begin()
48
49     def __exit__(self):
50         self.end()
51
52     def begin(self):
53         glColor4f(*self.rgba)
54         if self.texture:
55             self.texture.begin()
56
57         # backface culling
58         glEnable(GL_CULL_FACE)
59         glFrontFace(GL_CW)
60         glCullFace(GL_BACK)
61         # alpha test
62         glEnable(GL_ALPHA_TEST);
63         glAlphaFunc(GL_GREATER, 0.5);
64
65     def end(self):
66         if self.texture:
67             self.texture.end()
68
69     def onInitialize(self):
70         pass
71         #if self.texture:
72         #    self.texture.onInitialize()
73