2 Game Engine bge.texture Module
3 ==============================
6 This documentation is still very weak, and needs some help! Right now they are mostly a collection
7 of the docstrings found in the bge.texture source code + some random places filled with text.
13 The bge.texture module allows you to manipulate textures during the game.
15 Several sources for texture are possible: video files, image files, video capture, memory buffer, camera render or a mix of that.
17 The video and image files can be loaded from the internet using an URL instead of a file name.
19 In addition, you can apply filters on the images before sending them to the GPU, allowing video effect: blue screen, color band, gray, normal map.
21 bge.texture uses FFmpeg to load images and videos. All the formats and codecs that FFmpeg supports are supported by this module, including but not limited to::
28 * video4linux capture card (this includes many webcams)
29 * videoForWindows capture card (this includes many webcams)
32 The principle is simple: first you identify a texture on an existing object using
33 the :materialID: function, then you create a new texture with dynamic content
34 and swap the two textures in the GPU.
36 The GE is not aware of the substitution and continues to display the object as always,
37 except that you are now in control of the texture.
39 When the texture object is deleted, the new texture is deleted and the old texture restored.
41 .. module:: bge.texture
43 .. class:: VideoFFmpeg(file [, capture=-1, rate=25.0, width=0, height=0])
54 repeat count, -1 for infinite repeat
58 .. attribute:: framerate
64 Tells if an image is available
75 fast scale of image (near neighbour)
83 .. attribute:: preseek
84 number of frames of preseek
88 .. attribute:: deinterlace
100 stop video (play will replay it from start)
102 .. method:: refresh()
103 Refresh video - get its status
105 .. class:: ImageFFmpeg(file)
109 .. attribute:: status
113 Tells if an image is available
124 fast scale of image (near neighbour)
127 flip image vertically
129 .. attribute:: filter
132 .. method:: refresh()
133 Refresh image, i.e. load it
135 .. method:: reload([newname])
136 Reload image, i.e. reopen it
138 .. class:: ImageBuff()
140 Image source from image buffer
142 .. attribute:: filter
146 flip image vertically
151 .. method:: load(imageBuffer, width, height)
152 Load image from buffer
154 .. method:: plot(imageBuffer, width, height, positionX, positionY)
158 fast scale of image (near neighbour)
164 bool to tell if an image is available
166 .. class:: ImageMirror(scene)
168 Image source from mirror
173 .. attribute:: background
176 .. attribute:: capsize
182 .. attribute:: filter
186 flip image vertically
191 .. method:: refresh(imageMirror)
192 Refresh image - invalidate its current content
195 fast scale of image (near neighbour)
201 bool to tell if an image is available
204 use whole viewport to render
206 .. class:: ImageMix()
210 .. attribute:: filter
214 flip image vertically
216 .. method:: getSource(imageMix)
219 .. method:: getWeight(imageMix)
220 get image source weight
225 .. method:: refresh(imageMix)
226 Refresh image - invalidate its current content
229 fast scale of image (near neighbour)
231 .. method:: setSource(imageMix)
234 .. method:: setWeight(imageMix)
235 set image source weight
238 bool to tell if an image is available
240 .. class:: ImageRender(scene, camera)
242 Image source from render
247 .. attribute:: background
250 .. attribute:: capsize
253 .. attribute:: filter
257 flip image vertically
262 .. method:: refresh(imageRender)
263 Refresh image - invalidate its current content
266 fast scale of image (near neighbour)
272 bool to tell if an image is available
275 use whole viewport to render
277 .. class:: ImageViewport()
279 Image source from viewport
284 .. attribute:: capsize
285 size of viewport area being captured
287 .. attribute:: filter
291 flip image vertically
296 .. attribute:: position
297 upper left corner of captured area
299 .. method:: refresh(imageViewport)
300 Refresh image - invalidate its current content
303 fast scale of image (near neighbour)
309 bool to tell if an image is available
312 use whole viewport to capture
314 .. class:: Texture(gameObj)
318 .. attribute:: bindId
321 .. method:: close(texture)
322 Close dynamic texture and restore original
324 .. attribute:: mipmap
327 .. method:: refresh(texture)
328 Refresh texture from source
330 .. attribute:: source
333 .. class:: FilterBGR24()
335 Source filter BGR24 objects
337 .. class:: FilterBlueScreen()
339 Filter for Blue Screen objects
344 .. attribute:: limits
345 blue screen color limits
347 .. attribute:: previous
348 previous pixel filter
350 .. class:: FilterColor()
352 Filter for color calculations
354 .. attribute:: matrix
355 matrix [4][5] for color calculation
357 .. attribute:: previous
358 previous pixel filter
360 .. class:: FilterGray()
362 Filter for gray scale effect
364 .. attribute:: previous
365 previous pixel filter
367 .. class:: FilterLevel()
369 Filter for levels calculations
371 .. attribute:: levels
372 levels matrix [4] (min, max)
374 .. attribute:: previous
375 previous pixel filter
377 .. class:: FilterNormal()
379 Filter for Blue Screen objects
381 .. attribute:: colorIdx
382 index of color used to calculate normal (0 - red, 1 - green, 2 - blue)
387 .. attribute:: previous
388 previous pixel filter
390 .. class:: FilterRGB24()
392 Returns a new input filter object to be used with :class:`ImageBuff` object when the image passed
393 to the ImageBuff.load() function has the 3-bytes pixel format BGR.
395 .. class:: FilterRGBA32()
397 Source filter RGBA32 objects
399 .. function:: getLastError()
400 Last error that occurred in a bge.texture function.
402 :return: the description of the last error occurred in a bge.texture function.
405 .. function:: imageToArray(image,mode)
406 Returns a :class:`~bgl.buffer` corresponding to the current image stored in a texture source object.
408 :arg image: Image source object.
409 :type image: object of type :class:`VideoFFmpeg`, :class:`ImageFFmpeg`, :class:`ImageBuff`, :class:`ImageMix`, :class:`ImageRender`, :class:`ImageMirror` or :class:`ImageViewport`
410 :arg mode: optional argument representing the pixel format.
411 You can use the characters R, G, B for the 3 color channels, A for the alpha channel,
412 0 to force a fixed 0 color channel and 1 to force a fixed 255 color channel.
413 Example: "BGR" will return 3 bytes per pixel with the Blue, Green and Red channels in that order.
414 "RGB1" will return 4 bytes per pixel with the Red, Green, Blue channels in that order and the alpha channel forced to 255.
415 The default mode is "RGBA".
418 :rtype: :class:`~bgl.buffer`
419 :return: A object representing the image as one dimensional array of bytes of size (pixel_size*width*height),
420 line by line starting from the bottom of the image. The pixel size and format is determined by the mode
423 .. function materialID(object,name)
424 Returns a numeric value that can be used in :class:`Texture` to create a dynamic texture.
426 The value corresponds to an internal material number that uses the texture identified
427 by name. name is a string representing a texture name with IM prefix if you want to
428 identify the texture directly. This method works for basic tex face and for material,
429 provided the material has a texture channel using that particular texture in first
430 position of the texture stack. name can also have MA prefix if you want to identify
431 the texture by material. In that case the material must have a texture channel in first
434 If the object has no material that matches name, it generates a runtime error. Use try/except to catch the exception.
436 Ex: bge.texture.materialID(obj, 'IMvideo.png')
438 :arg object: the game object that uses the texture you want to make dynamic
439 :type object: game object
440 :arg name: name of the texture/material you want to make dynamic.
444 .. function setLogFile(filename)
445 Sets the name of a text file in which runtime error messages will be written, in addition to the printing
446 of the messages on the Python console. Only the runtime errors specific to the VideoTexture module
447 are written in that file, ordinary runtime time errors are not written.
449 :arg filename: name of error log file
450 :type filename: string