Game Development Community

Release 1.4 DynamicTexture help

by Bill Vee · in Torque Game Engine · 11/26/2005 (10:01 am) · 23 replies

Ok first off I am not an expert programmer or I could fiqure this out but this is the first function I simply can't figure out how to impliment.

What I am trying to do is take the fxGuiSnooper resource and the fxRenderObject resource and by using the DynamicTexture bind the fxGuiSnooper texture to the fxRenderObject texture.

This is what I thought would work

void fxGuiSnooper::renderWorld(const RectI & updateRect)
{
[b]	DynamicTexture *textfx1 = new DynamicTexture( updateRect); [/b]

[b]textfx1->setUpdateRect(updateRect); [/b]
[b]textfx1->storePixels(); [/b]
	// Set-up OpenGL for a scene render.
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);
	glClear(GL_DEPTH_BUFFER_BIT);
	glDisable(GL_CULL_FACE);
	glMatrixMode(GL_MODELVIEW);
	dglSetCanonicalState();

	// Render Client Scene Graph.
	gClientSceneGraph->renderScene();

	// Disable Depth Test.
	glDisable(GL_DEPTH_TEST);
[b]textfx1->restorePixels(); [/b]
[b]textfx1->update(); [/b]
[b]fxRenderObject* fxRenderOb = static_cast<fxRenderObject*>(mAttachedObject); [/b]
[b]TextureHandle tex1;// = fxRenderOb->mTextureHandle; [/b]
[b]tex1  = fxRenderOb->mTextureHandle; [/b]
[b]fxRenderOb->mTextureHandle = tex1; [/b]
}

While it compiles fine it won't map the texture to the fxRenderObject.
Page «Previous 1 2
#1
11/29/2005 (11:38 am)
Ok it should be obvious from my code above that I m clueless on the use of DynamicTextures.

A simple working example code is all I ask.

What I simple want to do is render a GUI to a fxRenderObject.

I have search GG and while there is a link titled Forum Thread : 1.4's DynamicTexture and GUIs i cant get to it because GG says "You do not have access to this forum thread".
I have purchased a Torque Game Engine SDK "Indie" License over a year ago so I don't know why I can't access this thread.

And there is no other info on the forums that I can find on how to use DynamicTextures.
#2
11/30/2005 (5:46 am)
I've had a license for a couple of months and I can't get to that thread either (just tested it). Yes, I am logged in.
#3
11/30/2005 (6:40 am)
The Thread you found there is a Torque Shader Engine Thread
#4
11/30/2005 (9:50 am)
I thought that might be the case.
If it's not too much trouble if theres anything there that is relavent to TGE on how to use the DynamicTextures class in TGE could someone post it.
I am not asking for anything that is TSE related.
#5
11/30/2005 (11:50 am)
It's mostly TSE specific. No big code snippets that are useful on TGE.
#6
12/01/2005 (11:24 am)
So why are the GuiEffectCanvas and the DynamicTexture.cc files in TGE 1.4, if they don't work?
#7
12/01/2005 (11:38 am)
Thats what I want to know.
There is a resource for this in TGE from over a 2 years ago.
The DynamicTextures resource.

I assume its for TGE and not TSE only.

The only problem with the resource is, attleast for me, how you actualy implement the DynamicTextures.
#8
12/03/2005 (1:07 pm)
I know I only have a "Indie" License but come on a little guidance would be grateful.
I know TGE is near its life cycle and I am considering TSE.

I just got one question .
Is the DynamicTexture class functional or not for TGE?
#9
12/03/2005 (1:45 pm)
I wrote the GuiEffectCanvas and gDynamicTexture. They both work. I will do a TDN article after Marble Blast ships.
#10
12/03/2005 (1:48 pm)
Bill

I used the dynamic texture before to provide a T2D game surface inside a TGE game (rendering the T2D GUI to an in game surface).

I would suggest that you try to use an fxrenderobject and a dynamic texture for its texture to render the playgui GUI inside the demo (or in a game). This is fairly straightforward if just clientside and you can build from there. Also, Using the fxrenderobject will teach you a lot about TGE objects and code in general (with permanent thanks to Melv May for writing it)
#11
12/03/2005 (2:06 pm)
I have been using the fxrenderobject for some time and know how to use it very well.
What I don't know is how to use actualy use/code the dynamic texture class.

Your suggestion is exactly what I was trying to do,

By using fxGuiSnooper class as a means to render a camera screen render to a texture that is then used by the fxrenderobject.

I seem to be missing the one small insight on how to setup the dynamic texture class.

I can alter the fxrenderobject to use a dynamictexture but what I need to know is how to get the dynamictexture started.
#12
12/03/2005 (2:14 pm)
Hijack ...

Quote:
after Marble Blast ships.

When ... when!!!
#13
12/03/2005 (5:09 pm)
Bill,

You are aware that we offer the exact same level of support for ALL Torque users, regardless of license, unless they have an explicit support contract with us? There's no preferential treatmen here. We ignore everyone equally. ;)

void fxGuiSnooper::renderWorld(const RectI & updateRect)
{
   DynamicTexture *textfx1 = new DynamicTexture( updateRect); 

textfx1->setUpdateRect(updateRect); 
textfx1->storePixels(); 
   // Set-up OpenGL for a scene render.
   glEnable(GL_DEPTH_TEST);
   glDepthFunc(GL_LEQUAL);
   glClear(GL_DEPTH_BUFFER_BIT);
   glDisable(GL_CULL_FACE);
   glMatrixMode(GL_MODELVIEW);
   dglSetCanonicalState();

   // Render Client Scene Graph.
   gClientSceneGraph->renderScene();

   // Disable Depth Test.
   glDisable(GL_DEPTH_TEST);
textfx1->restorePixels(); 
textfx1->update(); 
fxRenderObject* fxRenderOb = static_cast<fxRenderObject*>(mAttachedObject); 
TextureHandle tex1;// = fxRenderOb->mTextureHandle; 
tex1  = fxRenderOb->mTextureHandle; 
fxRenderOb->mTextureHandle = tex1; 
}

