Results 1 to 4 of 4

Thread: Picking color

  1. #1
    Guest

    Picking color

    Dear everyone

    I have some question for you. You know, we can know the color on pixel using glReadpixel().
    My implementation is following.

    OnRButtonDown(UINT nFlags, CPoint point){
    unsigned char rgb[3];
    glReadBuffer(GL_FRONT);
    glReadPixels(point.x, m_vViewport[3] - point.y - 1, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, rgb);

    char ss[50];
    sprintf(ss,"%d %d %d",(int)rgb[2],(int)rgb[1],(int)rgb[0]);
    MessageBox(ss);
    }

    I draw some objects on the screen.
    But the result always shows 204 204 204
    Could you please explain this?
    Thank you

  2. #2
    Senior Member Regular Contributor
    Join Date
    Dec 2002
    Location
    Poland
    Posts
    234

    Re: Picking color

    Hi

    At the beginnig I wanted to thank you . Recently I was thinking about color picking too but something was wrong and I couldn't figure out what was it. When I looked to your code I noticed that you have something like "m_vViewport[3] - point.y" in glReadPixels() and I thought "What the hell is that?!". So I got back to my program and I tried to subtract mouse position Y from screen height and now every thing works JUST FINE! I am not sure why is that so. Meaby I just didn't know it but is OpenGL taking (0,0) as left-bottom corner of the screen? Thanx once again.

    OK, getting back to your code. Hmm... I am afraid that a problem is somewhere else in the code. My own was similiar. Are you using double buffering? Did you check if your result isn't your clear color?

    I can send you a piece of my code, if you wish. Just send me an e-mail.

    See you,

    Orzech

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: Picking color

    204 is CC in hex, which is what some compiler uses for uninitialized values in debug mode (to help debugging). Try initialize your array to something else and see if it actually get the values 204 or if it keeps its old values. If the old values remains, then I can only think of one thing; you don't have a rendering context at the time you're reading the color.

    Orzech, yes, OpenGL has the origin in the lower left corner.

  4. #4
    Senior Member Regular Contributor
    Join Date
    Dec 2002
    Location
    Poland
    Posts
    234

    Re: Picking color

    Originally posted by Bob:
    Orzech, yes, OpenGL has the origin in the lower left corner.
    Good to know that.

Similar Threads

  1. FBOs for color picking
    By phil0stine in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 12-26-2017, 09:01 AM
  2. Color picking with hidden faces?
    By samurle in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 04-14-2013, 02:28 PM
  3. Picking using unique color IDs
    By m.gbt in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 01-17-2012, 04:12 AM
  4. Delphi color picking
    By Morphius in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 11-07-2002, 05:16 PM
  5. Picking With Color
    By Binqay in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 02-20-2002, 01:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean