Game Development Community

problem on modifying GuiTSCtrl->onRender()

by lys · in Torque 3D Professional · 02/25/2013 (7:47 pm) · 3 replies

Hi, guys,

I modify the GuiTSCtrol->onRender() function in Torque 3D V2.0 source code. I want to load an image from file and display the image in front of the game play screen. The code I add is as follows:

IDirect3DSurface9 * backBuffer;
IDirect3DSurface9 * offSurface;

D3DDevice->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &backBuffer );

//load image from file to to offsurface
D3DXIMAGE_INFO Info;
D3DXGetImageInfoFromFile(L"C:abc.jpg", &Info);
D3DDevice -> CreateOffscreenPlainSurface(Info.Width, Info.Height, Info.Format, D3DPOOL_SYSTEMMEM, &offSurface, NULL);
D3DXLoadSurfaceFromFile(offSurface, NULL, NULL, L"C:abc.jpg", NULL, D3DX_FILTER_NONE, 0, NULL);

D3DDevice -> UpdateSurface(offSurface, NULL, backBuffer, NULL);

The image can be displayed correctly. But if I resize the window of press F11 to load the world editor, it crashes with error "Failed to create D3D Device ". I don't what's the problem...

#1
02/25/2013 (11:56 pm)
Why would you do this? Just create a gui and push it to the canvas in front of your GuiTSCtrl....

Look at the sample projects. See how they do things. They do things the way they do for a reason.

Most people have trouble using Torque because they have an idea of how "it should be done" based on prior experience. Instead of deciding how you are going to do it and then trying to force the engine to do it that way one should look at how the engine does what you think you want to do and then follow that path. Water flows in the channels that are present and only very slowly creates its own paths - this is how one should approach learning Torque. Go with the flow before you start making your own paths.
#2
02/26/2013 (12:00 am)
Would adding a GuiBitmapCtrl on top of the GuiTSCtrl not work in your case? If you look in playGui.gui you'll see it creates a GuiTSCtrl (which is what renders the world) and then adds several other controls as children. One of the first child controls happens to be a GuiBitmapCtrl named 'CenterPrintDlg', which simply draws the 'hudfill.png' image onto the screen.

Edit: Too slow at 3 a.m. :]
#3
02/26/2013 (12:20 am)
thanks Richard and Chris for your suggestions and answers.
To-> Richard, thanks very for your suggestion. I think i need to go step by step:).

To->Chris, i think your method will work and i will try later:)