Documentation

Classes

Class Renderer

3D renderer, interface for drawing 3d geometry. You can access this using CopperLicht.getRenderer().

Class Overview
Renderer()
3D renderer, interface for drawing 3d geometry.

Method Summary
Method Attributes Method Name and Description
 
beginScene(clearColor)
Starts the drawing process by clearing the whole scene.
 
Clears all dynamic lights in the rendering pipeline.
 
createMaterialType(vertexShaderSource, fragmentShaderSource, blendenabled, blendsfactor, blenddfactor)
Creates a new material type with custom shaders.
 
drawMesh(mesh)
Draws a Mesh with the current world, view and projection matrix.
 
Draws a mesh buffer.
 
Ends the drawing process by flushing the renderin instructions.
 
Returns the webgl shader program from a material type.
 
Returns the current height of the rendering surface in pixels.
 
Returns the currently used projection matrix.
 
Returns the currently used view matrix.
 
Returns access to the webgl interface.
 
Returns the current width of the rendering surface in pixels.
 
Returns the currently used view matrix.
 
Sets a material to activate for drawing 3d graphics.
 
Sets the projection transformation matrix.
 
Sets the view transformation matrix.
 
Sets the world transformation matrix.
Method Detail
beginScene(clearColor)
Starts the drawing process by clearing the whole scene. Is called by CopperLicht.draw3dScene(), so it shouldn't be necessary to call this yourself.
Parameters:
clearColor
{Number} Color for the background. See Core.createColor.

clearDynamicLights()
Clears all dynamic lights in the rendering pipeline. Is called by CopperLicht.draw3dScene(), so it shouldn't be necessary to call this yourself.

createMaterialType(vertexShaderSource, fragmentShaderSource, blendenabled, blendsfactor, blenddfactor)
Creates a new material type with custom shaders. Returns an id which can be used in Material.Type. There is a tutorial showing how to create a new material in the documentation, but also this short example may give an overview:
// add a cube to test out
var cubenode = new CubeSceneNode();
scene.getRootSceneNode().addChild(cubenode);
cubenode.getMaterial(0).Tex1 = 
  engine.getTextureManager().getTexture("crate_wood.jpg", true);

// now, we want to use a custom material for our cube, lets write
// a vertex and a fragment shader:
// (note: there must be no character, even no space behind 
// the '\' characters).
var vertex_shader = "           \
  uniform mat4 worldviewproj;   \
  attribute vec4 vPosition;     \
  attribute vec4 vNormal;       \
  attribute vec2 vTexCoord1;    \
  attribute vec2 vTexCoord2;    \
  varying vec2 v_texCoord1;     \
  varying vec2 v_texCoord2;     \
  void main()                   \
  {                             \
    gl_Position = worldviewproj * vPosition;\
    v_texCoord1 = vTexCoord1.st; \
    v_texCoord2 = vTexCoord2.st; \
  }";
  
 var fragment_shader = "        \
  uniform sampler2D texture1;   \
  uniform sampler2D texture2;   \
                                \
  varying vec2 v_texCoord1;     \
  varying vec2 v_texCoord2;     \
                                \
  void main()                   \
  {                             \
    vec2 texCoord = vec2(v_texCoord1.s, v_texCoord1.t); \
    gl_FragColor = texture2D(texture1, texCoord) * 2; \
  }";
 
 // create a solid material using the shaders. For transparent materials, 
 // take a look at the other parameters of createMaterialType  
 var newMaterialType = engine.getRenderer().createMaterialType(vertex_shader, fragment_shader);
 if (newMaterialType != -1)
   cubenode.getMaterial(0).Type = newMaterialType;
 else
   alert('could not create shader');
Parameters:
vertexShaderSource
{String} Source for the vertex shader of the new material. CopperLicht will set the current World-View-Projection matrix in a attribute named 'worldviewproj'. Positions will be stored in vPosition, normals in vNormal, the first texture coordinate in vTexCoord1 and the second in vTexCoord2. All other variables will need to be set manually by you. Use getGLProgramFromMaterialType to do this.
fragmentShaderSource
{String} Source for the fragment shader of the new material. If the fragment shader uses a variable 'texture1' and 'texture2' as in the example above, CopperLicht will set this to the textures of the current material.
blendenabled
{Boolean} this is optional and can be set to true to enable blending. See next two parameters. Note: When creating a transparent material, in order to let it be sorted correctly by CopperLicht, override the Material.isTransparent to return true for your material type.
blendsfactor
this is optional. Blend source factor, when blending is enabled. Set to a webGL blend factor like gl.ONE or gl.SRC_ALPHA. You can get the gl object by using getWebGL().
blenddfactor
this is optional. Blend destination factor, when blending is enabled. Set to a webGL blend factor like gl.ONE_MINUS_SRC_ALPHA or gl.ONE_MINUS_SRC_COLOR. You can get the gl object by using getWebGL().

drawMesh(mesh)
Draws a Mesh with the current world, view and projection matrix.
Parameters:
mesh
{Mesh} the mesh to draw

drawMeshBuffer(buf)
Draws a mesh buffer. Note, you might want to set the material of the mesh buffer before drawing it, use setMaterial() to do this before calling this function.
Parameters:
buf
{MeshBuffer} the mesh buffer to draw.

endScene()
Ends the drawing process by flushing the renderin instructions. Is called by CopperLicht.draw3dScene(), so it shouldn't be necessary to call this yourself.

{program} getGLProgramFromMaterialType(mattype)
Returns the webgl shader program from a material type. This is useful when you are using createMaterialType to create your own shaders and need to set material constants using for example uniform1i.
Parameters:
mattype
{int} The material type, like for example Material.EMT_SOLID, or your own material type returned by createMaterialType.
Returns:
{program} Returns the WebGL shader program or null if not found.

getHeight()
Returns the current height of the rendering surface in pixels.

getProjection()
Returns the currently used projection matrix.

getView()
Returns the currently used view matrix.

getWebGL()
Returns access to the webgl interface. This should not be needed.

getWidth()
Returns the current width of the rendering surface in pixels.

getWorld()
Returns the currently used view matrix.

setMaterial(mat)
Sets a material to activate for drawing 3d graphics. All 3d drawing functions will draw geometry using this material thereafter.
Parameters:
mat
{Material} Material to set

setProjection(m)
Sets the projection transformation matrix. This is automatically called by CopperLicht.draw3dScene(), so it shouldn't be necessary to call this yourself.
Parameters:
m
{Matrix} matrix representing the transformation matrix.

setView(m)
Sets the view transformation matrix. This is automatically called by CopperLicht.draw3dScene(), so it shouldn't be necessary to call this yourself.
Parameters:
m
{Matrix} matrix representing the transformation matrix.

setWorld(m)
Sets the world transformation matrix. This is automatically called by CopperLicht.draw3dScene(), so it shouldn't be necessary to call this yourself.
Parameters:
m
{Matrix} matrix representing the transformation matrix.

© 2010 N.Gebhardt, Ambiera
Documentation generated by JsDoc Toolkit