// InterlaceStencil.cpp: implementation of the CInterlaceStencil class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "mce.h"
#include "InterlaceStencil.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CInterlaceStencil::CInterlaceStencil()
{
}
CInterlaceStencil::~CInterlaceStencil()
{
}
void CInterlaceStencil::interlace_stencil_horizontal(int gliWindowWidth, int gliWindowHeight)
{
GLint gliY;
// seting screen-corresponding geometry
glViewport(0,0,gliWindowWidth,gliWindowHeight);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
// gluOrtho2D(0.0,gliWindowWidth-1,0.0,gliWindowHeight-1);
// -0.32 instead of 1 to avoid rounding errors (especiali on Nvidia chipsets)
gluOrtho2D(0.0,gliWindowWidth-0.32,0.0,gliWindowHeight-0.32);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// clearing and configuring stencil drawing
glDrawBuffer(GL_BACK);
glEnable(GL_STENCIL_TEST);
glClearStencil(0);
glClear(GL_STENCIL_BUFFER_BIT);
glStencilOp (GL_REPLACE, GL_REPLACE, GL_REPLACE); // colorbuffer is copied to stencil
glDisable(GL_DEPTH_TEST);
glStencilFunc(GL_ALWAYS,1,1); // to avoid interaction with stencil content
// drawing stencil pattern
glColor4f(1,1,1,0); // alfa is 0 not to interfere with alpha tests
//glColor3f(1,1,1);
for (gliY=0; gliY<gliWindowHeight; gliY+=2)
{
glLineWidth(1);
glBegin(GL_LINES);
glVertex2i(0,gliY);
glVertex2i(gliWindowWidth,gliY);
glEnd();
}
glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP); // disabling changes in stencil buffer
glFlush();
}
void CInterlaceStencil::interlace_stencil_vertical(int gliWindowWidth, int gliWindowHeight)
{
GLint gliX;
// seting screen-corresponding geometry
glViewport(0,0,gliWindowWidth,gliWindowHeight);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
// gluOrtho2D(0.0,gliWindowWidth-1,0.0,gliWindowHeight-1);
// -0.32 instead of 1 to avoid rounding errors (especiali on Nvidia chipsets)
gluOrtho2D(0.0,gliWindowWidth-0.32,0.0,gliWindowHeight-0.32);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// clearing and configuring stencil drawing
glDrawBuffer(GL_BACK);
glEnable(GL_STENCIL_TEST);
glClearStencil(0);
glClear(GL_STENCIL_BUFFER_BIT);
glStencilOp (GL_REPLACE, GL_REPLACE, GL_REPLACE); // colorbuffer is copied to stencil
glDisable(GL_DEPTH_TEST);
glStencilFunc(GL_ALWAYS,1,1); // to avoid interaction with stencil content
// drawing stencil pattern
glColor4f(1,1,1,0); // alfa is 0 not to interfere with alpha tests
for (gliX=0; gliX<gliWindowWidth; gliX+=2)
{
glLineWidth(1);
glBegin(GL_LINES);
glVertex2i(gliX,0);
glVertex2i(gliX,gliWindowHeight);
glEnd();
}
glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP); // disabling changes in stencil buffer
glFlush();
}