Re: [osg-users] Transformations using Quat and Mat

2017-11-14 Thread tianzjyh
Hi, Maurus, 
I think it's the order of the multiplies. It should be like vec*MatA*MatB,  If 
you want to apply an osg::Matrix on a osg::Vec. But I do not quiet know why 
osg::Quat does not obey this: for a osg::Quat, the form quat * vec is used.___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] [3rdparty] ImGui integration

2017-11-09 Thread tianzjyh
Great work!! Thanks.


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


Re: [osg-users] "Memory: Colors" game from scratch

2017-10-30 Thread tianzjyh
wonderful !



--

Cheers, 
TianZJ



At 2017-10-28 19:18:01, "michael kapelko"  wrote:
>Hi.
>
>You may remember that some time earlier this year I've posted about
>OpenSceneGraph cross-platform guide (
>https://github.com/OGStudio/openscenegraph-cross-platform-guide ) that
>describes how to render a simple cube on desktop, mobile, and web.
>
>Once that was over, I headed straight to creating the first
>cross-platform game with OpenSceneGraph. This gave birth to MJIN
>project ( https://bitbucket.org/ogstudio/mjin ), which builds on
>OpenSceneGraph.
>
>I have successfully built the game based on Memory board game.
>Here's web version:
>https://ogstudio.github.io/game-memory-colors/0.3/mjin-player.html
>Note the famous OpenSceneGraph background :)
>
>Once the game was done I decided to describe how to create it from scratch.
>I've just finished the third article. All articles are in the game's
>home repository:
>https://bitbucket.org/ogstudio-games/memory-colors
>
>If you wanted to create a simple game for a long time but did not know
>where to start, now is a good chance.
>
>Thanks.
>___
>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] Non-convex polytope picking

2017-09-14 Thread tianzjyh
Hi, Antoine, 
   Yes, I think so, you have to split the non-convex polygon. Convex polygon is 
convenient to do point-containing test since it is just an AND-combination of 
half-space. But non-convex polygon is not that simple.





--





Cheers, 
---
TianZJ



At 2017-09-15 01:34:44, "Antoine Rennuit"  wrote:
>Dear OSG forum,
>
>I am currently using PolytopeIntersector with rectangular polygons for 
>picking. I am thinking of extending this selection mode with polygons than 
>could potentially be complex, non-convex for instance (e.g. polygons resulting 
>from hand drawn areas).
>
>Now I understand that the osg::Polytope class can only handle convex polygons.
>
>Does that mean that if I want to pick using non-convex polygons I need to 
>split my non-convex polygon into multiple convex osg::Polytopes and call the 
>IntersectionVisitor multiple times? Is this handled in OSG? Are there helpers 
>or should I do all this on the app side?
>
>Kind regards,
>
>Antoine.
>
>--
>Read this topic online here:
>http://forum.openscenegraph.org/viewtopic.php?p=71725#71725
>
>
>
>
>
>___
>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] Efficient way to swap colors

2017-09-05 Thread tianzjyh
Hi, Antoine,
  I think changing the material of the geometry will be more efficient. Have a 
look at examples about osg::Material  :)





--

Cheers, 
TianZJ



At 2017-09-06 00:31:11, "Antoine Rennuit"  wrote:
>In order to achieve this I thought of using the BIND_OVERALL mode with 2 
>Vec3Arrays (one array for the white color and the other one for the blue 
>color) and simply swapping arrays to change the color (with 
>osg::Geometry::setColorArray()), and calling dirtyDisplayList() to update.
>
>Is this the most efficient way of changing the osg::Geometry color?
>Read this topic online here:
>http://forum.openscenegraph.org/viewtopic.php?p=71629#71629

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


Re: [osg-users] Can see parts of the back side of a model

2017-08-23 Thread tianzjyh
Hi, Clay, 
Could you please attach a picture relative to the problem. Also, could you 
please describe what is the model's behavior under normal OSG, saying it viewed 
by "osgviewer.exe".  


--



Cheers, 
---
TianZJ



At 2017-08-24 08:09:23, "Bruce Clay"  wrote:
>I am using OSG 3.4 with QT 5.8 and Visual Studio 2015.  I am also using the QT 
>osgWidget class I found on line.  When I load a model I >can see parts of the 
>inside or back side of the model.  One viewer noted that it looked like the 
>surface normals are inverted.  I could not >find anything in the osgWidget 
>class or anything in the qtOsgWidget class that has anyeffect on surface 
>normals.
>Read this topic online here:
>http://forum.openscenegraph.org/viewtopic.php?p=71514#71514

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


