Note that there are some explanatory texts on larger screens.

plurals
  1. POglDrawPixels/glCopyPixels to get a magnified view producing severely clamped image
    primarykey
    data
    text
    <p>Despite an earlier question (<a href="https://stackoverflow.com/questions/223894/opengl-rotation-using-gldrawpixels">asked here</a>), our project is constrained to using glDrawPixels, so we have to do some hackery.</p> <p>One of the feature requirements is to be able to have a magnified view show up on a clicked region of an image; so, looking at an image, I want to click the mouse, and have a 200% image window show up where the mouse is. As I drag my cursor, the window should follow the cursor.</p> <p>The context is set up like:</p> <p>The Big Red Book has code that looks like this:</p> <pre><code> Gl.glShadeModel(Gl.GL_FLAT); Gl.glClearColor(0.1f, 0.1f, 0.1f, 0.0f); Gl.glPixelStorei(Gl.GL_UNPACK_ALIGNMENT, 2); Gl.glPolygonMode(Gl.GL_FRONT_AND_BACK, Gl.GL_LINE); Gl.glDisable(Gl.GL_SCISSOR_TEST); Gl.glDisable(Gl.GL_ALPHA_TEST); Gl.glDisable(Gl.GL_STENCIL_TEST); Gl.glDisable(Gl.GL_DEPTH_TEST); Gl.glDisable(Gl.GL_BLEND); Gl.glDisable(Gl.GL_DITHER); Gl.glDisable(Gl.GL_LOGIC_OP); Gl.glDisable(Gl.GL_LIGHTING); Gl.glDisable(Gl.GL_FOG); Gl.glDisable(Gl.GL_TEXTURE_1D); Gl.glDisable(Gl.GL_TEXTURE_2D); Gl.glPixelTransferi(Gl.GL_MAP_COLOR, Gl.GL_TRUE); Gl.glPixelTransferf(Gl.GL_RED_SCALE, 1.0f); Gl.glPixelTransferi(Gl.GL_RED_BIAS, 0); Gl.glPixelTransferf(Gl.GL_GREEN_SCALE, 1.0f); Gl.glPixelTransferi(Gl.GL_GREEN_BIAS, 0); Gl.glPixelTransferf(Gl.GL_BLUE_SCALE, 1.0f); Gl.glPixelTransferi(Gl.GL_BLUE_BIAS, 0); Gl.glPixelTransferi(Gl.GL_ALPHA_SCALE, 1); Gl.glPixelTransferi(Gl.GL_ALPHA_BIAS, 0); </code></pre> <p>And then the call to make the smaller-but-zoomed image looks like</p> <pre><code> int width = (int)((this.Width * 0.2)/2.0); Gl.glReadBuffer(Gl.GL_FRONT_AND_BACK); Gl.glRasterPos2i(0, 0); Gl.glBitmap(0, 0, 0, 0, mStartX - (width*2), mStartY, null); Gl.glPixelZoom(2.0f, 2.0f); Gl.glCopyPixels(mStartX - width, mStartY, width, width, Gl.GL_COLOR); </code></pre> <p>where mStartY and mStartX are the points where the click happened.</p> <p>Problem is, the window that shows up is really mangling the lookup tables, and really clamping the image down to essentially a black-and-white binary image (ie, no shades of grey). </p> <p>The data is a black-and-white unsigned short array, and is set with this code:</p> <pre><code> float step = (65535.0f / (float)(max - min)); mColorTable = new ushort[65536]; int i; for (i = 0; i &lt; 65536; i++) { if (i &lt; min) mColorTable[i] = 0; else if (i &gt; max) mColorTable[i] = 65535; else mColorTable[i] = (ushort)((float)(i - min) * step); } .... //some irrelevant code Gl.glPixelMapusv(Gl.GL_PIXEL_MAP_R_TO_R, 65536, mColorTable); Gl.glPixelMapusv(Gl.GL_PIXEL_MAP_G_TO_G, 65536, mColorTable); Gl.glPixelMapusv(Gl.GL_PIXEL_MAP_B_TO_B, 65536, mColorTable); </code></pre> <p>Now, according to <a href="http://www.ugrad.cs.ubc.ca/~cs414/opengl/glCopyPixels.html" rel="nofollow noreferrer">this documentation</a>, I should use GL_PIXEL_MAP_I_TO_I and set INDEX_SCALE and INDEX_BIAS to zero, but doing that does not change the result, that the image is severely clamped. And by 'severely clamped' I mean it's either black or white, with very few shades of grey, but the original non-magnified image looks like what's expected.</p> <p>So, how do I avoid the clamping of the magnified view? Should I make a second control that follows the cursor and gets filled in with data from the first control? That approach seems like it would take the array copies outside of the graphics card and into C#, which would almost by definition be slower, and so make the control nonresponsive. </p> <p>Oh, I'm using C# and the Tao framework, if that matters.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload