[osg-users] wrapping an opengl texture to an osg texture

Qingjie Zhang 305479421 at qq.com
Thu Sep 24 23:27:34 PDT 2015


Hi,
I have an opengl texture(GLuint), I'd like to wrap it to an osg::Texture2D. Is there some way to do this?

Actually, I got the GLuint in this way:

Code:

struct MyCameraPostDrawCallback : public osg::Camera::DrawCallback
{
    virtual void operator()(osg::RenderInfo &renderInfo) const
	{
		int contextID = renderInfo.getContextID();
		GLuint handle= m_frontTex->getTextureObject(contextID)->id();
		
	}
}




I've googled and searched in this forum, finding maybe a way to do this by:

Code:

osg::Texture2D *_texture = new osg::Texture2D;
osg::Texture::TextureObject *textureObject = new osg::Texture::TextureObject(_texture, handle, GL_TEXTURE_2D);
		textureObject->setAllocated();
		_texture->setTextureObject(renderInfo.getContextID(), textureObject);
		osg::State *state = renderInfo.getState();
		unsigned int _textureStage = 0;
		
		state->setActiveTextureUnit(_textureStage);
		_texture->apply(*state);
		state->haveAppliedTextureAttribute(_textureStage, _texture);



But I don't know what the "_textureStage" should be, I tried "0", but "state->setActiveTextureUnit(_textureStage);" returns false.

Is this the right way to achieve my goal? If not, how should I do?
... 

Thank you!

Cheers,
Qingjie

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








More information about the osg-users mailing list