Skip to content

ExamplesProceduralsRenderingModes

Ben Toogood edited this page Jun 13, 2013 · 2 revisions

Rendering Modes

This example demonstrates how to render based on the current rendering context - specifically differentiating between OpenGL and !RenderMan. This procedural renders a cube in OpenGL but a sphere in !RenderMan.

320px-Cookbook_renderModeGL.jpg opengl

320px-Cookbook_renderModeRI.jpg renderman

Code

 #=====
 # Render Mode
 #
 # This cookbook example demonstrates how to render based on the current
 # rendering context - specifically differentiating between OpenGL and RenderMan.
 # This procedural renders a cube in OpenGL but a sphere in RenderMan.
 #
 #=====
 
 from IECore import *
 import IECoreGL
 import IECoreRI
 
 class renderMode(ParameterisedProcedural) :
 
 	def __init__(self) :
 		ParameterisedProcedural.__init__( self, "RenderMode cookbook example." )
 
 	def doBound(self, args) :
 		return Box3f( V3f( -1, -1, -1 ), V3f( 1, 1, 1 ) )
 
 	def doRenderState(self, renderer, args) :
 		pass
 
 	def doRender(self, renderer, args) :
 
 		# This checks the renderer against the GL renderer type
 		if renderer.typeId()==IECoreGL.Renderer.staticTypeId():
 			MeshPrimitive.createBox( Box3f( V3f(-1), V3f(1) ) ).render( renderer )
 
 		# This checks the renderer against the RenderMan renderer type
 		if renderer.typeId()==IECoreRI.Renderer.staticTypeId():
 			renderer.sphere( -1, 1, -1, 360, {} )
 
 # register
 registerRunTimeTyped( renderMode )
Clone this wiki locally