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: how to use glreadpixel() ?

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2012
    Posts
    8

    how to use glreadpixel() ?

    hello,

    I just draw a rectangle as follows:

    glColor3f(1.0,.0,.0);
    glBegin(GL_POLYGON);
    glVertex2f(.0,.0);
    glVertex2f(0.2,.0);
    glVertex2f(0.2,1.0);
    glVertex2f(.0,1.0);
    glEnd();

    my questions is:

    -- what is the x,y, width and height adequate for glReadPixels(x,y, width,height,GL_RGB,GL_UNSIGNED_BYTE,data);
    to retrieve only the color red (rectangle) knowing that the points of the rectangle are of type float?

    --how to retrieve the values ​​of the parameter data, and save them in a text file ?

    cordially

  2. #2
    Intern Contributor uwi2k2's Avatar
    Join Date
    Mar 2011
    Posts
    97
    hi,

    Quote Originally Posted by M77ATTAR View Post
    -- what is the x,y, width and height adequate for glReadPixels(x,y, width,height,GL_RGB,GL_UNSIGNED_BYTE,data);
    to retrieve only the color red (rectangle) knowing that the points of the rectangle are of type float?
    you canīt do a 1 to 1 merging from the vertex data to screen coordinates.
    there are complex math forms that can do that.
    sorry i cant help you more, but you may search for 'world coordinates to screen coordinates'.

    cu
    uwi
    uwi2k2 - OpenGL Trainer: www.opengl-trainer.com
    ---------------------------------------------------------
    Free Programming Helpline: www.programming-hotline.com
    ---------------------------------------------------------
    A Friday Night Programmer: www.uwiworld.net

  3. #3
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,264
    Use gluProject. It gives window's space coordinates for each vertex.
    ------------------------------
    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
  •