ENTRY | DOWNLOAD | MANUAL | ONGOING | |
MaterialMaterial is a special Context that can be assigned to the world, tags or sprites to define how their content (whatever is drawn in their onDraw()) interacts with light. Custom materials are defined by subclassing this class.
<world>.setMaterial(material)
<tag>.setMaterial(material) <sprite>.setMaterial(material)
<world>.unsetMaterial(material)
<tag>.unsetMaterial(material) <sprite>.unsetMaterial(material)
material = AMaterial(name)
Relevant examples: shading.py, ALL In Contextasphere = Sphere(self, 'sph1') redmaterial = MaterialRed('matRed') asphere.setMaterial(redmaterial) Custom material classes can be defined by inheriting from slut.material.Material and overwriting onPreDraw() accordingly. Saving and restoring OpenGL's material state is done by the Material class. The default onPostDraw() will restore the material state to the state as it was before onPreDraw() was called. For this reason onPostDraw() does not have to be implemented by the inheriting class. The MaterialRed from above may be defined as follows: class MaterialRed(Material): def onPreDraw(self): glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (0.3, 0.1, 0.1, 0.5)) glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, (0.5, 0.1, 0.1, 0.8)) glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, (1.0, 0.1, 0.1, 0.5)) glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, (0.0, 0.0, 0.0, 0.5)) glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, 30.0) The look of materials is highly dependent on the lights used for illumination. Slut's light handling is described in a different section: Light Relevant OpenGL documentation: glMaterial , glLight , glLightModel |
|
Initiated by Stephan Hechenberger Thanks to CADRE's 103 |