Results 1 to 3 of 3

Thread: A new question of glReadPixels()

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2008
    Posts
    12

    A new question of glReadPixels()

    Code :
    #include <windows.h>
    #include <gl\GL.h>
    #include <glut.h>
    #include <gl\glu.h>
    #include <stdio.h>
     
     
    void DrawRegion();
    void myInit(void);
    void myDisplay(void);
     
    int main(int argc, char **argv)
    {
        glutInit(&amp;argc, argv);
        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
        glutInitWindowSize(640, 480);
        glutInitWindowPosition(100, 150);
        glutCreateWindow("test");
        glutDisplayFunc(myDisplay);
        myInit();
        glutMainLoop();
     
        return 0;
    }
    void myInit(void)
    {
        glClearColor(1.0, 1.0, 1.0, 0.0);
        glPointSize(1.0);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluOrtho2D(0.0, 640.0, 0.0, 480.0);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
    }
    void myDisplay(void)
    {
        glClear(GL_COLOR_BUFFER_BIT);
        DrawRegion();
        //glFlush();
        glutSwapBuffers();
    }
    void DrawRegion(void)
    {
    	GLubyte Pixel = 0;
        glColor3ub(0, 0, 0);
    	//for(GLint i = 500; i > 100; i--)
    	//{
    	//	glBegin(GL_POINTS);
    	//	glVertex2i(i, 50);
    	//	glEnd();
    	//	glReadPixels(i + 1, 50, 1, 1, GL_RED, GL_UNSIGNED_BYTE, &amp;Pixel);
    	//    printf("%d ", Pixel);
    	//}
    	glBegin(GL_POINTS);
    	glVertex2i(50, 50);
    	glEnd();
    	glReadPixels(50, 50, 1, 1, GL_RED, GL_UNSIGNED_BYTE, &amp;Pixel);
    	printf("%d ", Pixel);
    	glReadPixels(49, 50, 1, 1, GL_RED, GL_UNSIGNED_BYTE, &amp;Pixel);
    	printf("%d ", Pixel);
    	glReadPixels(50, 49, 1, 1, GL_RED, GL_UNSIGNED_BYTE, &amp;Pixel);
    	printf("%d ", Pixel);
    	glReadPixels(49, 49, 1, 1, GL_RED, GL_UNSIGNED_BYTE, &amp;Pixel);
    	printf("%d ", Pixel);
    	glFlush();
    }
    This is my test code. I get the result "255 0 255 255" on my computer.In the past, I considered glReadPixels(50, 50, 1, 1, GL_RED, GL_UNSIGNED_BYTE, &Pixel) get the value of pixel(50,50).
    But, according to the result, glReadPixels(49, 50, 1, 1, GL_RED, GL_UNSIGNED_BYTE, &Pixel) get the value of pixel(50,50).

  2. #2
    V-man
    Guest

    Re: A new question of glReadPixels()

    Officially, the bottom left corner is 0, 0
    so I think you want to read 49, 49
    If it is not correct, send a bug report to the company.

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2008
    Posts
    12

    Re: A new question of glReadPixels()

    Is it a bug? Dose somebody else get the same result? Can it has relations to my computer?

Similar Threads

  1. A basic question concerning glReadPixels
    By art-ganseforth in forum OpenGL: Basic Coding
    Replies: 11
    Last Post: 09-30-2018, 12:00 PM
  2. A question about glReadPixels() in Windows.
    By coldwater in forum OpenGL: Windows
    Replies: 5
    Last Post: 10-03-2012, 03:00 PM
  3. Question with glReadPixels ?
    By HanWu in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 04-08-2009, 06:16 AM
  4. Performance of glReadPixels() question
    By cpsmusic in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 11-09-2007, 09:27 AM
  5. glReadPixels question
    By surgptr in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 11-05-2004, 12:46 PM

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