Re: [osg-users] RenderBin vs. SlaveCamera

2017-08-03 Thread tianzjyh
hi Modenbach,
  My approach is to use a separate camera(not a slave camera) different with 
the main camera, and add it to the root node.
  In my opinion, there is little difference between these different approaches, 
since they will all be treated as elements in scene graph and state graph.
  But I am a little confused about your using slave camera. Is not slave camera 
share the same scene with the main camera ?  How do you assign different scenes 
in you HUD display ?





--





Cheers, 
---
TianZJ



At 2017-08-03 17:59:41, "Werner Modenbach"  wrote:
>Hi all,
>
>I'm restructuring my project because I want to implement some multi pass 
>effects.
>I have some problems understanding the different approaches for example when
>creating HUD displays.
>The approach I used so far is attaching a SlaveCamera and puttung it in 
>PostRender pass.
>On the other hand I found an approach of just attaching the matrices to 
>the root node and
>assigning the HUD geometry to a RenderBin with high number.
>
>I'd like to understand the difference of the approaches and the pros and 
>cons.
>
>Is there any one who can help me with that?
>
>Thanks
>
>- Werner -
>
>___
>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] converting node coordinates

2017-06-23 Thread tianzjyh
Hi, Oliveira, 
I am not sure what exactly is causing the problem, but maybe it is the 
setVertexArray(). U should call VertexArray::dirty(),after you changed data in 
osg::Array at runtime, to tell the OSG to update corresponding data in the GPU 
memory.





--





Cheers, 
---
TianZJ

At 2017-06-23 01:12:47, "Bruno Oliveira"  
wrote:



However, when I do this, I can see my points, BUT when I try to manipulate my 
scene with the mouse, the data disappears if I zoom in, and appears again if I 
zoom out again.

This seems like my node's bounds are not well set, But I manually verified all 
node's bounds and they are correct


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


Re: [osg-users] how to convert osgb files to old version

2017-06-18 Thread tianzjyh
Hi, Yu,
You can manually use osgconv.exe to convert between model files.  Run 
"osgconv.exe --help" for help.
Also, u can use osgDB::readNodeFile() and osgDB::writeNodeFile() 
respectively with filenames with proper extension, such as ".osg" and ".osgb". 
--



Cheers, 
---
TianZJ



At 2017-06-18 16:14:01, "Haojia Yu"  wrote:
>Hi,
>
>I am working on an application based on osg 3.5.3, and i use it to generate 
>lots 
>of modles saved as osgb format. However, there are some other softwares based 
>on older osg versions, maybe osg 3.4.0 or 3.0.0 or even earlier, and they 
>...

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


Re: [osg-users] Geometry in world coordinates but with same screen size - how to do?

2017-01-19 Thread tianzjyh
Hi, Roko, 
Just check function osg::AutoTransform::setPosition(const Vec3d& pos), and 
try setting "pos" to (0,0,0), then maybe you will find a clue.





--





Cheers, 
---
TianZJ



At 2017-01-20 10:10:31, "Roko Talk"  wrote:
>Hi TianZJ,
>
>thank you for your reply :) - Are you sure combining stuff from within the 
>osgautotransform example is enough to achieve what I want for osg::Geometry? 
>Because for text I can realize it with the above posted command.
> 
>Many thanks! :)
>
>Cheers,
>Roko
>
>--
>Read this topic online here:
>http://forum.openscenegraph.org/viewtopic.php?p=70016#70016
>
>
>
>
>
>___
>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] Geometry in world coordinates but with same screen size - how to do?

2017-01-19 Thread tianzjyh


hi, Roko, 
The example "osgautotransform" demonstrates different kinds of text 
auto-transform, e.g. ranged min-scale, max-scale, fixed position. If you are 
not sure about the implementation inside the source code, just try to combine 
the different kinds of texts inside the example, and you will get your wanted 
text.




--





Cheers, 
---
TianZJ



