OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

Get RGB Values from Texture


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
dieslower81
User


Joined: 15 Feb 2010
Posts: 38

PostPosted: Tue Nov 07, 2017 3:56 pm    Post subject:
Get RGB Values from Texture
Reply with quote

Hi,

I have a osg::Texture2D that I'm using as a render to texture target.
I can see that it is working on the screen, but I need to have access to the RGB values of the texture itself so I can also copy them to another API.

How can I access the RGB values?

After rendering a frame, if I access _image in the texture2D class, it is null, but I do see that the Texture of texture2D has an array size of 1.
How and where are the RGB values stored?

Or do I need to get the RGB values not from the texture but from another object that is used in the camera to texture pipeline?

Thank you!

Maxim

_________________
Thank you,
--Maxim
Back to top
View user's profile Send private message
tang
Newbie


Joined: 02 Nov 2017
Posts: 4

PostPosted: Wed Nov 08, 2017 10:24 am    Post subject:
Re: Get RGB Values from Texture
Reply with quote

dieslower81 wrote:
Hi,

I have a osg::Texture2D that I'm using as a render to texture target.
I can see that it is working on the screen, but I need to have access to the RGB values of the texture itself so I can also copy them to another API.

How can I access the RGB values?

After rendering a frame, if I access _image in the texture2D class, it is null, but I do see that the Texture of texture2D has an array size of 1.
How and where are the RGB values stored?

Or do I need to get the RGB values not from the texture but from another object that is used in the camera to texture pipeline?

Thank you!

Maxim


Hi~!
I met this problem before(can't read RGB from texture when using render to texture.),i don't know why Until now. But i can offer you another way . It's render to image.
Code like that:
camera->setRenderOrder(osg::Camera::PRE_RENDER);
osg::Image* image = new osg::Image;
image->allocateImage(new_s, new_t, 1, GL_RGBA, GL_UNSIGNED_BYTE);
camera->attach(osg::Camera::COLOR_BUFFER, image,0, 0);
camera->setFinalDrawCallback(new MyCameraPostDrawCallback());
Then you can write RGB into picture.If you still can't understand my meaning.You can read this file that i upload or osg Examples(osgprerender).
Forgiving me for my english. I am chinese. This is my first reply.Hoping to help you.
Good Luck.
Back to top
View user's profile Send private message
tang
Newbie


Joined: 02 Nov 2017
Posts: 4

PostPosted: Fri Nov 10, 2017 6:33 am    Post subject:
Reply with quote

Hi,

I met this problem before(can't read RGB from texture when using render to texture.),i don't know why Until now. But i can offer you another way . It's render to image.
Code like that:
camera->setRenderOrder(osg::Camera::PRE_RENDER);
osg::Image* image = new osg::Image;
image->allocateImage(new_s, new_t, 1, GL_RGBA, GL_UNSIGNED_BYTE);
camera->attach(osg::Camera::COLOR_BUFFER, image,0, 0);
camera->setFinalDrawCallback(new MyCameraPostDrawCallback());
Then you can write RGB into picture.If you still can't understand my meaning.You can read this file that i upload or osg Examples(osgprerender).
Forgiving me for my english. I am chinese and i can't use this Forum expertly . This is my first reply.Hoping to help you.
Good Luck.

Cheers,
Tang
Back to top
View user's profile Send private message
SMesserschmidt (Sebastian Messerschmidt)
Forum Moderator


Joined: 10 Sep 2013
Posts: 822

PostPosted: Mon Nov 13, 2017 9:28 am    Post subject:
Get RGB Values from Textrue
Reply with quote

Hi Maxim,

Quote:
Hi,

I have a osg::Texture2D that I'm using as a render to texture target.
I can see that it is working on the screen, but I need to have access to the RGB values of the texture itself so I can also copy them to another API.

How can I access the RGB values?

set a postDrawCallback to the pass/camera that writes to the texture.


In the callback:

virtual void operator () (osg::RenderInfo& render_info) const
{
osg::State* state=render_info.getState();
state->apply(render_info.getCurrentCamera()->getStateSet());
state->applyTextureAttribute(0, mTexture);
mTexture->apply(*state);
mImage->readImageFromCurrentTexture(render_info.getContextID(),true,
GL_FLOAT ); //change the GL_FLOAT to your needs
}

the mTexture is passed to the callback using the original texture
attached to the MRT.

Cheers
Sebastian




Quote:

After rendering a frame, if I access _image in the texture2D class, it is null, but I do see that the Texture of texture2D has an array size of 1.
How and where are the RGB values stored?

Thank you!

Maxim

------------------------
Thank you,
--Maxim

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=72322#72322









------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
dieslower81
User


Joined: 15 Feb 2010
Posts: 38

PostPosted: Wed Nov 15, 2017 3:52 pm    Post subject:
Reply with quote

Thanks that helped me out a lot, but now I have an additional question:

How is the RGB actually stored in the image?

From my Image I can now get the Raw Data, but what does it represent and how is it stored?

Image->data(x,y,0)? what does it return? How do I get the individual R, G and B values?

Thank you!
--Maxim

_________________
Thank you,
--Maxim
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12027

PostPosted: Wed Nov 15, 2017 4:33 pm    Post subject:
Get RGB Values from Texture
Reply with quote

HI Maximum,

The pixel format and data type of the data stored in osg::Image map to
the same set supported by OpenGL, and uses exactly the same GL enums
so you can read up on OpenGL docs and they 1:1 map to the OSG.

As the pixel format and data type can be a wide range you have to
check the type and then cast to the appropriate type and then access
the data.

Robert.

On 15 November 2017 at 15:52, Maxim Stere <> wrote:
Quote:
Thanks that helped me out a lot, but now I have an additional question:

How is the RGB actually stored in the image?

From my Image I can now get the Raw Data, but what does it represent and how is it stored?

Image->data(x,y,0)? what does it return? How do I get the individual R, G and B values?

Thank you!
--Maxim

------------------------
Thank you,
--Maxim

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=72389#72389








------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
dieslower81
User


Joined: 15 Feb 2010
Posts: 38

PostPosted: Wed Nov 15, 2017 8:13 pm    Post subject:
Reply with quote

Hi Robert,

My Image is in GL_RGBA format stored as GL_UNSIGNED_BYTE

Given that information, is there a way to decompose the Unsigned Byte I get from Image->data(x,y,0) to R, G, B and A?

V/R,
--Maxim

_________________
Thank you,
--Maxim
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts Can't share Texture among several tex... mp3butcher General 1 Fri Aug 17, 2018 11:06 pm View latest post
No new posts minor change: move assumeSizedInterna... mp3butcher General 9 Wed Aug 15, 2018 10:07 pm View latest post
No new posts Minor change proposal : Blacklist usa... mp3butcher General 14 Mon Aug 13, 2018 1:42 pm View latest post
No new posts Load an obj file and mapping a given ... aaa3d General 3 Mon Aug 06, 2018 2:27 pm View latest post
No new posts how to interpret values shown by stat... wernerM General 2 Tue Jul 17, 2018 9:43 am View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP