[osg-users] osgText not working with programmable pipeline?

2012-07-04 Thread Preet
I compiled OSG against OpenGL 3 and disabled all the fixed function
stuff, and I can do basic things like build up geometry, apply shaders
and so on. Trying to draw text using osgText doesn't work out so well
though. I'm not sure what's going on... but basically the output looks
like font character quads, just not textured correctly (wild guess).
Here's a screenshot from the results of running osgtext in the example
folder: http://i.imgur.com/NX6dv.png?1

Do I need to specify my own shader for the text geode I create? If so,
are there any examples on how to do this?

Also here's the debug output for a minimal osg text example (just
create some text, attach it to a geode, and render the scene):
http://pastie.org/4200461

I see ShaderComposer is called but I don't know if it's doing
anything. Also this line doesn't seem right: Glyph::subload():
texture sub-image width and/or height of 0, ignoring operation. I'd
appreciate any advice.


Preet
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] osgText not working with programmable pipeline?

2012-07-04 Thread Preet
After some trial and error, osgText renders fine when explicitly
setting up shaders. Here's a bare minimum working example in case
anyone else runs into this.

Scene Graph:

// text geometry
std::string textStr(Hello World);
osg::ref_ptrosgText::Text myText = new osgText::Text;
myText-setFont(DroidSans-Bold.ttf);
myText-setCharacterSize(20.0f);
myText-setText(textStr);

// text node
osg::ref_ptrosg::Geode textGeode = new osg::Geode;
textGeode-addDrawable(myText);

// text shaders
osg::ref_ptrosg::Program shProgram = new osg::Program;
shProgram-setName(TextShader);

std::string vShader = std::string(#version 120\n) +
readFileAsString(vertexshader.glsl);
shProgram-addShader(new osg::Shader(osg::Shader::VERTEX,vShader));

std::string fShader = std::string(#version 120\n) +
readFileAsString(fragmentshader.glsl);
shProgram-addShader(new osg::Shader(osg::Shader::FRAGMENT,fShader));

osg::ref_ptrosg::Uniform textColor = new
osg::Uniform(MaterialColor,osg::Vec4(0,1,1,1));
osg::ref_ptrosg::Uniform textTexture = new osg::Uniform(GlyphTexture,0);

osg::StateSet *ss = textGeode-getOrCreateStateSet();
ss-addUniform(textColor);
ss-addUniform(textTexture);
ss-setAttributeAndModes(shProgram,osg::StateAttribute::ON);

osg::ref_ptrosg::Group nodeRoot = new osg::Group;
nodeRoot-addChild(textGeode);


Vertex Shader:
#version 120

varying mediump vec4 VertexColor;
varying mediump vec2 TexCoord0;

uniform vec4 MaterialColor;

void main()
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
VertexColor = MaterialColor;
TexCoord0 = gl_MultiTexCoord0.xy;
}


Fragment Shader:

varying vec4 VertexColor;
varying vec2 TexCoord0;

// set to zero by default
uniform sampler2D GlyphTexture;

void main()
{
gl_FragColor = VertexColor * texture2D(GlyphTexture,TexCoord0).;
}


Preet
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org