Hi Stephan and Thomas,<div>what do you think about the sample code I've sent? Is there something wrong with it?</div><div><br></div><div>Actually, since it works on a PC but not on iOS, maybe there is something wrong with the options used to build OSG for iOS (or maybe with CMake options)...I'm just guessing.</div>
<div><br></div><div>Thanks.</div><div>Alessandro</div><div><br><br><div class="gmail_quote">On Sat, Apr 23, 2011 at 10:06 PM, Alessandro Terenzi <span dir="ltr"><<a href="mailto:a.terenzi@gmail.com">a.terenzi@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div>Hi again, here's the code I'm using:</div><br>// my SubloadCallback:<br>ITexture2DSubloadCallback::ITexture2DSubloadCallback(osg::Texture2D* texture)<br>
{<br><blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:40px;border-top-style:none;border-right-style:none;border-bottom-style:none;border-left-style:none;border-width:initial;border-color:initial;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px">

const osg::Image* _image = texture->getImage();<br><br>// m_POT_width, m_POT_height are members of the subload callback</blockquote><blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:40px;border-top-style:none;border-right-style:none;border-bottom-style:none;border-left-style:none;border-width:initial;border-color:initial;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px">

m_POT_width = (double)mathNextPowerOf2((unsigned int)_image->s()), <br>m_POT_height = (double)mathNextPowerOf2((unsigned int)_image->t()), <br><br>// set the texture to beleive it is of power of two size<br>texture->setTextureSize(m_POT_width, m_POT_height);<br>

<br>// set to linear to disable mipmap generation<br>texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR);<br>texture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR);</blockquote>}<div>

<br>void ITexture2DSubloadCallback::load(const osg::Texture2D& texture, osg::State& state) const <br>{<br></div><blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:40px;border-top-style:none;border-right-style:none;border-bottom-style:none;border-left-style:none;border-width:initial;border-color:initial;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px">

<div> const osg::Image* _image = texture.getImage();</div><div> </div><div>glTexImage2D(GL_TEXTURE_2D, 0, </div><div>                     osg::Image::computeNumComponents(_image->getInternalTextureFormat()), </div><div>

                     (int)m_POT_width,</div><div>                     (int)m_POT_height,</div><div>                     0, </div><div>                     _image->getPixelFormat(), </div><div>                     _image->getDataType(), </div>

<div>                    0</div><div>                    );</div><div><br></div><div>state.checkGLErrors("ITexture2DSubloadCallback::load");</div></blockquote><div>}</div><div><br>void ITexture2DSubloadCallback::subload(const osg::Texture2D& texture, osg::State& state) const <br>

{<br></div><blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:40px;border-top-style:none;border-right-style:none;border-bottom-style:none;border-left-style:none;border-width:initial;border-color:initial;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px">

<div>const osg::Image* _image = texture.getImage();</div></blockquote><div><br></div><blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:40px;border-top-style:none;border-right-style:none;border-bottom-style:none;border-left-style:none;border-width:initial;border-color:initial;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px">

<div>glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,</div></blockquote><div>                    _image->s(), _image->t(), <br>                    _image->getPixelFormat(), <br>                    _image->getDataType(), <br>

                    _image->data()<br>                   );<br><br></div><blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:40px;border-top-style:none;border-right-style:none;border-bottom-style:none;border-left-style:none;border-width:initial;border-color:initial;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px">

<div>state.checkGLErrors("ITexture2DSubloadCallback::subload");</div></blockquote><div>}</div><div><br>// and here's how I create the textured quad that is attached to the scene's root...</div><div><br>
float width = 200;<br>
float height = 200;<br><br></div><div>osg::ref_ptr<osg::Geode> geode;<br>osg::ref_ptr<osg::Geometry> geom;<br><br></div><div>// create geometry...<br>geode = new osg::Geode;<br>geom = new osg::Geometry;<br><br>

</div><div>osg::Vec3 top_left(0, height, 0);<br>osg::Vec3 bottom_left(0, 0, 0);<br>osg::Vec3 bottom_right(width, 0, 0);<br>osg::Vec3 top_right(width, height, 0);<br>     </div><div>// vertices...<br>osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array(4);<br>

(*vertices)[0] = top_left;<br>(*vertices)[1] = bottom_left;<br>(*vertices)[2] = bottom_right;<br>(*vertices)[3] = top_right;<br>geom->setVertexArray(vertices.get());<br><br></div><div>// texcoords...<br>osg::ref_ptr<osg::Vec2Array> texcoords = new osg::Vec2Array(4);<br>

<br></div><div>(*texcoords)[0].set(0.0f,1.0f);<br>(*texcoords)[1].set(0.0f,0.0f);<br>(*texcoords)[2].set(1.0f,0.0f);<br>(*texcoords)[3].set(1.0f,1.0f);<br>geom->setTexCoordArray(0, texcoords.get());<br>   </div><div>// normals...<br>

osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array(1);<br>(*normals)[0].set(0.0f, 0.0f, 1.0f);<br>geom->setNormalArray(normals.get());<br>geom->setNormalBinding(osg::Geometry::BIND_OVERALL);<br>    <br>

// colors...</div><div>osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array(1);</div><div>(*colors)[0].set(1.0f, 1.0f, 1.0f, 1.0f);   // this is the color that will be displayed if the texture won't be displayed<br>

geom->setColorArray(colors.get());<br>geom->setColorBinding(osg::Geometry::BIND_OVERALL);<br>geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4));<br>geode->addDrawable(geom.get());<br><br></div><div>// texture...<br>

osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;<br>texture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR);<br>texture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);<br>texture->setWrap( osg::Texture2D::WRAP_S, osg::Texture2D::CLAMP );<br>

texture->setWrap( osg::Texture2D::WRAP_T, osg::Texture2D::CLAMP );<br>texture->setDataVariance(osg::Object::DYNAMIC);<br><br></div><div>osg::ref_ptr<osg::Image> image = osgDB::readImageFile("Icon.png"); // 57x57 image (NPOT)...<br>

if(image.valid())<br>    texture->setImage(image.get());<br><br></div><div><font color="#3333FF"><b>osg::ref_ptr<ITexture2DSubloadCallback> t2dscb = new ITexture2DSubloadCallback(texture);<br>texture->setSubloadCallback(t2dscb.get());<br>

</b></font><br></div><div>// stateset...<br>osg::StateSet* stateset = geom->getOrCreateStateSet();<br>stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED);<br>stateset->setTextureAttributeAndModes(0, texture.get(), osg::StateAttribute::ON);<br>

    </div><div>m_root->addChild(geode.get());</div><div><br></div><div>That's all. Hope you can help. Thanks!</div><div>Alessandro</div>
</blockquote></div><br></div>