Logo Search packages:      
Sourcecode: blender version File versions  Download package

KX_PolygonMaterial::KX_PolygonMaterial Class Reference

List of all members.

Detailed Description

This is the interface to materials in the game engine.

Materials define the render state to be applied to mesh objects.

Warning:  Some of the methods/variables are CObjects.  If you mix these up,
you will crash blender.

This example requires:
      - PyOpenGL http://pyopengl.sourceforge.net/
      - GLEWPy http://glewpy.sourceforge.net/
      import GameLogic
      import OpenGL
      from OpenGL.GL import *
      from OpenGL.GLU import *
      import glew
      from glew import *
      vertex_shader = \"\"\"
      void main(void)
            gl_Position = ftransform();
      fragment_shader =\"\"\"
      void main(void)
            gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
      class MyMaterial:
            def __init__(self):
                  self.pass_no = 0
                  # Create a shader
                  self.m_program = glCreateProgramObjectARB()
                  # Compile the vertex shader
                  self.shader(GL_VERTEX_SHADER_ARB, (vertex_shader))
                  # Compile the fragment shader
                  self.shader(GL_FRAGMENT_SHADER_ARB, (fragment_shader))
                  # Link the shaders together
            def PrintInfoLog(self, tag, object):
                  PrintInfoLog prints the GLSL compiler log
                  print "Tag: 	def PrintGLError(self, tag = ""):
            def PrintGLError(self, tag = ""):
                  Prints the current GL error status
                  if len(tag):
                        print tag
                  err = glGetError()
                  if err != GL_NO_ERROR:
                        print "GL Error: %s\\n"%(gluErrorString(err))
            def shader(self, type, shaders):
                  shader compiles a GLSL shader and attaches it to the current
                  type should be either GL_VERTEX_SHADER_ARB or GL_FRAGMENT_SHADER_ARB
                  shaders should be a sequence of shader source to compile.
                  # Create a shader object
                  shader_object = glCreateShaderObjectARB(type)
                  # Add the source code
                  glShaderSourceARB(shader_object, len(shaders), shaders)
                  # Compile the shader
                  # Print the compiler log
                  self.PrintInfoLog("vertex shader", shader_object)
                  # Check if compiled, and attach if it did
                  compiled = glGetObjectParameterivARB(shader_object, GL_OBJECT_COMPILE_STATUS_ARB)
                  if compiled:
                        glAttachObjectARB(self.m_program, shader_object)
                  # Delete the object (glAttachObjectARB makes a copy)
                  # print the gl error log
            def link(self):
                  Links the shaders together.
                  # clear error indicator		
                  self.PrintInfoLog("link", self.m_program)
                  linked = glGetObjectParameterivARB(self.m_program, GL_OBJECT_LINK_STATUS_ARB)
                  if not linked:
                        print "Shader failed to link"
                  valid = glGetObjectParameterivARB(self.m_program, GL_OBJECT_VALIDATE_STATUS_ARB)
                  if not valid:
                        print "Shader failed to validate"
            def activate(self, rasty, cachingInfo, mat):
                  if (self.pass_no == 1):
                        return True
                  self.pass_no = 0	
                  return False
      obj = GameLogic.getCurrentController().getOwner()
      mesh = obj.getMesh(0)
      for mat in mesh.materials:
            print mat.texture

@ivar texture: Texture name
@type texture: string (read only)

@ivar gl_texture: OpenGL texture handle (eg for glBindTexture(GL_TEXTURE_2D, gl_texture)
@type gl_texture: integer (read only)

@ivar material: Material name
@type material: string (read only)

@ivar tface: Texture face properties
@type tface: CObject (read only)

@ivar tile: Texture is tiling
@type tile: boolean
@ivar tilexrep: Number of tile repetitions in x direction.
@type tilexrep: integer
@ivar tileyrep: Number of tile repetitions in y direction.
@type tileyrep: integer

@ivar drawingmode: Drawing mode for the material.
      - 2  (drawingmode & 4)     Textured
      - 4  (drawingmode & 16)    Light
      - 14 (drawingmode & 16384) 3d Polygon Text
@type drawingmode: bitfield

@ivar transparent: This material is transparent.  All meshes with this
      material will be rendered after non transparent meshes from back
      to front.
@type transparent: boolean

@ivar zsort: Transparent polygons in meshes with this material will be sorted back to
      front before rendering.
      Non-Transparent polygons will be sorted front to back before rendering.
@type zsort: boolean

@ivar lightlayer: Light layers this material affects.
@type lightlayer: bitfield.

@ivar triangle: Mesh data with this material is triangles.  It's probably not safe to change this.
@type triangle: boolean

@ivar diffuse: The diffuse colour of the material.  black = [0.0, 0.0, 0.0] white = [1.0, 1.0, 1.0]
@type diffuse: list [r, g, b]
@ivar specular: The specular colour of the material. black = [0.0, 0.0, 0.0] white = [1.0, 1.0, 1.0]
@type specular: list [r, g, b] 
@ivar shininess: The shininess (specular exponent) of the material. 0.0 <= shininess <= 128.0
@type shininess: float
@ivar specularity: The amount of specular of the material. 0.0 <= specularity <= 1.0
@type specularity: float

Definition at line 3 of file KX_PolygonMaterial.py.

Public Member Functions

def activate
def setCustomMaterial
def setTexture
def updateTexture

The documentation for this class was generated from the following file:

Generated by  Doxygen 1.6.0   Back to index