Hi Selmar,
The type of the Sampler uniform must be _int_. If you change it, it
should work as expected.
(usually the OpenGL are signed and float-precision by "default")
Cheers
Sebastian
Hi,
I encountered something peculiar. Everything seems to work fine, though.
I get the following warning message:
Warning: detected OpenGL error 'invalid operation' at After Renderer::compile
Investigating the issue (and stripping it down somewhat), I found that the
error message disappears when I change 'unsigned int' in the following piece of
code to 'int':
Code:
unsigned int texUnit = 0;
ref_ptr<Uniform> uniform = new Uniform("sampler", texUnit);
stateSet->addUniform(uniform);
I'm curious if this is a bug or something I'm forgetting?
For completeness, here's the code that replicates the 'issue' for me:
Code:
#include <osgViewer/Viewer>
using namespace osg;
int main(int argc, char** argv)
{
osgViewer::Viewer viewer;
viewer.setUpViewInWindow(50, 50, 640, 480);
ref_ptr<Group> root = new Group;
ref_ptr<Geode> geode = new Geode;
ref_ptr<Geometry> geometry = new Geometry;
root->addChild(geode);
geode->addChild(geometry);
geometry->setUseDisplayList(false);
geometry->setUseVertexBufferObjects(true);
ref_ptr<StateSet> stateSet = geometry->getOrCreateStateSet();
ref_ptr<Program> program = new Program();
program->setName("TestProgram");
stateSet->setAttributeAndModes( program, StateAttribute::ON );
ref_ptr<Shader> vertShader = new Shader(osg::Shader::Type::VERTEX);
ref_ptr<Shader> fragShader = new Shader(osg::Shader::Type::FRAGMENT);
program->addShader(vertShader);
program->addShader(fragShader);
vertShader->setShaderSource(
"void main(void){\n"
"gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex;\n"
"}\n"
);
fragShader->setShaderSource(
"uniform sampler2D sampler;\n"
"void main (void){\n"
"gl_FragColor = vec4(1, 1, 1, 1) + texture2D(sampler, vec2(0,
0)).rgba;\n"
"}\n"
);
osg::Vec3 quadVerts[] = {
osg::Vec3(-1, -1, 1),
osg::Vec3(1, -1, 1),
osg::Vec3(1, 1, -1),
osg::Vec3(-1, 1, -1)};
geometry->setVertexArray( new Vec3Array(4, quadVerts) );
geometry->addPrimitiveSet( new DrawArrays(PrimitiveSet::QUADS, 0, 1) );
unsigned int texUnit = 0;
ref_ptr<Uniform> uniform = new Uniform("sampler", texUnit);
stateSet->addUniform(uniform);
viewer.setSceneData(root);
viewer.run();
}
Thanks,
Selmar[/code]
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=61034#61034
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org