Archive for April, 2007

Page 50 OpenGL Super Bible! Table 3-3 Some (Web server certificate)

Wednesday, April 25th, 2007

Page 50 OpenGL Super Bible! Table 3-3 Some common composite colors Composite Color Red Component Green Component Blue Component Black 0.0 0.0 0.0 Red 1.0 0.0 0.0 Green 0.0 1.0 0.0 Yellow 1.0 1.0 0.0 Blue 0.0 0.0 1.0 Magenta 1.0 0.0 1.0 Cyan 0.0 1.0 1.0 Dark gray 0.25 0.25 0.25 Light gray 0.75 0.75 0.75 Brown 0.60 0.40 0.12 Pumpkin orange 0.98 0.625 0.12 Pastel pink 0.98 .04 0.7 Barney purple 0.60 0.40 0.70 White 1.0 1.0 1.0 The last argument to glClearColor() is the alpha component. The alpha component is used for blending and special effects such as translucence. Translucence refers to an object s ability to allow light to pass through it. Suppose you are representing a piece of red stained glass, but a blue light is shining behind it. The blue light will affect the appearance of the red in the glass (blue + red = purple). You can use the alpha component value to make a blue color that is semitransparent; so it works like a sheet of water an object behind it shows through. There is more to this type of effect than the alpha value, and in Chapter 16 we will write an example program that demonstrates it; until then you should leave this value as 1.
Note: If you are looking for high quality webhost to host and run your jsp application check Vision jsp web hosting services

OpenGL Super Bible! Page 49 Clear a Window (Jetty web server)

Wednesday, April 25th, 2007

OpenGL Super Bible! Page 49 Clear a Window (Erase with a Color) The three lines of code we ve looked at so far from the AUX library are sufficient to initialize and create a window that OpenGL will draw in. From this point on, all OpenGL commands and function calls will operate on this window. The next line of code glClearColor(0.0f, 0.0f, 1.0f, 0.0f); is your first real OpenGL function call. This function sets the color used when clearing the window. The prototype for this function is void glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLcl ampf alpha); GLclampf is defined as a float under most implementations of OpenGL. In OpenGL, a single color is represented as a mixture of red, green, and blue components. The range for each component can vary from 0.0 to 1.0. This is similar to the Windows specification of colors using the RGB macro to create a COLORREF value. (See the Windows95 API Bible from Waite Group Press for details.) The difference is that in Windows each color component in a COLORREF can range from 0 to 255, giving a total of 256 x 256 x 256 or over 16 million colors. With OpenGL, the values for each component can be any valid floating-point value between 0 and 1, thus yielding a theoretically infinite number of potential colors. Practically speaking, OpenGL represents colors internally as 32-bit values, yielding a true maximum of 4,294,967,296 colors (called true color on some hardware). Thus the effective range for each component is from 0.0 to 1.0, in steps of approximately .00006. Naturally, both Windows and OpenGL take this color value and convert it internally to the nearest possible exact match with the available video hardware and palette. We ll explore this more closely in Chapter 8. Table 3-3 lists some common colors and their component values. These values can be used with any of the OpenGL color-related functions.
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision web and email hosting services

Page 48 OpenGL (Unable to start debugging on the web server) Super Bible! Figure 3-4 Default

Tuesday, April 24th, 2007

Page 48 OpenGL Super Bible! Figure 3-4 Default OpenGL window coordinate mapping Porting Note Although Windows maps desktop coordinates as shown in Figure 3-3, the X Window System maps desktop coordinates the same way that OpenGL does in Figure 3-4. If you are porting an AUX library program from another environment, you may need to change the call to auxInitPosition() to account for this. Create the OpenGL Window The last call to the AUX library actually creates the window on the screen. The code auxInitWindow(”My first OpenGL Program”); creates the window and sets the caption to My first OpenGL Program. Obviously, the single argument to auxInitWindow is the caption for the window title bar. If you stopped here, the program would create an empty window (black background is the default) with the caption specified, and then terminate, closing the OpenGL window immediately. The addition of our last getch() prevents the window from disappearing, but still nothing of interest happens in the window.
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision servlet hosting services

