Re: [osg-users] render depth buffer to image for one time

2011-07-02 Thread aaron wetzler
Sergey, thank you so much for your help. Its been very useful
and has helped me focus my attention on the right things. I have almost 
finished what I needed to do.

I have one last question:

I now have an RTT camera which I take its depth and color attachments from. The 
RTT camera is a slave to the master scene camera and takes its data from there 
also.

My problem is that when I just leave the natural settings of the master camera 
then it seems that the depth range changes according to the bounding box of the 
scene data.

[Image: http://forum.openscenegraph.org/files/capture2_125.png ]

The range in the above image it gives me is great but I dont want it to change. 
I want to fix that depth range and also be in control of it.  


In the next image I have set 
viewer.getCamera()-setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
 

I assumed this had to do with the near and far culling planes but it seems to 
affect the depth range also. 

[Image: http://forum.openscenegraph.org/files/capture1_105.png ]

So now my question is how do I set and fix the depth range to what I choose?


... 

Thank you!

Cheers,
aaron[img][/img]

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




Attachments: 
http://forum.openscenegraph.org//files/capture1_105.png
http://forum.openscenegraph.org//files/capture2_125.png


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


Re: [osg-users] render depth buffer to image for one time

2011-07-02 Thread aaron wetzler
I was being silly. I simply didnt pick the right values for the near and far 
planes.
This was my solution:

   
Code:
 
viewer.getCamera()-setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
 
double left,right,bottom,top,fovy,aspectratio,near,far;

viewer.getCamera()-getProjectionMatrixAsPerspective(fovy,aspectratio,near,far);

viewer.getCamera()-setProjectionMatrixAsPerspective(fovy,aspectratio,20,25);



... 

Thank you!

Cheers,
aaron

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





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


Re: [osg-users] render depth buffer to image for one time

2011-07-01 Thread aaron wetzler
Hi Sergey

I would like to understand exactly how the graphics pipeline works and am 
struggling to figure this out by digging through the code (are there free books 
that deal with OSG and its implementation details in-depth? I dont mean the QSG 
by Paul Martz...). Also, my understanding of OpenGL is lacking in some places 
especially in implementation details so perhaps this will help clear things up 
for me.

In the prerender example we have something like this:

0: camera-setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
1: camera-attach(osg::Camera::BufferComponent(osg::Camera::COLOR_BUFFER0), 
image);
2: camera-setPostDrawCallback(new MyCameraPostDrawCallback(image));
3: textureRect[tex_to_get]-setImage(0, image); 

As far as I understand this works as follows

0: This generates an FBO which has no data storage until I attach data storage 
to it (next step) ? Is this true? What happens then when I attach a color 
attachment but dont attach a depth buffer attachment? Does OSG automatically 
generate one for me? I ask because in regular OpenGL when you dont attach a 
depth attachment to an FBO then rendering to the FBO using 
glEnable(GL_DEPTH_TEST) produces incorrect results...

1: The image attached to the camera is the data storage for the FBO created in 
step 0. If this is the case then it means the FBO sits in RAM and not on the 
GPU. Is that true? 

2:Here we set a post render callback using the image as our input. As far as I 
understand this means that the image (which is sitting in RAM) is edited in 
place. That means that as long as we dont need the data for actual rendering 
then we are being efficient because we dont copy to the GPU. Which brings up 
the next line...

3: We specify that a texture has the image as its image. I dont entirely 
understand what this means. When we create the original texture then OpenGL 
allocates space on the GPU for that texture. By using setImage(0,image) then 
does that mean that whatever is in that image (which sits on RAM) must always 
be copied to the GPU texture  before the texture can be used at render time? 

All in all I feel quite confused and would like to understand how to do the 
above process efficiently.
Ideally I would like to : pass dynamic geometry to the GPU every frame and have 
that rendered to textures inside the GPU. Occassionally I would like to ask the 
GPU to send the RTT textures back to the CPU, update them on the CPU and then 
send them back to the GPU.
How should I be doing that in the most efficient way possible?



Thank you!

Cheers,
aaron

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





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


Re: [osg-users] render depth buffer to image for one time

2011-07-01 Thread Sergey Polischuk
Hi aaron

0: osg can manage missing attachments for you if they are needed. This 
behaviour is configurable with env variables and in code. I dont actually 
remember default behaviour, but i think it will attach color and\or depth 
renderbuffers if they needed and missing, not sure about stencil.

1: as far as i remember this works by creating renderbuffer and then using 
glReadPixels from fbo to ram (image data storage). You can use image with pbo 
to make use of asynchronous dma transfers. Render to texture works faster, but 
you dont get your data on cpu side.

2: cant say much because didnt looked at example sources

3: texture-setImage(...) works like initializing gl texture with data stored 
in osg image with glTexImage(...), it will be copied in gpu memory and updated 
by osg if image changes. In this step you could also benefit from using image 
with pbo to get asynchronous copy.

 How should I be doing that in the most efficient way possible?
Depends on data size, frequency of gpu-ram transfers and image processing 
speed on cpu. If you can process your image on gpu i'd stick with that and skip 
cpu processing altogether. Transfers gpu-ram not so fast in any case, though 
pbo usage can help hide latency.

Cheers,
Sergey.

01.07.2011, 19:49, aaron wetzler aaronwetz...@gmail.com:
 Hi Sergey

 I would like to understand exactly how the graphics pipeline works and am 
 struggling to figure this out by digging through the code (are there free 
 books that deal with OSG and its implementation details in-depth? I dont mean 
 the QSG by Paul Martz...). Also, my understanding of OpenGL is lacking in 
 some places especially in implementation details so perhaps this will help 
 clear things up for me.

 In the prerender example we have something like this:

 0: camera-setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
 1: camera-attach(osg::Camera::BufferComponent(osg::Camera::COLOR_BUFFER0), 
 image);
 2: camera-setPostDrawCallback(new MyCameraPostDrawCallback(image));
 3: textureRect[tex_to_get]-setImage(0, image);

 As far as I understand this works as follows

 0: This generates an FBO which has no data storage until I attach data 
 storage to it (next step) ? Is this true? What happens then when I attach a 
 color attachment but dont attach a depth buffer attachment? Does OSG 
 automatically generate one for me? I ask because in regular OpenGL when you 
 dont attach a depth attachment to an FBO then rendering to the FBO using 
 glEnable(GL_DEPTH_TEST) produces incorrect results...

 1: The image attached to the camera is the data storage for the FBO created 
 in step 0. If this is the case then it means the FBO sits in RAM and not on 
 the GPU. Is that true?

 2:Here we set a post render callback using the image as our input. As far as 
 I understand this means that the image (which is sitting in RAM) is edited in 
 place. That means that as long as we dont need the data for actual rendering 
 then we are being efficient because we dont copy to the GPU. Which brings up 
 the next line...

 3: We specify that a texture has the image as its image. I dont entirely 
 understand what this means. When we create the original texture then OpenGL 
 allocates space on the GPU for that texture. By using setImage(0,image) then 
 does that mean that whatever is in that image (which sits on RAM) must always 
 be copied to the GPU texture  before the texture can be used at render time?

 All in all I feel quite confused and would like to understand how to do the 
 above process efficiently.
 Ideally I would like to : pass dynamic geometry to the GPU every frame and 
 have that rendered to textures inside the GPU. Occassionally I would like to 
 ask the GPU to send the RTT textures back to the CPU, update them on the CPU 
 and then send them back to the GPU.
 How should I be doing that in the most efficient way possible?

 Thank you!

 Cheers,
 aaron

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

 ___
 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] render depth buffer to image for one time

2011-06-27 Thread aaron wetzler
SOLUTION


For anyone who struggled with this here is my solution.
I really have no idea how correct it is but it works for me


Code:
  //Setup of the viewer and scenedata here

   osg::ref_ptrosg::Camera  osgCam = viewer.getCamera(); 

   osg::ref_ptrosg::Image   colorImage= new osg::Image; 
   osg::ref_ptrosg::Image   zImage = new osg::Image; 

   colorImage-allocateImage(1024, 768, 1, GL_RGBA, GL_UNSIGNED_BYTE); 
   zImage-allocateImage(1024, 768, 1, GL_DEPTH_COMPONENT , GL_UNSIGNED_BYTE); 

   osgCam-attach(osg::Camera::COLOR_BUFFER, colorImage.get()); 
   osgCam-attach(osg::Camera::DEPTH_BUFFER, zImage.get()); /* */ 

   viewer.frame();  

   Sleep(100);
   osgDB::writeImageFile(*colorImage.get(),color.bmp); 
   osgDB::writeImageFile(*zImage.get(),depth.bmp); 





Cheers,
aaron

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





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


Re: [osg-users] render depth buffer to image for one time

2011-06-27 Thread Sergey Polischuk
Hi, Aaron

If you set singlethreaded mode and stop threading on viewer you can skip 
Sleep() step.
Used same thing couple of times :)

