Archive for November, 2007

Page 426 (Free web hosting services) OpenGL Super Bible! glDrawPixels Purpose Draws

Friday, November 30th, 2007

Page 426 OpenGL Super Bible! glDrawPixels Purpose Draws a block of pixels into the frame buffer. Include File Syntax void glDrawPixels(GLsizei width, GLsizei height, GLenum format, GLenum type, const Glvoid *pixels); Description This function copies pixel data from memory 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. Besides the format and type arguments, several other parameters define the encoding of pixel data in memory and control the processing of the pixel data before it is placed in the frame buffer. See the Reference Section pages for glPixelMap, glPixelStore, glPixelTransfer, and glPixelZoom. Parameters 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. format GLenum: The colorspace of the pixels to be drawn. Valid formats are as follows: GL_COLOR_INDEX Color index pixels GL_LUMINANCE Grayscale pixels GL_LUMINANCE_ALPHA Grayscale + alpha pixels (2 components) GL_RGB RGB pixels (3 components) GL_RGBA RGBA pixels (4 components) GL_RED Red pixels GL_GREEN Green pixels GL_BLUE Blue pixels GL_ALPHA Alpha pixels GL_STENCIL_INDEX Stencil buffer values GL_DEPTH_COMPONENT Depth buffer values type
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.

OpenGL Super Bible! Page 425 Reference Section glCopyPixels

Thursday, November 29th, 2007

OpenGL Super Bible! Page 425 Reference Section glCopyPixels Purpose Copies a rectangular block of pixels in the frame buffer. Include File 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 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 CH11OGLVIEW.C. See Also glPixelMap, glPixelStore, glPixelTransfer, glPixelZoom
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.

Page 424 OpenGL Super Bible! glPixelStorei(GL_UNPACK_ALIGNMENT, 4); glPixelZoom(xscale, (Dedicated web hosting)

Wednesday, November 28th, 2007

Page 424 OpenGL Super Bible! 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.
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.

OpenGL Super Bible! Page 423 Interestingly enough, the

Tuesday, November 27th, 2007

OpenGL Super Bible! Page 423 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;
We recommend cheap and reliable webhost to host and run your web applications: Coldfusion Web Hosting services.

Page 422 OpenGL Super Bible! DeleteObject(bitmap); DeleteObject(brush); DeleteObject(busy); (Post office web site)

Monday, November 26th, 2007

Page 422 OpenGL Super Bible! DeleteObject(bitmap); DeleteObject(brush); DeleteObject(busy); DeleteDC(hdc); /* * Restore the cursor and return */ SetCursor(oldcursor); return (1); } Displaying the Bitmap The OpenGL part of our example program begins with displaying the .BMP file. Like most OpenGL programs, this one starts out by setting the current viewport and viewing transformations. 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); After this, you draw the bitmap. Here we are scaling the image to fit the current window while maintaining a 1:1 aspect ratio. The following code should look very familiar you used it in the PrintDIBitmap function above: 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);
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check mysql web server services.

