361 363














Open GL Super Bible:Raster Graphics in OpenGL
















To access the contents, click the chapter and section titles.


Open GL Super Bible


(Publisher: Macmillan Computer Publishing)

Author(s): Waite group Press

ISBN: 1571690735

Publication Date: 08/01/96

 




Previous
Table of Contents
Next




Copying Pixmaps
OpenGL also provides a function to copy an area on the screen to another locationas needed, for instance, in scrolling or “magnifying glass" views:


int mousex, mousey;

glReadBuffer(GL_FRONT);
glDrawBuffer(GL_FRONT);
glPixelZoom(2.0, 2.0);
glRasterPos2i(0, 0);
glCopyPixels(mousex - 8, mousey - 8, 16, 16, GL_COLOR);

Here the glCopyPixels function copies pixels from the given location to the current raster position:


void glCopyPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum
type)

The x and y parameters specify the lower-left corner of the area to be copied. Width and height specify the size of the image to be copied. Pixels are copied from the specified (x,y) location to the current raster position. The type argument specifies which values are to be copied. For most applications, the pixel type is GL_COLOR to copy color indices or RGB values.

Pixel zoom is applied to the output pixels but not to the input pixels. In the example just above, a 16 x 16-pixel image will be copied to the lower-left corner of the window and scaled to 32 x 32 pixels. Offsets and sizes specified with calls to glPixelStore do not affect glCopyPixels. Changes made with glPixelTransfer and glPixelMap do, however.
A Bitmap File Viewer
Now that wełve covered all the bitmap-related functions that are available, letłs write a Windows .BMP file-viewing program using OpenGL. Our goals for this program are fairly straightforward:


•  Load any Windows .BMP file
•  Scale the image to the current window size
•  Provide simple controls to change the image brightness and gamma correction
•  Show a magnified view of the image underneath the mouse pointer
•  Save the displayed image to disk
•  Print
the displayed image

The final code for this program can be found in CH11\OGLVIEW.C.

About Windows Bitmap Files
Before we write the code, letłs review the ubiquitous Windows bitmap format. Despite their limitations, Windows .BMP files are probably the most common and widely supported files used by PCs capable of from 2 to 16.7 million colors. With only a few exceptions, .BMP files do not utilize data compression schemes, so itłs easy to read and use these files in your OpenGL programs.

A .BMP file is organized into three or four sections, depending on the type of colors used (see Figure 11-3). All .BMP files start with a BITMAPFILEHEADER structure containing an identification string (“BM") the total size of the file, and an offset to the actual image data. Here is that structure:

typedef struct
{
WORD bfType; /* “BM" */
DWORD bfSize; /* Size of file in bytes */
WORD bfReserved1; /* Reserved, always 0 */
WORD bfReserved2; /* Reserved, always 0 */
DWORD bfOffBits; /* Offset to image in bytes */
} BITMAPFILEHEADER;


Figure 11-3  Organization of a .BMP file
Following the file header is a BITMAPINFOHEADER structure that describes the contents of the image, as follows:


typedef struct
{
DWORD biSize; /* Size of BITMAPINFOHEADER in bytes */
LONG biWidth; /* Width of image in pixels */
LONG biHeight; /* Height of image in pixels */
WORD biPlanes; /* # of color planes (always 1) */
WORD biBitCount; /* # of color bits */
DWORD biCompression; /* Type of compression used */
DWORD biSizeImage; /* Size of the image in bytes */
LONG biXPelsPerMeter; /* Horizontal pixels per meter */
LONG biYPelsPerMeter; /* Vertical pixels per meter */
DWORD biClrUsed; /* Number of color used */
DWORD biClrImportant; /* Number of 'importantł colors */
} BITMAPINFOHEADER;

For color index (palette) images, a color palette follows the BITMAPINFOHEADER structure for every color in the image. Image data follows immediately after.




Previous
Table of Contents
Next














 


Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.












Wyszukiwarka

Podobne podstrony:
363 Wykup środka trwałego po zakończeniu trwania umowy leasingu finansowego
FRFU 42 361
360 361
363 06
359 363 6v4nwcjnb4dbnstjd3npiah3dmipkvb5oncshxa
361 06
363 ind
363,23,artykul
361 08
363 00
13 (363)

więcej podobnych podstron