如何在OpenGL中更改特定像素的模板缓冲区值(glDrawPixel)

时间:2017-01-19 11:32:57

标签: c++ opengl

我开发了一个程序来读取模板缓冲区值。

for(int i=0; i<height; i++)
{
    for(int j=0; j<width; j++)
    {
        int stencilValue;
        glReadPixels(j,i,1,1, GL_STENCIL_INDEX, GL_UNSIGNED_INT, &stencilValue);
    }
}

我们说我只有3x3像素,模板测试的结果是

1 1 1
1 1 1 
0 0 0 

并将模板缓冲区数据保存到

vector<Vector3i> S;

现在我想将像素(2,1)处的模板缓冲区值更改为1

预期结果是

1 1 1
1 1 1
0 1 0

我该怎么做? 我试着用

int Image[3][3];
for(unsigned int i=0; i<height; i++)
    for(unsigned int j=0; j<width; j++)
          Image[j][i] = S[j](i);
Image[2][1] = 1;
glDrawPixels(3, 3, GL_STENCIL_BITS, GL_UNSIGNED_INT, Image);

但结果与我的预期不一样。 当我增加窗口大小时,有像204这样的奇怪值。 问题是什么?

0 个答案:

没有答案