Re: [osg-users] Image from shader

2019-10-04 Thread Chris Djali
Hi,

OSGOcean is probably setting up the necessary fixed-function stuff to put its 
texture in texture unit zero, but you'll need to tell the fragment shader that 
its texUnit0 uniform refers to that texture unit. It should be enough just to 
add a uniform to the same stateset as you're adding your shader that sets 
texUnit0 to 0 e.g.

Code:
stateSet->addUniform(new osg::Uniform("texUnit0", 0));



Cheers,
Chris

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





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


[osg-users] Crash on some machines while rendering a progressive line strip

2019-10-04 Thread Rakesh Prasad
Hi,
I have a code which renders a progressive line strip. When the line strip is 
unmasked to display it crashes on some machines. I use osg 3.6.4 with MFC 
Visual Studio 2019 with V142. The same problem was observed on osg 3.4.0 with 
MFC and Visual Studio 2013 v120. I am completely clueless as why it would crash 
since its not on my machine. I dont have the crash stack and other variable 
values. I have some observations.I will list my code and try to explain as best 
as possible.
I migrated from osg 3.4.0 hoping 3.6.4 will resolve the issue.

createHUDClubHdPts is called to create the scenegraph with the arrays. After 
which every frame AddCurPtToHandClubPath is called. This function updates the 
point in the array. As the frames are rendered a line that progressed based on 
the coordinates is displayed.  The render target is a MFC MDI client window. 
The render frames are called from a thread of class OpenThreads::Thread

While trying to debug the issue using logs.  I found that when the 
numPtsinHandClubPath value goes to 199 it crashes. We can see that the array 
size is 2000.  Everytime it used to crash after 200 values were updated into 
the coordinate vector and color vector.

It has never crashed on two of my machines so I dont have the stack and 
variable values. Few remote machines it has crashed.
Do let me know if there is any query or clarity required.
... 

Thank you!

Cheers,
Rakesh

Code:

//following variables are defined in COSGViewer
osg::MatrixTransform* mtClubHandPath;
osg::ref_ptr osgGeodeHandClubPath;
unsigned int MaxPtsInHandCLubPath;
osg::ref_ptr geomHandPath;
osg::ref_ptr geomClubPath;
osg::ref_ptr coordsHandPath;
osg::ref_ptr coordsClubPath;
osg::ref_ptr coloursHandPath;
osg::ref_ptr coloursClubPath;
osg::ref_ptr drawArrayHandPath;
osg::ref_ptr drawArrayClubPath;


osg::MatrixTransform* COSGViewer::createHUDClubHdPts(int X0, int Y0, int X1, 
int Y1, int textYOffset)
{
mtClubHandPath = new osg::MatrixTransform();
osg::Matrix m;
m.makeTranslate(0, 0, 0);
mtClubHandPath->setMatrix(m);

RECT rect;
::GetWindowRect(m_hWnd, &rect);


osg::ref_ptr linesGeom = new osg::Geometry();
osgGeodeHandClubPath = new osg::Geode();

osg::ref_ptr stateset = 
osgGeodeHandClubPath->getOrCreateStateSet();

stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
stateset->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);

osg::ref_ptr linewidth = new osg::LineWidth();
linewidth->setWidth(4.0f);
stateset->setAttributeAndModes(linewidth, osg::StateAttribute::ON);

unsigned int n_points = 2000;
MaxPtsInHandCLubPath = n_points;
numPtsinHandClubPath = 0;
geomHandPath = new osg::Geometry();
geomClubPath = new osg::Geometry();

coordsHandPath = new osg::Vec3Array;// (n_points);
coordsClubPath = new osg::Vec3Array;// (n_points);
coloursHandPath = new osg::Vec4Array;// (n_points);
coloursClubPath = new osg::Vec4Array;// (n_points);


for (unsigned int j = 0; j < n_points; ++j) {

coordsHandPath->push_back(osg::Vec3(0, 0, 0));
coordsClubPath->push_back(osg::Vec3(0, 0, 0));
coloursHandPath->push_back(osg::Vec4(1.0, 0, 0, 1.0));
coloursClubPath->push_back(osg::Vec4(0, 0, 1.0, 1.0));


}