At 2017-01-20 08:55:08, "Roko Talk"  wrote:
>Ps. To specify what I'm exactly looking for, it is an equivalent for 
>osg::Geometry of the following stuff for osgText::TextBase:::
>
>
>Code:
>
>CharacterSizeMode OBJECT_COORDS_WITH_MAXIMUM_SCREEN_SIZE_CAPPED_BY_FONT_HEIGHT
>
>
>
>
>I hope now it is clear what I'm looking for :)
>
>--
>Read this topic online here:
>http://forum.openscenegraph.org/viewtopic.php?p=70014#70014
>
>
>
>
>
>___
>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] Visualization of billboards depending on pre-conditions

2017-01-08 Thread tianzjyh
Hi, 
But why not do occlusion query every frame? Is there any problem? because 
multi-pass depth test should also be done every frame.





--





Cheers, 
---
TianZJ



At 2017-01-08 22:46:27, "Hartwig Wiesmann"  wrote:
>Hi Tian,
>
>an occlusion query is difficult because the scene is continuously changing.
>
>Ad Robert: drawing the sign itself is not the issue. I would either like to 
>see the sign completely or not at all.
>
>I will do some tests with multi-passes.
>
>Thank you!
>
>Cheers,
>Hartwig
>
>--
>Read this topic online here:
>http://forum.openscenegraph.org/viewtopic.php?p=69928#69928
>
>
>
>
>
>___
>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] Visualization of billboards depending on pre-conditions

2017-01-08 Thread tianzjyh
Hi, 
Occlusion query is a better idea, especially for rendering many billboards.


About the performance, here is a discussion, 

http://gamedev.stackexchange.com/questions/118651/opengl-occlusion-culling-huge-performance-drop
which points out that calling all the queries together and waiting for 
query results asynchronously should minimize the performance loss.
If you want to implement like that, you should pay more attention to depth 
test when some billboards overlap each other.





--





Cheers, 
---
TianZJ



At 2017-01-08 18:32:35, "Robert Osfield"  wrote:
>Hi Hartwig,
>
>You can use the occlussion query extension to do the test but the
>round trip to the GPU and back be prohibitive for real-time
>performance. This is even before you start having to do a second pass
>to decide whether to render or not the signs.
>
>Do you really need to do this?  It would be far more complicated and
>slower than just rendering the whole sign all the time.
>
>The only way it would be possible to implement this efficiently would
>be if you were able to use an OpenGL extension where you could
>conditionally render some geometry based on an occlusion query test
>all down on the GPU with non CPU intervention.
>
>However, I'm not sure such a GL extension exists, I think I've seen
>discussion about such an approach quite a while back but don't recall
>if it was just hypothetical or there was some practice implementation
>was possible.
>
>Robert.
>
>On 7 January 2017 at 18:39, Hartwig Wiesmann
> wrote:
>> Hi,
>>
>> I would like to show a complete billboard when a certain part of the 
>> billboard is visible. Although other parts may be (partially) hidden by 
>> other items.
>>
>> Example: assume that the billboard is a sign consisting out of a foot, pole 
>> and the sign itself. Whenever the foot is visible (depth test passes for the 
>> whole foot) I would like to show the complete sign. Even if the depth test 
>> for the sign fails for certain parts of the sign (but not for the foot).
>>
>> Does anybody have any ideas how to set up such a test and following 
>> visualisation efficiently?
>>
>> Thank you!
>>
>> Cheers,
>> Hartwig
>>
>> --
>> Read this topic online here:
>> http://forum.openscenegraph.org/viewtopic.php?p=69920#69920
>>
>>
>>
>>
>>
>> ___
>> 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
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Visualization of billboards depending on pre-conditions

2017-01-07 Thread tianzjyh
Hi, Hartwig,
I think you have to use multi-pass rendering to make this special depth 
test work. 

Here is my idea, 
pass 1:  render foot separately to a texture without depth test, and writes 
only 1 or 0 to the texture, 1 while the pixel is part of foot, 0 otherwise. 
pass 2:  render foot separately to a texture with depth test, and also 
writes only 1 or 0 to the texture, 1 while the pixel is part of foot, 0 
otherwise. 
pass 3:  read these two textures back to your client memory from GPU, and 
compare whether these two textures are the same. If are the same, render the 
whole billboard, otherwise depends on your decision.


   You can set the view-port smaller but with the same width-height ratio when 
rendering the first two passes, so the texture size will be small enough to be 
efficiently. 


Idea above is based on rasterization and should work conditionlessly.


