I use glReadPixels
function but I got a wrong value.
void GLObjectManager::push_back(GLObject* obj) {
lock_guard<std::mutex> lock(_mutex);
obj->setIndex(numOfObject);
GLfloat green = numOfObject * 50;
GLfloat fcolor[4] = { 0.0f, green / 255.0f, 0.0f, 1.0f };
obj->setFakeColors(fcolor, 4);
objList.push_back(obj);
numOfObject++;
}
set a color function
void GLObject::drawFake() {
glPushMatrix();
if (_isVisible) {
glShadeModel(GL_FLAT);
glEnableClientState(GL_VERTEX_ARRAY);
glColor4f(fakeColors[0], fakeColors[1], fakeColors[2], fakeColors[3]);
// glColor4ub(fakeColors[0], fakeColors[1], fakeColors[2], fakeColors[3]);
if (vertex != NULL) glVertexPointer(3, GL_FLOAT, 0, vertex);
glEnableClientState(GL_NORMAL_ARRAY);
if (normal != NULL) glNormalPointer(GL_FLOAT, 0, normal);
motion();
if (indices != NULL) glDrawElements(GL_TRIANGLE_STRIP, indiceLength, GL_UNSIGNED_SHORT, indices);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
}
glPopMatrix();
}
and drawing function
int x = engine->state.x[pointerIndex];
int y = screenManager->scrHeight - engine->state.y[pointerIndex];
glReadPixels(x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
and glReadPixels
function
I expected 0, 50, 100
but it returns 0, 50, 99
(pixels[1] value)
what is the problem?
glReadPixels
function? or glColor4f
function?
please give me a hint…