Menu

[r124]: / InterlaceStencil.cpp  Maximize  Restore  History

Download this file

109 lines (91 with data), 3.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
// 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();
}