I think another idea is to use ray-intersect-test. Let's say your foot is a 
rectangle geometry with a texture, then you can cast a ray to the camera from 
each point of the four corners(if four is not enough, cast more), and see if 
any ray hit something. It is also an easy way to see if the foot is hidden by 
other items. 


Cheers, 
---
TianZJ



At 2017-01-08 02:39:18, "Hartwig Wiesmann"  wrote:
>Hi,
>
>I would like to show a complete billboard when a certain part of the billboard 
>is visible. Although other parts may be (partially) hidden by other items.
>
>Example: assume that the billboard is a sign consisting out of a foot, pole 
>and the sign itself. Whenever the foot is visible (depth test passes for the 
>whole foot) I would like to show the complete sign. Even if the depth test for 
>the sign fails for certain parts of the sign (but not for the foot).
>
>Does anybody have any ideas how to set up such a test and following 
>visualisation efficiently?
>
>Thank you!
>
>Cheers,
>Hartwig
>
>--
>Read this topic online here:
>http://forum.openscenegraph.org/viewtopic.php?p=69920#69920
>
>
>
>
>
>___
>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] How to draw 3D to screen

2017-01-06 Thread tianzjyh
Hi Philippe, 


Good joke!


Thanks for your sharing article How To Ask Questions The Smart Way.


Hope Rambabu and Bhanu would calm down and have a good look at it .



--





Cheers, 
---
TianZJ

At 2017-01-06 04:53:53, "philippe renon"  wrote:

Hi Robert,


How to draw 3D to screen ?



;)


Seriously, I admire your patience...


Rambabu,

If you are reading this, I suggest you take a look at this page : How To Ask 
Questions The Smart Way


|
| |
How To Ask Questions The Smart Way
| |
|


You will help yourself by asking precise questions with context, etc...


Cheers,

Philippe.


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


Re: [osg-users] Draw Instanced intersections

2017-01-03 Thread tianzjyh
Hi, Oliveira,


there maybe many reasons that why no intersection. I cannot give you advise 
without more information. u can check about examples within OSG source code, 
e.g. "osgintersection".


--

Cheers, 
---
TianZJ






At 2017-01-03 17:55:02, "Bruno Oliveira" <bruno.manata.olive...@gmail.com> 
wrote:

Hi TianZJ, Thanks for the quick answer.


I checked the intersector, but intersector->getIntersections() returns no 
intersections at all.





2017-01-03 9:32 GMT+00:00 tianzjyh <tianz...@126.com>:

Hi, Oliveira,
You can check the intersections of your intersector(e.g. 
LineSegmentIntersector::Intersection), and you will find they contain an 
"osg::NodePath", which means the whole path of the node(e.g. matrix transform 
nodes upon the drawable instance).



--





Cheers, 
---
TianZJ

At 2017-01-03 16:58:16, "Bruno Oliveira" <bruno.manata.olive...@gmail.com> 
wrote:

Hello,


I'm implementing a draw instanced optimized scene. This is for drawing a set of 
polygons.


Previously I was creating a drawable for each polygon, but now I am using draw 
instancing. With one drawable per polygon I can easily use osg intersectors for 
computing scene intersections. But how can I perform scene intersections with 
draw instanced objects and get, for instance, intersected instance IDs?






 


___
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] Draw Instanced intersections

2017-01-03 Thread tianzjyh
Hi, Oliveira,
You can check the intersections of your intersector(e.g. 
LineSegmentIntersector::Intersection), and you will find they contain an 
"osg::NodePath", which means the whole path of the node(e.g. matrix transform 
nodes upon the drawable instance).



--





Cheers, 
---
TianZJ

At 2017-01-03 16:58:16, "Bruno Oliveira"  
wrote:

Hello,


I'm implementing a draw instanced optimized scene. This is for drawing a set of 
polygons.


Previously I was creating a drawable for each polygon, but now I am using draw 
instancing. With one drawable per polygon I can easily use osg intersectors for 
computing scene intersections. But how can I perform scene intersections with 
draw instanced objects and get, for instance, intersected instance IDs?

___
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, 
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" <aa...@fosslib.net> 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 <tianz...@126.com>:
>
>> 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 

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


[osg-users] Change Graphic Context Runtimely

2016-11-21 Thread tianzjyh
Hi, 
  I found it difficult to achieve dynamic switching OpenGL context at run time.


  In the following code, I try to achieve this switching in a single 
