Re: [osg-users] glMultiTexCoord4f , OSG with OGL code

2009-08-07 Thread Ulrich Hertlein

On 6/08/09 8:19 PM, Pau Moreno wrote:

No I'm not having errors of compiling shaders, and executing it. Returning to 
the topic
of this post: If I comment the MultitexCoord line, nothing is showing in the 
viewer,
but that's logic. The problem if is it uncommented ( I need theis function so I 
can
pass my parameters to the shader in each vertex I have) the application 
crashes, and I


'osg::Geometry::setVertexAttribArray()' passes per-vertex attribute data (via 
glVertexAttrib*) and 'osg::Program::addBindAttribLocation()' binds a vertex attrib 
location to a name.


Hope this helps.
Cheers,
/ulrich
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] glMultiTexCoord4f , OSG with OGL code

2009-08-07 Thread Pau Moreno
Hi,

Thanks Ulrich, but I think this set one parameter for each vertex, and I really 
need 32 values for each vertex (that's what I'm using multitexcoord) Finally I 
think I have this problem solved, I had some problems with the glew 
initialization. Now I'm having other problems uploading a texture to the GPU :P

Thank you!

Cheers,
Pau

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=15981#15981





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


Re: [osg-users] glMultiTexCoord4f , OSG with OGL code

2009-08-07 Thread Jean-Sébastien Guay

Hi Pau,


Thanks Ulrich, but I think this set one parameter for each vertex, and I really 
need 32 values for each vertex (that's what I'm using multitexcoord) Finally I 
think I have this problem solved, I had some problems with the glew 
initialization. Now I'm having other problems uploading a texture to the GPU :P


Small correction, attribute arrays are vec4 arrays, so you can have 4 
32-bit float attributes per vertex with one attribute array. Most cards 
support at least 16 attribute arrays, and in OpenGL 2.x the standard 
vertex attributes take up spots in those 16+. Including TexCoords! So 
when you're using texcoords for multiple texture units, you're actually 
using attribute arrays, just with a less general name.


I had a project where I needed 27 floats per vertex (spherical harmonics 
coefficients) so I used 7 attribute arrays (9 to 15) to store them, then 
used a = i / 4 and b = i % 4 in the shader to get the ith coefficient 
(where a+9 gives the attribute array to index into and b gives the 
element in the vec4).


I would recommend using attribute arrays (use arrays numbered 6 and up 
or just count down from 15 so you don't collide with the standard 
attributes) since in OpenGL 3.x that's how all rendering works (i.e. you 
choose in which attribute array your vertices go, in which your 
texcoords go, etc. - there are no predefined arrays named vertex array 
and texcoord array for unit 0 anymore.). It's also much more general 
and makes it clear that you don't actually want to do texturing with 
these values, but something else. For your 32 floats you would use 8 
arrays, perhaps 8 to 15.


On a general note, avoid using straight GL code wherever you can. Even 
if you wanted to use straight texcoord arrays for what you want to do, 
you could have just used geometry-setTexCoordArray(unit, array) instead 
of glMultiTexCoord4f. It leads to cleaner code, less problems, and OSG 
can find ways to improve the performance of your app in ways you might 
not know about. In this case, I assume you are using glMultiTexCoord4f 
between glBegin and glEnd, in which case using vertex+texcoord arrays in 
an osg::Geometry would be a big speed gain for anything but non-trivial 
geometry (even if your geometry changes per frame, in which case you'd 
do geometry-setUseDisplayLists(false) ).


Hope this helps,

J-S
--
__
Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com
   http://www.cm-labs.com/
http://whitestar02.webhop.org/
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] glMultiTexCoord4f , OSG with OGL code

2009-08-06 Thread Stephan Huber
Hi,

Pau Moreno schrieb:
   brickVertexObject-readShaderFile  ( osg::Shader::VERTEX   , 
 /home/Pau/OSG/Test1/Debug/Shaders/TestG80_VS.glsl );
   brickFragmentObject-readShaderFile( osg::Shader::FRAGMENT , 
 /home/Pau/OSG/Test1/Debug/Shaders/TestG80_GS2.glsl );
   brickGeometryObject-readShaderFile( osg::Shader::GEOMETRY , 
 /home/Pau/OSG/Test1/Debug/Shaders/TestG80_FS.glsl );

are you sure, that your load the correct files? From the used naming
convention i think you loaded the geometry shader source into the
fragment-shader and vice versa.

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


Re: [osg-users] glMultiTexCoord4f , OSG with OGL code

2009-08-06 Thread Pau Moreno
Hi,

I saw this mistake before and I correct it but I'm still having the same error. 
With all the shaders :S Any idea?

Thank you!

Cheers,
Pau

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=15927#15927





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


Re: [osg-users] glMultiTexCoord4f , OSG with OGL code

