http://developer.hoops3d.com
  OpenGL Specific Issues
  OpenGL Frame buffer capture

Post New Topic  Post A Reply
profile | register | preferences | faq | search

UBBFriend: Email This Page to Someone! next newest topic | next oldest topic
Author Topic:   OpenGL Frame buffer capture
GnomeUK
Junior Member
posted March 10, 2006 06:06 AM     Click Here to See the Profile for GnomeUK   Click Here to Email GnomeUK     Edit/Delete Message   Reply w/Quote
I would like to capture the contents of the OpenGL frame buffer to save it to a file. The reason for this, is that using the hoops image driver we do not appear to get anti-aliasing! and I really need to save a picture of the final rendered image. Is there a way of doing this directly? glReadPixels always gives me back a blank screen!

IP: Logged

rmazeffa
Junior Member
posted April 17, 2006 02:25 PM     Click Here to See the Profile for rmazeffa     Edit/Delete Message   Reply w/Quote
There are 2 ways of achieving this depending on how strict your requirements are:

1. Obtaining the exact contents of the framebuffer

You can do this by using HOOPS IM to register a callback at the 'finish picture' callback point (see the IM documentation), and from within that callback, call glReadPixels to query the contents of the frame buffer. The reason your attempt at glReadPixels failed is most likely due to the fact that no current OpenGL context was active at the time of the call. However, an OGL context is active during the HOOPS immediate-mode rendering logic, which is what the various IM callbacks interrupt.


2. Using HOOPS to render to an offscreen OGL frame buffer, and querying that.

This is a little more elegent than #1 since it uses HOOPS' official offscreen OGL-rendering support, but because the 'virtual' offscreen OGL context might have different capabilities that the on-screen one, there is a risk of the image not exactly matching what is visible on-screen. Some sample code:

static const char* extra_pointer_format(void)
{
char buffer[4096];
sprintf (buffer, "%p", (void*) buffer);
if (buffer[0] == '0' && buffer[1] == 'x')
return "";
else
return "0x";
}

void create_ogl_based_image()
{
HC_KEY image_key;
char tempstr[1024];
int w = 1024, h = 1024;
char const *imageDriver = "?driver/opengl/image";


HC_Open_Segment("/my_image");
HC_Set_Visibility("off");
image_key = HC_KInsert_Image (0.0, 0.0, 0.0, "rgb, name = bnc", w, h, null);
HC_Close_Segment ();

HC_Open_Segment (imageDriver);
/* give the key to the image, let the driver know that the key is in fact an image */
sprintf (tempstr, "use window id = %s%p, debug = %d",
extra_pointer_format(), (void*)image_key,
Debug_USE_WINDOW_IS_IMAGE);

HC_Set_Driver_Options (tempstr);

/* the offscreen render should be isolated from the main window */
HC_Set_Driver_Options ("isolated, subscreen = (-1, 1, -1, 1)");

/* setup the desired rendering options, making sure the match the options in
the on-screen window */
HC_Set_Rendering_Options("hsra = hardware z buffer");
HC_Set_Window_Frame("off");

/* include the scene information
HC_Read_Metafile("bnc.hmf", ".", "");

HC_Update_One_Display (".");
HC_Close_Segment ();

/* the image now contains the scene and can be queried. We can now delete the driver */
HC_Delete_Segment (imageDriver);

HC_Update_Display ();

}

IP: Logged

All times are PT (US)

next newest topic | next oldest topic

Administrative Options: Close Topic | Archive/Move | Delete Topic
Post New Topic  Post A Reply
Hop to:

Contact Us | http://developer.hoops3d.com

Copyright©2004 Tech Soft America. All Rights Reserved.


Ultimate Bulletin Board 5.46