我正在尝试创建一些隔行扫描图像以在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);
答案 0 :(得分:1)
我认为模板缓冲区不适合这个。如今,使用片段着色器更容易进行行隔行扫描。在OpenGL-3之前的几天,我会使用多边形点画(就像我在隔行扫描的3D电视补丁中所做的那样,我已经将其包含在mplayer中)。这样可以省去将几何体放在正确位置的麻烦。
在着色器中,您可以基于每个像素在两个源图像之间进行选择,使用gl_FragCoord视口像素坐标作为条件。或者你绘制两行和{/ 1}}行/列的片段。