Cheers, Sergey.

27.06.2011, 20:11, aaron wetzler aaronwetz...@gmail.com:
 SOLUTION

 For anyone who struggled with this here is my solution.
 I really have no idea how correct it is but it works for me

 Code:
   //Setup of the viewer and scenedata here

    osg::ref_ptrosg::Camera  osgCam = viewer.getCamera();

    osg::ref_ptrosg::Image   colorImage= new osg::Image;
    osg::ref_ptrosg::Image   zImage = new osg::Image;

    colorImage-allocateImage(1024, 768, 1, GL_RGBA, GL_UNSIGNED_BYTE);
    zImage-allocateImage(1024, 768, 1, GL_DEPTH_COMPONENT , GL_UNSIGNED_BYTE);

    osgCam-attach(osg::Camera::COLOR_BUFFER, colorImage.get());
    osgCam-attach(osg::Camera::DEPTH_BUFFER, zImage.get()); /* */

    viewer.frame();

    Sleep(100);
    osgDB::writeImageFile(*colorImage.get(),color.bmp);
    osgDB::writeImageFile(*zImage.get(),depth.bmp);

 Cheers,
 aaron

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

 ___
 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] render depth buffer to image for one time

2011-06-27 Thread Robert Osfield
Hi Aaron,

Is there any reason why an osg::Camera FinalDrawCallback wouldn't work
fine for handling the writes when required?  This would work fine for
multi-threaded usage and any length of time the the rendering would
take.