There are all sorts of weird things here. For one, it's allocating a new DynamicTexture every frame. It's unclear that the code is following the documentation in the header file. The last several lines don't even do anything! Even if the DT was working properly, you'd not see any results.

This is what I would try, with a DynamicTexture allocated as a member.

void fxGuiSnooper::renderWorld(const RectI & updateRect)
{
   textfx1->setUpdateRect(updateRect); 
   textfx1->storePixels(); 

   // Set-up OpenGL for a scene render.
   glEnable(GL_DEPTH_TEST);
   glDepthFunc(GL_LEQUAL);
   glClear(GL_DEPTH_BUFFER_BIT);
   glDisable(GL_CULL_FACE);
   glMatrixMode(GL_MODELVIEW);
   dglSetCanonicalState();

   // Render Client Scene Graph.
   gClientSceneGraph->renderScene();

   // Disable Depth Test.
   glDisable(GL_DEPTH_TEST);

   textfx1->update(); 
   textfx1->restorePixels(); 

   fxRenderObject* obj= static_cast<fxRenderObject*>(mAttachedObject); 
   obj->mTextureHandle = textfx1->getTextureHandle(); 
}

This has a much higher chance of working, or at least doing something interesting.

I'd like to point out that I've NEVER used or even closely looked at this code before. I took a ten minute break from MBU work to write this, which I did by:

1. Reading over the header file documentation to understand the structure of the code. Pat did us a nice favor by including fairly verbose, clear documentation about how all this works.

2. For the functions on whose operation I was unclear, analyzing the implementation. An example - which function actually grabs the pixel data from the back buffer? update() seemed a likely candidate, and once I saw that there was some GL code that seemed to relate to reading pixels from a buffer, that made me more confident that was the case. And checking the code, nothing else seems to do that in that class.

3. Based on the documentation, my brief scan of the code in the class, and my existing knowledge of Torque's GUI system, and OpenGL, I made the guess you see above.

I'm sure that Pat's TDN docs are going to be very enlightening, but in their absence the docs in the header and some clear thinking are almost certain to get you where you need to be. :)
#14
12/03/2005 (8:35 pm)
I did read the header and your right it is very detailed.
On my first attempt I coded it exactly the way the header and your code suggested.

And the engine crashes on call DynamicTexture::setUpdateRect

void DynamicTexture::setUpdateRect( const RectI &newRect ) {
   
 // Check to see if this is being called as part of the contructor
   [b]if( mTextureHandle == NULL ) {[/b]
      GBitmap *bmp = new GBitmap( newRect.extent.x, newRect.extent.y, 0, GBitmap::BitmapFormat::RGBA );
      mTextureHandle = new TextureHandle( NULL, bmp, true );
   }
and my debugger says the call to if( mTextureHandle == NULL ) is causing an exception error

The original code I posted would attleast display the GUI just before it crashes.
Doing it the way the header sugested simple crashes before the GUI is rendered.
#15
12/03/2005 (8:43 pm)
What is the value of this? (the this pointer)

If you're not already running a debug build (ie, torqueDemo_DEBUG.exe), then you should be - it'll help catch many errors.
#16
12/03/2005 (9:48 pm)
See if this helps.
Debug

Let me state one thing.
I think that GG is one of the best concepts ever.
Allowing amateurs like myself to access such a quality piece of work is just great.
#17
12/03/2005 (10:52 pm)
It appears from the debug output that the value of the 'this' pointer is NULL or something close enough to it that it's crashing trying to use it.
#18
12/06/2005 (6:45 pm)
It is as I asked from the start.
The DynamicTexture is NULL or not declared somehow when it starts to render the object.
I have tried declaring the DynamicTexture in the Fxrenderobject class and/or fxGuiSnooper class and it crashes on render at DynamicTexture::setUpdateRect.
I have tried declaring the DynamicTexture in the Fxrenderobject.cc and/or fxGuiSnooper.cc and it crashes on render at DynamicTexture::setUpdateRect.

I know I am just overlooking something.
If someone can just show me how to setup the DynamicTexture to use in a Fxrenderobject I can do the rest.

I can't get the DynamicTexture to work in 1.4 or the DynamicTexture resource on a clean version of 1.2 or 1.3.

Someone has got to have gotten this to work by now.

Yes the resource and the 1.4 versions are well documented and I have coded it exactly the way it and Ben have suggested but no luck.
It always crashes on DynamicTexture::setUpdateRect with the you pointer at ? as if it was not defined correctly.
#19
12/24/2005 (9:01 am)
*bump

Patiently waiting on a TDN article on the proper use of the DynamicTexture class.

p.s I guess this won't be under my Christmas tree.
Thats alright I still believe in Santa.
#20
12/24/2005 (9:09 am)
Hmm, looks like you managed to post in such a way that I totally missed this thread... twice! :(

Anyway, if it's a pointer, make sure you're allocating a DynamicTexture for it! Also check to make sure, if it's not a pointer, that the object it's a part of is valid. This problem probably has nothing to do with the fact it's a DT and everything to do with general C++ programming correctness.
Page «Previous 1 2