0
실제로 더 큰 글자의 간단한 프로그램이 있는데, 이것을 제쳐두고 간단한 픽셀 읽기/쓰기를 시도했습니다 (Opengl
).
픽셀 색상을 읽는 것을 포함하는 첫 번째 섹션은 성공하지만, 픽셀을 쓰고 읽는 작업과 관련된 두 번째 작업이 실패합니다!glReadPixels는 OpenGL에서 잘못된 색상을 읽습니다.
두 번째 읽기 절차가 실패의 원인이 무엇 : 여기
#include <iostream>
#include <glut.h>
using namespace std;
void init(void)
{
glClearColor(1.0,0.0,0.0,0.0);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0,100.0,0.0,100.0);
}
void displayfnc()
{
glClear(GL_COLOR_BUFFER_BIT);
unsigned char current[3];
int r,g,b;
//x=0 to 6 is right
glBegin (GL_POINTS);
glColor3f (0.0,0.0,1.0);
glVertex2i (6,0);
glEnd();
//works well.
glReadPixels(6,0, 1, 1 , GL_RGB , GL_UNSIGNED_BYTE ,current);
r = current[0];
g = current[1];
b = current[2];
cout<<"read from x=6::::"<<"r:"<<r<<"g:"<<g<<"b:"<<b<<endl;
//x =7 and other isnt right
glBegin (GL_POINTS);
glColor3f (0.0,0.0,1.0);
glVertex2i (7,0);
glEnd();
//the problem is here in the reading.why this happen?
glReadPixels(7,0, 1, 1 , GL_RGB , GL_UNSIGNED_BYTE ,current);
r = current[0];
g = current[1];
b = current[2];
cout<<"Read from x=7::::"<<"r:"<<r<<"g:"<<g<<"b:"<<b<<endl;
glFlush();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(100,100);
glutInitWindowPosition(0, 0);
glutCreateWindow("BoundaryFill");
init();
glutDisplayFunc(displayfnc);
glutMainLoop();
return 0;
}
출력입니다 : 여기 문제를 보여줍니다 프로그램이 무엇입니까?
붙여 넣기 콘솔 출력뿐만 아니라 같아요 도움이 될 것입니다. – alexrider
@Alexrider : 완료되었습니다. – Breeze
RGB 값 _after_'glFlush()를 확인하면 어떨까요? – user1095108