geomHandPath->setVertexArray(coordsHandPath);
geomClubPath->setVertexArray(coordsClubPath);

drawArrayHandPath = new 
osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP);
//geomHandPath->addPrimitiveSet(new 
osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP, 0, n_points));
geomHandPath->addPrimitiveSet(drawArrayHandPath);

drawArrayClubPath = new 
osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP);
geomClubPath->addPrimitiveSet(drawArrayClubPath);


geomHandPath->setColorArray(coloursHandPath, 
osg::Array::BIND_PER_VERTEX);
geomClubPath->setColorArray(coloursClubPath, 
osg::Array::BIND_PER_VERTEX);

geomHandPath->setDataVariance(osg::Object::DYNAMIC);
geomClubPath->setDataVariance(osg::Object::DYNAMIC);

osgGeodeHandClubPath->addDrawable(geomHandPath);
osgGeodeHandClubPath->addDrawable(geomClubPath);

mtClubHandPath->addChild(osgGeodeHandClubPath);
return mtClubHandPath;
}



void COSGViewer::AddCurPtToHandClubPath(int ccurFr, int cPrevFr)
{
if (ccurFr != -1)
{
if (ccurFr == cPrevFr)
return;
}

osg::Vec3Array * lcoordsHandPath = 
dynamic_cast(geomHandPath->getVertexArray());
osg::Vec3Array * lcoordsClubPath = 
dynamic_cast(geomClubPath->getVertexArray());

osg::Vec4Array * lcolorHandPath = 

Re: [osg-users] Image from shader

2019-10-04 Thread Lucas Amparo
Hi, Chris. Thanks for the answer.

I've inserted "gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;" in my 
vertex shader before... and forgot to mention this here. Sorry.

Thanks for the code but, with my poor knowledge about OSG and OpenGL I need to 
pass a texture for fragment shader, right? In the texUnit0?

My simulation was a little bit complex (and confuse), not made by me. I'm just 
adding a feature to a finished plugin, made by the Older-Me haha

All the texture, I believe are passed by the OSGOcean, because when I load my 
camera with the osg::Node without my shaders, it's works properly.
But, when I load my node with shader, "brokes"...

Thank you!

Cheers,
Lucas

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





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


Re: [osg-users] vcpkg gl3+

2019-10-04 Thread Glenn Waldron
Gijsbert,

Using the default OSG build does NOT prevent you from using GL3 and GL4
features.  However, it will not support a CORE profile -- for that you'll
need to rebuild them yourself with the correct options. Hope this helps.

Glenn Waldron / osgEarth


On Fri, Oct 4, 2019 at 5:04 AM Gijsbert dos Santos 
wrote:

> Hi,
>
> Currently I'm using the vcpkg build of openscenegraph + osgEarth, but it
> seems that it defaults all of the build settings, which means that it's
> using mostly openGL2 functions. I'd like to use more modern openGL
> functions, but it's unclear to me how to actually make that happen.
>
> I'd like to use at least openGL 3, preferably the latest (currently 4.6).
>
> Do I need to manually build it from source or is there a way to make vcpkg
> cooperate a little?
>
> Thank you!
>
> Cheers,
> Gijsbert
>
> --
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=76776#76776
>
>
>
>
>
> ___
> 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] Image from shader

2019-10-04 Thread Chris Djali
Hi,

If you're not seeing any errors in the console, I don't think you've added your 
shader to the scene properly. You have to assign something to gl_Position 
otherwise the rasteriser has no idea where your vertex is, so doesn't know 
which pixels any triangles cover, and nothing will get drawn.

Also, I reckon two things that you've got wrong that stop you from getting 
image2 are:
image2 looks like it has some basic lighting, hence why the cylinder's 
colour varies from left to right. You're not doing any lighting, just 
forwarding the vertex colour.

image2 looks like it has a texture, at least on the brown bit. You're 
not sampling from a texture anywhere.



I'd start with these shaders generated by 3DLabs GLSL ShaderGen and comment out 
things or add things until you get the result you're after:

