Technology Demo

Render To Texture Demo

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Spot for images


This project will show you how to render a view to a texture that can then be applied to entities. It is useful for creating reflections.

Set Up

To complete this project, we need to create a cube and a second camera. We also need to set up a folder to hold an image that we will use as the background of our scene, which will also be projected onto our cube.

Create a new Textures folder in the project by right clicking on the project title and selecting New > Folder. Right click on the new Textures folder and select Import Resources > Files, and select your image. We also need to import the TexturePanel.lua file to our

self.bkPanel = com.darkwindmedia.core.TexturePanel()
self.bkPanel.texture = luster.resources.Texture("Textures/bkgd.jpg")
self.bkPanel.renderQueueGroup = 49 -- Set the panel to be drawn first

The above code creates a background panel and sets its texture to our image and then tells the panel that it's the first thing to be drawn in the scene.

Setting up the Renderer

Now we need to set up the camera that will be rendering the image onto the cube. First, we need to create another camera - however, you can use the default camera as well. A second camera can be positioned differently from the first to make sure you get the texture to look exactly as you want it.

self.camera2 = luster.display.Camera()
self.camera2.position = luster.Vector3(3,3,4)

Now that our second camera is added, we can set up the renderer.

self.renderer = luster.display.RenderTexture("test",1024,1024)

Here, we create a renderer that takes the arguments "test", 1024 and 1024. The first argument is a name for the renderer, and the next two are the width and height of the texture. Then, we add a viewport that takes the camera as an argument.

Applying it in a Material

When creating a material for our cube, we use the same directions as in the Flash demo. When we set the texture unit, we make a slight change this


to this


After inputting the mouse controls to enable us to roll our box around as also seen in the Flash demo, we can run our program. We should be able to see the background image applied to the cube.