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
Interestingly enough, the Windows StretchBlt function can display bitmap images faster than glDrawPixels. Of course, StretchBlt cannot perform the glPixelMap and glPixelTransfer functions, though.
The final code for the RepaintWindow function is in Listing 11-12.
Listing 11-12 RepaintWindow function
void
RepaintWindow(RECT *rect) /* I - Client area rectangle */
{
GLint xoffset, /* X offset of image */
yoffset; /* Y offset of image */
GLint xsize, /* X size of scaled image */
ysize; /* Y size of scaled image */
GLfloat xscale, /* Scaling in X direction */
yscale; /* Scaling in Y direction */
/*
* Reset the viewport and clear the window to white
*/
glViewport(0, 0, rect->right, rect->bottom);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, rect->right - 1.0, 0.0, rect->bottom - 1.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glClearColor(1.0, 1.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
/*
* If we have loaded a bitmap image, scale it to fit the window
*/
if (BitmapBits != NULL)
{
xsize = rect->right;
ysize = BitmapInfo->bmiHeader.biHeight * xsize /
BitmapInfo->bmiHeader.biWidth;
if (ysize > rect->bottom)
{
ysize = rect->bottom;
xsize = BitmapInfo->bmiHeader.biWidth * ysize /
BitmapInfo->bmiHeader.biHeight;
};
xscale = (float)xsize / (float)BitmapInfo->bmiHeader.biWidth;
yscale = (float)ysize / (float)BitmapInfo->bmiHeader.biHeight;
xoffset = (rect->right - xsize) * 0.5;
yoffset = (rect->bottom - ysize) * 0.5;
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glPixelZoom(xscale, yscale);
glRasterPos2i(xoffset, yoffset);
glDrawPixels(BitmapInfo->bmiHeader.biWidth,
BitmapInfo->bmiHeader.biHeight,
GL_RGB, GL_UNSIGNED_BYTE, BitmapBits);
};
glFinish();
}
Summary
In this chapter you have learned about most of the OpenGL bitmap functions. Beyond the simple application of character fonts, bitmaps can be full-color images for window backgrounds or texture images (explored in the chapter coming up). OpenGL functions such as glPixelMap, glPixelTransfer, and glPixelZoom can be used for special effects, as well.
Reference Section
glCopyPixels
Purpose
Copies a rectangular block of pixels in the frame buffer.
Include File
<GL/gl.h>
Syntax
void glCopyPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum type);
Description
This function copies pixel data from the indicated area in the framebuffer to the current raster position. Use glRasterPos to set the current raster position. If the current raster position is not valid, then no pixel data is copied.
Calls to glPixelMap, glPixelTransfer, and
glPixelZoom affect the operation of glCopyPixels, as indicated in their
pages in this Reference Section.
Parameters
x
GLint: The lower-left corner window horizontal coordinate.
y
GLint: The lower-left corner window vertical coordinate.
width
GLsizei: The width of the image in pixels.
height
GLsizei: The height of the image in pixels. If negative, the image is drawn from top to bottom. By default, images are drawn bottom to top.
type
GLenum: The type of pixel values to be copied.
Valid types are as follows:
GL_COLOR
Color buffer values
GL_STENCIL
Stencil buffer values
GL_DEPTH
Depth buffer values
Returns
None.
Example
See the example in CH11\OGLVIEW.C.
See Also
glPixelMap, glPixelStore, glPixelTransfer,
glPixelZoom
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:
371 373373 377373 376372 373371 374371 374373 374373 376 2y6ernrrl7llggqrqhkgl7gq4x4c2niirkuh5yq01 (371)371 Reklamacja zużytych materiałów budowlanych uznana przez producenta10 (371)więcej podobnych podstron