0
$\begingroup$

I got this script from a tutorial: http://www.tutorialsforblender3d.com/Game_Engine/VideoTexture/VideoTexture_Render_1.html

It allows to set a video texture In the game that's is a render of a camera in real time. For making security cameras monitors for example. The only thing I need is to add a command line to scale down the resolution and it will be good to go. Can Someone Help? See the File.

Script:

import bge

# get current scene
scene = GameLogic.getCurrentScene()

# get the current controller
controller = GameLogic.getCurrentController()

# get object script is attached to
obj = controller.owner

# check to see RenderToTexture has been added
if obj.has_key("RenderToTexture") == True:

    # update the texture
    obj["RenderToTexture"].refresh(True)

    # if RenderToTexture hasn't been added 
else:

    # import VideoTexture module
    import VideoTexture

    # get a list of objects in the scene
    objList = scene.objects

    # get camera name being used for render to texture
    camName = obj['cam']

    # get camera object
    cam = objList["OB" + camName]

    # get the texture material ID
    matID = VideoTexture.materialID(obj, "MA" + obj['material'])

    # set the texture
    renderToTexture = VideoTexture.Texture(obj, matID)

    # get the texture image
    renderToTexture.source = VideoTexture.ImageRender(scene,cam)

    # save RenderToTexture as an object variable
    obj["RenderToTexture"] = renderToTexture
$\endgroup$
  • $\begingroup$ oh my! the script box got messed. $\endgroup$ – Hicky8 Jun 11 '17 at 2:14
  • 1
    $\begingroup$ Add four spaces to the start of each line to get a clean script box. $\endgroup$ – sambler Jun 11 '17 at 9:03
  • $\begingroup$ Looks like it works right to me - if I change the viewport shading to texture or material. $\endgroup$ – sambler Jun 11 '17 at 9:10
  • $\begingroup$ that's not the thing. it works for me too. but I whant to make the video Texture in a lower resolution $\endgroup$ – Hicky8 Jun 11 '17 at 15:09
  • $\begingroup$ Lower resolution as in the size of the image shown on the monitors or to pixelate the image? Do you want the same size image on each monitor? $\endgroup$ – sambler Jun 12 '17 at 3:31
2
$\begingroup$

When setting up the image source specify a capsize.

e.g.:

source.capsize = [50, 50]

Based on your code:

BGE 2.50+

setup

import bge

controller = bge.logic.getCurrentController()
owner = controller.owner

cameraName = owner['cam']
materialName = owner['material']

scene = bge.logic.getCurrentScene()
camera = scene.cameras[cameraName]

materialId = bge.texture.materialID(owner, "MA" + materialName)

renderToTexture = bge.texture.Texture(owner, materialId)
owner["RenderToTexture"] = renderToTexture

source = bge.texture.ImageRender(scene, camera)
source.capsize = [50, 50]
renderToTexture.source = source

refresh

import bge

controller = bge.logic.getCurrentController()
controller.owner["RenderToTexture"].refresh(True)

enter image description here

BGE 2.49

setup

import GameLogic
import VideoTexture

controller = GameLogic.getCurrentController()
owner = controller.owner

cameraName = owner['cam']
materialName = owner['material']

scene = GameLogic.getCurrentScene()
camera = scene.cameras["OB" + cameraName]

materialId = VideoTexture.materialID(owner, "MA" + materialName)

renderToTexture = VideoTexture.Texture(owner, materialId)
owner["RenderToTexture"] = renderToTexture

source = VideoTexture.ImageRender(scene, camera)
source.capsize = [50, 50]
renderToTexture.source = source

refresh

import GameLogic

controller = GameLogic.getCurrentController()
controller.owner["RenderToTexture"].refresh(True)
$\endgroup$
  • $\begingroup$ aw.. I just copied your code and it doesn't work. I'm using Blender 2.78b $\endgroup$ – Hicky8 Jun 12 '17 at 18:39
  • 1
    $\begingroup$ The above samples are adoptions of the code you posted with your question. Unfortunately it is not the code you use in your sample blend file. E.g. you use different property names. Please adjust either the code or your setup. Ensure you run "setup" (once) before running "refresh" (each frame). $\endgroup$ – Monster Jun 13 '17 at 3:39
  • $\begingroup$ Thank you! Now I can make a very cheap "filter" Bloom VFX! $\endgroup$ – Hicky8 Jun 13 '17 at 4:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.