thread(rendering thread not included), but I got a frozen window after pressing 
the switch key.


  My purpose is mainly to implement a quad-buffer switch option for users.


  Which step have made the froze of the main loop?


Codes:
--
1#include 
2
3#include 
4#include 
5#include 
6#include 
7#include 
8
9osg::GraphicsContext* createGC(float x, float y, float w, float h, bool stereo)
10{
11osg::DisplaySettings* ds = osg::DisplaySettings::instance().get();
12osg::ref_ptr traits = new 
osg::GraphicsContext::Traits;
13traits->windowName = "";
14traits->windowDecoration = true;
15traits->x = x;
16traits->y = y;
17traits->width = w;
18traits->height = h;
19traits->doubleBuffer = true;
20traits->quadBufferStereo = stereo;
21traits->alpha = ds->getMinimumNumAlphaBits();
22traits->stencil = ds->getMinimumNumStencilBits();
23traits->sampleBuffers = ds->getMultiSamples();
24traits->samples = ds->getNumMultiSamples();
25
26return osg::GraphicsContext::createGraphicsContext(traits.get());
27}
28
29bool _stereo = false;
30osg::ref_ptr _newgc = NULL;
31
32class SwitchGC : public osgGA::GUIEventHandler
33{
34public:
35virtual bool handle(const osgGA::GUIEventAdapter& ea, 
osgGA::GUIActionAdapter& aa)
36{
37switch (ea.getEventType())
38{
39case osgGA::GUIEventAdapter::EventType::KEYDOWN:
40{
41   if (ea.getKey() == osgGA::GUIEventAdapter::KEY_S)
42   {
43   //
44   osgViewer::Viewer* viewer = dynamic_cast();
45   if (viewer)
46   {
47   _stereo = !_stereo;
48   _newgc = createGC(0, 0, 1000, 1000, _stereo);
49   //viewer->getCamera()->setGraphicsContext(gc);
50   osg::DisplaySettings::instance()->setStereo(_stereo);
51   if (_stereo)
52   {
53   
osg::DisplaySettings::instance()->setStereoMode(osg::DisplaySettings::QUAD_BUFFER);
54   }
55   }
56
57   return true;
58   }
59}
60break;
61default:
62break;
63}
64
65return false;
66}
67private:
68};
69
70int main(int, char**)
71{
72osgViewer::Viewer* viewer = new osgViewer::Viewer();
73
74_stereo = !_stereo;
75osg::GraphicsContext* gc = createGC(0, 0, 1000, 1000, _stereo);
76osg::DisplaySettings::instance()->setStereo(_stereo);
77if (_stereo)
78{
79osg::DisplaySettings::instance()->setStereoMode(osg::DisplaySettings::QUAD_BUFFER);
80}
81
82
83viewer->getCamera()->setGraphicsContext(gc);
84viewer->setSceneData(osgDB::readNodeFile("cow.osg"));
85
86osg::Camera* camera = viewer->getCamera();
87const osg::GraphicsContext::Traits* traits = gc->getTraits();
88
89camera->setClearColor(osg::Vec4(0.2, 0.2, 0.2, 1.0));
90camera->setViewport(new osg::Viewport(0, 0, traits->width, traits->height));
91camera->setProjectionMatrixAsPerspective(30.0f, 
static_cast(traits->width) / static_cast(traits->height), 1.0f, 
1.0f);
92
93viewer->addEventHandler(new SwitchGC());
94viewer->setCameraManipulator(new osgGA::TrackballManipulator);
95
96while (!viewer->done())
97{
98if (_newgc.get() != NULL)
99{
100osg::GraphicsContext*oldgc =  viewer->getCamera()->getGraphicsContext();
101if (oldgc)
102{
103oldgc->close(true);
104}
105
106viewer->getCamera()->setGraphicsContext(_newgc);
107_newgc = NULL;
108
109camera->setClearColor(osg::Vec4(0.2, 0.2, 0.2, 1.0));
110camera->setViewport(new osg::Viewport(0, 0, traits->width, traits->height));
111camera->setProjectionMatrixAsPerspective(30.0f, 
static_cast(traits->width) / static_cast(traits->height), 1.0f, 
1.0f);
112
113viewer->realize();
114viewer->addEventHandler(new SwitchGC());
115viewer->setCameraManipulator(new osgGA::TrackballManipulator);
116
117}
118
119viewer->frame();
120
121}
122return 0;
123}
124

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