Page 1 of 1

Setting ImageSource to Runtime generated RGBA Information

Posted: 26 Jul 2018, 20:20
by DigitalKarnage
I'm currently trying to render images which are generated at runtime. I have tried drawing this image over the Noesis application window, this fails cause i'm unable to restore the state of the OpenGL context to a state in which it works previous to instantiation of the GLRenderDevice provided by the Application Framework. So instead (for integration purposes) like to just set the source information based on the pixel data I have obtained from the generator.

Is there anyway to do this. I'm not looking for restoring states, i'm looking for being able to set the pixel information for ImageSource

Re: [C++] Setting ImageSource to Runtime generated RGBA Information

Posted: 26 Jul 2018, 23:15
by jsantos
The most efficient way to do this is creating a Texture with that RGBA pixel information and then passing that texture to a TextureSource.

Re: [C++] Setting ImageSource to Runtime generated RGBA Information

Posted: 27 Jul 2018, 01:25
by DigitalKarnage
Awesome works well.
GLuint TextureID = 0;

glGenTextures(1, &TextureID);
glBindTexture(GL_TEXTURE_2D, TextureID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glGenerateMipmap(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, 0);

Ptr<GLRenderDevice> GraphicsDevice = MakePtr<GLRenderDevice>();
Image* ImageElement= _WindowView->GetContent()->FindName<Image>("Image_src"); // _WindowContent is the IView* Xaml object associated with the drawing 

const auto& Height = ImageElement->GetRenderSize().height;
const auto& Width = ImageElement->GetRenderSize().width;

Ptr<Texture> NsTexture = GraphicsDevice->WrapTexture(TextureID, Width, Height , 0, TextureFormat::BGRA8, false);
Ptr<TextureSource> NsTextureSource = MakePtr<TextureSource>(NsTexture);
ImageElement->SetSource(NsTextureSource);


Re: [C++] Setting ImageSource to Runtime generated RGBA Information

Posted: 27 Jul 2018, 13:28
by jsantos
Thanks for the feedback!

Re: [C++] Setting ImageSource to Runtime generated RGBA Information

Posted: 02 Jul 2019, 11:41
by ducdanganhit
Awesome works well.
GLuint TextureID = 0;

glGenTextures(1, &TextureID);
glBindTexture(GL_TEXTURE_2D, TextureID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glGenerateMipmap(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, 0);

Ptr<GLRenderDevice> GraphicsDevice = MakePtr<GLRenderDevice>();
Image* ImageElement= _WindowView->GetContent()->FindName<Image>("Image_src"); // _WindowContent is the IView* Xaml object associated with the drawing 

const auto& Height = ImageElement->GetRenderSize().height;
const auto& Width = ImageElement->GetRenderSize().width;

Ptr<Texture> NsTexture = GraphicsDevice->WrapTexture(TextureID, Width, Height , 0, TextureFormat::BGRA8, false);
Ptr<TextureSource> NsTextureSource = MakePtr<TextureSource>(NsTexture);
ImageElement->SetSource(NsTextureSource);

Hello,
Where is the image source to show?
If I want to read an image from local, how to set it to be rendered?
Thanks in advanced!