Archive for November, 2007

Web hosting ecommerce - Page 416 OpenGL Super Bible! * Couldn’t allocate

Monday, November 19th, 2007

Page 416 OpenGL Super Bible! * Couldn’t allocate memory for bitmap info - return NULL */ fclose(fp); return (NULL); }; if (fread(*info, 1, infosize, fp) < infosize) { /* * Couldn't read the bitmap header - return NULL */ free(*info); fclose(fp); return (NULL); }; /* * Now that we have all the header info read in, allocate memory for the * bitmap and read *it* in */ if ((bitsize = (*info)->bmiHeader.biSizeImage) == 0) bitsize = ((*info)->bmiHeader.biWidth * (*info)->bmiHeader.biBitCount + 7) / 8 * abs((*info)->bmiHeader.biHeight); if ((bits = malloc(bitsize)) == NULL) { /* * Couldn’t allocate memory - return NULL! */ free(*info); fclose(fp); return (NULL); }; if (fread(bits, 1, bitsize, fp) < bitsize) { /* * Couldn't read bitmap - free memory and return NULL! */ free(*info); free(bits); fclose(fp); return (NULL); }; /* * OK, everything went fine - return the allocated bitmap */
Check Tomcat Web Hosting services for best quality webspace to host your web application.

OpenGL Super Bible! (Java web server) Page 415 (*info)->bmiHeader.biBitCount + 7)

Sunday, November 18th, 2007

