I want to know what Z-equal mode is and how to implement it in Opengl.I have seen this in a paper and it is written as “When painting on the object so only the part of the surface whose appearance changes needs to be redrawn. Since painting is usually localized to a small region, this involves redrawing many fewer polygons and can easily be done in realtime.These incremental changes are drawn using z-equal mode into the front-buffer and no buffer swaps are done…”
Z-equal mode is a variation of z-buffering where the screen is updated only if what is being drawn has the same depth as what has been drawn previously. This usually is enough to insure that polygons are only drawn on top of themselves and hence where they are visible
but drawing to front buffer only is fragile.
Is your paper titled “Direct WYSIWYG Painting and Texturing on 3D Shapes” ?
Beware that it is 20 years old.
One can use a classic RGBA color buffer for this, it would provide 32bits of precision.
The idea is to disable lighting (and antialiasing if present) and render the texture object normally, but with a different texture : same size, but each texel storing its s,t coordinates.
Once rendered, read the pixel below mouse pointer to retrieve the texture s,t coordinates.
As you posted in “OpenGL coding: advanced” I though you were already used to GL and computer graphics, but it now sounds you are just starting.
I did not read the paper, but you have several ways to do the “sphere” brush, a very precise way could be for example readpixels on a wider zone, with both RGBA+depth, reconstruct object space coordinate for each point, and only include those within the sphere centered on middle pixel.
Imagine first the texture A you want to draw on is 256x256, and that we draw a single texel at a time.
Create a second texture B of the same size, having the addition of 2 color gradients :
- horizontal goes from black to full red (so each column has increasing red component value)
- vertical goes from black to full blue (so each line has increasing blue component value)
Then, drawing a frame will be split in 2 parts :
- draw object with texture A, the real lighting if needed, etc.
- swapbuffers, clear
- draw same object, with texture B this time, same texcoords (this will never be seen on screen)
- readpixels at the cursor position
- the values you get can be mapped directly to position of the texel to be painted. texcoord s = red component, t = blue
Is that ok so far ?
Now, for larger textures :
- you have to take advantage of the 32 bits of a RGBA texture, allowing in theory up to 65000*65000 texture.
- decide on a way to pack the S and T bits among the 4 bytes of RGBA texture
- texture B will have to be drawn with GL_NEAREST filtering to prevent interpolation to get in the way.
- once a pixel RGBA value is read, unpack to S and T values
Reading color buffer :
glReadPixels(x, y, width, height, GL_RGBA,GL_UNSIGNED_INT_8_8_8_8,&colordata);
When using readpixels you can choose to read the depth buffer too :
glReadPixels(x, y, width, height,GL_DEPTH_COMPONENT,GL_FLOAT,&zdata);