2009-08-06 Thread Pau Moreno
Ok, I finally can solve it with this function:

loadShaderSourceFromFile(...)

No I'm not having errors of compiling shaders, and executing it. Returning to 
the topic of this post: If I comment the MultitexCoord line, nothing is showing 
in the viewer, but that's logic. The problem if is it uncommented ( I need 
theis function so I can pass my parameters to the shader in each vertex I have) 
the application crashes, and I got a Warning:

Warning: detected OpenGL error 'invalid operation' after RenderBin::draw(,)

Any Ideas? Thanksss!!

Cheers,
Pau

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=15928#15928





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


Re: [osg-users] glMultiTexCoord4f , OSG with OGL code

2009-08-05 Thread Ulrich Hertlein

Hi Pau,

On 5/08/09 1:58 AM, Pau Moreno wrote:

I've realized that the problem is that I'm losing the graphics context. I'm 
having the
same problem with the inicialization of a shader, and it crashes here before the
glMultiTexCoord4f(), so I think if I solve the problem with the shader this 
maybe
solves my first issue. My problem is that I have to work with a geometry 
shader, so I
have to do all the initializations in OGL. I finally found a solution to 
initialize
glew doing viewer.setRealizeOperation( ... ); but when I do viewer.realize, 
seems that
I loose the Graphics Context again. I want to initialize my shader
(glCreateProgramObjectARB) in a diferent place than where I do glewInit... how 
I can do
that?


Why are you manually creating GLSL programs?

If you could just use osg::Program you wouldn't have any context issues in the 
first place.

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


Re: [osg-users] glMultiTexCoord4f , OSG with OGL code

2009-08-05 Thread Pau Moreno
Hi,

Since I know, OSG doesn't have support for geometry shaders, does it? I'll 
check it again.

Thank you!

Cheers,
Pau

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=15857#15857





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


Re: [osg-users] glMultiTexCoord4f , OSG with OGL code

2009-08-05 Thread Thrall, Bryan
Pau Moreno wrote on Wednesday, August 05, 2009 12:22 PM:
 Since I know, OSG doesn't have support for geometry shaders, does it?
I'll
 check it again. 

It has had support since January, 2008, according to the SVN log; see
osg::Shader.

-- 
Bryan Thrall
FlightSafety International
bryan.thr...@flightsafety.com
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] glMultiTexCoord4f , OSG with OGL code

2009-08-05 Thread Pau Moreno
Hi,

Ok, I've decided to follow your idea and do it with the osg shaders but I'm 
getting the next error


Code:
FRAGMENT glCompileShader  FAILED
FRAGMENT Shader  infolog:
(0) : error C: syntax error, unexpected $end at token EOF
(0) : error C0501: type name expected at token null atom

VERTEX glCompileShader  FAILED
VERTEX Shader  infolog:
(0) : error C: syntax error, unexpected $end at token EOF
(0) : error C0501: type name expected at token null atom

GEOMETRY glCompileShader  FAILED
GEOMETRY Shader  infolog:
(0) : error C: syntax error, unexpected $end at token EOF
(0) : error C0501: type name expected at token null atom

glLinkProgram  FAILED
Program  infolog:
Vertex info
---
(0) : error C: syntax error, unexpected $end at token EOF
(0) : error C0501: type name expected at token null atom

Geometry info
-
(0) : error C: syntax error, unexpected $end at token EOF
(0) : error C0501: type name expected at token null atom

Fragment info
-
(0) : error C: syntax error, unexpected $end at token EOF
(0) : error C0501: type name expected at token null atom




Here I have where I initialize the shader:


Code:
osg::StateSet* brickState = node-getOrCreateStateSet();

osg::Program* brickProgramObject= new osg::Program;
osg::Shader* brickVertexObject  = new osg::Shader( 
osg::Shader::VERTEX );
osg::Shader* brickFragmentObject= new osg::Shader( 
osg::Shader::FRAGMENT );
osg::Shader* brickGeometryObject= new osg::Shader( 
osg::Shader::GEOMETRY );

brickProgramObject-addShader( brickFragmentObject );
brickProgramObject-addShader( brickVertexObject   );
brickProgramObject-addShader( brickGeometryObject );

brickVertexObject-readShaderFile  ( osg::Shader::VERTEX   , 
/home/Pau/OSG/Test1/Debug/Shaders/TestG80_VS.glsl );
brickFragmentObject-readShaderFile( osg::Shader::FRAGMENT , 
/home/Pau/OSG/Test1/Debug/Shaders/TestG80_GS2.glsl );
brickGeometryObject-readShaderFile( osg::Shader::GEOMETRY , 
/home/Pau/OSG/Test1/Debug/Shaders/TestG80_FS.glsl );