OpenGL Super Bible! Page 415 (*info)->bmiHeader.biBitCount + 7) / 8 * abs((*info)->bmiHeader.biHeight); fread(bits, 1, bitsize, fp); fclose(fp); Listing 11-9 contains the final code for LoadDIBitmap, with error checking. Listing 11-9 LoadDIBitmap function void * LoadDIBitmap(char *filename, /* I - File to load */ BITMAPINFO **info) /* O - Bitmap information */ { FILE *fp; /* Open file pointer */ void *bits; /* Bitmap pixel bits */ long bitsize, /* Size of bitmap */ infosize; /* Size of header information */ BITMAPFILEHEADER header; /* File header */ /* * Try opening the file; use “rb” mode to read this *binary* file. */ if ((fp = fopen(filename, “rb”)) == NULL) return (NULL); /* * Read the file header and any following bitmap information */ if (fread(&header, sizeof(BITMAPFILEHEADER), 1, fp) < 1) { /* * Couldn't read the file header - return NULL */ fclose(fp); return (NULL); }; if (header.bfType != 'MB') /* Check for BM reversed */ { /* * Not a bitmap file - return NULL */ fclose(fp); return (NULL); }; infosize = header.bfOffBits - sizeof(BITMAPFILEHEADER); if ((*info = (BITMAPINFO *)malloc(infosize)) == NULL) { /*
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.

Ipower web hosting - Page 414 OpenGL Super Bible! Following the file

Saturday, November 17th, 2007

Page 414 OpenGL Super Bible! 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. Reading the .BMP File Because the .BMP file format is so simple, reading a .BMP file is almost trivial. You start by opening the file and reading a BITMAPFILEHEADER structure. if ((fp = fopen(filename, “rb”)) == NULL) return (NULL); fread(&header, sizeof(BITMAPFILEHEADER), 1, fp); if (header.bfType != ‘MB’) /* Check for BM reversed */ { /* * Not a bitmap file - return NULL */ fclose(fp); return (NULL); }; If the header looks good, you then read the BITMAPINFO structure along with any color palette definitions. infosize = header.bfOffBits - sizeof(BITMAPFILEHEADER); fread(*info, 1, infosize, fp); And finally, you read the bitmap data and close the file. if ((bitsize = (*info)->bmiHeader.biSizeImage) == 0) bitsize = ((*info)- >bmiHeader.biWidth *
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 413 A Bitmap File (Cheap web hosting)

Friday, November 16th, 2007

OpenGL Super Bible! Page 413 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 CH11OGLVIEW.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
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.

Page 412 OpenGL Super Bible! Once (Multiple domain web hosting) you have

Thursday, November 15th, 2007

Page 412 OpenGL Super Bible! Once you have the size of the viewport, you then allocate memory for the pixmap. It s important to note that Windows bitmaps (and OpenGL pixmaps by default) must have the beginning of each line at a 32-bit boundary. To accomplish this, we do the following: width = viewport[2] * 3; /* Real width of scanline * width = (width + 3) & ~3; /* Aligned to 4 bytes */ You must round the computed actual byte width of the viewport (in this case, 3 bytes for every pixel wide) up to the nearest 32-bit (or 4-byte) boundary. The total size of the pixmap then becomes bitsize = width * viewport[3]; /* Size of bitmap, aligned */ After allocating memory for the pixmap, we call glReadPixels to get the contents of the current viewport and fill in the Windows BITMAPHEADER structure with all the necessary information. Copying Pixmaps OpenGL also provides a function to copy an area on the screen to another location as 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.
Please visit our professional web hosting services to find out about cheap and reliable webhost service that will surely answer all your demands.

Free web servers - OpenGL Super Bible! Page 411 { temp =

Wednesday, November 14th, 2007

OpenGL Super Bible! Page 411 { temp = rgb[0]; rgb[0] = rgb[2]; rgb[2] = temp; }; /* * Finally, initialize the bitmap header information */ (*info)- >bmiHeader.biSize = sizeof(BITMAPINFOHEADER); (*info)->bmiHeader.biWidth = viewport[2]; (*info)->bmiHeader.biHeight = viewport[3]; (*info)- >bmiHeader.biPlanes = 1; (*info)->bmiHeader.biBitCount = 24; (*info)- >bmiHeader.biCompression = BI_RGB; (*info)->bmiHeader.biSizeImage = bitsize; (*info)->bmiHeader.biXPelsPerMeter = 2952; /* 75 DPI */ (*info)- >bmiHeader.biYPelsPerMeter = 2952; /* 75 DPI */ (*info)->bmiHeader.biClrUsed = 0; (*info)->bmiHeader.biClrImportant = 0; return (bits); } The first thing you need to do is find out the size of the current viewport, using glGetIntegerv as shown just below. (This function is described in Chapter 14). This places the current X origin, Y origin, X size, and Y size into the viewport array, as shown in Table 11-3. /* * Grab the current viewport */ glGetIntegerv(GL_VIEWPORT, viewport); Table 11-3 Viewport Array Definitions Index Description 0 X origin of viewport (pixels) 1 Y origin of viewport (pixels) 2 X size of viewport (pixels) 3 Y size of viewport (pixels)
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.

Page 410 OpenGL Super Bible! temp; /* Temporary (Web server address)

Tuesday, November 13th, 2007

Page 410 OpenGL Super Bible! temp; /* Temporary var for swapping */ /* * Grab the current viewport */ glGetIntegerv(GL_VIEWPORT, viewport); /* * Allocate memory for the header and bitmap */ if ((*info = (BITMAPINFO *)malloc(sizeof(BITMAPINFOHEADER))) == NULL) { /* * Couldn’t allocate memory for bitmap info - return NULL */ return (NULL); }; width = viewport[2] * 3; /* Real width of scanline */ width = (width + 3) & ~3; /* Aligned to 4 bytes */ bitsize = width * viewport[3]; /* Size of bitmap, aligned */ if ((bits = calloc(bitsize, 1)) == NULL) { /* * Couldn’t allocate memory for bitmap pixels - return NULL */ free(*info); return (NULL); }; /* * Read pixels from the framebuffer */ glFinish(); /* Finish all OpenGL commands */ glPixelStorei(GL_PACK_ALIGNMENT, 4); /* Force 4-byte alignment */ glPixelStorei(GL_PACK_ROW_LENGTH, 0); glPixelStorei(GL_PACK_SKIP_ROWS, 0); glPixelStorei(GL_PACK_SKIP_PIXELS, 0); glReadPixels(0, 0, viewport[2], viewport[3], GL_RGB, GL_UNSIGNED_BYTE, bits); /* * Swap red and blue for the bitmap */ for (i = 0; i < viewport[3]; i ++) for (j = 0, rgb = ((GLubyte *)bits) + i * width; j < viewport[2]; j ++, rgb += 3)
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.

Web server address - OpenGL Super Bible! Page 409 In this example,

Monday, November 12th, 2007

OpenGL Super Bible! Page 409 In this example, the GL_UNPACK_ROW_LENGTH value specifies the width of the original image in pixels. Set this when the width specified with glDrawPixels is different from the width of the image. GL_UNPACK_SKIP_PIXELS specifies the number of pixels to skip on the left side of the image. Here we skip the first (640 300) / 2, or 170 pixels on the left side of the image to show the middle. GL_UNPACK_SKIP_ROWS is similar but specifies the number of rows or scanlines in the image to skip. Normally, this value represents the number of rows from the bottom, but you can change this by specifying a negative Y scaling with glPixelZoom. NOTE: The GL_UNPACK_ROW_LENGTH, GL_UNPACK_SKIP_PIXELS, and GL_UNPACK_SKIP_ROWS attributes refer to the original pixmap size in pixels, not the size after zooming! Reading Pixmaps OpenGL provides a function called glReadPixels that can read an image from the screen. Beyond the obvious application of saving your created image to disk, it can also be used for cool effects with texture mapping. Unlike glDrawPixels, glReadPixels ignores the current raster position and requires you to specify an (x,y) viewport coordinate for the lower-left corner of the image to read. Listing 11-8 demonstrates how to read the current viewport into a Windows bitmap structure suitable for saving to a file or using as a texture. Listing 11-8 ReadDIBitmap function /* * ‘ReadDIBitmap()’ - Read the current OpenGL viewport into a * 24-bit RGB bitmap. * * Returns the bitmap pixels if successful and NULL otherwise. */ void * ReadDIBitmap(BITMAPINFO **info) /* O - Bitmap information */ { long i, j, /* Looping var */ bitsize, /* Total size of bitmap */ width; /* Aligned width of a scanline */ GLint viewport[4]; /* Current viewport */ void *bits; /* RGB bits */ GLubyte *rgb, /* RGB looping var */
From our experience, we can recommend PHP Web Hosting services, if you need affordable webhost to host and run your web application.

Page 408 OpenGL Super Bible! glPixelTransferi(GL_MAP_COLOR, GL_TRUE); glPixelMap(GL_PIXEL_MAP_R_TO_R, (Php web hosting)

Sunday, November 11th, 2007

Page 408 OpenGL Super Bible! glPixelTransferi(GL_MAP_COLOR, GL_TRUE); glPixelMap(GL_PIXEL_MAP_R_TO_R, 256, lut); glPixelMap(GL_PIXEL_MAP_G_TO_G, 256, lut); glPixelMap(GL_PIXEL_MAP_B_TO_B, 256, lut); Figure 11-2 Image without gamma correction (left) and with a gamma correction of 1.7 (right) Scaling a Pixmap Besides adjusting the colors of a pixmap, you can adjust the size of the pixmap using the glPixelZoom function. This function accepts two floating point parameters specifying the X and Y scaling factors for the image: glPixelZoom(1.0, 1.0); /* Don t scale the image */ glPixelZoom(-1.0, 1.0); /* Flip the image horizontally */ glPixelZoom(1.0, -2.0); /* Flip the image and double the height */ glPixelZoom(0.33, 0.33); /* Draw the image 1/3 size */ As you can see, glPixelZoom allows you to scale and flip an image just about any way you like. For other nonlinear effects, such as rippling water or perspective correction, you ll need to use texture mapping (Chapter 12). Panning a Pixmap The glPixelStore function can be used to pan inside an image. For example, to display the center 300 x 300 pixel area of a 640 x 480 pixel image, you would use glPixelStorei(GL_UNPACK_ROW_LENGTH, 640); glPixelStorei(GL_UNPACK_SKIP_PIXELS, (640 - 300) / 2); glPixelStorei(GL_UNPACK_SKIP_ROWS, (480 - 300) / 2); glDrawPixels(300, 300, GL_RGB, GL_UNSIGNED_BYTE, BitmapBits);
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.

OpenGL Super Bible! Page 407 (Submit web site) 0xff, 0xff, 0,

Saturday, November 10th, 2007

OpenGL Super Bible! Page 407 0xff, 0xff, 0, 0, /* **************** */ 0xff, 0xff, 0, 0, /* **************** */ 0xff, 0xff, 0, 0, /* **************** */ 0×73, 0xce, 0, 0, /* *** **** *** */ 0×73, 0xce, 0, 0, /* *** **** *** */ 0×3f, 0xfc, 0, 0, /* ************ */ 0×1f, 0xf8, 0, 0, /* ********** */ 0×0f, 0xf0, 0, 0, /* ******** */ 0×03, 0xc0, 0, 0 /* **** */ }; glViewport(0, 0, rect->right, rect->bottom); glClearIndex(0.0); glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, rect->right - 1.0, 0.0, rect->bottom - 1.0, -1.0, 1.0); /* * This bitmap is aligned to 4-byte boundaries */ glPixelTransferi(GL_UNPACK_ALIGNMENT, 4); glPixelTransferi(GL_INDEX_OFFSET, 1); for (i = 0; i < 100; i ++) { glRasterPos2i(rand() % rect->right, rand() % rect->bottom); glDrawPixels(16, 16, GL_COLOR_INDEX, GL_BITMAP, smiley); }; glFinish(); } Color Mapping Tables Sometimes it is necessary to apply color corrections that are more complicated than simple linear scale and offset. One application is gamma correction, in which the intensity of each color value is adjusted to a power curve that compensates for irregularities on your monitor or printer (see Figure 11-2). The glPixelMap function allows you to do this by specifying a lookup table, as follows: GLfloatlut[256]; GLfloatgamma_value; int i; gamma_value = 1.7; /* For NTSC video monitors */ for (i = 0; i < 256; i ++) lut[i] = pow(i / 255.0, 1.0 / gamma_value);
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.