draw to texture

hi everyone,

i want know how to draw in game to a texture. i want to use this rendered texture in the further process and to combine it with the (then) current rendered image (everything clear so far :S).

so far, the only way i found to draw to textures is to use the KX_PolygonMaterial.
here’s the link: http://www.blender.org/documentation/blender_python_api_2_57_release/bge.types.html

but i can’t even run the sample script.

thx for help

See videotexture module - it has code to render scene and apply rendered scene as texture

thx, but can you send me a link where i can find the functions etc like the blender api or is there a possibility to print the module in the console?

btw, i’m using blender 2.57 and theres no videotexture module listed.

as you mention KX_PolygonMaterial you probably work with c code of Blender.
so there in Blender 2.57b code

see

\source\gameengine\VideoTexture\ImageViewport.cpp

void ImageViewport::calcImage (unsigned int texId, double ts)

this function reads image from viewport

this file is included with ge_videotex module which is activated if during compile time ( in CMake config menu ) ffmpeg lib is selected to be used.

hi skurdakov,

thx for the quick response!
i can read and write c code but i dont know how to “run” the code in blender…so unfortunately i’m still stuck with python (maybe you can tell me how to do it or give me links, whatever)

but when i’m “in” python, can i just call the function calcImage after importing VideoTexture?

thank you very much again for your help,

lampadi

Try videotexture examples

say

http://wiki.blender.org/index.php/Dev:Source/GameEngine/2.49/VideoTexture

then taking key phrases to search in google.

I could recall that I applied rendered scene to texture, but cannot say where is my code is ( and also I heavily modified code for my testing purposes - so even if I find it would largely useless - the modifications were not production ready - just hacks to study blender ), so it is possible - but you have to dig with it yourself.

ok. i gonna have a look at this. thx.

where did you learn to use c code for blender?

just took code and started to experiment.
in case of videotexture python makes calls to c code - so it is possible to trace how the process goes inside, so placed breakpoints in videotexture code and launched python examples.

does that mean, that you build blender from scratch each time you changed some code in videotexture source?
somehow you have to tell blender that it should recompile the videotexture source, right?
how can i do that, change source code and compile the changed code so that blender is “up to date”?

thx a lot for your patience with my questions :slight_smile:

do i need to run those SConstruct etc scripts to build blender? …so, i build blender with those python scripts and then, each time i make changes to videotexture, i rebuild only this module by running the belonging python script?

if you work on windows - I would recommend using CMake it allows to work from inside visual studio - without need to make build outside ( on linux though too see http://wiki.blender.org/index.php/User:Ideasman42/CMakeQTCreatorLinux ) - and yes, if you change one file, only one file is recompiled.

if you chose windows then these links are for you

http://blog.sobbayi.com/2010/12/how-to-build-blender-2-5-with-ms-visual-c-2010-express/ or here
http://wiki.blender.org/index.php/User:Lusque/Windows/msvc ( see building with CMAKE part )
http://www.geneome.com/tutorials/blender-tutorials/building-blender-with-msvc-using-cmake/ ( except get Express 2010 http://www.microsoft.com/express/Downloads/Download-2010.aspx

and sdk here
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=35aeda01-421d-4ba5-b44b-543dc8c33a20 )

and
http://sourceforge.net/projects/sevenzip/ will allow extract iso.

one thing which migh be needed for vc2010 is to compile debug python or to install additionally http://www.microsoft.com/express/Downloads/#2008-Visual-CPP ( then you would be able to debug with stock python debug dll ) though maybe already Blender team provides vc2010 ready python debug dll ( did not check it - I have both 2008 and 2010 express editions here ).

@lampadi - If you’re using 2.57, the correct module isn’t VideoTexture, but bge.texture. That module is how you can render things to a texture, and it doesn’t require you to rebuild Blender to do this - the normal download from the Blender homepage will work fine.

thx you two!!
@skurdakov: i’m using windows and code::blocks…but building inside sounds good. i gonna try building blender today if it isn’t too time consuming…
@solarluna: thx for that. how did you find out…it isn’t listed in the api?

Well, I don’t recall how I found out, but if you use the import bge command, and then use print(dir(bge)), it will show you the submodules for Blender. bge.render = Rasterizer, bge.logic = GameLogic, bge.texture = VideoTexture, etc.

probably stupid question…but what is svn and cmake? i guess cmake makes makefiles out of the text files???

if you read blender.org it tells you the functions called in bge, as SolarLune mentions.

i tried to follow the tutorials to build blender with mingw and cmake but i get this error message: libgmp-10.dll is missing
any ideas?

I find that a useful way to find out the contents of a Python module in bge is to run a small script to print(dir(<module>)) to the console. Just put the script in a Python controller attached to any object and triggered by an “always” sensor. By default, “always” only fires once unless you toggle the “use positive pulse mode” button.

eg:


import bge

print(dir(bge))

print(dir(bge.texture))

print(dir(bge.texture.ImageRender))

print(bge.texture.ImageRender())

The printout for this last line is interesting, it asks for a scene object in pos1. If I specify the scene, it then asks for a camera object in pos2. Sounds promising. :wink:

It’s not ideal, but it’s the best way I’ve found to get my head around undocumented or poorly documented parts of the bge api. Hope it helps.

yeah, i use the same method…except for the last line;) clever, to force a error and then read out the attribute etc
thx a lot for that

Glad that I provided some inspiration. :slight_smile:

Another method that I occasionally resort to is actually reading the source code and finding stuff out that way. Blender’s source is immense :eek:, but a bit of digging has occasionally given me some good results, such as finding that features were unsupported during the beta phase, etc. Blender’s code has a reputation for having poor comments, but sometimes there are gems that can really shed light on things and I can at least understand what parameters functions require sometimes.

[edit]
One of the things that digging through the source brought to light is a unique type that is hard-coded into the textures or materials (it was a while ago…) that allows for the excellent display in the ui of all textures in a material in a nicely ordered list in which each element can be toggled (just look at the textures part of the ui and the Python ui files to see what I mean). I believe that CListTypes can be used to achieve something similar, but the custom data type appears to work so much better.
[/edit]

I know very little C/C++ though. You mentioned that you can read and write C so digging through the source will likely be more fruitful for you.

Best of luck. :wink: