Horde3D

Next-Generation Graphics Engine
It is currently 16.11.2024, 21:15

All times are UTC + 1 hour




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: 01.04.2008, 19:59 
Offline

Joined: 01.04.2008, 18:54
Posts: 1
Location: Germany
Hello,
I'd like to implement support of ogg/theora video streams.
The possibility to render videos as animated textures would be really nice.

Of course it would be useful to create this as extension.

But I've got 2 problems with realizing this:
- How to load the decoded Framedata (converted from YUV to RGB-data) into Horde3D
- How to realize this as Extension (Do I need to define a new SceneNodeType?)

I hope somebody can help me.



PS: Is this the right forum?


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: 02.04.2008, 09:33 
Offline
Tool Developer

Joined: 13.11.2007, 11:07
Posts: 1150
Location: Germany
You can use the Horde3DUtils::createTGAImage and Horde3D::updateResourceData methods for that. We have done something similar here at our lab using DirectShow.

You first create a Texture Resource with the dimensions of your video source

Following code is untested:
Code:
char* img = 0;
unsigned int imgsize = 0;
unsigned char* tgaImgData = new unsigned char[videoBufferSize];
Horde3DUtils::createTGAImage(tgaImgData, width, height, depth, &img, &imgsize);
delete[] tgaImgData;
textureID = Horde3D::addResource(ResourceTypes::Texture2D, textureName, ResourceFlags::NoCompression);
Horde3D::loadResource(textureID, (char*) img, imgsize))
Horde3DUtils::freeMem(&img);   


Later you will update the texture data using updateResourceData
Code:
Horde3D::updateResourceData(textureID, ResourceData::Tex2DPixelData, imgData, size);


Since the texture data is not really a scene node I'm not sure if it would make sense to realize something like that as a SceneNode extension


Top
 Profile  
Reply with quote  
PostPosted: 17.07.2008, 14:41 
Offline

Joined: 03.07.2008, 01:23
Posts: 50
See also this thread: viewtopic.php?f=7&t=399


Top
 Profile  
Reply with quote  
PostPosted: 20.07.2008, 19:16 
Offline

Joined: 05.07.2008, 21:12
Posts: 26
I also have the same problem :( I want to play a ogg/theora file and I have no idea on how to make Horde change the texture of a object...

What update resources do exactly? And how I "paste" the theora texture to a quad? Or whatever other object (for example if I wanted to make a TV in-game play the video)


Top
 Profile  
Reply with quote  
PostPosted: 20.07.2008, 19:32 
Offline
Tool Developer

Joined: 13.11.2007, 11:07
Posts: 1150
Location: Germany
It updates the data of the resource :-)

What exactly is the problem? Did you tried the example code above?


Top
 Profile  
Reply with quote  
PostPosted: 20.07.2008, 19:34 
Offline

Joined: 05.07.2008, 21:12
Posts: 26
As I said, I do not understood even what I do with above example, how I render the texture that is attached to root? (that is the impression that the example gives me), and update data is needed every frame to update the texture of a video?


Top
 Profile  
Reply with quote  
PostPosted: 20.07.2008, 19:39 
Offline
Tool Developer

Joined: 13.11.2007, 11:07
Posts: 1150
Location: Germany
The texture can be used by any material. So an easy setup may be taking a snapshot of the video and use it in your model as a normal texture. You can then later search for this texture resource and update it with the updateResourceData method. This way you are ensuring that the texture exists and is already loaded. The little bit more complicated way is to add the material resource using the texture dynamically and add the texture resource dynamically as well, like in the example above.

To set a new frame you have to update it in every frame, since you have to copy the updated image from the source to the graphics card.


Top
 Profile  
Reply with quote  
PostPosted: 20.07.2008, 19:47 
Offline

Joined: 05.07.2008, 21:12
Posts: 26
But that is quite stupid... I mean, some decoders can already decode directly on the video card, and if you are for example rendering to texture, you are rendering already on the video card, updating it every frame means doing a unecessary blit...

Also, I do not understood the code of the example :( Can you make a commented version that explains what exactly it is doing? (reading the docs does not helped either, and I am examining them since several weeks ago since I wanted to load objects dynamically, since I do not want to do 729 .XML files...)


Top
 Profile  
Reply with quote  
PostPosted: 20.07.2008, 20:08 
Offline
Tool Developer

Joined: 13.11.2007, 11:07
Posts: 1150
Location: Germany
Well if the decoder is creating an OpenGL texture resource you can think about creating an extension within the engine that extends Texture2DResource or something like that, but that would probably depend on the decoder code.

The code above is quit straight forward:
Code:
// We need a pointer for the tga image
char* img = 0;
// And a variable for the tga image block size
unsigned int imgsize = 0;
// we create some dummy data for the tga image based on the video buffer configuration
unsigned char* tgaImgData = new unsigned char[videoBufferSize];
// Now we create a tga image for the video image that can be loaded by the engine
Horde3DUtils::createTGAImage(tgaImgData, width, height, depth, &img, &imgsize);
// since we created the buffer only as a dummy we don't need it any longer, the dummy TGA image is now
// stored in the 'img' pointer
delete[] tgaImgData;
// Now add the texture resource within the engine
textureID = Horde3D::addResource(ResourceTypes::Texture2D, textureName, ResourceFlags::NoCompression);
// Load the resource based on the dummy TGA image
Horde3D::loadResource(textureID, (char*) img, imgsize))
// Free the allocated memory for the TGA image, since we don't use it any longer
Horde3DUtils::freeMem(&img);   


After the texture resource was created within the engine we can update it using updateTextureResource as mentioned before.

Quote:
I wanted to load objects dynamically, since I do not want to do 729 .XML files

If you don't use 729 different videos you don't have to create 729 XML files.
And you can always check the source code, too, if you don't understand some of my proposals immediately.


Top
 Profile  
Reply with quote  
PostPosted: 20.07.2008, 20:19 
Offline

Joined: 05.07.2008, 21:12
Posts: 26
Thank you Volker!

In fact now your code is exactly what I tought, it loads the texture, but how I render it?

And about the 729: That are the possible combinations of asteroids using the avaible assets (9 models, 9 difuse texture and 9 bump textures), I wonder how I load just those 9+9+9 assets, and when adding a asteroid to the scene I could select between them all (ie: the routine would be: add one of the random 9 models, with default material, then change the textures of that material as needed... but how I do that?)

As you see, I think that in both cases the problem is the same, the engine supports dynamically creating or loading textures, but what I do with them?


Top
 Profile  
Reply with quote  
PostPosted: 20.07.2008, 20:37 
Offline
Tool Developer

Joined: 13.11.2007, 11:07
Posts: 1150
Location: Germany
Textures are referenced by materials. So in your example you are creating nine materials that referencing nine different textures. One material would then reference the bump and the diffuse texture just like e.g. the stones.material.xml in the examples.
You can also create the XML code on the fly and don't have to create files for that. Just provide the dynamically created string to the loadResource method.
So you are loading your nine different models and then can set the material of each mesh using
setNodeParami(MeshNodeParams::MaterialRes, matResHandle); see also this thread.

You can also add only one material and clone it later. But unfortunately setting the texture units to different texture resources is currently not yet implemented. But that will be changed soon.


Top
 Profile  
Reply with quote  
PostPosted: 20.07.2008, 20:58 
Offline

Joined: 05.07.2008, 21:12
Posts: 26
Indeed, that is what I wanted to know :( No way to change the texture of a material :(


Top
 Profile  
Reply with quote  
PostPosted: 20.07.2008, 21:19 
Offline
Tool Developer

Joined: 13.11.2007, 11:07
Posts: 1150
Location: Germany
You can reload the material data already, it's just not that convenient than using setResourceParami (not yet implemented). But it is possible! The only difference is that you have to create a dynamic XML string on the fly.


Top
 Profile  
Reply with quote  
PostPosted: 20.07.2008, 21:44 
Offline

Joined: 05.07.2008, 21:12
Posts: 26
So, I suppose that then to attach the OGG texture to a object, I would to the same? (ie: generate a XML and change the material)


Top
 Profile  
Reply with quote  
PostPosted: 20.07.2008, 21:52 
Offline
Tool Developer

Joined: 13.11.2007, 11:07
Posts: 1150
Location: Germany
You don't attach a texture to an object. You attach it to a material that is used by an object.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group