Game Development Community

Rendering to a bitmap image.

by Kevin Yancey · in Torque Game Builder · 06/09/2007 (9:58 am) · 5 replies

I am working on a puzzle game and I was wondering if there is a way to render a scenegraph to an image instead of the screen? I want to create preview images of each level at runtime and display them in my level selection screen.

#1
06/11/2007 (7:55 am)
Hmm, interesting. Could you not just take a screenshot of each level and use that as a static sprite in game?
#2
06/11/2007 (8:55 am)
If the user's gfx card supports it you can add C++ code to render to texture by changing render target.
#3
06/11/2007 (10:45 am)
Kevin,

The short answer is no. Its a puzzle game that allows the player to build their own puzzles in addition to playing the built-in ones. Thus, the images have to be rendered at runtime.

Neo,

I've looked into the code some, and it seems that the SceneGraphs is dependent on the t2dSceneWindow to provide it a rendering surface. This would make it difficult to take that approach, but I'm still looking into it. If anyone has more knowledge they can share about this, it would be much appreciated. It seems to me that a feature like this would come in handy in a number of scenarios.
#4
06/11/2007 (12:12 pm)
[edit] Sheesh I missed half the stuff in here

As for the render target stuff yes it needs a bit of work but quite doable I assure you.
I might have spouted off too soon in that direction as I didn't read the last line of of your post it seems, i.e. you are looking for ways to capture your level, not dynamically rendering to a texture, etc.

You can use glReadPixels to read back a section of the screen (the current implementation has a bug - it won't work in D3D, but this has been fixed for the next beta release).

So when you need to you can capture the part the screen to a buffer and then scale that buffer as you see fit etc and save it to file etc. Otherwise you can just use the screenShot() console function and load the image from file.
#5
06/12/2007 (9:06 am)
The screenshot option seems to be the easiest, if not the most efficient. Though since you plan to do it at run time then the added time of loading won't be as big of a deal. You may also want to look at DynamicTexture in the engine.