Robert.

On Mon, Jun 27, 2011 at 5:11 PM, aaron wetzler aaronwetz...@gmail.com wrote:
 SOLUTION


 For anyone who struggled with this here is my solution.
 I really have no idea how correct it is but it works for me


 Code:
  //Setup of the viewer and scenedata here

   osg::ref_ptrosg::Camera  osgCam = viewer.getCamera();

   osg::ref_ptrosg::Image   colorImage= new osg::Image;
   osg::ref_ptrosg::Image   zImage = new osg::Image;

   colorImage-allocateImage(1024, 768, 1, GL_RGBA, GL_UNSIGNED_BYTE);
   zImage-allocateImage(1024, 768, 1, GL_DEPTH_COMPONENT , GL_UNSIGNED_BYTE);

   osgCam-attach(osg::Camera::COLOR_BUFFER, colorImage.get());
   osgCam-attach(osg::Camera::DEPTH_BUFFER, zImage.get()); /* */

   viewer.frame();

   Sleep(100);
   osgDB::writeImageFile(*colorImage.get(),color.bmp);
   osgDB::writeImageFile(*zImage.get(),depth.bmp);





 Cheers,
 aaron

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





 ___
 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] render depth buffer to image for one time

2011-06-27 Thread aaron wetzler
Thanks hybr and robertosfield for your comments. Both useful and I will use 
those tips.

Although my solution does work its not enough and Im now stuck on a couple of 
things. If you could point me in the right direction or to the right links that 
would be great

1)How do I render the depth image to the screen instead of rendering the color 
buffer? 
Whats the name of the function that lets me define which buffer I want rendered 
to the screen (or FBO for that matter)

2) I actually want to invert my depth image and edit its values. How do I do 
that before writing the image?

3) The dimensions I put in the allocateImage call i.e. (1024, 768)  have no 
effect on the size of the written image. How can I change that?


Looking forward to hearing from you

Aaron

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





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


Re: [osg-users] render depth buffer to image for one time

2011-06-27 Thread Sergey Polischuk
Hi, Aaron.

