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 

how to set raw image to texture in OSG


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General [forum]
View previous topic :: View next topic  
Author Message
Harshal
Newbie


Joined: 01 Jun 2015
Posts: 2

PostPosted: Tue Jun 02, 2015 5:21 am    Post subject:
how to set raw image to texture in OSG
Reply with quote

Hi,

I am trying to set an image on disk to my texture. Image dimension is 1800 by 1200 i.e. width = 1800 & height = 1200. But I am doing something wrong here due to which I am getting bad output. Can anyone help me here. This is my code -


std::ifstream imageToRead;
imageToRead.open("E:\\my code\\OpenSceneGraph-3.3.7\\OpenSceneGraph-Data-3.0.0\\Images\\1.jpg", std::ios::in | std::ios_base::binary);

imageToRead.seekg(0, std::ios::end);
int n = imageToRead.tellg();
imageToRead.seekg(0, std::ios::beg);

char* res = new char[n];

imageToRead.read(res, n);

imageToRead.clear();
imageToRead.close();

osg::Image* bufferImage = new osg::Image;
bufferImage->setImage(1800, 1200, 1, GL_RGB, GL_RGB, GL_UNSIGNED_BYTE, (unsigned char*)res, Image::USE_NEW_DELETE);

osg::Texture2D* texture = new osg::Texture2D(bufferImage);
texture->setResizeNonPowerOfTwoHint(false);
stateset->setTextureAttributeAndModes(0, texture);

...


Thank you!

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


Joined: 10 Sep 2013
Posts: 703

PostPosted: Tue Jun 02, 2015 2:09 pm    Post subject:
how to set raw image to texture in OSG
Reply with quote

Hi Harshal,


osgDB::readImageFile is your friend (see examples for usage)
As far as I know JPEG is compressed so, simply assigning the data will
result in displaying the raw-compressed data.

Cheers
Sebastian
Quote:
Hi,

I am trying to set an image on disk to my texture. Image dimension is 1800 by 1200 i.e. width = 1800 & height = 1200. But I am doing something wrong here due to which I am getting bad output. Can anyone help me here. This is my code -


std::ifstream imageToRead;
imageToRead.open("E:\\my code\\OpenSceneGraph-3.3.7\\OpenSceneGraph-Data-3.0.0\\Images\\1.jpg", std::ios::in | std::ios_base::binary);

imageToRead.seekg(0, std::ios::end);
int n = imageToRead.tellg();
imageToRead.seekg(0, std::ios::beg);

char* res = new char[n];

imageToRead.read(res, n);

imageToRead.clear();
imageToRead.close();

osg::Image* bufferImage = new osg::Image;
bufferImage->setImage(1800, 1200, 1, GL_RGB, GL_RGB, GL_UNSIGNED_BYTE, (unsigned char*)res, Image::USE_NEW_DELETE);

osg::Texture2D* texture = new osg::Texture2D(bufferImage);
texture->setResizeNonPowerOfTwoHint(false);
stateset->setTextureAttributeAndModes(0, texture);

...


Thank you!

Cheers,
Harshal
Code:




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









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


Joined: 01 Jun 2015
Posts: 2

PostPosted: Wed Jun 03, 2015 5:55 am    Post subject:
Reply with quote

Thanks Sebastian

I debug my application and found that simply displaying raw image data is not enough. I was doing wrong. OSG has provided plugins for each image format where it creates appropriate image buffer. I used bmp_load(...) for obtaining .bmp image buffer and it works.
...


Thank you!

Cheers,
Harshal
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 [forum] 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 osg::Image::setImage problem evanyftsai General 6 Sat Feb 18, 2017 2:38 am View latest post
No new posts Multitexture: projection a texture on... Ekaterina General 2 Mon Feb 06, 2017 1:48 pm View latest post
No new posts How to set texture coordinates Ekaterina General 0 Fri Jan 13, 2017 5:39 pm View latest post
No new posts Camera::resizeAttachments + texture rect James Turner General 1 Wed Jan 04, 2017 5:22 pm View latest post
No new posts Any good site/software to get texture... vinothrajendran4 VirtualPlanetBuilder [vpb] 1 Fri Dec 30, 2016 9:31 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