Vertex:

Code:

/***
*  Fixed.vert Fixed Function Equivalent Vertex Shader  *
*Automatically Generated by GLSL ShaderGen *
*  https://github.com/mojocorp/ShaderGen   *
***/
vec4 Ambient;
vec4 Diffuse;
vec4 Specular;


void pointLight(in int i, in vec3 normal, in vec3 eye, in vec3 ecPosition3)
{
   float nDotVP;   // normal . light direction
   float nDotHV;   // normal . light half vector
   float pf;   // power factor
   float attenuation;  // computed attenuation factor
   float d;// distance from surface to light source
   vec3  VP;   // direction from surface to light position
   vec3  halfVector;   // direction of maximum highlights

   // Compute vector from surface to light position
   VP = vec3 (gl_LightSource[i].position) - ecPosition3;

   // Compute distance between surface and light position
   d = length(VP);

   // Normalize the vector from surface to light position
   VP = normalize(VP);

   // Compute attenuation
   attenuation = 1.0 / (gl_LightSource[i].constantAttenuation +
gl_LightSource[i].linearAttenuation * d +
gl_LightSource[i].quadraticAttenuation * d * d);

   halfVector = normalize(VP + eye);

   nDotVP = max(0.0, dot(normal, VP));
   nDotHV = max(0.0, dot(normal, halfVector));

   if (nDotVP == 0.0)
   {
   pf = 0.0;
   }
   else
   {
   pf = pow(nDotHV, gl_FrontMaterial.shininess);

   }
   Ambient  += gl_LightSource[i].ambient * attenuation;
   Diffuse  += gl_LightSource[i].diffuse * nDotVP * attenuation;
   Specular += gl_LightSource[i].specular * pf * attenuation;
}

vec3 fnormal(void)
{
//Compute the normal 
vec3 normal = gl_NormalMatrix * gl_Normal;
normal = normalize(normal);
return normal;
}

void ftexgen(in vec3 normal, in vec4 ecPosition)
{

gl_TexCoord[0] = gl_MultiTexCoord0;
}

void flight(in vec3 normal, in vec4 ecPosition, float alphaFade)
{
vec4 color;
vec3 ecPosition3;
vec3 eye;

ecPosition3 = (vec3 (ecPosition)) / ecPosition.w;
eye = vec3 (0.0, 0.0, 1.0);

// Clear the light intensity accumulators
Ambient  = vec4 (0.0);
Diffuse  = vec4 (0.0);
Specular = vec4 (0.0);

pointLight(0, normal, eye, ecPosition3);

color = gl_FrontLightModelProduct.sceneColor +
Ambient  * gl_FrontMaterial.ambient +
Diffuse  * gl_FrontMaterial.diffuse;
color += Specular * gl_FrontMaterial.specular;
color = clamp( color, 0.0, 1.0 );
gl_FrontColor = color;

gl_FrontColor.a *= alphaFade;
}


void main (void)
{
vec3  transformedNormal;
float alphaFade = 1.0;

// Eye-coordinate position of vertex, needed in various calculations
vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;

// Do fixed functionality vertex transform
gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex;
transformedNormal = fnormal();
flight(transformedNormal, ecPosition, alphaFade);
ftexgen(transformedNormal, ecPosition);
}




Fragment:

Code:

/***
* Fixed.frag Fixed Function Equivalent Fragment Shader *
*Automatically Generated by GLSL ShaderGen *
*  https://github.com/mojocorp/ShaderGen   *
***/
uniform sampler2D texUnit0;

void main (void) 
{
vec4 color;

color = gl_Color;

color *= texture2D(texUnit0, gl_TexCoord[0].xy);

gl_FragColor = color;
}





Cheers,
Chris[/code]

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





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


Re: [osg-users] vcpkg gl3+

2019-10-04 Thread Chris Hanson
Try the

vckpg list OpenSceneGraph

and see what features it lists available.

On Fri, Oct 4, 2019 at 1:45 AM Gijsbert dos Santos 
wrote:

