Daki
Posts: 57
Joined: 16 Aug 2013, 00:48

Re: How to change Image source at runtime?

07 Sep 2013, 17:09

I would also like to chime in that this is very high priority for me. My game is centered entirely around user generated content and part of that is user-made images that I render in various parts of the UI. It is a requirement of my game that the user can just drop a loose image in a folder and I will find it and display it (I can't have this go through the build tool).

I am using Ogre and before I was handling this by loading the image into memory and generating an Ogre::Texture from it. My previous UI system had support for rendering Ogre::Textures.
 
User avatar
jsantos
Site Admin
Posts: 3906
Joined: 20 Jan 2012, 17:18
Contact:

Re: How to change Image source at runtime?

09 Sep 2013, 14:38

We have a ticket to implement this in Unity but in C++ it can already be done. Although I would like to test it before if you can try these are the steps:

1. Create a texture using the rendersystem
Ptr<ImageSet> imageSet = *new ImageSet(ImageSetLayout_2D, 1);
imageSet->SetImage(image.GetPtr());
texture = NsGetSystem<IRenderSystem>()->CreateTexture2D(imageSet.GetPtr());
2. Create an UI Image and set its source from the created texture using a TextureSource
Ptr<Image> image = *new Image();
Ptr<ImageSource> source = *new TextureSource(texture, w, h);
image->SetSource(source);
 
Daki
Posts: 57
Joined: 16 Aug 2013, 00:48

Re: How to change Image source at runtime?

10 Sep 2013, 05:42

It looks like IDX9RenderSystem does not have a CreateTexture2D method so I am not sure how to get an appropriate Texture2D object for this system (i.e. one that isn't the pure virtual ITexture2D). I am actually not even sure what the class of the render system is since that interface is pure virtual and I don't see anything which implements it.

I cannot use ITexture2D because I need smart pointers to these objects as function parameters and member variables and there is an inlined file ptr.inl which attempts to call functions on its templated base type, which if is ITexture2D will not compile.
 
User avatar
jsantos
Site Admin
Posts: 3906
Joined: 20 Jan 2012, 17:18
Contact:

Re: How to change Image source at runtime?

11 Sep 2013, 01:49

An example, creating a texture filled in red
#include <NsRender/IRenderSystem.h>
#include <NsDrawing/Image.h>
#include <NsDrawing/ImageSet.h>
#include <NsDrawing/Color.h>

using namespace Noesis;
using namespace Noesis::Core;
using namespace Noesis::Drawing;
using namespace Noesis::Render;

Ptr<ITexture2D> CreateTexture()
{
    Ptr<Image> image = *new Image(ImageFormat_A8R8G8B8, 32, 32);
    image->Fill(Color::Red);

    Ptr<ImageSet> mipMaps = GenerateMipmapChain(image.GetPtr());

    return NsGetSystem<IRenderSystem>()->CreateTexture2D(mipMaps.GetPtr());
}
Instead of filling in red like the example, you will have to set properly the content using the interface provided by the image class.
 
Daki
Posts: 57
Joined: 16 Aug 2013, 00:48

Re: How to change Image source at runtime?

11 Sep 2013, 03:12

My issue is with being able to pass around Ptr<ITexture2D> objects. The code you provided compiles when I try to use that logic in a member function it will not. Here is an example:

Test.h
#pragma once

#include <NsRender/IRenderSystem.h>

class Test
{
public:
	static Noesis::Core::Ptr<Noesis::Render::ITexture2D> createTexture();
};
Test.cpp
#include "stdafx.h"
#include "Test.h"

#include <NsCore/NsSystem.h>
#include <NsDrawing/Image.h>
#include <NsDrawing/ImageSet.h>
#include <NsDrawing/Color.h>

using namespace Noesis;
using namespace Noesis::Core;
using namespace Noesis::Drawing;
using namespace Noesis::Render;

Ptr<ITexture2D> Test::createTexture()
{
	Ptr<Image> image = *new Image(ImageFormat_A8R8G8B8, 32, 32);
    image->Fill(Color::Red);

    Ptr<ImageSet> mipMaps = GenerateMipmapChain(image.GetPtr());

    return NsGetSystem<IRenderSystem>()->CreateTexture2D(mipMaps.GetPtr());
}
The errors are:

ptr.inl, line121, use of undefined type 'Noesis::Render::ITexture2D'
ptr.inl, line121, left of '->Release' must point to class/struct/union/generic type
 
User avatar
jsantos
Site Admin
Posts: 3906
Joined: 20 Jan 2012, 17:18
Contact:

Re: How to change Image source at runtime?

11 Sep 2013, 03:18

ptr.inl, line121, use of undefined type 'Noesis::Render::ITexture2D'
ptr.inl, line121, left of '->Release' must point to class/struct/union/generic type
at least the following headers are missing in my sample:
#include <NsCore/Ptr.h>
#include <NsRender/ITexture2D.h>
 
Daki
Posts: 57
Joined: 16 Aug 2013, 00:48

Re: How to change Image source at runtime?

12 Sep 2013, 02:32

:oops:

Whoops! Thanks for pointing that out. Sorry for the delayed response but everything is working now. :)
 
eniac
Posts: 2
Joined: 11 Sep 2013, 08:52

Re: How to change Image source at runtime?

12 Sep 2013, 08:41

I am also interested in uploading images at runtime to replace UI brushes!

If I am following this conversation correctly..

for my example, imagine a save game menu that takes a screenshot at your location and then the screenshot is used as the brush/background in a list of buttons in the load/save game menu. I would want to update the UI thumbnails on the fly

I also want the image of each button to animate with it's parent/the rest of the UI when I activate/deactivate the container menu.

for my application I am looking at using ogre + noesis gui + GL - will noesis work with GL texture resources (allowing me to control the content)? If not do you have any suggestions on how to approach this?

Best,

Marc
 
eniac
Posts: 2
Joined: 11 Sep 2013, 08:52

Re: How to change Image source at runtime?

12 Sep 2013, 08:43

after re reading the previous posts, I think I have my answer :)
 
User avatar
jsantos
Site Admin
Posts: 3906
Joined: 20 Jan 2012, 17:18
Contact:

Re: How to change Image source at runtime?

13 Sep 2013, 04:05

Hi eniac, welcome.

For now, the texture that must be passed to the GUI must be created by filling a Image class (as the code shown above). But we are going to add (because Unity needs it) the possibility to use your own created DX and GL textures.

Who is online

Users browsing this forum: Google [Bot] and 56 guests