Re: [osg-users] Shader problem on nvidia card
Hi Aitor, The warning you are getting OpenGL version test failed, requires valid graphics context. suggests that you are trying to do rendering from a thread that doesn't have a graphics context current. I know nothing about how you are setting up your graphics context or how you manage you frame loop so I can do little to advice beyond suggesting that you try the same scene graph with a standard OSG example that is known to set up graphics contexts correctly and then see how you can fix your application to match this. Robert. On Wed, Dec 22, 2010 at 2:56 PM, Aitor Ardanza aitoralt...@terra.es wrote: Hi, I have a problem when I apply a shader to an object in osg. I tried it on two machines. One with an intel G41 graphics card, which does not give me any problem, and the other is a NVidia GTX 480, which gives me the problem. When osg try to compile the shader, skip the following error: FRAGMENT glCompileShader FAILED VERTEX glCompileShader FAILED glLinkProgram FAILED Error: In Texture::Extensions::setupGLExtensions(..) OpenGL version test failed, requires valid graphics context. Vertex program: Code: uniform mat4 boneMatrices[2]; attribute vec4 weights; attribute vec4 matrixIndices; attribute float numBones; varying vec2 Texcoord; varying vec3 ViewDirection; varying vec3 LightDirection; varying vec3 Normal; void main( void ) { vec4 normal = vec4( gl_Normal.xyz, 0.0 ); vec4 tempPosition = vec4( 0.0, 0.0, 0.0, 0.0 ); vec4 tempNormal = vec4( 0.0, 0.0, 0.0, 0.0 ); for(int i = 0; i int(numBones); i++ ) { // Apply influence of bone i tempPosition += vec4((boneMatrices[int(matrixIndices[i])] * gl_Vertex).xyz,1.0) * weights[i]; // Transform normal by bone i tempNormal += (boneMatrices[int(matrixIndices[i])] * normal) * weights[i]; } gl_Position = gl_ModelViewProjectionMatrix * tempPosition; Texcoord = gl_MultiTexCoord0.xy; vec4 fvObjectPosition = gl_ModelViewMatrix * gl_Vertex; ViewDirection = normalize(-fvObjectPosition.xyz); LightDirection = normalize(gl_LightSource[0].position.xyz - fvObjectPosition.xyz); Normal = normalize(gl_NormalMatrix * tempNormal.xyz); } Fragment program: Code: uniform sampler2D baseMap; varying vec3 ViewDirection; varying vec3 LightDirection; varying vec3 Normal; varying vec2 Texcoord; void main( void ) { float NdotL = max(dot(Normal, LightDirection), 0.0); vec4 diffuse = NdotL * gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse; vec4 ambient = gl_FrontMaterial.ambient * gl_LightSource[0].ambient; vec4 globalAmbient = gl_LightModel.ambient * gl_FrontMaterial.ambient; vec3 fvReflection = normalize( ( ( 2.0 * Normal ) * NdotL ) - LightDirection ); float fRDotV = max( 0.0, dot( fvReflection, ViewDirection ) ); vec4 specular = gl_FrontMaterial.specular * gl_LightSource[0].specular * pow(fRDotV,200.0); vec4 color = diffuse + globalAmbient + ambient + specular; gl_FragColor = texture2D( baseMap, Texcoord ) * color; } I fail to understand what may be the problem... any idea? Thank you! Cheers, Aitor -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=35085#35085 ___ 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
Re: [osg-users] Shader Problem
hi CG when you remove a shader, osg::Program need to be relinked. this is done by osgUtil::GLObjectVisitor in osgViewer::Renderer::draw method. So this seem can be done at runtime. Which OSG version did you use ? Did you use osgViewer ? David Callu 2008/6/12 CG [EMAIL PROTECTED]: Hi all, Are there any ways to remove the shader during runtime? I've tried the removeShader function but the effect of the shader is still applied to my models (e.g tank) i.e. the appearance of the models do not go back to the state before shader is applied. Regards, Cg -- Chat online and in real-time with friends and family! Windows Live Messenger http://get.live.com/messenger/overview ___ 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
Re: [osg-users] Shader Problem
Hi David, I'm using osg 2.4 and osgViewer. Regards, Cg Date: Thu, 12 Jun 2008 11:09:49 +0200From: [EMAIL PROTECTED]: [EMAIL PROTECTED]: Re: [osg-users] Shader Problemhi CGwhen you remove a shader, osg::Program need to be relinked.this is done by osgUtil::GLObjectVisitor in osgViewer::Renderer::draw method.So this seem can be done at runtime.Which OSG version did you use ?Did you use osgViewer ?David Callu 2008/6/12 CG [EMAIL PROTECTED]: Hi all, Are there any ways to remove the shader during runtime? I've tried the removeShader function but the effect of the shader is still applied to my models (e.g tank) i.e. the appearance of the models do not go back to the state before shader is applied. Regards,Cg Chat online and in real-time with friends and family! Windows Live Messenger___osg-users mailing [EMAIL PROTECTED]://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org _ Easily publish your photos to your Spaces with Photo Gallery. http://get.live.com/photogallery/overview___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Shader Problem
Hi CG When your remove a shader, void Program::dirtyProgram() is called to request a relink in the next frame. Program is relinked in the next frame in void Program::apply( osg::State state ) const method. Follow your code in a debugger to see if all is properly done. Are you sure your shader is well removed from your program ? HTH David Callu 2008/6/12 CG [EMAIL PROTECTED]: Hi David, I'm using osg 2.4 and osgViewer. Regards, Cg -- Date: Thu, 12 Jun 2008 11:09:49 +0200 From: [EMAIL PROTECTED] To: osg-users@lists.openscenegraph.org Subject: Re: [osg-users] Shader Problem hi CG when you remove a shader, osg::Program need to be relinked. this is done by osgUtil::GLObjectVisitor in osgViewer::Renderer::draw method. So this seem can be done at runtime. Which OSG version did you use ? Did you use osgViewer ? David Callu 2008/6/12 CG [EMAIL PROTECTED]: Hi all, Are there any ways to remove the shader during runtime? I've tried the removeShader function but the effect of the shader is still applied to my models (e.g tank) i.e. the appearance of the models do not go back to the state before shader is applied. Regards, Cg -- Chat online and in real-time with friends and family! Windows Live Messenger http://get.live.com/messenger/overview ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org -- Always-on security tools provide safer ways to connect and share anywhere. Find out more. Windows Live http://get.live.com/familysafety/overview ___ 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
Re: [osg-users] Shader Problem
Hi David, Just found out that the fault lies in my 3D model. Apparently, my shader only works for 3D models that are in OpenFlt format. It doesn't work for ive fomat. I've appended my shader code below: uniform sampler2D tex;uniform float fAmp; void main(){ vec4 texelColor = texture2D(tex, gl_TexCoord[0].st); texelColor = texelColor * fAmp; gl_FragColor = texelColor;} Thanks, Cg Date: Thu, 12 Jun 2008 16:46:04 +0200From: [EMAIL PROTECTED]: [EMAIL PROTECTED]: Re: [osg-users] Shader ProblemHi CGWhen your remove a shader, void Program::dirtyProgram() is called to request a relink in the next frame.Program is relinked in the next frame in void Program::apply( osg::State state ) const method.Follow your code in a debugger to see if all is properly done.Are you sure your shader is well removed from your program ?HTHDavid Callu 2008/6/12 CG [EMAIL PROTECTED]: Hi David, I'm using osg 2.4 and osgViewer. Regards,Cg Date: Thu, 12 Jun 2008 11:09:49 +0200From: [EMAIL PROTECTED]: [EMAIL PROTECTED]: Re: [osg-users] Shader Problem hi CGwhen you remove a shader, osg::Program need to be relinked.this is done by osgUtil::GLObjectVisitor in osgViewer::Renderer::draw method.So this seem can be done at runtime.Which OSG version did you use ?Did you use osgViewer ?David Callu 2008/6/12 CG [EMAIL PROTECTED]: Hi all, Are there any ways to remove the shader during runtime? I've tried the removeShader function but the effect of the shader is still applied to my models (e.g tank) i.e. the appearance of the models do not go back to the state before shader is applied. Regards,Cg Chat online and in real-time with friends and family! Windows Live Messenger___osg-users mailing [EMAIL PROTECTED]://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org Always-on security tools provide safer ways to connect and share anywhere. Find out more. Windows Live___osg-users mailing [EMAIL PROTECTED]://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org _ Easily publish your photos to your Spaces with Photo Gallery. http://get.live.com/photogallery/overview___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org