Thanks ! That is really a simple and nice example for me, I will try it and
feedback when I get succeed.
I think your solution is loading texture separatly , while my osg file is
binding with texture. I donot know how to convert fbx to osg format for
external texture file.
However, the following shader works for my young.osg file here :
Code:
static const char gVertexShader1[] =
"varying vec2 v_texCoord; \n"
"void main() { \n"
" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; \n"
" v_texCoord = gl_MultiTexCoord0.xy;
\n"
"} \n";
static const char gFragmentShader1[] =
"varying mediump vec2 v_texCoord;
\n"
"uniform sampler2D sam;
\n"
"void main() {
\n"
"gl_FragColor = texture2D(sam, v_texCoord);
\n"
"}
Sergey Kurdakov wrote:
> Hi Liu,
>
>
> consider this simple pseudo code example ( just fix
> createTexturedQuadGeometry in code below so that it has #if
> defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) line instead of
> #if defined(OSG_GLES1_AVAILABLE) || !defined(OSG_GLES2_AVAILABLE) ) )
>
>
> have u_Texture sampler in your shader
>
> uniform sampler2D u_Texture;
>
>
> then create geode
>
> osg::Geode* geode = new osg::Geode();
> osg::Program* program = new osg::Program();
>
> osg::Shader* vert = new osg::Shader(osg::Shader::VERTEX,
> gVertexShader);
> osg::Shader* frag = new osg::Shader(osg::Shader::FRAGMENT,
> gFragmentShader );
>
> program->addShader(vert);
> program->addShader(frag);
> geode->addDrawable(makePlain ());
> osg::StateSet* pStateSet = geode->getOrCreateStateSet();
>
>
> osg::Image* pImage = new osg::Image;
>
>
> load image here, now
>
> osg::Texture2D* pTex = new osg::Texture2D();
> pTex->setFilter( pTex->MIN_FILTER,pTex->LINEAR);
> pTex->setFilter( pTex->MAG_FILTER,pTex->LINEAR);
> pTex->setImage(0, pImage);
>
>
>
> pStateSet->setTextureAttribute( 0, pTex, osg::StateAttribute::ON );
>
> pStateSet->addUniform(new osg::Uniform("u_Texture", 0));
>
> pStateSet->setAttribute(program);
>
>
> makePlain could be as following:
>
>
> osg::Geometry*
> makePlain()
> {
>
> osg::ref_ptr<osg::Geometry> geom= osg::createTexturedQuadGeometry(
> osg::Vec3(-0.5f, 0.0f,-0.5f),
>
> osg::Vec3(1.0f,0.0f,0.0f),
>
> osg::Vec3(0.0f,0.0f,1.0f) );
>
> if( geom == NULL )
> geom = new osg::Geometry;
>
> geom->setUseVertexBufferObjects(true);
>
> return( geom.release() );
> }
>
>
> this simple example should work, then you should move further.
>
> Regards
> Sergey
>
>
>
> On Fri, Nov 7, 2014 at 3:56 PM, Liu Xiao < ()> wrote:
>
> > Thanks so much for your quick reply , it really helps.
> >
> > Also this post gives me a good example of shader:
> > http://forum.openscenegraph.org/viewtopic.php?t=6482
> > (http://forum.openscenegraph.org/viewtopic.php?t=6482)
> >
> > But still I have problem on drawing the texture.
> >
> >
> > Sergey Kurdakov wrote:
> >
> > > Hi Liu,
> > >
> > >
> > > use setUseVertexAttributeAliasing as Robert recently explained for
> > > similar question
> > >
> > > ===
> > > The aliasing of gl_* uniforms to osg_* equivialants is not done by
> > > default. You can switch it one yourself if required though via
> > > osg::State, from the osgsimplegl3 example:
> > >
> > > // for non GL3/GL4 and non GLES2 platforms we need enable the osg_
> > > uniforms that the shaders will use,
> > > // you don't need thse two lines on GL3/GL4 and GLES2 specific builds
> > > as these will be enable by default.
> > > gc->getState()->setUseModelViewAndProjectionUniforms(true);
> > > gc->getState()->setUseVertexAttributeAliasing(true);
> > >
> > >
> > > In your own shaders if you are building against GL1/2 (default build of
> > > OSG) then you can simply use the gl_* parameters.
> > >
> > > Also have a look at the shaders in OpenSceneGraph-Data and the osgshaders
> > > example.
> > > ===
> > >
> > >
> > >
> > >
> > > Regards
> > > Sergey
> > >
> > > On Fri, Nov 7, 2014 at 12:14 PM, Liu Xiao < ()> wrote:
> > >
> > >
> > > > Hi,
> > > >
> > > > When I trying to use the osg 3.2.1 (with OSG_GLES2_AVAILABLE:BOOL=ON )
> > > > example_osgViewerIPhone, I got the following errors:
> > > >
> > > >
> > > > Code:
> > > > VERTEX glCompileShader "" FAILED
> > > > VERTEX Shader "" infolog:
> > > > ERROR: 0:6: Use of undeclared identifier 'gl_Vertex'
> > > > ERROR: 0:7: Use of undeclared identifier 'gl_FrontColor'
> > > >
> > > > FRAGMENT glCompileShader "" FAILED
> > > > FRAGMENT Shader "" infolog:
> > > > ERROR: 0:4: 'vec4' : declaration must include a precision qualifier for
> > > > type
> > > > ERROR: 0:5: Use of undeclared identifier 'base'
> > > > ERROR: 0:6: Use of undeclared identifier 'color'
> > > > ERROR: 0:6: Use of undeclared identifier 'gl_Color'
> > > > ERROR: 0:7: Use of undeclared identifier 'color'
> > > >
> > > > glLinkProgram "" FAILED
> > > > Program "" infolog:
> > > > ERROR: One or more attached shaders not successfully compiled
> > > >
> > > >
> > > >
> > > > My Config file is as follows:
> > > >
> > > >
> > > > Code:
> > > > #ifndef OSG_CONFIG
> > > > #define OSG_CONFIG 1
> > > >
> > > > /* #undef OSG_NOTIFY_DISABLED */
> > > > /* #undef OSG_USE_FLOAT_MATRIX */
> > > > /* #undef OSG_USE_FLOAT_PLANE */
> > > > #define OSG_USE_FLOAT_BOUNDINGSPHERE
> > > > #define OSG_USE_FLOAT_BOUNDINGBOX
> > > > #define OSG_USE_REF_PTR_IMPLICIT_OUTPUT_CONVERSION
> > > > /* #undef OSG_USE_UTF8_FILENAME */
> > > > #define OSG_DISABLE_MSVC_WARNINGS
> > > >
> > > > /* #undef OSG_GL1_AVAILABLE */
> > > > /* #undef OSG_GL2_AVAILABLE */
> > > > /* #undef OSG_GL3_AVAILABLE */
> > > > /* #undef OSG_GLES1_AVAILABLE */
> > > > #define OSG_GLES2_AVAILABLE
> > > > /* #undef OSG_GL_LIBRARY_STATIC */
> > > > /* #undef OSG_GL_DISPLAYLISTS_AVAILABLE */
> > > > /* #undef OSG_GL_MATRICES_AVAILABLE */
> > > > /* #undef OSG_GL_VERTEX_FUNCS_AVAILABLE */
> > > > /* #undef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE */
> > > > /* #undef OSG_GL_FIXED_FUNCTION_AVAILABLE */
> > > >
> > > > #endif
> > > >
> > > >
> > > >
> > > >
> > > > Can anyone help with this? Or is there any examples of osg ios can I
> > > > learn?
> > > >
> > > > Thank you!
> > > >
> > > > Cheers,
> > > > Liu
> > > >
> > > > ------------------
> > > > Read this topic online here:
> > > >
> > >
> >
> >
> >
> > >
> > > > http://forum.openscenegraph.org/viewtopic.php?p=61538#61538
> > > > (http://forum.openscenegraph.org/viewtopic.php?p=61538#61538)
> > > > (http://forum.openscenegraph.org/viewtopic.php?p=61538#61538
> > > > (http://forum.openscenegraph.org/viewtopic.php?p=61538#61538))
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > _______________________________________________
> > > > osg-users mailing list
> > > > ()
> > > > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> > > >
> > > > (http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org)
> > > >
> > > > (http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> > > >
> > > > (http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org))
> > > >
> > > >
> > >
> > >
> > > ------------------
> > > Post generated by Mail2Forum
> > >
> >
> >
> > ------------------
> > Read this topic online here:
> > http://forum.openscenegraph.org/viewtopic.php?p=61545#61545
> > (http://forum.openscenegraph.org/viewtopic.php?p=61545#61545)
> >
> >
> >
> >
> >
> > _______________________________________________
> > osg-users mailing list
> > ()
> > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> > (http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org)
> >
> >
> >
>
>
> ------------------
> Post generated by Mail2Forum
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=61555#61555
Attachments:
http://forum.openscenegraph.org//files/young_565.osg
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org