1) You can render scene depth to texture(using additional camera), then render 
screen aligned quad with this texture on screen. Or you can use osgPPU nodekit 
to do this, in this case you will need to make pipeline of two units: 
UnitDepthBufferBypass and UnitOut (iirc)

2) You have two options: first you can work with raw data in your image before 
writing (there are interfaces to pointer to raw data), second - you can 
preprocess it with shaders (again, using osgPPU (add one UnitInOut with correct 
shader between two mentioned earlier) or add shader that will process data when 
drawing screen aligned quad mentioned earlier)

3) iirc image will resize if it is not large enough to capture entire 
window(with framebuffer rendering) or viewport (with fbo rendering) so you may 
need to setup your window correctly or create camera that render to fbo with 
correct dimensions and use it for image capture.

Cheers,
Sergey.

28.06.2011, 01:55, aaron wetzler aaronwetz...@gmail.com:
 Thanks hybr and robertosfield for your comments. Both useful and I will use 
 those tips.

 Although my solution does work its not enough and Im now stuck on a couple of 
 things. If you could point me in the right direction or to the right links 
 that would be great

 1)How do I render the depth image to the screen instead of rendering the 
 color buffer?
 Whats the name of the function that lets me define which buffer I want 
 rendered to the screen (or FBO for that matter)

 2) I actually want to invert my depth image and edit its values. How do I do 
 that before writing the image?

 3) The dimensions I put in the allocateImage call i.e. (1024, 768)  have no 
 effect on the size of the written image. How can I change that?

 Looking forward to hearing from you

 Aaron

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

 ___
 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] render depth buffer to image for one time

2009-05-18 Thread Maxime BOUCHER
Alright, for whom it may concerns, it's all in the GraphicsContext especially 
in the pixel buffer.

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





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


Re: [osg-users] render depth buffer to image for one time

2009-05-18 Thread Maxime BOUCHER
Hi,

Please excuse all my spam...
I tried the almost same code than mister Jojo.
I tried 2 instances:
-One using a created camera diffrent from the viewer's one.
-The other using the viewer's camera.

In the first case, I can grab the color image, but the camera isn't oriented at 
all as I tell it to (bad bad camera).
In the second case I got nothing.

Thus, I guess the only solution is using the viewer, isn't it?
If you have nice documentation about the viewer, please, let me know!

Thank you!

Cheers,
Maxime

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





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


Re: [osg-users] render depth buffer to image for one time

2009-05-15 Thread Maxime BOUCHER
Hi!


jojo wrote:
 As I understand, the command camera-attach(osg::Camera::COLOR_BUFFER, 
 depth.get(),0,0); tells osg, that I want the color buffer of the camera to be 
 stored in the image depth. This works, but when I change it to 
 camera-attach(osg::Camera::DEPTH_BUFFER, depth.get(),0,0); I get the same 
 result. A colored picture.
 
 Regards,
 jojo


I've read your post with great interest!
I work with the COLOR_BUFFER (for now...) and I've a question for you.
I tried to reproduce your code in mine (thus I don't exactly do the same 
things) and it seems my _depth image (that I use to store colors...) is 
initialized at allocationImage but the buffer data is never refreshed.
I tried:

Code:

_depth-allocateImage(vec-x(), vec-y(), 1, GL_COLOR, GL_INT);



and

Code:
 
_depth-allocateImage(vec-x(), vec-y(), 1, GL_RGBA, GL_INT);


Is there any instruction to do that that I skiped?

Thanks!


Max

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





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


Re: [osg-users] render depth buffer to image for one time

2009-05-15 Thread Johannes Leidheiser
Hi Max,
I think you should use _depth-allocateImage(vec-x(), vec-y(), 1, GL_RGBA, 
GL_UNSIGNED_BYTE); instead of GL_INT because the color buffer of your graphics 
card has 8 bit per color channel. 

Regards,
jojo

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





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


Re: [osg-users] render depth buffer to image for one time

2009-05-15 Thread Maxime BOUCHER
Thanks.
I tried but it does'nt change the results.

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





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


Re: [osg-users] render depth buffer to image for one time

2009-05-15 Thread Raymond de Vries

Hi,

I think you should use GL_LUMINANCE instead of GL_RGBA too.

Best regards
Raymond


