Re: [osg-users] Texturing with GLBeginEndAdapter

2016-12-29 Thread tianzjyh
Hi, 
I checked again about the function "State::setActiveTextureUnit()", and it 
seems like it's designed to be called inside the class "State" but not for 
users's calling. 
   So to enable the GL_TEXTURE_2D mode, and to make a specified unit to be the 
current, you can use
>state->applyTextureMode(0, GL_TEXTURE_2D, true); //this will call 
State::setActiveTextureUnit(0) internally.


   and to bind a texture object to target GL_TEXTURE_2D, call
>state->applyTextureAttribute(0, texture[0]);   
//texture[0]->apply(*state) should work too


Sorry for misleading you. 
Function "State::setActiveTextureUnit()" only makes a specified unit to be 
the current, without enabling GL_TEXTURE_2D mode.


As I understand, in the function drawImplementation(), you can even call 
native gl*() funtions(like glEnable(GL_TEXTURE_2D), glBindTexture(...)). Just 
remember to restore the gl state you have changed when leaving the funtion. But 
do not worry about this too much, as OSG's state manager will minimize the 
affect——when rendering other drawables, OSG will make states to be as you have 
pre-settled on them, while those you have not settled somehow will be unsure 
since you are not using OSG's state system.


--





Cheers, 
---
TianZJ



At 2016-12-29 21:34:40, "Aaron Andersen"  wrote:
>Hello TanZJ,
>
>Thank you for the information. I don't think I quite understood your  
>intention though. I apologize if this is obvious but as I said my  
>OpenGL skills are lacking... Here is my code after applying your  
>suggestion about applying the texture to the state:
>
>class MyDrawable {
>osg::ref_ptr texture[3];
>public:
> MyDrawable()
> {
> for (int i : {0, 1, 2})
> {
> const std::string filename = std::to_string(i + 1) + ".png";
>
> if (osg::Image * image = osgDB::readImageFile(filename))
> {
> texture[i] = new osg::Texture2D;
> texture[i]->setImage(image);
> }
> else
> {
> std::cerr << "ERROR LOADING IMAGE " << filename << std::endl;
> }
> }
> }
>
> virtual void drawImplementation(osg::RenderInfo & renderInfo)  
>const override
> {
> const float Z = 0.f;
>
> osg::State * state = renderInfo.getState();
> osg::GLBeginEndAdapter & gl = state->getGLBeginEndAdapter();
>
> state->setActiveTextureUnit(0);
>
> gl.Color4f(1.f, 1.f, 1.f, 1.f);
>
> float x = 50.f, y = 50.f, w = 64.f, h = 64.f, offset;
>
> offset = 0.f;
>
> // apply the first texture so it will draw on the first rect
> texture[0]->apply(*state);
> gl.Begin(GL_QUADS);
> gl.TexCoord2f(0.f, 0.f);
> gl.Vertex3f(offset + x, y, Z);
> gl.TexCoord2f(0.f, 1.f);
> gl.Vertex3f(offset + x + w, y, Z);
> gl.TexCoord2f(1.f, 1.f);
> gl.Vertex3f(offset + x + w, y + h, Z);
> gl.TexCoord2f(1.f, 0.f);
> gl.Vertex3f(offset + x, y + h, Z);
> gl.End();
>
> offset = 256.f;
>
> // apply the second texture so it will draw on the second rect
> texture[1]->apply(*state);
> gl.Begin(GL_QUADS);
> gl.TexCoord2f(0.f, 0.f);
> gl.Vertex3f(offset + x, y, Z);
> gl.TexCoord2f(0.f, 1.f);
> gl.Vertex3f(offset + x + w, y, Z);
> gl.TexCoord2f(1.f, 1.f);
> gl.Vertex3f(offset + x + w, y + h, Z);
> gl.TexCoord2f(1.f, 0.f);
> gl.Vertex3f(offset + x, y + h, Z);
> gl.End();
>
> offset = 512.f;
>
> // apply the third texture so it will draw on the third rect
> texture[2]->apply(*state);
> gl.Begin(GL_QUADS);
> gl.TexCoord2f(0.f, 0.f);
> gl.Vertex3f(offset + x, y, Z);
> gl.TexCoord2f(0.f, 1.f);
> gl.Vertex3f(offset + x + w, y, Z);
> gl.TexCoord2f(1.f, 1.f);
> gl.Vertex3f(offset + x + w, y + h, Z);
> gl.TexCoord2f(1.f, 0.f);
> gl.Vertex3f(offset + x, y + h, Z);
> gl.End();
> }
>};
>
>Can you see what I'm doing wrong? No textures show up at all when I  
>try this code.
>
>Thank you,
>Aaron
>
>Quoting tianzjyh :
>
>> Hi, Andersen,
>> Let's say you have three images, then you can wrap them using  
>> osg::Texture2D, something like this:
>> >
>>> osg::Image* image0 = osgDB::readImageFile("filename0.xxx");
>>> osg::Texture2D* tex0 = new osg::Texture2D(image0);
>>> tex1->setWrap(..., ...);
>>> tex1->setFilter(..., ...);
>>>
>>
>>
>> And then you can apply them in the drawImplementation() of your  
>> drawable like this :
>>>
>>> osg::State& state = *renderInfo.getState();
>>> state.setActiveTextureUnit(0);//set texture unit 0 as  
>>> current texture
>>> tex0->apply(state);//apply texture paras to  
>>> current texture
>>> ...drawQuad0...
>>>
>>> ...deal with other two 

Re: [osg-users] [build] x86_64, cmd line, built OK - but warning in Xcode

2016-12-29 Thread Hartwig Wiesmann
Hi,

I know that these compiler warnings are not critical but I find them still 
annoying and I think it is also not a good programming style to use the "wrong" 
integer type.

I also know that a simple modification might break some code (especially for 
virtual methods). But wouldn't it be in general a good idea to replace the 
mostly "unsigned int" types with size_t? Especially in constructors where very 
often a size is passed size_t can be used without problems (all STL size() 
methods return size_t types as a default type).

Cheers,
Hartwig

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





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


Re: [osg-users] Tearing hair out over simple GLSL instancing

2016-12-29 Thread Andrew Cunningham
Hi guys,
Can you help me out with this one more time:)

As I said, I am now able to draw my geometry ( a simple square) using hardware 
instancing. It works perfectly with excellent performance for millions of 
squares- except for one thing.  

Now I want to light the squares. I have turned on lighting, assigned a normal 
array to the geometry being instanced and assigned material colors, but I get  
unlit 'black squares' while the rest of my scene is lit just fine. Clearly 
something to do with hardware instancing using the vertex shader.

Do I need to add a fragment shader? I am a bit lost here.

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





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


Re: [osg-users] Check if sampler2D is valid in fragment shader

2016-12-29 Thread Sebastian Messerschmidt



Am 29.12.2016 um 17:07 schrieb Rômulo Cerqueira:

Hi Christian,



You could traverse the scene graph and check the state sets to see if they bind 
a texture to a texture unit.

Then depending on these findings, choose the correct shader code.


I appreciated it. Can you give me some example?
Basically alot of scenegraph handling is built around the 
VisitorPattern. To use it, derive your visitor from the osg::NodeVisitor 
base class and override the appropriate apply-functions.

There are a lot of examples in the OSG code base and the examples.
In your case you might want to consider to use the osg::Node-apply 
function and simply check for a StateSet which contains the texture. In 
case you find a texture you might use the proposed pragmatic shader 
composition.
Simply set a "USE_TEXTURE"-define for the nodes with textures (via the 
stateSet->setDefine).


Cheers
Sebastian


...

Thank you!

Cheers,
Rômulo

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





___
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] Check if sampler2D is valid in fragment shader

2016-12-29 Thread Rômulo Cerqueira
Hi Christian,


> You could traverse the scene graph and check the state sets to see if they 
> bind a texture to a texture unit. 
> 
> Then depending on these findings, choose the correct shader code. 


I appreciated it. Can you give me some example?
... 

Thank you!

Cheers,
Rômulo

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





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


Re: [osg-users] Texturing with GLBeginEndAdapter

2016-12-29 Thread Aaron Andersen

Hello TanZJ,

Thank you for the information. I don't think I quite understood your  
intention though. I apologize if this is obvious but as I said my  
OpenGL skills are lacking... Here is my code after applying your  
suggestion about applying the texture to the state:


class MyDrawable {
osg::ref_ptr texture[3];
public:
MyDrawable()
{
for (int i : {0, 1, 2})
{
const std::string filename = std::to_string(i + 1) + ".png";

if (osg::Image * image = osgDB::readImageFile(filename))
{
texture[i] = new osg::Texture2D;
texture[i]->setImage(image);
}
else
{
std::cerr << "ERROR LOADING IMAGE " << filename << std::endl;
}
}
}

virtual void drawImplementation(osg::RenderInfo & renderInfo)  
const override

{
const float Z = 0.f;

osg::State * state = renderInfo.getState();
osg::GLBeginEndAdapter & gl = state->getGLBeginEndAdapter();

state->setActiveTextureUnit(0);

gl.Color4f(1.f, 1.f, 1.f, 1.f);

float x = 50.f, y = 50.f, w = 64.f, h = 64.f, offset;

offset = 0.f;

// apply the first texture so it will draw on the first rect
texture[0]->apply(*state);
gl.Begin(GL_QUADS);
gl.TexCoord2f(0.f, 0.f);
gl.Vertex3f(offset + x, y, Z);
gl.TexCoord2f(0.f, 1.f);
gl.Vertex3f(offset + x + w, y, Z);
gl.TexCoord2f(1.f, 1.f);
gl.Vertex3f(offset + x + w, y + h, Z);
gl.TexCoord2f(1.f, 0.f);
gl.Vertex3f(offset + x, y + h, Z);
gl.End();

offset = 256.f;

// apply the second texture so it will draw on the second rect
texture[1]->apply(*state);
gl.Begin(GL_QUADS);
gl.TexCoord2f(0.f, 0.f);
gl.Vertex3f(offset + x, y, Z);
gl.TexCoord2f(0.f, 1.f);
gl.Vertex3f(offset + x + w, y, Z);
gl.TexCoord2f(1.f, 1.f);
gl.Vertex3f(offset + x + w, y + h, Z);
gl.TexCoord2f(1.f, 0.f);
gl.Vertex3f(offset + x, y + h, Z);
gl.End();

offset = 512.f;

// apply the third texture so it will draw on the third rect
texture[2]->apply(*state);
gl.Begin(GL_QUADS);
gl.TexCoord2f(0.f, 0.f);
gl.Vertex3f(offset + x, y, Z);
gl.TexCoord2f(0.f, 1.f);
gl.Vertex3f(offset + x + w, y, Z);
gl.TexCoord2f(1.f, 1.f);
gl.Vertex3f(offset + x + w, y + h, Z);
gl.TexCoord2f(1.f, 0.f);
gl.Vertex3f(offset + x, y + h, Z);
gl.End();
}
};

Can you see what I'm doing wrong? No textures show up at all when I  
try this code.


Thank you,
Aaron

Quoting tianzjyh :


Hi, Andersen,
Let's say you have three images, then you can wrap them using  
osg::Texture2D, something like this:

>

osg::Image* image0 = osgDB::readImageFile("filename0.xxx");
osg::Texture2D* tex0 = new osg::Texture2D(image0);
tex1->setWrap(..., ...);
tex1->setFilter(..., ...);




And then you can apply them in the drawImplementation() of your  
drawable like this :


osg::State& state = *renderInfo.getState();
state.setActiveTextureUnit(0);//set texture unit 0 as  
current texture
tex0->apply(state);//apply texture paras to  
current texture

...drawQuad0...

...deal with other two quads...




--

Cheers,
---
TianZJ



At 2016-12-29 07:32:01, "Aaron Andersen"  wrote:

Hello,

There is some code in a library which I want to adapt for OSG. The
code is pretty old and uses the old style OpenGL. I don't have the
time it would take to rewrite this code so I would like to use the
GLBeginEndAdapter to make this code work with OSG.

Looking at the GLBeginEndAdapter there isn't much documentation so I
was hoping someone could help me out. Please keep in mind my OpenGL
skills are lacking (which I why enjoy using a rendering engine like
OSG :-).

I've created a subclass to the Drawable class called "MyDrawable". In
the drawImplementation function I'm have a couple
gl.Begin(GL_QUADS)/gl.End() calls to draw 3 simple rectangles. I'm
unsure of how to apply 3 separate textures to these 3 rectangles. From
reading the ShapeDrawable class it looks like the state of the
Drawable applies the texture to everything you draw.

So how can I apply many different textures to my drawing, with 1
texture per shape I draw with GL_QUADS?

Thank you for any insight you can provide.
Aaron


___
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] Check if sampler2D is valid in fragment shader

2016-12-29 Thread Christian Buchner
> I will receive the final scene with or without textures

You could traverse the scene graph and check the state sets to see if they
bind a texture to a texture unit.
Then depending on these findings, choose the correct shader code.

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


Re: [osg-users] Texturing with GLBeginEndAdapter

2016-12-29 Thread tianzjyh
Hi, Andersen,
Let's say you have three images, then you can wrap them using osg::Texture2D, 
something like this:
>
>osg::Image* image0 = osgDB::readImageFile("filename0.xxx");
>osg::Texture2D* tex0 = new osg::Texture2D(image0);
>tex1->setWrap(..., ...);
>tex1->setFilter(..., ...);
>


And then you can apply them in the drawImplementation() of your drawable like 
this :
>
>osg::State& state = *renderInfo.getState();
>state.setActiveTextureUnit(0);//set texture unit 0 as current texture
>tex0->apply(state);//apply texture paras to current 
>texture
>...drawQuad0...
>
>...deal with other two quads...
>


--

Cheers, 
---
TianZJ



At 2016-12-29 07:32:01, "Aaron Andersen"  wrote:
>Hello,
>
>There is some code in a library which I want to adapt for OSG. The  
>code is pretty old and uses the old style OpenGL. I don't have the  
>time it would take to rewrite this code so I would like to use the  
>GLBeginEndAdapter to make this code work with OSG.
>
>Looking at the GLBeginEndAdapter there isn't much documentation so I  
>was hoping someone could help me out. Please keep in mind my OpenGL  
>skills are lacking (which I why enjoy using a rendering engine like  
>OSG :-).
>
>I've created a subclass to the Drawable class called "MyDrawable". In  
>the drawImplementation function I'm have a couple  
>gl.Begin(GL_QUADS)/gl.End() calls to draw 3 simple rectangles. I'm  
>unsure of how to apply 3 separate textures to these 3 rectangles. From  
>reading the ShapeDrawable class it looks like the state of the  
>Drawable applies the texture to everything you draw.
>
>So how can I apply many different textures to my drawing, with 1  
>texture per shape I draw with GL_QUADS?
>
>Thank you for any insight you can provide.
>Aaron
>
>
>___
>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] Capture image on iOS get black image

2016-12-29 Thread duc nguyen
Dear Raymond,

Yes, your right. But I am mentioning about glReadPixels, not glReadBuffer()

I've tested using SnapImageDrawCallback class on Windows OS and it done to 
create a screenshot of osgviewer, but on iOS it still return black image 


reedev wrote:
> Dear Duc,
> 
> If you read your own first mail with the code snippet you pasted:
> 
>     virtual void operator () (osg::RenderInfo& renderInfo) const 
>     { 
> #if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) 
>         glReadBuffer(_readBuffer); 
> #else 
>         osg::notify(osg::NOTICE)<<"Error: GLES unable to do 
> glReadBuffer"< #endif 
> 
> I guess that's clear, right?
> 
> Cheers
> Raymond
> 
> 


Cheers
Duc

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





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


Re: [osg-users] Texturing with GLBeginEndAdapter

2016-12-29 Thread Alberto Luaces
Aaron Andersen writes:

> I've created a subclass to the Drawable class called "MyDrawable". In
> the drawImplementation function I'm have a couple
> gl.Begin(GL_QUADS)/gl.End() calls to draw 3 simple rectangles. I'm
> unsure of how to apply 3 separate textures to these 3 rectangles. From
> reading the ShapeDrawable class it looks like the state of the
> Drawable applies the texture to everything you draw.

Hi Aaron, if I am not mistaken, it is unlikely that the original code
did that (without any multi-texturing tricks, I think).

Probably it had a glBegin/glEnd block, a texture binding change, and
then the next glBegin/glEnd block.

That translates in OSG as —as you figured out— several Drawables with
their own StateSet each one (at least one StateSet per different
texture).  You can try to group into the same Drawable all the
primitives sharing the same texture.

-- 
Alberto

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