1 #include <GLviewer/OutputAttachments/GLProjectionOutputAttachment.hh>
13 GLProjectionOutputAttachment::~GLProjectionOutputAttachment() {
17 int GLProjectionOutputAttachment::Draw() {
25 int GLProjectionOutputAttachment::InitShader(std::string vertexCode, std::string fragmentCode) {
27 glGetIntegerv(GL_VIEWPORT, vp.
GetData());
30 glGetIntegerv(GL_STENCIL_BITS, &stencilbits);
32 glGetIntegerv(GL_ALPHA_BITS, &alphaBits);
34 unsigned int imgWidth = vp[2] - vp[0];
35 unsigned int imgHeight = vp[3] - vp[1];
37 specialDisplayTex_.Create();
38 specialDisplayTex_.
Set(GL_LINEAR, GL_LINEAR, GL_CLAMP, GL_CLAMP, GL_TEXTURE0);
39 specialDisplayTex_.SetTextureNr(GL_TEXTURE0);
41 specialDisplayTex_.Allocate(imgWidth, imgHeight, GL_RGBA8);
43 specialDisplayTex_.Allocate(imgWidth, imgHeight, GL_RGB8);
44 specialDisplayDepth_.Create();
45 specialDisplayDepth_.Set(GL_NEAREST, GL_NEAREST, GL_CLAMP, GL_CLAMP, GL_TEXTURE1);
46 specialDisplayDepth_.SetTextureNr(GL_TEXTURE1);
48 specialDisplayDepth_.Allocate(imgWidth, imgHeight, GL_DEPTH_COMPONENT);
50 specialDisplayDepth_.Allocate(imgWidth, imgHeight, GL_DEPTH24_STENCIL8_EXT);
52 specialDisplayRenderingFBO_.Create();
53 specialDisplayRenderingFBO_.AttachTexture(specialDisplayTex_, GL_COLOR_ATTACHMENT0_EXT);
54 specialDisplayRenderingFBO_.AttachTexture(specialDisplayDepth_, GL_DEPTH_ATTACHMENT_EXT);
56 specialDisplayRenderingFBO_.AttachTexture(specialDisplayDepth_, GL_STENCIL_ATTACHMENT_EXT);
57 specialDisplayRenderingFBO_.CheckComplete();
59 shaderF_.Create(GL_FRAGMENT_SHADER, fragmentCode.c_str());
60 shaderV_.Create(GL_VERTEX_SHADER, vertexCode.c_str());
63 shaderProg_.AttachShader(shaderF_);
64 shaderProg_.AttachShader(shaderV_);
75 int GLProjectionOutputAttachment::StandardDraw_() {
77 glGetIntegerv(GL_VIEWPORT, vp.
GetData());
79 unsigned int imgWidth = vp[2] - vp[0];
80 unsigned int imgHeight = vp[3] - vp[1];
83 target_->ClearColorBuffer(ClearColor_[0],ClearColor_[1],ClearColor_[2],ClearColor_[3]);
84 target_->ClearDepthBuffer();
87 shaderProg_.SetUniform(
"tex", specialDisplayTex_.GetTextureNrInUniformFormat());
88 shaderProg_.SetUniform(
"dep", specialDisplayDepth_.GetTextureNrInUniformFormat());
89 shaderProg_.SetUniform(
"w", (
float)imgWidth);
90 shaderProg_.SetUniform(
"h", (
float)imgHeight);
92 glMatrixMode(GL_PROJECTION);
95 gluOrtho2D(0, imgWidth, 0, imgHeight);
96 glMatrixMode(GL_MODELVIEW);
101 glPushAttrib(GL_ENABLE_BIT);
102 glEnable(GL_TEXTURE_2D);
103 specialDisplayTex_.BindTU();
104 specialDisplayDepth_.BindTU();
106 glColor3f(1.0, 0.0, 0.0);
107 glTexCoord2f(0.0, 0.0);
108 glVertex2f(0.0, 0.0);
110 glColor3f(0.0, 1.0, 0.0);
111 glTexCoord2f(0.0, 1.0);
112 glVertex2f(0.0, imgHeight);
114 glColor3f(0.0, 0.0, 1.0);
115 glTexCoord2f(1.0, 1.0);
116 glVertex2f(imgWidth, imgHeight);
118 glColor3f(1.0, 1.0, 1.0);
119 glTexCoord2f(1.0, 0.0);
120 glVertex2f(imgWidth, 0.0);
124 glMatrixMode(GL_MODELVIEW);
126 glMatrixMode(GL_PROJECTION);
130 GLF_THROW_ON_OPENGL_ERROR
void Set(const T &scalar)
set all elements to a scalat value
const T * GetData() const
get the data pointer the member function itself is const (before {..}) because it doesn't change the...
Interface for render targets.