Johannes Leidheiser wrote:

Hi Max,
I think you should use _depth-allocateImage(vec-x(), vec-y(), 1, GL_RGBA, GL_UNSIGNED_BYTE); instead of GL_INT because the color buffer of your graphics card has 8 bit per color channel. 


Regards,
jojo

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





___
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] render depth buffer to image for one time

2009-05-15 Thread Johannes Leidheiser
GL_LUMINANCE is for gray scale images. For example if you want to save the 
depth buffer.
Besides you should post a little bit more code. I don't know how much 
experience your have with open scene graph. Maybe you didn't call the frame() 
method of your viewer, the camera is not attached to a node or maybe there is 
just nothing to see in the viewing frustum?
Did you display the camera normaly which means with turned off offscreen 
rendering?

Regards,
Johannes

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





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


Re: [osg-users] render depth buffer to image for one time

2009-05-15 Thread Raymond de Vries

Hi Johannes,

Uhm, it's a little confusing who you are addressing with 'you'. You do 
that twice and I think you mean 2 different people...


Anyway, I was trying to help in another direction. I have indeed used 
GL_LUMINANCE for grabbing depth images. I guess I was mislead somehow by 
the subject of the message, as well as the lack of context because the 
history is not in the messages.


good luck
Raymond


Johannes Leidheiser wrote:

GL_LUMINANCE is for gray scale images. For example if you want to save the 
depth buffer.
Besides you should post a little bit more code. I don't know how much 
experience your have with open scene graph. Maybe you didn't call the frame() 
method of your viewer, the camera is not attached to a node or maybe there is 
just nothing to see in the viewing frustum?
Did you display the camera normaly which means with turned off offscreen 
rendering?

Regards,
Johannes

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





___
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] render depth buffer to image for one time

2009-05-15 Thread Maxime BOUCHER

jojo wrote:
 GL_LUMINANCE is for gray scale images. For example if you want to save the 
 depth buffer.


Ok, thus, I should use GL_RGBA.


jojo wrote:
 
 Besides you should post a little bit more code. I don't know how much 
 experience your have with open scene graph. Maybe you didn't call the frame() 
 method of your viewer, the camera is not attached to a node or maybe there is 
 just nothing to see in the viewing frustum?
 