> Hi,
>
> Currently I'm using the vcpkg build of openscenegraph + osgEarth, but it
> seems that it defaults all of the build settings, which means that it's
> using mostly openGL2 functions. I'd like to use more modern openGL
> functions, but it's unclear to me how to actually make that happen.
>
> I'd like to use at least openGL 3, preferably the latest (currently 4.6).
>
> Do I need to manually build it from source or is there a way to make vcpkg
> cooperate a little?
>
> Thank you!
>
> Cheers,
> Gijsbert
>
> --
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=76776#76776
>
>
>
>
>
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>


-- 
Chris 'Xenon' Hanson, omo sanza lettere. xe...@alphapixel.com
http://www.alphapixel.com/
Training • Consulting • Contracting
3D • Scene Graphs (Open Scene Graph/OSG) • OpenGL 2 • OpenGL 3 • OpenGL 4 •
GLSL • OpenGL ES 1 • OpenGL ES 2 • OpenCL
Legal/IP • Forensics • Imaging • UAVs • GIS • GPS •
osgEarth • Terrain • Telemetry • Cryptography • LIDAR • Embedded • Mobile •
iPhone/iPad/iOS • Android
@alphapixel  facebook.com/alphapixel (775)
623-PIXL [7495]
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Image from shader

2019-10-04 Thread Lucas Amparo
Guys,

It's possible to take a simples "screenshot" from an osg::Viewer?

Thank you!

Cheers,
Lucas

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





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


Re: [osg-users] Image from shader

2019-10-04 Thread Lucas Amparo


AnyOldName3 wrote:
> Hi,
> 
> I'm pretty sure you're not using your shaders at all. You're not setting 
> gl_Position in the vertex shader, so it's not going to compile, and OSG will 
> fall back to either its basic shader or fixed-function mode depending on how 
> you've set it up. You should be seeing errors printed to the console when you 
> run your application.
> 
> Cheers,
> Chris


Hi, thanks for your answer.
The shader works for my purpose.
Before, just a depthmap from simulation.

The console don't show any error, just deprecated warnings.

Do you believe if I set gl_Position, the colors could be solved?

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





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


[osg-users] Question about idle event handling in the wxWidgets example

2019-10-04 Thread YH Zhang
Hi, in the \examples\osgviewerWX\osgviewerWX.cpp

I see such code snippet


Code:

void MainFrame::OnIdle(wxIdleEvent &event)
{
if (!_viewer->isRealized())
return;

_viewer->frame();

event.RequestMore();
}




This makes the frame() function call runs continuously.

I just change the code by those steps:

1, first, I comment out all the codes in the "void 
MainFrame::OnIdle(wxIdleEvent &event)", and this means the OnIdle just do 
nothing.

2, second, I add some code snippet to some event handling function like:


Code:


void OSGCanvas::OnMouseWheel(wxMouseEvent &event)
{
int delta = event.GetWheelRotation() / event.GetWheelDelta() * 
event.GetLinesPerAction();

if (_graphics_window.valid()) {
_graphics_window->getEventQueue()->mouseScroll(
delta>0 ?
osgGA::GUIEventAdapter::SCROLL_UP :
osgGA::GUIEventAdapter::SCROLL_DOWN);
}

// those code were added by me, which force a refresh of the view
MainFrame * f = (MainFrame *)GetParent();

if (!f->_viewer->isRealized())
return;

f->_viewer->frame();

}





My question is: My thought was remove the idle event handling, because it waste 
some CPU resource to refresh the opengl window again and again. My change is 
try to only update the view when some true event happens. Any ideas?

Thank you!

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





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


[osg-users] vcpkg gl3+

2019-10-04 Thread Gijsbert dos Santos
Hi,

Currently I'm using the vcpkg build of openscenegraph + osgEarth, but it seems 
that it defaults all of the build settings, which means that it's using mostly 
openGL2 functions. I'd like to use more modern openGL functions, but it's 
unclear to me how to actually make that happen. 

I'd like to use at least openGL 3, preferably the latest (currently 4.6).

Do I need to manually build it from source or is there a way to make vcpkg 
cooperate a little?

Thank you!

Cheers,
Gijsbert

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





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