I have googled for hours, and read the opengl.org forums for hours, and hacked my code for a couple of days now – to no avail. Info:
Goal: to calculate a triangle’s ‘face color’, by averaging the color of every pixel that is textured onto it.
I have tried two attempts, both failing, but I have a STRONG suspicion that glReadPixels is the culprit.
NOTE: EVERYTHING DONE IN BOTH APPROACHES IS IN ORTHO MODE.
http://lucidsoft.org/~oliver/approacha
^-- code
Approach A)
Render the model’s skin to a quad stretching from 0,0 -> SKINWIDTH, SKINHEIGHT
Next, render a triangle onto this skin, using the texture coordinates of that face of the model, drawing only to STENCIL!
Then, scan every pixel on the entire screen, if stencil == 1, then read the color of that pixel and save it.
Problem: stencil never tests true, when reading pixels with glReadPixels
http://lucidsoft.org/~oliver/approachb
^-- code
Approach B)
Much like A, except only render the triangle derived from texture coordinates [not the large quad of the skin], and render it to color buffer not to stencil. The idea on this approach is that i can read every pixel on the entire screen, add up the color values (black = 0.0 x 3, so that will not throw anything off), and divide this by the number of pixels in the triangle.
Problem: I never hit anything except for 0 0 0 for color, from glReadPixels
***Before you think you might have an answer to this!!!
I have tried a few different data types for the last value of glReadPixels; but not much seems to really change… but maybe this is the issue?
I have tried doing the glRenderBuffer() or whatever, and siwtching from FRONT to BACK and all that. It just seemed to create a big mess [i got a lot of hits for FRONT when I moved my window around, because it was reading off of my desktop) i am using double buffering of course…
Yes, I have 8 bits of stencil available. I test when my program runs. I’m running in 24bit color…
Yes, I realize what I am doing is slow, but that does not really matter to me. This will be done upon compiling a model…
I’m running a gf4 ti on linux, while this could be a driver issue I highly doubt it
If anybody could please give me any suggestions or ideas to hack at this code with; or if anybody has another idea for how to achieve this same thing; I would really appreciate it.
oliver.