I am trying to read the color of a rectangle drawn on the screen, but when I try to read from a coord, it appears that it reads it from an offset but this offset is not consistent. (I am using the SDL2 library in case that helps) I have found that it is inverting the coordinates e.g. if y is 0 it actually is y_Max.
I need to know how I can read a pixel from the correct coord, I do not care what method I use but a faster one is optimal.
I do not fully understand all of the code being thrown in here, I'm pretty new to images but I know I cast my project matrix here,
glEnable(GL_TEXTURE_2D);
GLuint texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, image->format->BytesPerPixel, image->w, image->h, 0, GL_RGB, GL_UNSIGNED_BYTE, image->pixels);
glOrtho(0.0f, 640.0f, 480.0f, 0.0f, -1.0f, 1.0f);
and then here I am drawing my rectangle.
glColor3f(Chrome[0], Chrome[1], Chrome[2]);
glTranslatef(0, 0, 0.0f);
glBindTexture(GL_TEXTURE_2D, texture);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(x*128.0f, 0, 0.0f);
glTexCoord2f(1.0f, 0.0f);
glVertex3f(128.0f*x+128, 0.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(128.0f*x+128, 128.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(x*128.0f, 128.0f, 0.0f);
glEnd();
glPopMatrix();
unsigned char pixel[3];
glReadPixels(5, 5, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, pixel);
std::cout << "R: " << (int)pixel[0] << std::endl;
std::cout << "G: " << (int)pixel[1] << std::endl;
std::cout << "B: " << (int)pixel[2] << std::endl;
std::cout << "X: " << std::endl;
std::cout << "Y: " << std::endl;
std::cout << std::endl;