Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 73735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:14:53+00:00 2026-05-10T20:14:53+00:00

Despite an earlier question ( asked here ), our project is constrained to using

  • 0

Despite an earlier question (asked here), our project is constrained to using glDrawPixels, so we have to do some hackery.

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.

The context is set up like:

The Big Red Book has code that looks like this:

        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); 

And then the call to make the smaller-but-zoomed image looks like

        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); 

where mStartY and mStartX are the points where the click happened.

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).

The data is a black-and-white unsigned short array, and is set with this code:

        float step = (65535.0f / (float)(max - min));         mColorTable = new ushort[65536];         int i;         for (i = 0; i < 65536; i++)         {             if (i < min)                 mColorTable[i] = 0;             else if (i > 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); 

Now, according to this documentation, 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.

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.

Oh, I’m using C# and the Tao framework, if that matters.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T20:14:54+00:00Added an answer on May 10, 2026 at 8:14 pm

    Here’s the answer. The problem is that the LUT is being applied twice, so before calling the copy, call:

    Gl.glPixelTransferi(Gl.GL_MAP_COLOR, Gl.GL_FALSE); 

    Then, once done, call:

    Gl.glPixelTransferi(Gl.GL_MAP_COLOR, Gl.GL_TRUE); 

    That way, the ‘extreme clamping’ I was describing is removed.

    @thing2k– your solution causes the copy to happen outside the graphics card, so slows down the drawing on mouse drag, but doesn’t fix the double clamp.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 70k
  • Answers 71k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Need to put where the resource is coming from. <TextBox… May 11, 2026 at 1:07 pm
  • added an answer Try GoFlow, a workflow engine for Django. May 11, 2026 at 1:07 pm
  • added an answer Like all C/C++ programs, the compiler has to know in… May 11, 2026 at 1:07 pm

Related Questions

Why are SQL distributions so non-standard despite an ANSI standard existing for SQL? Are
Despite primarily being a windows user, I am a huge fan of rsync. Now,
Despite having very little Linux experience, I'm too enticed by VPS (and too sick
Despite this being one of the best error messages I've ever seen (second only
Well, after a long time writing .net programs in C# I started to feel
I'm a beginner C++ programmer, and to stretch my mind I've been trying some
A couple of months back I started a relatively simple C# app which I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.