My camera is attached to the root of the scene graph.
I retrieve the image during the rendering loop (it's true I didn't do it at 
first...), thus after 5 viewer.frame ('cause I setted it at 5).
There is something to see from my camera.


jojo wrote:
 
 Did you display the camera normaly which means with turned off offscreen 
 rendering?
 


However, I don't know what you mean here, it seems to be a key point...

I've read things about pre-render, but you don't do any, right?

Here's a bit of my code:

I create the camera:

Code:
ref_ptrCamera MyPTMutils::createCamera(Matrix cameraIntrinsic, Matrix 
cameraPosition)
{
// parameters for MyPTM
double width = cameraIntrinsic(0, 2)*2;
double height = cameraIntrinsic(1, 2)*2;
double fy = cameraIntrinsic(1, 1);

// create camera for MyPTM
ref_ptrCamera new_camera = new Camera();

new_camera-setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
new_camera-setViewport(0, 0, width, height);

new_camera-setProjectionMatrixAsPerspective((360./PI)*atan(height/(2*fy)) , 
(double)width/height, 1.0, 1000.0);
new_camera-setViewMatrix(Matrix::inverse(cameraPosition));

return (new_camera);
}



I modify the camera (I know this can seem strange out of the context):

Code:

MyPTM::MyPTM(Geode* _arg_geode, std::string imgpath , int _arg_textureUnit, 
float focal, Quat rotation, Vec3d position)
{
ref_ptrosg::Image img = osgDB::readImageFile(imgpath);
cu = img-s(); 
cv = img-t();
Vec2f *vec = new Vec2f(cu,cv);
MyPTMutils::setClosestPowerOfTwo(vec);

...

_camera = MyPTMutils::createCamera(cameraIntrinsic, transform);

_texture = new Texture2D(osgDB::readImageFile(imgpath));

_camera-setReferenceFrame(Transform::ABSOLUTE_RF);

_camera-setDataVariance(Object::DYNAMIC);

_depth = new Image();

_depth-allocateImage(vec-x(), vec-y(), 1, GL_RGBA, GL_UNSIGNED_BYTE);

_camera-attach(osg::Camera::COLOR_BUFFER, _depth.get(),0,0);





And the print:

Code:

float* bl = (float*)(_depth-data());
osgDB::writeImageFile(*_depth.get(),depth.png);




This makes me think: why a float* ?

And the main

Code:

MyPTM* myptm2 = new MyPTM((Geode*) (root-getChild(2)), 
../Media/Data_Calibrage/Image/IMG_5316_small.jpg, 0, 720.0, r, camposition);

myptm2-_camera-setView(viewer);

viewer.addSlave(myptm2-_camera.get());


viewer.setSceneData( root.get());
viewer.realize();

int once = 0;
while( !viewer.done() )
{
viewer.frame();
if (once == 50)
  myptm2-printDepthImage();
once++;
}




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





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


Re: [osg-users] render depth buffer to image for one time

2009-05-15 Thread Maxime BOUCHER
I forgot: thanks for everything!

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





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


Re: [osg-users] render depth buffer to image for one time

2009-05-01 Thread Johannes Leidheiser
As I understand, the command camera-attach(osg::Camera::COLOR_BUFFER, 
depth.get(),0,0); tells osg, that I want the color buffer of the camera to be 
stored in the image depth. This works, but when I change it to 
camera-attach(osg::Camera::DEPTH_BUFFER, depth.get(),0,0); I get the same 
result. A colored picture.

Regards,
jojo

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





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


Re: [osg-users] render depth buffer to image for one time

2009-05-01 Thread Johannes Leidheiser
Hi,
I tried to fix it a few more times, but I can't. It's working for color but not 
for the depth buffer.
When I execute the following code I get the variables texture2D and depth 
filled with white color. I draw the image and the texture on a rectangle.

Thanks for help,
jojo


Code:
osgViewer::Viewer* v = new osgViewer::Viewer;
v-setCameraManipulator(new osgGA::TrackballManipulator());
v-getCameraManipulator()-setHomePosition(getCameraPosition2(), 
getLookAtPoint(), getUpVector());
osg::ref_ptrosg::GraphicsContext::Traits traits = new 
osg::GraphicsContext::Traits;
traits-target = osg::Camera::FRAME_BUFFER_OBJECT;
traits-x =0;
traits-y = 0;
traits-width = 720;
traits-height = 576;
traits-windowDecoration = false;
traits-doubleBuffer = false;
traits-sharedContext = 0;
traits-pbuffer = true;

osg::GraphicsContext* _gc= 
osg::GraphicsContext::createGraphicsContext(traits.get());

v-getCamera()-setGraphicsContext(_gc);

osg::Camera* camera = v-getCamera();

camera-setViewport(new osg::Viewport(0,0,720,576));
double fovy, aspectRatio, zNear, zFar;
camera-getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar);
std::cout fovy aspectRatiozNear zFar\n;
fovy+=41.0;
camera-setProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar);
std::cout fovy aspectRatiozNear zFar\n;
v-setSceneData(osgDB::readNodeFile(Scene1.osg));
v-setDataVariance(osg::Object::DYNAMIC);
v-setThreadingModel(osgViewer::Viewer::SingleThreaded);
v-realize();
osg::ref_ptrosg::Image depth = new osg::Image;
osg::ref_ptrosg::Image color = new osg::Image;
color-allocateImage(720, 576, 1, GL_RGBA, GL_UNSIGNED_BYTE);
depth-allocateImage(720, 576, 1, GL_DEPTH_COMPONENT, GL_FLOAT);
camera-attach(osg::Camera::COLOR_BUFFER, color.get());
camera-attach(osg::Camera::DEPTH_BUFFER, depth.get());

osg::ref_ptrosg::Texture2D texture2D = new osg::Texture2D;
texture2D-setTextureSize(720, 576);
texture2D-setInternalFormat(GL_DEPTH_COMPONENT);
texture2D-setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR);
texture2D-setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);

camera-attach(osg::Camera::DEPTH_BUFFER, texture2D.get(), 0, 0, false);

//camera-attach(osg::Camera::DEPTH_BUFFER, depth.get(),0,0);


