Chee Yap
PIXEL MANIPULATION
1. Introduction |
2. Fragments and Pixels |
3. Frame Buffers |
4. Color Buffers |
5. Depth Buffers |
6. Stencil Buffer: Filling Non-Convex Polygons |
7. Tesselation |
8. Proof of Parity Theorem |
9. Pixmap Reading and Drawing |
10. Pixel Formats and Types |
11. Pixel Storage Mode |
12. BitMaps |
13. Fonts |
14. pixmap.cc - program to read/draw images. |
15. pan.cc - program for panning images. |
Unfortunately, in step (3), because of rounding errors, one cannot reliably predict whether P or the decal would be displayed at any pixel position where they both appear. So this does not work. Of course, the above solution will work if we move the decal slightly in front of F. But then, a side view of the model will appear odd.
Question: how would you modify the solution if (iii) fails?
But we can proceed as follows. Pick an arbitrary point O (possible a vertex of P). Then for each edge of P (including the edges incident on O), we form a triangle. Call these the O-triangles. Relative to the set of O-triangles, every point in the plane now has a covering number which is the number of triangles it is contained in. This covering number is dependent on O (consider the case where O is slightly on side of an edge, versus slightly on the other side).
we specify the stencil test. This test invokes a comparison function denoted by func. The comparison is between the MASKED reference value refVal and the MASKED current stencil pixel. By MASKED we mean that the respective values are first AND'ed with the mask bitMask. The possible values of func are GL_NEVER, GL_ALWAYS, GL_LESS, GL_LEQUAL, GL_NOTEQUAL, etc. For our current application, we set func = GL_ALWAYS; the other two arguments are irrelevant.
The possible values of each of these 3 arguments are GL_KEEP, GL_ZERO, GL_REPLACE, GL_INCR, GL_DECR, GL_INVERT. The last one is what we need here, and it performs a bitwise inversion of the current stencil pixel. The function fail is invoked if the stencil test (from previous bullet) fails. Otherwise, we invoke zfail or zpass, depending on whether the depth test fails or passes. Interestingly, we see that stencil operation depends on the depth test as well! For our current application, we set zpass = GL_INVERT and zfail = GL_KEEP. The argument fail is irrelevant.
gluTessBeginPolygon(tobj, userData); |
gluTessBeginContour(toj); |
: |
glTessVertex(tobj, coords3d, vertexData); : |
gluTessEndContour(toj); |
gluTessEndPolygon(tobj); |
Each ``polygon'' is really a polygonal region. A polygonal region is a connected set whose boundary components are called ``contours''. Hence, within the gluTessBeginPolygon and gluTessEndPolygon block, there can be one or more contour block.
Since no other O-triangles change their contribution to the covering number of q, this proves our result. Q.E.D.
ASIDES: (1) We can select only one buffer to read from, but can select more than one buffers to write to. (2) We can in fact select NO buffers to write to using GL_NONE. Interesting question: Why would we want to select no buffers? We already saw an example above!
This moves data from the buffer selected for reading (by glReadBuffer()), to the buffer(s) selected for writing (by glDrawBuffer()).
Examples of PARAM are GL_PACK_SWAP_BYTES and GL_UNPACK_SKIP_ROWS. The value of the former is a boolean, and the latter is an integer. However, we can use integer values to specify the value of GL_PACK_SWAP_BYTES: 0 for false value, and non-zero for true value.
Packing modes determine how pixmap data is stored into memory. They are therefore relevant to glPixelRead().
Unpacking modes determine how pixmap data are retrieved from memory. They are therefore relevant to glPixelDraw() and glBitMap().
Other affected commands relates to texture operations such as glTexImage*().
int wid = 0; |
glPixelStorei(GL_UNPACK_ROW_LENGTH, wid); |
int offset_x = 0; |
glPixelStorei(GL_UNPACK_SKIP_PIXELS, offset_x); |
int offset_y = 0; |
glPixelStorei(GL_UNPACK_SKIP_ROWS, offset_y); |
In the command glPixelDraw(w, h, ...), the default assumption is that the pixmap has w columns and h rows. But in case we are trying to draw a subimage in the pixmap, we need to specify the actual number of columns in each row, using the GL_UNPACK_ROW_LENGTH parameter. The other two parameters tells OpenGL what is the x- and y-offsets for the lower-left corner of the subimage.
glColor3f(1.0, 1.0, 1.0); // white |
glColor3f(1.0, 1.0, 1.0); // set raster position |
glColor3f(1.0, 1.0, 1.0); // red |
glBitMap(...); // display the bitmap |
glColor3f(1.0, 1.0, 1.0); // white |
glColor3f(1.0, 1.0, 1.0); // set raster position |
glColor3f(1.0, 1.0, 1.0); // red |
glBitMap(...); // display the bitmap |