brickProgramObject-setParameter( GL_GEOMETRY_INPUT_TYPE_EXT   , 
GL_POINTS );
brickProgramObject-setParameter( GL_GEOMETRY_OUTPUT_TYPE_EXT  , 
GL_TRIANGLE_STRIP );
brickProgramObject-setParameter( GL_GEOMETRY_VERTICES_OUT_EXT , 16 );


glGenTextures(1, triTableTex );
glActiveTexture(GL_TEXTURE2);
glEnable(GL_TEXTURE_2D);

glBindTexture(GL_TEXTURE_2D, triTableTex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);

glTexImage2D( GL_TEXTURE_2D, 0, GL_ALPHA16I_EXT, 16, 256, 0, 
GL_ALPHA_INTEGER_EXT, GL_INT, triTable);

float isolevel = 0.2;
osg::Uniform* triTableU = new osg::Uniform(triTableTex, 0 );
osg::Uniform* isolevelU = new osg::Uniform(isolevel, isolevel );

osg::Uniform* vtxDecal0U = new osg::Uniform(vertDecals[0], 
osg::Vec3f( 0.0f, 0.0f , 0.0f   
   ) );
osg::Uniform* vtxDecal1U = new osg::Uniform(vertDecals[1], 
osg::Vec3f( this-m_vStep.x , 0.0f , 0.0f   
   ) );
osg::Uniform* vtxDecal2U = new osg::Uniform(vertDecals[2], 
osg::Vec3f( this-m_vStep.x , this-m_vStep.y  , 0.0f   
   ) );
osg::Uniform* vtxDecal3U = new osg::Uniform(vertDecals[3], 
osg::Vec3f( 0.0f, this-m_vStep.y  , 0.0f   
   ) );
osg::Uniform* vtxDecal4U = new osg::Uniform(vertDecals[4], 
osg::Vec3f( 0.0f, 0.0f , 
this-m_vStep.z   ) );
osg::Uniform* vtxDecal5U = new osg::Uniform(vertDecals[5], 
osg::Vec3f( this-m_vStep.x , 0.0f , this-m_vStep.z
   ) );
osg::Uniform* vtxDecal6U = new osg::Uniform(vertDecals[6], 
osg::Vec3f( this-m_vStep.x , this-m_vStep.y  , this-m_vStep.z   ) );
osg::Uniform* vtxDecal7U = new osg::Uniform(vertDecals[7], 
osg::Vec3f( 0.0f, this-m_vStep.y  , this-m_vStep.z
   ) );

brickState-addUniform( triTableU );
brickState-addUniform( isolevelU );
brickState-addUniform( vtxDecal0U );
brickState-addUniform( vtxDecal1U );
brickState-addUniform( vtxDecal2U );
brickState-addUniform( vtxDecal3U );
brickState-addUniform( vtxDecal4U );
brickState-addUniform( vtxDecal5U );
brickState-addUniform( vtxDecal6U );
brickState-addUniform( vtxDecal7U );

brickState-setAttributeAndModes( 

Re: [osg-users] glMultiTexCoord4f , OSG with OGL code

2009-08-04 Thread Thrall, Bryan
Pau Moreno wrote on Tuesday, August 04, 2009 3:18 PM:
 I'm trying to use multitexture in a class that inherit from Drawable.
I use
 glMultiTexCoord4f inside of the drawImplementation, because I need
this
 function to work with this parameters I have in a geomtryShader, but
by some
 reason a get  a Segmentation Fault while I'm using it... Shall I have
to
 activate something? I've read something about activate the texture in
the
 StateSet, but I don't know what exactly do... 

You need to tell OSG about any OGL calls you make; otherwise, it gets
confused about the current OGL state. See
osg::State::haveAppliedAttribute(), haveAppliedMode(), etc.

If that doesn't help, can you provide more details, such as a complete
simple test case (a model or code perhaps modified from osgviewer)
showing what you're doing?

-- 
Bryan Thrall
FlightSafety International
bryan.thr...@flightsafety.com
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] glMultiTexCoord4f , OSG with OGL code

2009-08-04 Thread Pau Moreno
Hi,

I've realized that the problem is that I'm losing the graphics context. I'm 
having the same problem with the inicialization of a shader, and it crashes 
here before the glMultiTexCoord4f(), so I think if I solve the problem with the 
shader this maybe solves my first issue.
My problem is that I have to work with a geometry shader, so I have to do all 
the initializations in OGL. I finally found a solution to initialize glew doing 
viewer.setRealizeOperation( ... ); but when I do viewer.realize, seems that I 
loose the Graphics Context again. I want to initialize my shader 
(glCreateProgramObjectARB) in a diferent place than where I do glewInit... how 
I can do that?

Thank you!

Cheers,
Pau

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=15800#15800





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