CodeGuru
Earthweb Search
Forums Wireless Jars Gamelan Developer.com
CodeGuru Navigation
Member Sign In
User ID:
Password:
Remember Me:
Forgot Password?
Not a member?
Click here for more information and to register.

jobs.internet.com

internet.commerce
Partners & Affiliates
Memory Upgrades
Laptops
Car Donations
Imprinted Promotions
Online Education
Best Price
Logo Design
KVM over IP
Phone Cards
Disney World Tickets
Promotional Items
Corporate Gifts
Computer Deals
Boat Donations


RSS Feeds

RSSAll

RSSVC++/C++

RSS.NET/C#

RSSVB

See more EarthWeb Network feeds

Home >> Visual C++ / C++ >> Graphics & Multimedia >> OpenGL

Looking for ways to overcome project jams? Discover strategies for becoming a better project manager. Download Exclusive eBook Now.

How to snap an OpenGL client and send it to the clipboard
Rating: none

Pierre Alliez (view profile)
August 10, 1999


(continued)



Turbo Screen Sharing
Adobe Acrobat Connect Professional offers users the ability to have a more productive and engaging web conferencing experience while providing the IT department with a program that efficiently utilizes bandwidth and minimally impacts the infrastructure. Learn More! »

Informal Learning: Extending the Impact of Enterprise Ideas and Information
Forward-thinking organizations are turning to enterprise learning in their quest to be better informed, better skilled, better supported at the point of need, and more competitive in their respective marketplaces. Learn More! »

Rapid E-Learning: Maturing Technology Brings Balance and Possibilities
Rapid e-learning addresses both time and cost issues by using technology tools to shift the dynamics of e-learning development. Learn why more skilled learning professionals use these tools and how you can get a solution to keep pace with your business demands. »

Delivering on the Promise of ELearning
This white paper defines the framework to launch e-learning as a set of teaching, training, and learning practices not bound by a specific technology platform or learning management system. It offers practical suggestions for creating digital learning experiences that engage learners by building interest and motivation and providing opportunities for active participation. »

This article demonstrates how to snap an OpenGL client and send it to ClipBoard.
We suppose your screen configuration is set to true color.
We could send the same buffer in a .bmp file in a few lines too....

// Snap OpenGL client and send it to ClipBoard
// so that you can insert it in your favorite
// image editor, Powerpoint, etc...
// Replace CRenderView by your own CView-derived class
void CRenderView::SnapClient()
{
 BeginWaitCursor();

 // Get client geometry
 CRect rect;
 GetClientRect(&rect);
 CSize size(rect.Width(),rect.Height());
 TRACE("  client zone : (%d;%d)\n",size.cx,size.cy);
 // Lines have to be 32 bytes aligned, suppose 24 bits per pixel
 // I just cropped it
 size.cx -= size.cx % 4;
 TRACE("  final client zone : (%d;%d)\n",size.cx,size.cy);

 // Create a bitmap and select it in the device context
 // Note that this will never be used ;-) but no matter
 CBitmap bitmap;
 CDC *pDC = GetDC();
 CDC MemDC;
 ASSERT(MemDC.CreateCompatibleDC(NULL));
 ASSERT(bitmap.CreateCompatibleBitmap(pDC,size.cx,size.cy));
 MemDC.SelectObject(&bitmap);

 // Alloc pixel bytes
 int NbBytes = 3 * size.cx * size.cy;
 unsigned char *pPixelData = new unsigned char[NbBytes];

 // Copy from OpenGL
 ::glReadPixels(0,0,size.cx,size.cy,GL_RGB,GL_UNSIGNED_BYTE,pPixelData);

 // Fill header
 BITMAPINFOHEADER header;
 header.biWidth = size.cx;
 header.biHeight = size.cy;
 header.biSizeImage = NbBytes;
 header.biSize = 40;
 header.biPlanes = 1;
 header.biBitCount =  3 * 8; // RGB
 header.biCompression = 0;
 header.biXPelsPerMeter = 0;
 header.biYPelsPerMeter = 0;
 header.biClrUsed = 0;
 header.biClrImportant = 0;

 // Generate handle
 HANDLE handle = (HANDLE)::GlobalAlloc (GHND,sizeof(BITMAPINFOHEADER) + NbBytes);
 if(handle != NULL)
 {
  // Lock handle
  char *pData = (char *) ::GlobalLock((HGLOBAL)handle);
  // Copy header and data
  memcpy(pData,&header,sizeof(BITMAPINFOHEADER));
  memcpy(pData+sizeof(BITMAPINFOHEADER),pPixelData,NbBytes);
  // Unlock
  ::GlobalUnlock((HGLOBAL)handle);

  // Push DIB in clipboard
  OpenClipboard();
  EmptyClipboard();
  SetClipboardData(CF_DIB,handle);
  CloseClipboard();
 }

 // Cleanup
 MemDC.DeleteDC();
 bitmap.DeleteObject();
 delete [] pPixelData;

 EndWaitCursor();
}
 
 

Tools:
Add www.codeguru.com to your favorites
Add www.codeguru.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed

Is it time to make your move to the multi-threaded and parallel processing world? Find out!
Best Practices for Developing a Web Site. Checklists, Tips & Strategies. Download Exclusive eBook Now.
Intel Go Parallel Portal: Translating Multicore Power into Application Performance. Learn more.
Becoming a Better Project Manager. Checklists, Tips & Strategies. Download Exclusive eBook Now.
Improve How You Manage Information: Becoming a Better Project Manager. Exclusive eBook - Download Now.


RATE THIS ARTICLE:   Excellent  Very Good  Average  Below Average  Poor  

(You must be signed in to rank an article. Not a member? Click here to register)

Latest Comments:
Gray box, still. - Legacy CodeGuru (10/20/2003)
How to snap OpenGL Image and Save it to *.bmp IN MSVC 6.0 - Legacy CodeGuru (05/17/2003)
How can I save a graphic as a JPG file? - Legacy CodeGuru (10/17/2002)
How can I capture screen into OpenGL? - Legacy CodeGuru (02/21/2002)
Here's how to do it without truncating the image - Legacy CodeGuru (02/04/2002)

View All Comments
Add a Comment:
Title:
Comment:
Pre-Formatted: Check this if you want the text to display with the formatting as typed (good for source code)



(You must be signed in to comment on an article. Not a member? Click here to register)


JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers