“3d” means that the function takes 3 parameters of type GLdouble (not double!).
OpenGL keeps track of a large number of drawing attributes that an application can set and query using OpenGL commands. These are called OpenGL states; they function much like global variables whose value is maintained by OpenGL. Changing a state produces no output; rather, it affects drawing that occurs after the state change is made.
Here are some OpenGL states you definitely should know about:Here are some others we have run across briefly:
- Drawing color (set with glColor*)
- Clear color (set with glClearColor)
- Projection (set in various ways; we primarily used gluOrtho2D)
- Viewport dimensions (set with glViewport)
- Raster position (set with glRasterPos*)
Any two of the above (along with lots of others) would be correct.
- Line width (set with glLineWidth)
- Point size (set with glPointSize)
- Depth test enabled (set by passing GL_DEPTH_TEST to glEnable or glDisable)
- Drawing buffer (set with glDrawBuffer)
- Reading buffer (set with glReadBuffer)
OpenGL does not handle input. Thus, such things as mouse-button state and mouse position are not OpenGL states. Double buffering is also not an OpenGL state; double buffering is a procedure that is followed: draw in the back buffer, then swap front and back.
An interface is 2 1/2-dimensional if objects can have front-back a relationship, but there is no actual depth (z-coordinate).
The quintessential 2 1/2-D interface is one involving overlapping windows.
OpenGL has no curve primitives. We approximate a curve in OpenGL by using a polyline with closely spaced vertices. Closer vertices make a smoother curve, but also slower rendering.
An event is something that happens external to a program that needs processing by the program. Examples are input events (keypress, mouse button press or release, mouse movement) or windowing-related events (redisplay needed, window resize, window status change).
glBegin(GL_QUADS); glVertex2d(0., 0.); glVertex2d(1., 0.); glVertex2d(1., 1.); glVertex2d(0., 1.); glEnd();The above draws a filled square. So would GL_TRIANGLE_FAN or GL_POLYGON. You could also use GL_TRIANGLE_STRIP or GL_QUAD_STRIP, but the vertices would need to be given in a different order. To draw an outlined square, use GL_LINE_LOOP.
glFinish();The command glFlush sends commands to the server, but does not wait for them to be completed. The GLUT function glutSwapBuffers calls glFlush (not glFinish!) before swapping.
Graphics libraries draw objects by making them out of simple graphical pieces. The simplest pieces, out of which all complex objects are constructed, are called graphics primitives. These may include points, lines, filled regions, curves, various types of surfaces, raster images, and text.OpenGL primitives include points, lines, filled polygons, bitmaps, and general raster images.
- GL_POINTS
- GL_LINES
- GL_LINE_STRIP
- GL_LINE_LOOP
- GL_TRIANGLES
- GL_TRIANGLE_STRIP
- GL_TRIANGLE_FAN
- GL_QUADS
- GL_QUAD_STRIP
- GL_POLYGON
Additional instructions given at time of test: In your answer, distinguish between filled/unfilled by shading the interior of filled polygons.
Additional instructions given at time of test: In your answer, distinguish between filled/unfilled by shading the interior of filled polygons.
We are given values at 0 and 1, so we can do the simple form of lirping (we do not need to compute “t”).We handle the three components (R, G, B) by lirping each one separately:
Thus, (R, G, B) = (0.3, 0.7, 0.85).
- R: (1 – 0.3) × 0 + 0.3 × 1 = 0 + 0.3 = 0.3.
- G: (1 – 0.3) × 1 + 0.3 × 0 = 0.7 + 0 = 0.7.
- B: (1 – 0.3) × 1 + 0.3 × 0.5 = 0.7 + 0.15 = 0.85.
- Bitmap/raster fonts
- Outline/stroke fonts
Here are a couple of advantages for each. You only needed to give one from each of the lists below.Bitmap/raster fonts are better than outline/stroke fonts because:
- Bitmap fonts are are faster.
- Bitmap fonts are better-looking, at their designed size.
Outline/stroke fonts are better than bitmap/raster fonts because:
- Outline/stroke fonts look much better than bitmap fonts when resized or rotated.
- With outline/stroke fonts, a single font allows production of text at any size.
The synthetic camera model describes how to generate a 2-D image of a 3-D scene, similarly to the way most cameras work. A special point in the 3-D scene is chosen: the center of projection. The image to be generated is considered to lie in a plane somewhere in the scene. To map a given point in the scene to the image, draw a straight line through this point and the center of projection. If this line hits the image, then where it hits is where the given point appears in the image.
In extent testing, we determine which object was selected by a pointing device (e.g., a mouse) by iterating through the objects in the scene, generally in front-to-back order. For each object, we test whether the mouse position lies in its extent. The first object for which the test succeeds (if any) is the object picked.
We discussed two methods. You only needed to describe one. They are:
- Buffer Reading
- Draw each object in the scene in a different, solid color. Read the color of the pixel at the mouse position to determine which object was picked. If possible, do all this off-screen to avoid annoying the user.
- Selection Mode
- Set the clipping region to a small (single pixel?) region around the mouse position. Give each object in the scene a “name”, and send this name through the pipeline with the primitives making up the object. Get a list of the names of objects that were rendered (i.e., were not discarded by the clipping operation). These are the objects at the mouse position; the closest one is the one picked.
OpenGL presumes a client-server relationship between the application and the rendering hardware/software. OpenGL was designed to allow the application to manage the client-server information flow in an efficient manner. In particular:You only needed to mention one of the above.
- The glFlush and glFinish commands allow for buffer flushes (in case client-server communication is buffered) and synchronization.
- Call lists allow client-server communication to be minimized by giving OpenGL implementations a mechanism for storing long sequences of commands on the server for repeated playback.
glNewList(my_list, GL_COMPILE); for (int i=1; i<=10; ++i) cout << "i = " << i << endl; glEndList(); // 1-10 in a display list
Display lists only hold OpenGL commands, not arbitrary C++ code. The above code creates an empty display list, as well as doing some printing while the display list is being created.
// Draw a blue point at (0, 0) glBegin(GL_POINTS); glVertex2d(0., 0.); // The point glEnd(); glColor3d(0., 0., 1.); // Make the color blue glFlush(); // And go draw it!
OpenGL states only affect drawing that occurs after the state is set. Thus, in order to make the point blue, the glColor* command must be executed before the glVertex* command.