v-frame();



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





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


Re: [osg-users] render depth buffer to image for one time

2009-04-30 Thread Paul Martz
depthReadP-readPixels(0,0,719,575, GL_RGB ,GL_UNSIGNED_BYTE);

Shouldn't the type be GL_DEPTH instead of GL_RGB? I think you can find this
info under glReadPixels in the OpenGL blue book.

Paul Martz
Skew Matrix Software LLC
http://www.skew-matrix.com
+1 303 859 9466

-Original Message-
From: osg-users-boun...@lists.openscenegraph.org
[mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of Johannes
Leidheiser
Sent: Thursday, April 30, 2009 2:38 PM
To: osg-users@lists.openscenegraph.org
Subject: [osg-users] render depth buffer to image for one time


Hi,
for my current project I need to render the depth buffer of a scene off
screen into a texture or an image. During the last few days I tried to solve
it but I couldn't get a good result. I got it work to render the color
buffer into an image, but I need the depth buffer. In the following code I
tried different ways to solve the problem, so it's a little bit mixed. Maybe
somebody can give me a hint? I think I'm not far away from the solution.

Thank you in advance,
Jojo


Code:
osg::Image* renderToImage()
{
osgViewer::Viewer* v = new osgViewer::Viewer;
v-setCameraManipulator(new osgGA::TrackballManipulator());
v-getCameraManipulator()-setHomePosition(getCameraPosition2(),
getLookAtPoint(), getUpVector());
osg::ref_ptrosg::GraphicsContext::Traits traits = new
osg::GraphicsContext::Traits;
traits-x =0;
traits-y = 0;
traits-width = 720;
traits-height = 576;
traits-windowDecoration = false;
traits-doubleBuffer = false;
traits-sharedContext = 0;
traits-pbuffer = true;

osg::GraphicsContext* _gc=
osg::GraphicsContext::createGraphicsContext(traits.get());

osg::Camera* camera = v-getCamera();
camera-setGraphicsContext(_gc);
camera-setViewport(new osg::Viewport(0,0,720,576));
double fovy, aspectRatio, zNear, zFar;
camera-getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear,
zFar);
std::cout fovy aspectRatiozNear
zFar\n;
fovy+=41.0;
camera-setProjectionMatrixAsPerspective(fovy, aspectRatio, zNear,
zFar);
std::cout fovy aspectRatiozNear
zFar\n;
//camera-setViewMatrixAsLookAt(getCameraPosition2(),
getLookAtPoint(), getUpVector());
v-setSceneData(osgDB::readNodeFile(Scene1.osg));
v-setDataVariance(osg::Object::DYNAMIC);
v-setThreadingModel(osgViewer::Viewer::SingleThreaded);
v-realize();
osg::ref_ptrosg::Image depth = new osg::Image;
//depth-allocateImage(720, 576, 1, GL_LUMINANCE, GL_UNSIGNED_BYTE);

camera-attach(osg::Camera::DEPTH_BUFFER, depth.get(),0,0);

v-frame();

float* bl =(float*)depth-data();
for(int i=0; i  1; i++)
std::cout Depth:   bl[i]\n;
osgDB::writeImageFile(*depth.get(),depth.png);
osg::ref_ptrosg::Image depthReadP = new osg::Image;
depthReadP-readPixels(0,0,719,575, GL_RGB ,GL_UNSIGNED_BYTE);
osgDB::writeImageFile(*depthReadP.get(),depthReadP.png);

delete v;
osg::notify(osg::NOTICE)Successstd::endl;
return new osg::Image();

}


[/code]

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





___
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] render depth buffer to image for one time

2009-04-30 Thread Paul Martz
In my previous post, that should be GL_DEPTH_COMPONENT, sorry.

Paul Martz
Skew Matrix Software LLC
http://www.skew-matrix.com
+1 303 859 9466

