我画了一个红色三角形,它是屏幕的一半(屏幕是1024 * 768,背景颜色是黑色)。然后我使用glReadPixels读取每个像素的颜色。应该有1024 * 768/2像素(r = 255,g = 0,b = 0),因为红色三角形是屏幕尺寸的一半,其余的像素应该是(r = 0,g = 0,b = 0)。但是,有少量像素既不是(r = 255,g = 0,b = 0)也不是(r = 0,g = 0,b = 0):
有些是(r = 64,g = 0,b = 0)
有些是(r = 128,g = 0,b = 0)
有些是(r = 191,g = 0,b = 0)
你知道会发生什么吗?
这是我的片段着色器:
in vec3 fragmentColor;
out vec3 color;
void main(){
color = vec3(1,0.,0.);
}
这就是我读取像素颜色的方式:
unsigned char *mycolor = (unsigned char *)malloc(3*width_here*height_here*sizeof(unsigned char *));
glReadPixels(0, 0, width_here, height_here, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid*)(mycolor));