我正在尝试创建一些隔行扫描图像以在 3DTV 上输出。我的方法使用 OpenGL 的模板缓冲区在每个偶数行像素上绘制线条网格。在我的笔记本电脑上,生成的图像看起来是交错的,但是当我输出到 3DTV(通过 HDMI 电缆)时,看起来好像没有在每行偶数行像素上绘制线条。我的笔记本电脑和电视的垂直分辨率为 1080 像素。下面使用的屏幕坐标范围从屏幕左下角的 (-1, -1) 到右上角的 (1, 1)。这是我用来在模板缓冲区上绘制网格的代码。如果有人可以为我检查一下,看看我是否做错了什么,我将不胜感激。如果我的代码没问题,问题可能是电视调整了笔记本电脑的输出大小。
glEnable(GL_STENCIL_TEST);
glClearStencil(0);
glClear(GL_STENCIL_BUFFER_BIT);
glStencilOp (GL_REPLACE, GL_REPLACE, GL_REPLACE);
glDisable(GL_DEPTH_TEST);
glStencilFunc(GL_ALWAYS,1,1);
const int stencilsize = 2500;
// hardcoding 2500, not the greatest solution in the world i know...
GLfloat stencilVertices[stencilsize] = {0.0};
//if we know the window height, we can draw a line in the stencil buffer on even row of pixels in the window
currheight = 1080;
GLint i = 0;
GLfloat ht = -1;
/*start ht @ -1, increase by 4/currheight each time, until 1 is reached*/
while ((ht < 1) && (i < stencilsize-4))
{
stencilVertices[i] = -1; //left edge of screen
i++;
stencilVertices[i] = ht; //current line's y coord
i++;
stencilVertices[i] = 1; //right edge of screen
i++;
stencilVertices[i] = ht; //current line's y coord
i++;
ht += 4.0/currheight; //increase ht by (4/(height of window)) each time to mark even rows only (until ht == 1)
}
glGenBuffers(1, &m_ui32Stencilpattern);
glBindBuffer(GL_ARRAY_BUFFER, m_ui32Stencilpattern);
glBufferData(GL_ARRAY_BUFFER, (stencilsize * sizeof(GLfloat)), stencilVertices, GL_STATIC_DRAW);
glEnableVertexAttribArray(VERTEX_ARRAY);
glVertexAttribPointer(VERTEX_ARRAY, 2, GL_FLOAT, GL_FALSE, 0, 0);
glDrawArrays(GL_LINES, 0, stencilsize);