Free web hosting services - OpenGL Super Bible! Page 47 Position the Window

Tuesday, April 24th, 2007

OpenGL Super Bible! Page 47 Position the Window After setting the display mode, you need to tell the AUX library where to put the window and how big to make it. The next line of code does this: auxInitPosition(100,100,250,250); The parameters represent the upper-left corner of the window and its width and height. Specifically, this line tells the program to place the upper-left corner at coordinates (100,100), and to make the window 250 pixels wide and 250 pixels high. On a screen of standard VGA resolution (640 x 480), this window will take up a large portion of the display. At SuperVGA resolutions (800 x 600 and above), the window will take less space even though the number of pixels remains the same (250 x 250). Here is the prototype for this function: auxInitPosition(GLint x, GLint y, GLsizei width, GLsizei height); The GLint and GLsizei data types are defined as integers (as described in the earlier section about data types). The x parameter is the number of screen pixels counted from the left side of the screen, and y is the number of pixels counted down from the top of the screen. This is how Windows converts desktop screen coordinates to a physical location by default. OpenGL s default method for counting the x coordinate is the same; however, it counts the y coordinate from bottom to top just the opposite of Windows. See Figures 3-3 and 3-4. Figure 3-3 Default Windows screen coordinate mapping
Note: In case you are looking for affordable webhost to host and run your web application check Vision cheap hosting services

Cedant web hosting - Page 46 OpenGL Super Bible! The Includes Here

Monday, April 23rd, 2007

Page 46 OpenGL Super Bible! The Includes Here are the include files: #include #include #include #include These includes define the function prototypes used by the program. The windows.h header file is required by all Windows GUI applications; even though this is a console-mode program, the AUX library creates a GUI window to draw in. The file conio.h is for console I/O. It s included because we use cprintf() to print a message, and getch() to terminate the program when a key is pressed. The file gl.h defines the OpenGL functions that are prefixed with gl; and glaux.h contains all the functions necessary for the AUX library. The Body Next comes the main body of the program: void main(void) { Console mode C and C++ programs always start execution with the function main(). If you are an experienced Windows nerd, you may wonder where WinMain() is in this example. It s not there because we start with a console-mode application, so we don t have to start with window creation and a message loop. It is possible with Win32 to create graphical windows from console applications, just as it is possible to create console windows from GUI applications. These details are buried within the AUX library (remember, the AUX library is designed to hide these platform details). Display Mode: Single-Buffered The next line of code auxInitDisplayMode(AUX_SINGLE | AUX_RGBA); tells the AUX library what type of display mode to use when creating the window. The flags here tell it to use a single-buffered window (AUX_SINGLE) and to use RGBA color mode (AUX_RGBA). A single-buffered window means that all drawing commands are performed on the window displayed. An alternative is a double- buffered window, where the drawing commands are actually executed to create a scene off screen, then quickly swapped into view on the window. This is often used to produce animation effects and will be demonstrated later in this chapter. RGBA color mode means that you specify colors by supplying separate intensities of red, green, and blue components (more on color modes in Chapter 8) .
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision best web hosting services

OpenGL Super Bible! Page 45 (My space web page) // These are

Monday, April 23rd, 2007