-Original Message-
From: osg-users-boun...@lists.openscenegraph.org
[mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of Johannes
Leidheiser
Sent: Thursday, April 30, 2009 2:38 PM
To: osg-users@lists.openscenegraph.org
Subject: [osg-users] render depth buffer to image for one time


Hi,
for my current project I need to render the depth buffer of a scene off
screen into a texture or an image. During the last few days I tried to solve
it but I couldn't get a good result. I got it work to render the color
buffer into an image, but I need the depth buffer. In the following code I
tried different ways to solve the problem, so it's a little bit mixed. Maybe
somebody can give me a hint? I think I'm not far away from the solution.

Thank you in advance,
Jojo


Code:
osg::Image* renderToImage()
{
osgViewer::Viewer* v = new osgViewer::Viewer;
v-setCameraManipulator(new osgGA::TrackballManipulator());
v-getCameraManipulator()-setHomePosition(getCameraPosition2(),
getLookAtPoint(), getUpVector());
osg::ref_ptrosg::GraphicsContext::Traits traits = new
osg::GraphicsContext::Traits;
traits-x =0;
traits-y = 0;
traits-width = 720;
traits-height = 576;
traits-windowDecoration = false;
traits-doubleBuffer = false;
traits-sharedContext = 0;
traits-pbuffer = true;

osg::GraphicsContext* _gc=
osg::GraphicsContext::createGraphicsContext(traits.get());

osg::Camera* camera = v-getCamera();
camera-setGraphicsContext(_gc);
camera-setViewport(new osg::Viewport(0,0,720,576));
double fovy, aspectRatio, zNear, zFar;
camera-getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear,
zFar);
std::cout fovy aspectRatiozNear
zFar\n;
fovy+=41.0;
camera-setProjectionMatrixAsPerspective(fovy, aspectRatio, zNear,
zFar);
std::cout fovy aspectRatiozNear
zFar\n;
//camera-setViewMatrixAsLookAt(getCameraPosition2(),
getLookAtPoint(), getUpVector());
v-setSceneData(osgDB::readNodeFile(Scene1.osg));
v-setDataVariance(osg::Object::DYNAMIC);
v-setThreadingModel(osgViewer::Viewer::SingleThreaded);
v-realize();
osg::ref_ptrosg::Image depth = new osg::Image;
//depth-allocateImage(720, 576, 1, GL_LUMINANCE, GL_UNSIGNED_BYTE);

camera-attach(osg::Camera::DEPTH_BUFFER, depth.get(),0,0);

v-frame();

float* bl =(float*)depth-data();
for(int i=0; i  1; i++)
std::cout Depth:   bl[i]\n;
osgDB::writeImageFile(*depth.get(),depth.png);
osg::ref_ptrosg::Image depthReadP = new osg::Image;
depthReadP-readPixels(0,0,719,575, GL_RGB ,GL_UNSIGNED_BYTE);
osgDB::writeImageFile(*depthReadP.get(),depthReadP.png);

delete v;
osg::notify(osg::NOTICE)Successstd::endl;
return new osg::Image();

}


[/code]

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





___
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] render depth buffer to image for one time

2009-04-30 Thread Johannes Leidheiser
Hi Paul,
you are right, I only used that for testing. But also with GL_DEPTH_COMPONENT 
it doesn't work. In my experience the readPixel command doesn't work for of 
screen rendering?!

I would prefer the version with the variable depth which is attached to the 
camera.

In my first post I forgot to say that I still use version 2.6 of osg.

Regards,
jojo

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





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


Re: [osg-users] render depth buffer to image for one time

2009-04-30 Thread Paul Martz
I'm not sure why the code you posted doesn't work.

When I want to read the screen (color, depth, whatever), I use a post draw
callback attached to the Camera. This should work whether your framebuffer
is a window or an FBO.

Paul Martz
Skew Matrix Software LLC
http://www.skew-matrix.com
+1 303 859 9466

-Original Message-
From: osg-users-boun...@lists.openscenegraph.org
[mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of Johannes
Leidheiser
Sent: Thursday, April 30, 2009 3:30 PM
To: osg-users@lists.openscenegraph.org
Subject: Re: [osg-users] render depth buffer to image for one time

Hi Paul,
you are right, I only used that for testing. But also with
GL_DEPTH_COMPONENT it doesn't work. In my experience the readPixel command
doesn't work for of screen rendering?!

I would prefer the version with the variable depth which is attached to the
camera.

In my first post I forgot to say that I still use version 2.6 of osg.

Regards,
jojo

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





___
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