2010-05-16 23:13:30 +00:00
|
|
|
|
2011-07-30 23:16:22 +00:00
|
|
|
Rasterizer (bge.render)
|
2011-07-31 03:15:37 +00:00
|
|
|
=======================
|
2010-05-16 23:13:30 +00:00
|
|
|
|
2010-06-03 14:26:38 +00:00
|
|
|
*****
|
|
|
|
Intro
|
|
|
|
*****
|
|
|
|
|
2010-05-16 23:25:05 +00:00
|
|
|
.. module:: bge.render
|
|
|
|
|
2015-09-04 01:11:26 +10:00
|
|
|
Example of using a :class:`bge.types.SCA_MouseSensor`,
|
|
|
|
and two :class:`bge.types.KX_ObjectActuator` to implement MouseLook:
|
2015-01-22 03:20:39 -02:00
|
|
|
|
|
|
|
.. note::
|
|
|
|
This can also be achieved with the :class:`bge.types.KX_MouseActuator`.
|
|
|
|
|
2010-05-16 23:13:30 +00:00
|
|
|
.. code-block:: python
|
|
|
|
|
2012-05-25 12:37:14 +00:00
|
|
|
# To use a mouse movement sensor "Mouse" and a
|
2010-05-16 23:13:30 +00:00
|
|
|
# motion actuator to mouse look:
|
2012-05-25 12:37:14 +00:00
|
|
|
import bge
|
2010-05-16 23:13:30 +00:00
|
|
|
|
2011-07-31 03:15:37 +00:00
|
|
|
# scale sets the speed of motion
|
|
|
|
scale = 1.0, 0.5
|
2012-05-25 12:37:14 +00:00
|
|
|
|
2010-05-16 23:13:30 +00:00
|
|
|
co = bge.logic.getCurrentController()
|
2012-05-25 12:37:14 +00:00
|
|
|
obj = co.owner
|
|
|
|
mouse = co.sensors["Mouse"]
|
|
|
|
lmotion = co.actuators["LMove"]
|
|
|
|
wmotion = co.actuators["WMove"]
|
|
|
|
|
2010-05-16 23:13:30 +00:00
|
|
|
# Transform the mouse coordinates to see how far the mouse has moved.
|
|
|
|
def mousePos():
|
2012-05-25 12:37:14 +00:00
|
|
|
x = (bge.render.getWindowWidth() / 2 - mouse.position[0]) * scale[0]
|
|
|
|
y = (bge.render.getWindowHeight() / 2 - mouse.position[1]) * scale[1]
|
2010-05-16 23:13:30 +00:00
|
|
|
return (x, y)
|
2012-05-25 12:37:14 +00:00
|
|
|
|
2010-05-16 23:13:30 +00:00
|
|
|
pos = mousePos()
|
2012-05-25 12:37:14 +00:00
|
|
|
|
2010-05-16 23:13:30 +00:00
|
|
|
# Set the amount of motion: X is applied in world coordinates...
|
2012-05-25 12:37:14 +00:00
|
|
|
wmotion.useLocalTorque = False
|
|
|
|
wmotion.torque = ((0.0, 0.0, pos[0]))
|
|
|
|
|
2010-05-16 23:13:30 +00:00
|
|
|
# ...Y is applied in local coordinates
|
2012-05-25 12:37:14 +00:00
|
|
|
lmotion.useLocalTorque = True
|
|
|
|
lmotion.torque = ((-pos[1], 0.0, 0.0))
|
|
|
|
|
2010-05-16 23:13:30 +00:00
|
|
|
# Activate both actuators
|
2012-05-25 12:37:14 +00:00
|
|
|
co.activate(lmotion)
|
|
|
|
co.activate(wmotion)
|
|
|
|
|
2010-05-16 23:13:30 +00:00
|
|
|
# Centre the mouse
|
2012-05-25 12:37:14 +00:00
|
|
|
bge.render.setMousePosition(int(bge.render.getWindowWidth() / 2), int(bge.render.getWindowHeight() / 2))
|
2010-05-16 23:13:30 +00:00
|
|
|
|
2010-06-03 14:26:38 +00:00
|
|
|
*********
|
|
|
|
Constants
|
|
|
|
*********
|
2010-05-16 23:13:30 +00:00
|
|
|
|
|
|
|
.. data:: KX_TEXFACE_MATERIAL
|
|
|
|
|
|
|
|
Materials as defined by the texture face settings.
|
|
|
|
|
|
|
|
.. data:: KX_BLENDER_MULTITEX_MATERIAL
|
|
|
|
|
|
|
|
Materials approximating blender materials with multitexturing.
|
|
|
|
|
|
|
|
.. data:: KX_BLENDER_GLSL_MATERIAL
|
|
|
|
|
|
|
|
Materials approximating blender materials with GLSL.
|
2015-03-24 10:17:22 +00:00
|
|
|
|
2013-07-29 22:31:32 +00:00
|
|
|
.. DATA:: VSYNC_OFF
|
|
|
|
|
|
|
|
Disables vsync
|
|
|
|
|
|
|
|
.. DATA:: VSYNC_ON
|
|
|
|
|
|
|
|
Enables vsync
|
|
|
|
|
|
|
|
.. DATA:: VSYNC_ADAPTIVE
|
|
|
|
|
2015-09-04 01:11:26 +10:00
|
|
|
Enables adaptive vsync if supported.
|
|
|
|
Adaptive vsync enables vsync if the framerate is above the monitors refresh rate.
|
|
|
|
Otherwise, vsync is diabled if the framerate is too low.
|
2010-05-16 23:13:30 +00:00
|
|
|
|
bge.render.getStereoEye() and bge.types.LEFT_EYE/RIGHT_EYE
This function allows the user to run specific code for each of the
rendered stereoscopic eyes in the Game Engine.
The initial use case is to set the camera projection matrix in
a scene.pre_draw callback function for each eye, to be used in VR
(Virtual Reality) installations.
Reviewed by Mitchell Stokes and Campbell Barton, thank you guys.
Sample Test Python Script:
"""
import bge
import bgl
import blf
def init():
"""init function - runs once"""
scene = bge.logic.getCurrentScene()
scene.post_draw.append(write)
def write():
"""write on screen - depending on the eye"""
width = bge.render.getWindowWidth()
height = bge.render.getWindowHeight()
# OpenGL setup
bgl.glMatrixMode(bgl.GL_PROJECTION)
bgl.glLoadIdentity()
bgl.gluOrtho2D(0, width, 0, height)
bgl.glMatrixMode(bgl.GL_MODELVIEW)
bgl.glLoadIdentity()
eye = bge.render.getStereoEye()
if eye == bge.render.LEFT_EYE:
blf.position(0, (width * 0.2), (height * 0.3), 0)
blf.size(0, 40, 72)
blf.draw(0, "Left")
else: # bge.render.RIGHT_EYE:
blf.position(0, (width * 0.7), (height * 0.3), 0)
blf.size(0, 40, 72)
blf.draw(0, "Right")
"""
2015-01-22 02:42:40 -02:00
|
|
|
.. data:: LEFT_EYE
|
|
|
|
|
|
|
|
Left eye being used during stereoscopic rendering.
|
|
|
|
|
|
|
|
.. data:: RIGHT_EYE
|
|
|
|
|
|
|
|
Right eye being used during stereoscopic rendering.
|
|
|
|
|
BGE: Various render improvements.
bge.logic.setRender(flag) to enable/disable render.
The render pass is enabled by default but it can be disabled with
bge.logic.setRender(False).
Once disabled, the render pass is skipped and a new logic frame starts
immediately. Note that VSync no longer limits the fps when render is off
but the 'Use Frame Rate' option in the Render Properties still does.
To run as many frames as possible, untick the option
This function is useful when you don't need the default render, e.g.
when doing offscreen render to an alternate device than the monitor.
Note that without VSync, you must limit the frame rate by other means.
fbo = bge.render.offScreenCreate(width,height,[,samples=0][,target=bge.render.RAS_OFS_RENDER_BUFFER])
Use this method to create an offscreen buffer of given size, with given MSAA
samples and targetting either a render buffer (bge.render.RAS_OFS_RENDER_BUFFER)
or a texture (bge.render.RAS_OFS_RENDER_TEXTURE). Use the former if you want to
retrieve the frame buffer on the host and the latter if you want to pass the render
to another context (texture are proper OGL object, render buffers aren't)
The object created by this function can only be used as a parameter of the
bge.texture.ImageRender() constructor to send the the render to the FBO rather
than to the frame buffer. This is best suited when you want to create a render
of specific size, or if you need an image with an alpha channel.
bge.texture.<imagetype>.refresh(buffer=None, format="RGBA", ts=-1.0)
Without arg, the refresh method of the image objects is pretty much a no-op, it
simply invalidates the image so that on next texture refresh, the image will
be recalculated.
It is now possible to pass an optional buffer object to transfer the image (and
recalculate it if it was invalid) to an external object. The object must implement
the 'buffer protocol'. The image will be transfered as "RGBA" or "BGRA" pixels
depending on format argument (only those 2 formats are supported) and ts is an
optional timestamp in the image depends on it (e.g. VideoFFmpeg playing a video file).
With this function you don't need anymore to link the image object to a Texture
object to use: the image object is self-sufficient.
bge.texture.ImageRender(scene, camera, fbo=None)
Render to buffer is possible by passing a FBO object (see offScreenCreate).
bge.texture.ImageRender.render()
Allows asynchronous render: call this method to render the scene but without
extracting the pixels yet. The function returns as soon as the render commands
have been send to the GPU. The render will proceed asynchronously in the GPU
while the host can perform other tasks.
To complete the render, you can either call refresh() directly of refresh the texture
to which this object is the source. Asynchronous render is useful to achieve optimal
performance: call render() on frame N and refresh() on frame N+1 to give as much as
time as possible to the GPU to render the frame while the game engine can perform other tasks.
Support negative scale on camera.
Camera scale was previously ignored in the BGE.
It is now injected in the modelview matrix as a vertical or horizontal flip
of the scene (respectively if scaleY<0 and scaleX<0).
Note that the actual value of the scale is not used, only the sign.
This allows to flip the image produced by ImageRender() without any performance
degradation: the flip is integrated in the render itself.
Optimized image transfer from ImageRender to buffer.
Previously, images that were transferred to the host were always going through
buffers in VideoTexture. It is now possible to transfer ImageRender
images to external buffer without intermediate copy (i.e. directly from OGL to buffer)
if the attributes of the ImageRender objects are set as follow:
flip=False, alpha=True, scale=False, depth=False, zbuff=False.
(if you need to flip the image, use camera negative scale)
2016-06-09 23:56:45 +02:00
|
|
|
.. data:: RAS_OFS_RENDER_BUFFER
|
|
|
|
|
|
|
|
The pixel buffer for offscreen render is a RenderBuffer. Argument to :func:`offScreenCreate`
|
|
|
|
|
|
|
|
.. data:: RAS_OFS_RENDER_TEXTURE
|
|
|
|
|
|
|
|
The pixel buffer for offscreen render is a Texture. Argument to :func:`offScreenCreate`
|
|
|
|
|
|
|
|
|
|
|
|
*****
|
|
|
|
Types
|
|
|
|
*****
|
|
|
|
|
|
|
|
.. class:: RASOffScreen
|
|
|
|
|
2018-11-30 08:38:25 +11:00
|
|
|
An off-screen render buffer object.
|
BGE: Various render improvements.
bge.logic.setRender(flag) to enable/disable render.
The render pass is enabled by default but it can be disabled with
bge.logic.setRender(False).
Once disabled, the render pass is skipped and a new logic frame starts
immediately. Note that VSync no longer limits the fps when render is off
but the 'Use Frame Rate' option in the Render Properties still does.
To run as many frames as possible, untick the option
This function is useful when you don't need the default render, e.g.
when doing offscreen render to an alternate device than the monitor.
Note that without VSync, you must limit the frame rate by other means.
fbo = bge.render.offScreenCreate(width,height,[,samples=0][,target=bge.render.RAS_OFS_RENDER_BUFFER])
Use this method to create an offscreen buffer of given size, with given MSAA
samples and targetting either a render buffer (bge.render.RAS_OFS_RENDER_BUFFER)
or a texture (bge.render.RAS_OFS_RENDER_TEXTURE). Use the former if you want to
retrieve the frame buffer on the host and the latter if you want to pass the render
to another context (texture are proper OGL object, render buffers aren't)
The object created by this function can only be used as a parameter of the
bge.texture.ImageRender() constructor to send the the render to the FBO rather
than to the frame buffer. This is best suited when you want to create a render
of specific size, or if you need an image with an alpha channel.
bge.texture.<imagetype>.refresh(buffer=None, format="RGBA", ts=-1.0)
Without arg, the refresh method of the image objects is pretty much a no-op, it
simply invalidates the image so that on next texture refresh, the image will
be recalculated.
It is now possible to pass an optional buffer object to transfer the image (and
recalculate it if it was invalid) to an external object. The object must implement
the 'buffer protocol'. The image will be transfered as "RGBA" or "BGRA" pixels
depending on format argument (only those 2 formats are supported) and ts is an
optional timestamp in the image depends on it (e.g. VideoFFmpeg playing a video file).
With this function you don't need anymore to link the image object to a Texture
object to use: the image object is self-sufficient.
bge.texture.ImageRender(scene, camera, fbo=None)
Render to buffer is possible by passing a FBO object (see offScreenCreate).
bge.texture.ImageRender.render()
Allows asynchronous render: call this method to render the scene but without
extracting the pixels yet. The function returns as soon as the render commands
have been send to the GPU. The render will proceed asynchronously in the GPU
while the host can perform other tasks.
To complete the render, you can either call refresh() directly of refresh the texture
to which this object is the source. Asynchronous render is useful to achieve optimal
performance: call render() on frame N and refresh() on frame N+1 to give as much as
time as possible to the GPU to render the frame while the game engine can perform other tasks.
Support negative scale on camera.
Camera scale was previously ignored in the BGE.
It is now injected in the modelview matrix as a vertical or horizontal flip
of the scene (respectively if scaleY<0 and scaleX<0).
Note that the actual value of the scale is not used, only the sign.
This allows to flip the image produced by ImageRender() without any performance
degradation: the flip is integrated in the render itself.
Optimized image transfer from ImageRender to buffer.
Previously, images that were transferred to the host were always going through
buffers in VideoTexture. It is now possible to transfer ImageRender
images to external buffer without intermediate copy (i.e. directly from OGL to buffer)
if the attributes of the ImageRender objects are set as follow:
flip=False, alpha=True, scale=False, depth=False, zbuff=False.
(if you need to flip the image, use camera negative scale)
2016-06-09 23:56:45 +02:00
|
|
|
|
|
|
|
Use :func:`offScreenCreate` to create it.
|
|
|
|
Currently it can only be used in the :class:`bge.texture.ImageRender`
|
|
|
|
constructor to render on a FBO rather than the default viewport.
|
|
|
|
|
|
|
|
.. attribute:: width
|
|
|
|
|
|
|
|
The width in pixel of the FBO
|
|
|
|
|
|
|
|
:type: integer
|
|
|
|
|
|
|
|
.. attribute:: height
|
|
|
|
|
|
|
|
The height in pixel of the FBO
|
|
|
|
|
|
|
|
:type: integer
|
|
|
|
|
|
|
|
.. attribute:: color
|
|
|
|
|
|
|
|
The underlying OpenGL bind code of the texture object that holds
|
|
|
|
the rendered image, 0 if the FBO is using RenderBuffer.
|
|
|
|
The choice between RenderBuffer and Texture is determined
|
|
|
|
by the target argument of :func:`offScreenCreate`.
|
|
|
|
|
|
|
|
:type: integer
|
|
|
|
|
2015-03-23 21:40:11 +01:00
|
|
|
|
2010-06-03 14:26:38 +00:00
|
|
|
*********
|
|
|
|
Functions
|
|
|
|
*********
|
|
|
|
|
2010-05-16 23:13:30 +00:00
|
|
|
.. function:: getWindowWidth()
|
|
|
|
|
|
|
|
Gets the width of the window (in pixels)
|
2015-03-24 10:17:22 +00:00
|
|
|
|
2010-05-16 23:13:30 +00:00
|
|
|
:rtype: integer
|
|
|
|
|
|
|
|
.. function:: getWindowHeight()
|
|
|
|
|
|
|
|
Gets the height of the window (in pixels)
|
2015-03-24 10:17:22 +00:00
|
|
|
|
2010-05-16 23:13:30 +00:00
|
|
|
:rtype: integer
|
|
|
|
|
2012-01-22 20:25:25 +00:00
|
|
|
.. function:: setWindowSize(width, height)
|
|
|
|
|
|
|
|
Set the width and height of the window (in pixels). This also works for fullscreen applications.
|
2015-03-24 10:17:22 +00:00
|
|
|
|
2015-09-04 01:11:26 +10:00
|
|
|
.. note:: Only works in the standalone player, not the Blender-embedded player.
|
2015-09-03 15:05:36 +02:00
|
|
|
|
2015-09-27 16:32:16 +02:00
|
|
|
:arg width: width in pixels
|
2012-01-22 20:25:25 +00:00
|
|
|
:type width: integer
|
2015-09-27 16:32:16 +02:00
|
|
|
:arg height: height in pixels
|
2012-01-22 20:25:25 +00:00
|
|
|
:type height: integer
|
|
|
|
|
2013-04-13 21:09:02 +00:00
|
|
|
.. function:: setFullScreen(enable)
|
|
|
|
|
|
|
|
Set whether or not the window should be fullscreen.
|
2015-03-24 10:17:22 +00:00
|
|
|
|
2015-09-04 01:11:26 +10:00
|
|
|
.. note:: Only works in the standalone player, not the Blender-embedded player.
|
2015-09-03 15:05:36 +02:00
|
|
|
|
2015-09-27 16:32:16 +02:00
|
|
|
:arg enable: ``True`` to set full screen, ``False`` to set windowed.
|
2013-04-13 21:09:02 +00:00
|
|
|
:type enable: bool
|
|
|
|
|
|
|
|
.. function:: getFullScreen()
|
|
|
|
|
|
|
|
Returns whether or not the window is fullscreen.
|
2015-03-24 10:17:22 +00:00
|
|
|
|
2015-09-04 01:11:26 +10:00
|
|
|
.. note:: Only works in the standalone player, not the Blender-embedded player; there it always returns False.
|
2015-09-03 15:05:36 +02:00
|
|
|
|
2013-04-13 21:09:02 +00:00
|
|
|
:rtype: bool
|
2012-01-22 20:25:25 +00:00
|
|
|
|
2015-04-07 18:32:25 +02:00
|
|
|
.. function:: getDisplayDimensions()
|
|
|
|
|
2015-09-27 16:32:16 +02:00
|
|
|
Get the display dimensions, in pixels, of the display (e.g., the
|
|
|
|
monitor). Can return the size of the entire view, so the
|
|
|
|
combination of all monitors; for example, ``(3840, 1080)`` for two
|
|
|
|
side-by-side 1080p monitors.
|
2018-11-30 08:38:25 +11:00
|
|
|
|
2015-09-27 16:32:16 +02:00
|
|
|
:rtype: tuple (width, height)
|
2015-04-07 18:32:25 +02:00
|
|
|
|
2010-05-16 23:13:30 +00:00
|
|
|
.. function:: makeScreenshot(filename)
|
|
|
|
|
2015-03-24 10:17:22 +00:00
|
|
|
Writes an image file with the current displayed frame.
|
|
|
|
|
2015-09-04 01:11:26 +10:00
|
|
|
The image is written to *'filename'*.
|
|
|
|
The path may be absolute (eg. ``/home/foo/image``) or relative when started with
|
|
|
|
``//`` (eg. ``//image``). Note that absolute paths are not portable between platforms.
|
|
|
|
If the filename contains a ``#``,
|
|
|
|
it will be replaced by an incremental index so that screenshots can be taken multiple
|
|
|
|
times without overwriting the previous ones (eg. ``image-#``).
|
|
|
|
|
|
|
|
Settings for the image are taken from the render settings (file format and respective settings,
|
|
|
|
gamma and colospace conversion, etc).
|
|
|
|
The image resolution matches the framebuffer, meaning, the window size and aspect ratio.
|
|
|
|
When running from the standalone player, instead of the embedded player, only PNG files are supported.
|
|
|
|
Additional color conversions are also not supported.
|
2015-03-24 10:17:22 +00:00
|
|
|
|
|
|
|
:arg filename: path and name of the file to write
|
2010-05-16 23:13:30 +00:00
|
|
|
:type filename: string
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: enableVisibility(visible)
|
|
|
|
|
2015-09-27 16:32:16 +02:00
|
|
|
Deprecated; doesn't do anything.
|
2010-05-16 23:13:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
.. function:: showMouse(visible)
|
|
|
|
|
|
|
|
Enables or disables the operating system mouse cursor.
|
2015-03-24 10:17:22 +00:00
|
|
|
|
2015-09-27 16:32:16 +02:00
|
|
|
:arg visible:
|
2010-05-16 23:13:30 +00:00
|
|
|
:type visible: boolean
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: setMousePosition(x, y)
|
|
|
|
|
|
|
|
Sets the mouse cursor position.
|
2015-03-24 10:17:22 +00:00
|
|
|
|
2015-09-27 16:32:16 +02:00
|
|
|
:arg x: X-coordinate in screen pixel coordinates.
|
2010-05-16 23:13:30 +00:00
|
|
|
:type x: integer
|
2015-09-27 16:32:16 +02:00
|
|
|
:arg y: Y-coordinate in screen pixel coordinates.
|
2010-05-16 23:13:30 +00:00
|
|
|
:type y: integer
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: setBackgroundColor(rgba)
|
|
|
|
|
2015-09-27 17:19:30 +02:00
|
|
|
Deprecated and no longer functional. Use :py:meth:`bge.types.KX_WorldInfo.backgroundColor` instead.
|
2010-05-16 23:13:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
.. function:: setEyeSeparation(eyesep)
|
|
|
|
|
|
|
|
Sets the eye separation for stereo mode. Usually Focal Length/30 provides a confortable value.
|
2015-03-24 10:17:22 +00:00
|
|
|
|
2010-05-16 23:13:30 +00:00
|
|
|
:arg eyesep: The distance between the left and right eye.
|
|
|
|
:type eyesep: float
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: getEyeSeparation()
|
|
|
|
|
|
|
|
Gets the current eye separation for stereo mode.
|
2015-03-24 10:17:22 +00:00
|
|
|
|
2010-05-16 23:13:30 +00:00
|
|
|
:rtype: float
|
|
|
|
|
2015-03-24 10:17:22 +00:00
|
|
|
|
2010-05-16 23:13:30 +00:00
|
|
|
.. function:: setFocalLength(focallength)
|
|
|
|
|
|
|
|
Sets the focal length for stereo mode. It uses the current camera focal length as initial value.
|
2015-03-24 10:17:22 +00:00
|
|
|
|
|
|
|
:arg focallength: The focal length.
|
2010-05-16 23:13:30 +00:00
|
|
|
:type focallength: float
|
|
|
|
|
|
|
|
.. function:: getFocalLength()
|
|
|
|
|
|
|
|
Gets the current focal length for stereo mode.
|
2015-03-24 10:17:22 +00:00
|
|
|
|
2010-05-16 23:13:30 +00:00
|
|
|
:rtype: float
|
|
|
|
|
bge.render.getStereoEye() and bge.types.LEFT_EYE/RIGHT_EYE
This function allows the user to run specific code for each of the
rendered stereoscopic eyes in the Game Engine.
The initial use case is to set the camera projection matrix in
a scene.pre_draw callback function for each eye, to be used in VR
(Virtual Reality) installations.
Reviewed by Mitchell Stokes and Campbell Barton, thank you guys.
Sample Test Python Script:
"""
import bge
import bgl
import blf
def init():
"""init function - runs once"""
scene = bge.logic.getCurrentScene()
scene.post_draw.append(write)
def write():
"""write on screen - depending on the eye"""
width = bge.render.getWindowWidth()
height = bge.render.getWindowHeight()
# OpenGL setup
bgl.glMatrixMode(bgl.GL_PROJECTION)
bgl.glLoadIdentity()
bgl.gluOrtho2D(0, width, 0, height)
bgl.glMatrixMode(bgl.GL_MODELVIEW)
bgl.glLoadIdentity()
eye = bge.render.getStereoEye()
if eye == bge.render.LEFT_EYE:
blf.position(0, (width * 0.2), (height * 0.3), 0)
blf.size(0, 40, 72)
blf.draw(0, "Left")
else: # bge.render.RIGHT_EYE:
blf.position(0, (width * 0.7), (height * 0.3), 0)
blf.size(0, 40, 72)
blf.draw(0, "Right")
"""
2015-01-22 02:42:40 -02:00
|
|
|
.. function:: getStereoEye()
|
|
|
|
|
|
|
|
Gets the current stereoscopy eye being rendered.
|
|
|
|
This function is mainly used in a :class:`bge.types.KX_Scene.pre_draw` callback
|
|
|
|
function to customize the camera projection matrices for each
|
|
|
|
stereoscopic eye.
|
|
|
|
|
|
|
|
:rtype: LEFT_EYE, RIGHT_EYE
|
|
|
|
|
2010-05-16 23:13:30 +00:00
|
|
|
.. function:: setMaterialMode(mode)
|
|
|
|
|
|
|
|
Set the material mode to use for OpenGL rendering.
|
2015-03-24 10:17:22 +00:00
|
|
|
|
2015-09-27 16:32:16 +02:00
|
|
|
:arg mode: material mode
|
2010-05-16 23:13:30 +00:00
|
|
|
:type mode: KX_TEXFACE_MATERIAL, KX_BLENDER_MULTITEX_MATERIAL, KX_BLENDER_GLSL_MATERIAL
|
|
|
|
|
|
|
|
.. note:: Changes will only affect newly created scenes.
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: getMaterialMode(mode)
|
|
|
|
|
|
|
|
Get the material mode to use for OpenGL rendering.
|
2015-03-24 10:17:22 +00:00
|
|
|
|
2010-05-16 23:13:30 +00:00
|
|
|
:rtype: KX_TEXFACE_MATERIAL, KX_BLENDER_MULTITEX_MATERIAL, KX_BLENDER_GLSL_MATERIAL
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: setGLSLMaterialSetting(setting, enable)
|
|
|
|
|
|
|
|
Enables or disables a GLSL material setting.
|
2015-03-24 10:17:22 +00:00
|
|
|
|
2015-09-27 16:32:16 +02:00
|
|
|
:arg setting:
|
2010-05-16 23:13:30 +00:00
|
|
|
:type setting: string (lights, shaders, shadows, ramps, nodes, extra_textures)
|
2015-09-27 16:32:16 +02:00
|
|
|
:arg enable:
|
2010-05-16 23:13:30 +00:00
|
|
|
:type enable: boolean
|
|
|
|
|
|
|
|
|
2015-09-27 16:32:16 +02:00
|
|
|
.. function:: getGLSLMaterialSetting(setting)
|
2010-05-16 23:13:30 +00:00
|
|
|
|
|
|
|
Get the state of a GLSL material setting.
|
2015-03-24 10:17:22 +00:00
|
|
|
|
2015-09-27 16:32:16 +02:00
|
|
|
:arg setting:
|
2010-05-16 23:13:30 +00:00
|
|
|
:type setting: string (lights, shaders, shadows, ramps, nodes, extra_textures)
|
|
|
|
:rtype: boolean
|
|
|
|
|
2011-08-31 05:51:51 +00:00
|
|
|
.. function:: setAnisotropicFiltering(level)
|
2010-05-16 23:13:30 +00:00
|
|
|
|
2011-08-31 05:51:51 +00:00
|
|
|
Set the anisotropic filtering level for textures.
|
2015-03-24 10:17:22 +00:00
|
|
|
|
2011-08-31 05:51:51 +00:00
|
|
|
:arg level: The new anisotropic filtering level to use
|
|
|
|
:type level: integer (must be one of 1, 2, 4, 8, 16)
|
2015-03-24 10:17:22 +00:00
|
|
|
|
2013-04-14 00:40:24 +00:00
|
|
|
.. note:: Changing this value can cause all textures to be recreated, which can be slow.
|
2015-03-24 10:17:22 +00:00
|
|
|
|
2011-08-31 05:51:51 +00:00
|
|
|
.. function:: getAnisotropicFiltering()
|
|
|
|
|
|
|
|
Get the anisotropic filtering level used for textures.
|
2015-03-24 10:17:22 +00:00
|
|
|
|
2011-08-31 05:51:51 +00:00
|
|
|
:rtype: integer (one of 1, 2, 4, 8, 16)
|
2013-04-14 00:40:24 +00:00
|
|
|
|
|
|
|
.. function:: setMipmapping(value)
|
|
|
|
|
|
|
|
Change how to use mipmapping.
|
2015-03-24 10:17:22 +00:00
|
|
|
|
2013-04-14 00:40:24 +00:00
|
|
|
:type value: RAS_MIPMAP_NONE, RAS_MIPMAP_NEAREST, RAS_MIPMAP_LINEAR
|
2015-03-24 10:17:22 +00:00
|
|
|
|
2013-04-14 00:40:24 +00:00
|
|
|
.. note:: Changing this value can cause all textures to be recreated, which can be slow.
|
|
|
|
|
|
|
|
.. function:: getMipmapping()
|
|
|
|
|
|
|
|
Get the current mipmapping setting.
|
2015-03-24 10:17:22 +00:00
|
|
|
|
2013-04-14 00:40:24 +00:00
|
|
|
:rtype: RAS_MIPMAP_NONE, RAS_MIPMAP_NEAREST, RAS_MIPMAP_LINEAR
|
2015-03-24 10:17:22 +00:00
|
|
|
|
2010-05-16 23:13:30 +00:00
|
|
|
.. function:: drawLine(fromVec,toVec,color)
|
|
|
|
|
|
|
|
Draw a line in the 3D scene.
|
2015-03-24 10:17:22 +00:00
|
|
|
|
2010-05-16 23:13:30 +00:00
|
|
|
:arg fromVec: the origin of the line
|
|
|
|
:type fromVec: list [x, y, z]
|
|
|
|
:arg toVec: the end of the line
|
|
|
|
:type toVec: list [x, y, z]
|
|
|
|
:arg color: the color of the line
|
|
|
|
:type color: list [r, g, b]
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: enableMotionBlur(factor)
|
|
|
|
|
2010-07-16 09:10:46 +00:00
|
|
|
Enable the motion blur effect.
|
2015-03-24 10:17:22 +00:00
|
|
|
|
2010-05-16 23:13:30 +00:00
|
|
|
:arg factor: the ammount of motion blur to display.
|
|
|
|
:type factor: float [0.0 - 1.0]
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: disableMotionBlur()
|
|
|
|
|
2010-07-16 09:10:46 +00:00
|
|
|
Disable the motion blur effect.
|
2010-05-16 23:13:30 +00:00
|
|
|
|
2014-07-11 15:18:43 -07:00
|
|
|
.. function:: showFramerate(enable)
|
|
|
|
|
|
|
|
Show or hide the framerate.
|
|
|
|
|
2015-09-27 16:32:16 +02:00
|
|
|
:arg enable:
|
2014-07-11 15:18:43 -07:00
|
|
|
:type enable: boolean
|
|
|
|
|
|
|
|
.. function:: showProfile(enable)
|
|
|
|
|
|
|
|
Show or hide the profile.
|
|
|
|
|
2015-09-27 16:32:16 +02:00
|
|
|
:arg enable:
|
2014-07-11 15:18:43 -07:00
|
|
|
:type enable: boolean
|
|
|
|
|
|
|
|
.. function:: showProperties(enable)
|
|
|
|
|
|
|
|
Show or hide the debug properties.
|
|
|
|
|
2015-09-27 16:32:16 +02:00
|
|
|
:arg enable:
|
2014-07-11 15:18:43 -07:00
|
|
|
:type enable: boolean
|
|
|
|
|
|
|
|
.. function:: autoDebugList(enable)
|
|
|
|
|
|
|
|
Enable or disable auto adding debug properties to the debug list.
|
|
|
|
|
2015-09-27 16:32:16 +02:00
|
|
|
:arg enable:
|
2014-07-11 15:18:43 -07:00
|
|
|
:type enable: boolean
|
|
|
|
|
|
|
|
.. function:: clearDebugList()
|
|
|
|
|
|
|
|
Clears the debug property list.
|
|
|
|
|
2013-07-29 22:31:32 +00:00
|
|
|
.. function:: setVsync(value)
|
|
|
|
|
|
|
|
Set the vsync value
|
|
|
|
|
|
|
|
:arg value: One of VSYNC_OFF, VSYNC_ON, VSYNC_ADAPTIVE
|
|
|
|
:type value: integer
|
|
|
|
|
|
|
|
.. function:: getVsync()
|
|
|
|
|
|
|
|
Get the current vsync value
|
|
|
|
|
|
|
|
:rtype: One of VSYNC_OFF, VSYNC_ON, VSYNC_ADAPTIVE
|
BGE: Various render improvements.
bge.logic.setRender(flag) to enable/disable render.
The render pass is enabled by default but it can be disabled with
bge.logic.setRender(False).
Once disabled, the render pass is skipped and a new logic frame starts
immediately. Note that VSync no longer limits the fps when render is off
but the 'Use Frame Rate' option in the Render Properties still does.
To run as many frames as possible, untick the option
This function is useful when you don't need the default render, e.g.
when doing offscreen render to an alternate device than the monitor.
Note that without VSync, you must limit the frame rate by other means.
fbo = bge.render.offScreenCreate(width,height,[,samples=0][,target=bge.render.RAS_OFS_RENDER_BUFFER])
Use this method to create an offscreen buffer of given size, with given MSAA
samples and targetting either a render buffer (bge.render.RAS_OFS_RENDER_BUFFER)
or a texture (bge.render.RAS_OFS_RENDER_TEXTURE). Use the former if you want to
retrieve the frame buffer on the host and the latter if you want to pass the render
to another context (texture are proper OGL object, render buffers aren't)
The object created by this function can only be used as a parameter of the
bge.texture.ImageRender() constructor to send the the render to the FBO rather
than to the frame buffer. This is best suited when you want to create a render
of specific size, or if you need an image with an alpha channel.
bge.texture.<imagetype>.refresh(buffer=None, format="RGBA", ts=-1.0)
Without arg, the refresh method of the image objects is pretty much a no-op, it
simply invalidates the image so that on next texture refresh, the image will
be recalculated.
It is now possible to pass an optional buffer object to transfer the image (and
recalculate it if it was invalid) to an external object. The object must implement
the 'buffer protocol'. The image will be transfered as "RGBA" or "BGRA" pixels
depending on format argument (only those 2 formats are supported) and ts is an
optional timestamp in the image depends on it (e.g. VideoFFmpeg playing a video file).
With this function you don't need anymore to link the image object to a Texture
object to use: the image object is self-sufficient.
bge.texture.ImageRender(scene, camera, fbo=None)
Render to buffer is possible by passing a FBO object (see offScreenCreate).
bge.texture.ImageRender.render()
Allows asynchronous render: call this method to render the scene but without
extracting the pixels yet. The function returns as soon as the render commands
have been send to the GPU. The render will proceed asynchronously in the GPU
while the host can perform other tasks.
To complete the render, you can either call refresh() directly of refresh the texture
to which this object is the source. Asynchronous render is useful to achieve optimal
performance: call render() on frame N and refresh() on frame N+1 to give as much as
time as possible to the GPU to render the frame while the game engine can perform other tasks.
Support negative scale on camera.
Camera scale was previously ignored in the BGE.
It is now injected in the modelview matrix as a vertical or horizontal flip
of the scene (respectively if scaleY<0 and scaleX<0).
Note that the actual value of the scale is not used, only the sign.
This allows to flip the image produced by ImageRender() without any performance
degradation: the flip is integrated in the render itself.
Optimized image transfer from ImageRender to buffer.
Previously, images that were transferred to the host were always going through
buffers in VideoTexture. It is now possible to transfer ImageRender
images to external buffer without intermediate copy (i.e. directly from OGL to buffer)
if the attributes of the ImageRender objects are set as follow:
flip=False, alpha=True, scale=False, depth=False, zbuff=False.
(if you need to flip the image, use camera negative scale)
2016-06-09 23:56:45 +02:00
|
|
|
|
|
|
|
.. function:: offScreenCreate(width,height[,samples=0][,target=bge.render.RAS_OFS_RENDER_BUFFER])
|
|
|
|
|
|
|
|
Create a Off-screen render buffer object.
|
|
|
|
|
|
|
|
:arg width: the width of the buffer in pixels
|
|
|
|
:type width: integer
|
|
|
|
:arg height: the height of the buffer in pixels
|
|
|
|
:type height: integer
|
|
|
|
:arg samples: the number of multisample for anti-aliasing (MSAA), 0 to disable MSAA
|
|
|
|
:type samples: integer
|
|
|
|
:arg target: the pixel storage: :data:`RAS_OFS_RENDER_BUFFER` to render on RenderBuffers (the default),
|
2018-11-30 08:38:25 +11:00
|
|
|
:data:`RAS_OFS_RENDER_TEXTURE` to render on texture.
|
BGE: Various render improvements.
bge.logic.setRender(flag) to enable/disable render.
The render pass is enabled by default but it can be disabled with
bge.logic.setRender(False).
Once disabled, the render pass is skipped and a new logic frame starts
immediately. Note that VSync no longer limits the fps when render is off
but the 'Use Frame Rate' option in the Render Properties still does.
To run as many frames as possible, untick the option
This function is useful when you don't need the default render, e.g.
when doing offscreen render to an alternate device than the monitor.
Note that without VSync, you must limit the frame rate by other means.
fbo = bge.render.offScreenCreate(width,height,[,samples=0][,target=bge.render.RAS_OFS_RENDER_BUFFER])
Use this method to create an offscreen buffer of given size, with given MSAA
samples and targetting either a render buffer (bge.render.RAS_OFS_RENDER_BUFFER)
or a texture (bge.render.RAS_OFS_RENDER_TEXTURE). Use the former if you want to
retrieve the frame buffer on the host and the latter if you want to pass the render
to another context (texture are proper OGL object, render buffers aren't)
The object created by this function can only be used as a parameter of the
bge.texture.ImageRender() constructor to send the the render to the FBO rather
than to the frame buffer. This is best suited when you want to create a render
of specific size, or if you need an image with an alpha channel.
bge.texture.<imagetype>.refresh(buffer=None, format="RGBA", ts=-1.0)
Without arg, the refresh method of the image objects is pretty much a no-op, it
simply invalidates the image so that on next texture refresh, the image will
be recalculated.
It is now possible to pass an optional buffer object to transfer the image (and
recalculate it if it was invalid) to an external object. The object must implement
the 'buffer protocol'. The image will be transfered as "RGBA" or "BGRA" pixels
depending on format argument (only those 2 formats are supported) and ts is an
optional timestamp in the image depends on it (e.g. VideoFFmpeg playing a video file).
With this function you don't need anymore to link the image object to a Texture
object to use: the image object is self-sufficient.
bge.texture.ImageRender(scene, camera, fbo=None)
Render to buffer is possible by passing a FBO object (see offScreenCreate).
bge.texture.ImageRender.render()
Allows asynchronous render: call this method to render the scene but without
extracting the pixels yet. The function returns as soon as the render commands
have been send to the GPU. The render will proceed asynchronously in the GPU
while the host can perform other tasks.
To complete the render, you can either call refresh() directly of refresh the texture
to which this object is the source. Asynchronous render is useful to achieve optimal
performance: call render() on frame N and refresh() on frame N+1 to give as much as
time as possible to the GPU to render the frame while the game engine can perform other tasks.
Support negative scale on camera.
Camera scale was previously ignored in the BGE.
It is now injected in the modelview matrix as a vertical or horizontal flip
of the scene (respectively if scaleY<0 and scaleX<0).
Note that the actual value of the scale is not used, only the sign.
This allows to flip the image produced by ImageRender() without any performance
degradation: the flip is integrated in the render itself.
Optimized image transfer from ImageRender to buffer.
Previously, images that were transferred to the host were always going through
buffers in VideoTexture. It is now possible to transfer ImageRender
images to external buffer without intermediate copy (i.e. directly from OGL to buffer)
if the attributes of the ImageRender objects are set as follow:
flip=False, alpha=True, scale=False, depth=False, zbuff=False.
(if you need to flip the image, use camera negative scale)
2016-06-09 23:56:45 +02:00
|
|
|
The later is interesting if you want to access the texture directly (see :attr:`RASOffScreen.color`).
|
|
|
|
Otherwise the default is preferable as it's more widely supported by GPUs and more efficient.
|
|
|
|
If the GPU does not support MSAA+Texture (e.g. Intel HD GPU), MSAA will be disabled.
|
|
|
|
:type target: integer
|
|
|
|
:rtype: :class:`RASOffScreen`
|