OpenGL Super Bible! Page 45 // These are the OpenGL functions that do something in the window glClearColor(0.0f, 0.0f, 1.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); glFlush(); // Stop and wait for a keypress cprintf(”Press any key to close the Windown”); getch(); } Console Modes A console-mode application is a Win32 program that runs in a text mode window. This is very much like running a DOS program under Windows NT or Windows 95, except the program is a true 32-bit application and has access to the entire Win32 API. Console-mode programs are not limited to text mode. They can in fact create GUI windows for auxiliary output (try calling MessageBox() with a NULL window handle from the above program), and GUI-based applications can even create console windows if needed. The AUX library allows you to easily write a console-based program with only a main() function that can create an auxiliary GUI window for OpenGL output. To build this program, you need to set your compiler and link options to build a Win32 console (or text-based) application. You will need to link to the AUX library glaux.lib and the OpenGL import library opengl32.lib. See your compiler s documentation for individual instructions on building console applications. The shortest.c program doesn t do very much. When run from the command line, it creates a standard GUI window with the caption My first OpenGL Program and a clear blue background. It then prints the message Press any key to close the window in the console window. The GUI window will not respond to any mouse or keyboard activity, and the console window waits for you to press a key before terminating (you will have to switch focus back to the console window first to do this). It doesn t even behave very well you can t move or resize the OpenGL window, and the window doesn t even repaint. If you obscure the window with another window and then uncover it, the client area goes black. This simple program contains three AUX library functions (prefixed with aux) and three real OpenGL functions (prefixed with gl). Let s examine the program line by line, after which we ll introduce some more functions and substantially improve on our first example.
Note: If you are looking for best quality webspace to host and run your tomcat application check Vision shared web hosting services

Page 44 OpenGL (Web hosting india) Super Bible! Dissecting a Short

Sunday, April 22nd, 2007

Page 44 OpenGL Super Bible! Dissecting a Short OpenGL Program In order to understand the AUX library better, let s take a look at possibly the world s shortest OpenGL program, which was written using the AUX library. Listing 3-1 presents the shortest.c program. Its output is shown in Figure 3-2. Figure 3-2 Output from shortest.c Listing 3-1 Shortest OpenGL program in the world // shortest.c // The shortest OpenGL program possible #include // Standard Window header required for all programs #include // Console I/O functions #include // OpenGL functions #include // AUX Library functions void main(void) { // These are the AUX functions to set up the window auxInitDisplayMode(AUX_SINGLE | AUX_RGBA); auxInitPosition(100,100,250,250); auxInitWindow(”My first OpenGL Program”);
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check Vision professional web hosting services

OpenGL Super (Best web site) Bible! Page 43 Unfortunately, it s unlikely

Sunday, April 22nd, 2007

OpenGL Super Bible! Page 43 Unfortunately, it s unlikely that all of the functionality of a useful application will be embodied entirely in the code used to draw in 3D, so you can t rely entirely on the AUX library for everything. Nevertheless, the AUX library excels in its role for learning and demonstration exercises. And for some applications, you may be able to employ the AUX library to iron out your 3D graphics code before integrating it into a complete application. Platform Independence OpenGL is a powerful and sophisticated API for creating 3D graphics, with over 300 commands that cover everything from setting material colors and reflective properties to doing rotations and complex coordinate transformations. You may be surprised that OpenGL has not a single function or command relating to window or screen management. In addition, there are no functions for keyboard input or mouse interaction. Consider, however, that one of the primary goals of the OpenGL designers was platform independence. Creating and opening a window is done differently under the various platforms. Even if OpenGL did have a command for opening a window, would you use it or would you use the operating system s own built-in API call? Another platform issue is the handling of keyboard and mouse input events under the different operating systems and environments. If every environment handled these the same, we would have only one environment to worry about and thus no need for an open API. This is not the case, however, and it probably won t be within our brief lifetimes! So OpenGL s platform independence comes at the cost of OS and GUI functions. AUX = Platform I/O, the Easy Way The AUX library was initially created as a toolkit to enable learning OpenGL without getting mired in the details of any particular operating system or user interface. To accomplish this, AUX provides rudimentary functions for creating a window and for reading mouse and keyboard activity. Internally, the AUX library makes use of the native environment s APIs for these functions. The functions exposed by the AUX library then remain the same on all platforms. The AUX library contains only a handful of functions for window management and the handling of input events, but saves you the trouble of managing these in pure C or C++ through the Windows API. The library also contains functions for drawing some relatively simple 3D objects such as a sphere, cube, torus (doughnut), and even a teapot. With very little effort, you can use the AUX library to display a window and perform some OpenGL commands. Though AUX is not really part of the OpenGL specification, it seems to follow that spec around to every platform to which OpenGL is ported. Windows is no exception, and the source code for the AUX library is even included free in the Win32 SDK from Microsoft.
Note: In case you are looking for affordable webhost to host and run your web application check Vision cheap hosting services

