source: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredShader.cpp @ 2858

Revision 2858, 1.8 KB checked in by mattausch, 16 years ago (diff)
Line 
1#include "DeferredShader.h"
2#include "glInterface.h"
3
4
5using namespace std;
6
7
8namespace CHCDemoEngine
9{
10
11void DeferredShader::Render(FrameBufferObject *fbo)
12{
13        glPushAttrib(GL_VIEWPORT_BIT);
14        glViewport(0, 0, fbo->GetWidth(), fbo->GetHeight());
15
16        glDisable(GL_ALPHA_TEST);
17        glDisable(GL_TEXTURE_2D);
18        glDisable(GL_LIGHTING);
19       
20        glMatrixMode(GL_PROJECTION);
21        glPushMatrix();
22        glLoadIdentity();
23
24        glMatrixMode(GL_MODELVIEW);
25        glPushMatrix();
26        glLoadIdentity();
27
28        const float offs = 0.5f;
29       
30        glOrtho(-offs, offs, -offs, offs, 0, 1);
31        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
32
33        cgGLEnableProfile(RenderState::sCgFragmentProfile);
34
35        cgGLBindProgram(sCgDeferredProgram);
36
37        cgGLSetTextureParameter(sPositionsTexParam, positionsTex);
38        cgGLEnableTextureParameter(sPositionsTexParam);
39
40        cgGLSetTextureParameter(sColorsTexParam, colorsTex);
41        cgGLEnableTextureParameter(sColorsTexParam);
42
43        cgGLSetTextureParameter(sNormalsTexParam, normalsTex);
44        cgGLEnableTextureParameter(sNormalsTexParam);
45       
46        glColor3f(1.0f, 1.0f, 1.0f);
47
48        glBegin(GL_QUADS);
49
50        float offs2 = 0.5f;
51
52        glTexCoord2f(0, 0); glVertex3f(-offs2, -offs2, -0.5f);
53        glTexCoord2f(1, 0); glVertex3f( offs2, -offs2, -0.5f);
54        glTexCoord2f(1, 1); glVertex3f( offs2,  offs2, -0.5f);
55        glTexCoord2f(0, 1); glVertex3f(-offs2,  offs2, -0.5f);
56
57        glEnd();
58
59        cgGLDisableTextureParameter(sColorsTexParam);
60        cgGLDisableTextureParameter(sPositionsTexParam);
61        cgGLDisableTextureParameter(sNormalsTexParam);
62
63        cgGLDisableProfile(RenderState::sCgFragmentProfile);
64       
65        glEnable(GL_LIGHTING);
66        glDisable(GL_TEXTURE_2D);
67       
68        glMatrixMode(GL_PROJECTION);
69        glPopMatrix();
70
71        glMatrixMode(GL_MODELVIEW);
72        glPopMatrix();
73
74        glPopAttrib();
75
76        PrintGLerror("deferred shading");
77}
78
79
80} // namespace
Note: See TracBrowser for help on using the repository browser.