OpenGL Super Bible! Page 421 (X web hosting) busy = LoadCursor(NULL,

Saturday, November 24th, 2007

OpenGL Super Bible! Page 421 busy = LoadCursor(NULL, IDC_WAIT); oldcursor = SetCursor(busy); SetMapMode(pd.hDC, MM_TEXT); di.cbSize = sizeof(DOCINFO); di.lpszDocName = “OpenGL Image”; di.lpszOutput = NULL; StartDoc(pd.hDC, &di); StartPage(pd.hDC); /* * Clear the background to white */ rect.top = 0; rect.left = 0; rect.right = GetDeviceCaps(pd.hDC, HORZRES); rect.bottom = GetDeviceCaps(pd.hDC, VERTRES); brush = CreateSolidBrush(0×00ffffff); FillRect(pd.hDC, &rect, brush); /* * Stretch the bitmap to fit the page */ hdc = CreateCompatibleDC(pd.hDC); bitmap = CreateDIBitmap(hdc, &(info->bmiHeader), CBM_INIT, bits, info, DIB_RGB_COLORS); SelectObject(hdc, bitmap); xsize = rect.right; ysize = xsize * info->bmiHeader.biHeight / info- >bmiHeader.biWidth; if (ysize > rect.bottom) { ysize = rect.bottom; xsize = ysize * info->bmiHeader.biWidth / info- >bmiHeader.biHeight; }; xoffset = (rect.right - xsize) / 2; yoffset = (rect.bottom - ysize) / 2; StretchBlt(pd.hDC, xoffset, yoffset, xsize, ysize, hdc, 0, 0, info- >bmiHeader.biWidth, info->bmiHeader.biHeight, SRCCOPY); /* * That’s it. End the print job and free anything we allocated */ EndPage(pd.hDC); EndDoc(pd.hDC); DeleteDC(pd.hDC);
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.

Page 420 OpenGL (Free web hosting services) Super Bible! The offsets are

Friday, November 23rd, 2007

Page 420 OpenGL Super Bible! The offsets are computed by taking half of the difference of widths and heights: xoffset = (rect.right - xsize) / 2; yoffset = (rect.bottom - ysize) / 2; Normally you might pop up a busy printing dialog for the user, but in this case printing happens so fast it wouldn t be useful. The final code for the PrintDIBitmap function is in Listing 11-11. Listing 11-11 PrintDIBitmap function int PrintDIBitmap(HWND owner, /* I - Owner/parent window */ BITMAPINFO *info, /* I - Bitmap information */ void *bits) /* I - Bitmap pixel bits */ { PRINTDLG pd; /* Print dialog information */ long xsize, /* Size of printed image */ ysize, xoffset, /* Offset from edges for image */ yoffset; RECT rect; /* Page rectangle */ DOCINFO di; /* Document info */ HDC hdc; /* Device context for bitmap */ HBITMAP bitmap; /* Bitmap image */ HBRUSH brush; /* Background brush for page */ HCURSOR busy, /* Busy cursor */ oldcursor; /* Old cursor */ /* * Range check */ if (info == NULL || bits == NULL) return (0); /* * Initialize a PRINTDLG structure before displaying a standard Windows * print dialog */ memset(&pd, 0, sizeof(pd)); pd.lStructSize = sizeof(pd); pd.hwndOwner = owner; pd.Flags = PD_RETURNDC; pd.hInstance = NULL; if (!PrintDlg(&pd)) return (0); /* User chose ‘cancel’ */ /* * OK, user wants to print, so set the cursor to ‘busy’ and start the * print job */
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check mysql web server services.

OpenGL Super Bible! Page 419 Printing the Bitmap (Web site management)

Thursday, November 22nd, 2007

OpenGL Super Bible! Page 419 Printing the Bitmap Because Windows provides several convenient functions for printing within an application, it only makes sense to be able to print from our bitmap viewing program. For this example program, you will be using the standard GDI printing services. The first thing you do is display a standard Windows print dialog using PrintDlg, as shown here: memset(&pd, 0, sizeof(pd)); pd.lStructSize = sizeof(pd); pd.hwndOwner = owner; pd.Flags = PD_RETURNDC; pd.hInstance = NULL; if (!PrintDlg(&pd)) return (0); If the PrintDlg function returns 0, the user has clicked the Cancel button. Otherwise, the PRINTDLG structure will contain a device context (HDC) handle that we can use for printing. Next, you need to start the print job. di.cbSize = sizeof(DOCINFO); di.lpszDocName = “OpenGL Image”; di.lpszOutput = NULL; StartDoc(pd.hDC, &di); After this, you draw the bitmap using the StretchBlt function and end the print job. StretchBlt(pd.hDC, xoffset, yoffset, xsize, ysize, hdc, 0, 0, info->bmiHeader.biWidth, info->bmiHeader.biHeight, SRCCOPY); EndPage(pd.hDC); EndDoc(pd.hDC); We compute the first 4 parameters to StretchBlt based on the size of the output page. Basically, we want to scale the image to the page yet keep the aspect ratio (width/height) the same. xsize = rect.right; ysize = xsize * info->bmiHeader.biHeight / info- >bmiHeader.biWidth; if (ysize > rect.bottom) { ysize = rect.bottom; xsize = ysize * info->bmiHeader.biWidth / info->bmiHeader.biHeight; };
If you are looking for cheap and quality webhost to host and run your website check Jboss Web Hosting services.

Page 418 OpenGL Super Bible! infosize += info->bmiHeader.biClrUsed (Geocities web hosting)

Wednesday, November 21st, 2007

Page 418 OpenGL Super Bible! infosize += info->bmiHeader.biClrUsed * 4; break; }; size = sizeof(BITMAPFILEHEADER) + infosize + bitsize; /* * Write the file header, bitmap information, and bitmap pixel data */ header.bfType = ‘MB’; /* Non-portable sigh */ header.bfSize = size; header.bfReserved1 = 0; header.bfReserved2 = 0; header.bfOffBits = sizeof(BITMAPFILEHEADER) + infosize; if (fwrite(&header, 1, sizeof(BITMAPFILEHEADER), fp) < sizeof(BITMAPFILEHEADER)) { /* * Couldn't write the file header - return */ fclose(fp); return (-1); }; if (fwrite(info, 1, infosize, fp) < infosize) { /* * Couldn't write the bitmap header - return */ fclose(fp); return (-1); }; if (fwrite(bits, 1, bitsize, fp) < bitsize) { /* * Couldn't write the bitmap - return */ fclose(fp); return (-1); }; /* * OK, everything went fine - return */ fclose(fp); return (0); }
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.

Web server - OpenGL Super Bible! Page 417 fclose(fp); return (bits);

Tuesday, November 20th, 2007

OpenGL Super Bible! Page 417 fclose(fp); return (bits); } Writing the .BMP File As they say in the car repair manuals, Installation is the reverse of removal. To write a .BMP file, you simply add a BITMAPFILEHEADER structure to the bitmap in memory and write it to disk. Listing 11-10 is the SaveDIBitmap function. Listing 11-10 SaveDIBitmap function int SaveDIBitmap(char *filename, /* I - File to save to */ BITMAPINFO *info, /* I - Bitmap information */ void *bits) /* I - Bitmap pixel bits */ { FILE *fp; /* Open file pointer */ long size, /* Size of file */ infosize, /* Size of bitmap info */ bitsize; /* Size of bitmap pixels */ BITMAPFILEHEADER header; /* File header */ /* * Try opening the file; use “wb” mode to write this *binary* file. */ if ((fp = fopen(filename, “wb”)) == NULL) return (-1); if (info->bmiHeader.biSizeImage == 0)/* Figure out the bitmap size */ bitsize = (info->bmiHeader.biWidth * info->bmiHeader.biBitCount + 7) / 8 * abs(info- >bmiHeader.biHeight); else bitsize = info->bmiHeader.biSizeImage; infosize = sizeof(BITMAPINFOHEADER); switch (info->bmiHeader.biCompression) { case BI_BITFIELDS : infosize += 12; /* Add 3 RGB doubleword masks */ if (info- >bmiHeader.biClrUsed == 0) break; case BI_RGB : if (info->bmiHeader.biBitCount > 8 && info- >bmiHeader.biClrUsed == 0) break; case BI_RLE8 : case BI_RLE4 : if (info->bmiHeader.biClrUsed == 0) infosize += (1 << info- >bmiHeader.biBitCount) * 4; else
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.