[osg-users] Draw instance quads not working

Bruno Oliveira bruno.manata.oliveira at gmail.com
Mon May 22 11:17:59 PDT 2017


Hi,


I want to render several simple quads ( a simple rectangle). I pass the
quad centers via a 2D texture, and try to render them with the following
vertex shader:



            "#version 120\n"
            "#extension GL_EXT_draw_instanced : enable\n"
            "\n"
            "uniform sampler2D texVert;\n"
            "uniform sampler2D texColor;\n"
            "uniform float          texSize;\n"
            "\n"
            "void main() {\n"
            "\n"
            "  float row   = float(gl_InstanceID) / texSize;\n"
            "\n"
            "  vec2  uv    = vec2(fract(row), floor(row) / texSize);\n"
            "  vec4  vert  = gl_Vertex + texture2D(texVert, uv);\n"
            "\n"
            "  gl_Position = gl_ModelViewProjectionMatrix * vert;\n"
            "\n"
            "}\n"



*This is my code for creating 1000 quads:*

this->setUseDisplayList(false),
    this->setUseVertexBufferObjects(true);

    // Build Geometry
    // Simple Quad
  osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array(4);
  (*vertices)[0].set(-500, -500, 0.f );
  (*vertices)[1].set( 500, -500, 0.f );
  (*vertices)[2].set( 500,  500, 0.f );
  (*vertices)[3].set(-500,  500, 0.f );

  this->setUseDisplayList(false);
  this->setUseVertexBufferObjects(true);
  this->setVertexArray(vertices.get());
  this->addPrimitiveSet(new osg::DrawArrays(GL_QUADS, 0, 4, 1000));


*IMPORTANT NOTE*:
*If I use simple GL_POINTS, my code works fine and renders correclty 1000
points:*

  osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array(1);
  (*vertices)[0].set(0, 0, 0.f );

  this->setVertexArray(vertices);

    this->addPrimitiveSet( new osg::DrawArrays(GL_POINTS, 0, 1, 1000) );
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20170522/7a84d9df/attachment-0002.htm>


More information about the osg-users mailing list