Page 42 OpenGL Super Bible! Clean Code Many

Saturday, April 21st, 2007

Page 42 OpenGL Super Bible! Clean Code Many C/C++ compilers for Windows assume that any floating-point literal value is of type double unless explicitly told otherwise via the suffix mechanism. When using literals for floating point arguments, if you don t specify that these arguments are of type float instead of double, the compiler will issue a warning while compiling because it detects that you are passing a double to a function defined to accept only floats, resulting in a possible loss of precision. As our OpenGL programs grow, these warnings will quickly number in the hundreds and will make it difficult to find any real syntax errors. You can turn these warnings off using the appropriate compiler options but we advise against this. It s better to write clean, portable code the first time. So clean up those warning messages by cleaning up the code (in this case, by explicitly using the float type) not by disabling potentially useful warnings. Additionally, you may be tempted to use the functions that accept double- precision floating point arguments, rather than go to all the bother of specifying your literals as floats. However, OpenGL uses floats internally, and using anything other than the single-precision floating point functions will add a performance bottleneck, as the values are converted to floats anyway before being processed by OpenGL. The AUX Library For the remainder of this chapter, you will learn to use the Auxiliary (AUX) library as a way to learn OpenGL. The AUX library was created to facilitate the learning and writing of OpenGL programs without being distracted by the minutiae of your particular environment, be it UNIX, Windows, or whatever. You don t write final code when using AUX; it is more of a preliminary staging ground for testing your ideas. A lack of basic GUI features limits the library s use for building useful applications. A set of core AUX functions is available on nearly every implementation of OpenGL. These functions handle window creation and manipulation, as well as user input. Other functions draw some complete 3D figures as wireframe or solid objects. By using the AUX library to create and manage the window and user interaction, and OpenGL to do the drawing, it is possible to write programs that create fairly complex renderings. You can move these programs to different environments with a recompile. In addition to the core functions, each environment that implements an AUX library also implements some other helper functions to enable system-specific operations such as buffer swapping and image loading. The more your code relies on these additional AUX library functions, the less portable your code will be. On the other hand, by making full use of these functions you can create fantastic scenes that will amaze your friends and even the family dog without having to learn all the gritty details of Windows programming.
Note: If you are looking for high quality webhost to host and run your jsp application check Vision christian web host services

OpenGL Super (Web hosting contract) Bible! Page 41 Function Naming Conventions

Saturday, April 21st, 2007

OpenGL Super Bible! Page 41 Function Naming Conventions OpenGL functions all follow a naming convention that tells you which library the function is from, and often how many and what type of arguments the function takes. All functions have a root that represents the function s corresponding OpenGL command. For example, the glColor3f() function has the root Color. The gl prefix represents the gl library (see Table 3-1), and the 3f suffix means the function takes three floating point arguments. All OpenGL functions take the following format: Figure 3-1 illustrates the parts of an OpenGL function. This sample function with the suffix 3f takes three floating point arguments. Other variations take three integers (glColor3i()), three doubles (glColor3d()), and so forth. This convention of adding the number and type of arguments (see Table 3-1) to the end of OpenGL functions makes it very easy to remember the argument list without having to look it up. Some versions of glColor take four arguments to specify an alpha component, as well. Figure 3-1 Dissected OpenGL Function In the reference sections of this book, these families of functions are listed by their library prefix and root. Thus all the variations of glColor (glColor3f, glColor4f, glColor3i, etc.) will be listed under a single entry glColor.
Note: If you are looking for best quality webspace to host and run your tomcat application check Vision shared web hosting services