Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: get current mouse position's color

  1. #1
    Newbie Newbie
    Join Date
    Jan 2013
    Posts
    2

    get current mouse position's color

    Hi. I'm have a square(white color) in my screen. Now i get the mouse position(x and y) through this code:
    Code :
    POINT pt;
    GetCursorPos(&pt);
    I want to know if the mouse is on the my square.
    How to know the color of mouse position(x,y) on the screen?

  2. #2
    Newbie Newbie
    Join Date
    Jan 2013
    Posts
    2
    How to use glReadPixels() for reading color of a pixel. Can you give me an example please?
    Thanks

  3. #3
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,264
    Quote Originally Posted by dousti91 View Post
    How to use glReadPixels() for reading color of a pixel. Can you give me an example please?
    Thanks
    GLubyte rgba[4];
    glReadPixels(point.x, windowheight-1-point.y, 1, 1, GL_BGRA, GL_UNSIGNED_BYTE, rgba);

    You need to do windowheight-1-point.y because coordinate for y is from bottom=0 to top while for Windows, it is inverted. We read a BGRA format because that is the format that is typically used on Windows.
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •