Game Engine bge.render Module

Intro

# Example Uses an L{SCA_MouseSensor}, and two L{KX_ObjectActuator}s to implement MouseLook::
# To use a mouse movement sensor "Mouse" and a
# motion actuator to mouse look:
import bge.render
import bge.logic

# SCALE sets the speed of motion
SCALE=[1, 0.5]

co = bge.logic.getCurrentController()
obj = co.getOwner()
mouse = co.getSensor("Mouse")
lmotion = co.getActuator("LMove")
wmotion = co.getActuator("WMove")

# Transform the mouse coordinates to see how far the mouse has moved.
def mousePos():
   x = (bge.render.getWindowWidth()/2 - mouse.getXPosition())*SCALE[0]
   y = (bge.render.getWindowHeight()/2 - mouse.getYPosition())*SCALE[1]
   return (x, y)

pos = mousePos()

# Set the amount of motion: X is applied in world coordinates...
lmotion.setTorque(0.0, 0.0, pos[0], False)
# ...Y is applied in local coordinates
wmotion.setTorque(-pos[1], 0.0, 0.0, True)

# Activate both actuators
bge.logic.addActiveActuator(lmotion, True)
bge.logic.addActiveActuator(wmotion, True)

# Centre the mouse
bge.render.setMousePosition(bge.render.getWindowWidth()/2, bge.render.getWindowHeight()/2)

Constants

bge.render.KX_TEXFACE_MATERIAL

Materials as defined by the texture face settings.

bge.render.KX_BLENDER_MULTITEX_MATERIAL

Materials approximating blender materials with multitexturing.

bge.render.KX_BLENDER_GLSL_MATERIAL

Materials approximating blender materials with GLSL.

Functions

bge.render.getWindowWidth()

Gets the width of the window (in pixels)

Return type:integer
bge.render.getWindowHeight()

Gets the height of the window (in pixels)

Return type:integer
bge.render.makeScreenshot(filename)

Writes a screenshot to the given filename.

If filename starts with // the image will be saved relative to the current directory. If the filename contains # it will be replaced with the frame number.

The standalone player saves .png files. It does not support colour space conversion or gamma correction.

When run from Blender, makeScreenshot supports Iris, IrisZ, TGA, Raw TGA, PNG, HamX, and Jpeg. Gamma, Colourspace conversion and Jpeg compression are taken from the Render settings panels.

bge.render.enableVisibility(visible)

Doesn’t really do anything...

bge.render.showMouse(visible)

Enables or disables the operating system mouse cursor.

bge.render.setMousePosition(x, y)

Sets the mouse cursor position.

bge.render.setBackgroundColor(rgba)

Sets the window background colour.

bge.render.setMistColor(rgb)

Sets the mist colour.

bge.render.setAmbientColor(rgb)

Sets the color of ambient light.

bge.render.setMistStart(start)

Sets the mist start value. Objects further away than start will have mist applied to them.

bge.render.setMistEnd(end)

Sets the mist end value. Objects further away from this will be coloured solid with the colour set by setMistColor().

bge.render.disableMist()

Disables mist.

Note

Set any of the mist properties to enable mist.

bge.render.setEyeSeparation(eyesep)

Sets the eye separation for stereo mode. Usually Focal Length/30 provides a confortable value.

Parameters:
  • eyesep (float) – The distance between the left and right eye.
bge.render.getEyeSeparation()

Gets the current eye separation for stereo mode.

Return type:float
bge.render.setFocalLength(focallength)

Sets the focal length for stereo mode. It uses the current camera focal length as initial value.

Parameters:
  • focallength (float) – The focal length.
bge.render.getFocalLength()

Gets the current focal length for stereo mode.

Return type:float
bge.render.setMaterialMode(mode)

Set the material mode to use for OpenGL rendering.

Note

Changes will only affect newly created scenes.

bge.render.getMaterialMode(mode)

Get the material mode to use for OpenGL rendering.

Return type:KX_TEXFACE_MATERIAL, KX_BLENDER_MULTITEX_MATERIAL, KX_BLENDER_GLSL_MATERIAL
bge.render.setGLSLMaterialSetting(setting, enable)

Enables or disables a GLSL material setting.

bge.render.getGLSLMaterialSetting(setting, enable)

Get the state of a GLSL material setting.

Return type:boolean
bge.render.drawLine(fromVec, toVec, color)

Draw a line in the 3D scene.

Parameters:
  • fromVec (list [x, y, z]) – the origin of the line
  • toVec (list [x, y, z]) – the end of the line
  • color (list [r, g, b]) – the color of the line
bge.render.enableMotionBlur(factor)

Enable the motion blur effect.

Parameters:
  • factor (float [0.0 - 1.0]) – the ammount of motion blur to display.
bge.render.disableMotionBlur()

Disable the motion blur effect.

Table Of Contents

Previous topic

Game Engine bge.logic Module

Next topic

Game Engine bge.events module