Order of Events
Now, compile the program and launch it with the Windows Run command. Resize it several ways. Watch the shape of the rectangle as you do the resizing. Careful observation reveals that if the form only shrinks, the shape of the rectangle does not change. If the form enlarges either horizontally or vertically or both, the shape of the rectangle changes appropriately. An expected event is not firing. This calls for further investigation. In the variable declaration section add So that an Event.Log...
Definition 3
The third component of light from a light source is specular light. Ambient light has been scattered from many surfaces and seems to come from all directions. Diffuse light comes from a specific direction the source, of course , but scatters from surfaces, giving a soft, flat appearance to surfaces. Ambient and Diffuse components of a light source commonly share the same color. Specular light is also directional, but much tighter in reflection than diffuse light, often with a different color....
Content
This is a hands-on, learn-by-doing book. For greatest benefit from the book place it near the computer, turn on the computer, and launch Delphi. Create a separate directory or folder in a suitable location for placing various OpenGL projects. Naming the directory OPENGL is a good choice. Some people may prefer to develop a thorough background before they write their first line of code. I am not one of those people. While I do like to have a good understanding of the tools I am using and the...
Orthographic Projection
The call to glOrtho defines a clipping volume, which is a region in space in which objects can be seen. Any part of a scene that lies outside of the region is not visible clipped . Of course, though the rendered scenes may be conceptually three-dimensional, they must be projected onto a two-dimensional screen. The available projections are orthographic projection and perspective projection. You get one guess as to which kind glOrtho uses. In orthographic projection, also known as parallel...
Vertex Direction
How does OpenGL know which face of a polygon the programmer intended to be front and which to be back The answer lies in the order of the vertices. Consider the front square of this chapter's cube. glBegin GL_POLYGON near face glColor3f 0.5,0.0,0.0 glVertex3f -0.4,-0.4,-0.4 glVertex3f 0.4,-0.4,-0.4 glVertex3f 0.4, 0.4,-0.4 glVertex3f -0.4, 0.4,-0.4 glEnd Mentally number the vertices from one to four. Vertex one is the lower left corner. Vertex two is the lower right corner. Vertex three is the...
Directional Spotlights
A feature still missing from the spotlight illustrated thus far in the chapter is the ability to aim it. What kind of spotlight is it that you can't spot One thing needed for that purpose is to add some more ell fields in the form class declaration. xl,ylizlixrliyrlizrlianglelicutoff, x1iy1iz1ix2iy2iz2ixr1iyr1izr1, xr2,yr2,zr2iangle1iangle2isign glFloat The xrl, yrl, and zrl fields set up the axis of rotation for the cyan cube and the aiming direction of the spotlight. Similarly the anglel...
State Variables
In the FormPaint method Listing 2-2 , not only does glClearColor set the clear color background , but glColor sets the foreground color for drawing. These calls set state variables which remain the same until similar calls explicitly change them. If the command says to draw in blue, all drawing is done in blue until another call changes the state. OpenGL's state variables are in DLLs, not directly accessible to the programmer. You read and write OpenGL's state variables via function and...
Menu
Use the Menu Designer to add amp Translate as another main menu item. Click on it and fill in the event handler thusly procedure TForm1.Translate1Click Sender T0bject begin The glTranslate command takes three parameters that specify the relative amount of movement in each direction. The translation command has two forms procedure glTranslated x,y,z GLdouble stdcall procedure glTranslatef x,y,z GLfloat stdcall
o 1
search riy itkmowled e fa j sitemap comtact lis To access the contents, click the chapter and section titles. Publisher Wordware Publishing, Inc. Author s Jon Jacobs ISBN 1556226578 Publication Date 08 01 99 Another new command introduced here is glFlush. For the sake of efficiency, the graphics engine does not necessarily start drawing as soon as it receives its first command. It may continue to accumulate information in a buffer until given a little kick. The call to glFlush forces it to...
Mixing Windows Components
One of the really neat features of OpenGL is that it does not prevent using regular Windows components. This opens many possibilities for user interaction with your graphics constructs. The coming chapters will explore a number of different ways users can give information to your applications. Since these are illustrations and exercises, they are not the ultimate in slick, state-of-the-art front ends they are just enough to demonstrate a technique. For the first such demonstration, drop a...
Open the Cube
There is no way to avoid it. Polygons are two-faced. That is not a character assassination but a geometric statement. When a polygon facing the viewer rotates 180 degrees, it does not disappear it has a back face that the viewer can see. To illustrate, expose the inside of the cube by commenting out the right side as in Listing 3-3. procedure TForm1.FormPaint Sender TObject begin glClear GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT glBegin GL_POLYGON near face glColor3f 0.5,0.0,0.0 glVertex3f...
Description 1
An OpenGL command that causes material properties to track the current color set by glColor. It takes two parameters. The first tells which face or faces will be affected. The second tells which properties will track the current color. You must enable color tracking for this to work. An OpenGL command that defines characteristics of an OpenGL light source. You must enable lighting and enable the specific light. An OpenGL command that provides a simplified method of setting up a lighting...
Delphi Developers Guide to OpenGL 1
Publisher Wordware Publishing, Inc. Author s Jon Jacobs ISBN 1556226578 Publication Date 08 01 99 Save, compile, run, and experiment, not only with the values to give to each transformation, but also with the order of the transformation. Admittedly the difference is subtle for just one object in the scene, but many combinations will show a difference according to the sequence of the transformations. Order does matter try it and see.
The Interface Unit
If your version of Delphi does not have an OpenGL interface unit, you can download one from the Internet. Wherever you obtain the interface unit, simply reference it in the uses clause of any unit that invokes OpenGL commands. Be sure to place the .DCU Delphi Compiled Unit file in Delphi's library path, otherwise give a full path to it in the .DPR Delphi PRoject file. For example, in Delphi 3, the interface file is in the LIB directory under the DELPHI 3 directory. To see or modify the library...
Make a Scene
This is enough information to build a scene with multiple copies of the cube. Make the procedure TForm1.FormPaint Sender TObject glClear GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT errorCode glGetError if errorCode lt gt GL_NO_ERROR then raise Exception.Create 'Error in Paint' 13 gluErrorString errorCode end FormPaint Notice the sequence push the ModelView matrix, translate to the desired location, call the routine that builds the object about the origin, and pop the matrix. Do this for each...
Error Handling in Depth
Chapter 1 introduced glGetError, but gave it only superficial treatment. Checking it every time a command could possibly produce an error would have a performance penalty. Notice that FormPaint performs a single call to glGetError at the end of the method. Fortunately the graphics library is capable of storing multiple error codes. If several error codes have accumulated, multiple calls to glGetError are required to clear them all. Accordingly this application replaces its default exception...
Implementation 1
To demonstrate the specular component of a light source, load the Spot.Dpr project from OpenGL Chapter.5 Spot. Create a new directory called OpenGL Chapter.5 Spec and save the project as Specular.Dpr into the new directory. Save its main unit as Specl.Pas in the same directory. At the bottom of the FormCreate method add a new glLightfv command. end FormCreate Actually, LIGHT0 by default has a pure white specular component, but this illustration needs something a little less intense. Assign a...
Transformation Order Revisited
About the only thing left for this structure is to add scaling as well, but that would not add much to the OpenGL knowledge because the results are easy to predict. There is something else that can contribute significantly to the level of OpenGL understanding. The ability to switch back and forth between rotating before translation and rotating after translation reveals a dramatic difference between the two. Add the following to the case statement The form declaration needs to include the...
Culling
There it is Those polygons have a back side What if the cube was not open The shocking truth is that even if there is no possible way to see the back side of the polygons, OpenGL draws them Fortunately depth testing hidden surface removal keeps them from bleeding though. Better yet, an OpenGL command can tell it not even to draw them. procedure glCullFace mode GLenum stdcall The possible values for mode with obvious meanings are To cull faces means to remove them from the list of things to...
View Port Manipulation
The view port is the next experimental subject. The orthographic projection can change some of its boundary numbers, but still have the same boundary the view port . Just the arbitrary meaning of the numbers change. The view port boundary numbers have a real meaning, which is window coordinates. Changing these numbers changes the actual boundary of the view port. Restore the call to glOrtho to its symmetrical arrangement, but leave it at the bottom of FormCreate. glOrtho...




