Example for rendering something using the multisample. This provides anti aliasing for rendering things in a framebuffer
#include <OpenGLFramework/RenderingContext/glfPBuffer.hh>
#include <OpenGLFramework/SpecializedBatches/PMDWarp.hh>
#include <OpenGLFramework/Base/glfException.hh>
#include <OpenGLFramework/Base/glfFramebufferObject.hh>
#include <Utils/Param.hh>
#include <Utils/IOUtils.hh>
#include <Base/Image/ImageIO.hh>
#include <Base/Image/Image.hh>
#include <Image/Camera.hh>
#include <Gui/biasgl.h>
#include <GLviewer/Scenes/ScenePointLight.hh>
#include <GLviewer/GLProjectionParametersPerspective.hh>
#ifdef BIAS_HAVE_OPENSCENEGRAPH
#include <GLviewer/Scenes/ScenePlainOpenSceneGraph.hh>
#define HAVE_A_SCENEGRAPH
#endif
#ifdef BIAS_HAVE_OSG
#include <GLviewer/Scenes/SceneOSG.hh>
#define HAVE_A_SCENEGRAPH
#endif
using namespace std;
using namespace BIAS;
int main(int argc, char* argv[])
{
string *model = NULL;
string *projection = params.
AddParamString(
"Projection",
"",
"",
'p',GRP_NOSHOW);
int *numSamples = params.
AddParamInt(
"samples",
"number of samples used for multi sample buffers",
16, 0,16,'b',GRP_NOSHOW);
if(!IOUtils::ParseCommandLineEvalHelp(params, argc, argv) )
return 0;
#ifdef HAVE_A_SCENEGRAPH
bool hasmodel = false;
#endif
unsigned int width = 1024;
unsigned int height = 768;
try {
glViewport(0,0,width,height);
colorTexture.
Allocate(width, height, GL_RGB);
depthTexture.
Allocate(width, height, GL_DEPTH_COMPONENT);
GLF_THROW_ON_OPENGL_ERROR;
if(*projection != "") {
cout<<"Loading projection:"<<*projection<<endl;
int ret = proj.
XMLRead(*projection);
if(ret != 0) BIASERR("Reading projection failed!");
}
#ifdef BIAS_HAVE_OPENSCENEGRAPH
#endif
#ifdef BIAS_HAVE_OSG
BIAS::SceneOSG sceneOSG;
#endif
#ifdef HAVE_A_SCENEGRAPH
if(*model != ""){
cout<<"Loading model:"<<*model<<endl;
if(sceneOSG.AppendSubTreeFromFile(*model)>=0)
hasmodel= true;
}
#endif
glClearColor(0.0, 1.0, 0.0, 0.0);
glEnable(GL_MULTISAMPLE);
glEnable(GL_DEPTH_TEST);
glClearColor(0.0, 0.0, 0.0, 0.0);
glClearDepth(1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLineWidth(1);
#ifdef HAVE_A_SCENEGRAPH
if(hasmodel){
vector<SceneBase*> scenes; scenes.push_back(&lightScene);
scenes.push_back(&sceneOSG);
cout<<"Drawing target scene!"<<endl;
}
#endif
glDisable(GL_DEPTH_TEST);
glLineWidth(5);
glBegin(GL_LINES);
glColor3f(0.8,0.8,0.0);
glVertex2f(0.25,0.25);
glColor3f(0.0,0.0,1.0);
glVertex2f(-0.25,-0.25);
glEnd();
IOUtils::SaveCamera("colorBeforeBlit.mip",resultColor);
IOUtils::SaveCamera("depthBeforeBlit.mip", resultDepth);
colorRenderbuffer.
Create(GL_RGBA, width, height, *numSamples);
depthRenderbuffer.
Create(GL_DEPTH_COMPONENT, width, height, *numSamples);
glClearColor(1.0, 0.0, 0.0, 0.0);
glClearDepth(1.0);
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLineWidth(1);
#ifdef HAVE_A_SCENEGRAPH
if(hasmodel){
vector<SceneBase*> scenes; scenes.push_back(&lightScene);
scenes.push_back(&sceneOSG);
cout<<"Drawing source scene!"<<endl;
}
#endif
glDisable(GL_DEPTH_TEST);
glLineWidth(5);
glBegin(GL_LINES);
glColor3f(0.8,0.8,0.0);
glVertex2f(0.25,0.25);
glColor3f(0.0,0.0,1.0);
glVertex2f(-0.25,-0.25);
glEnd();
if(*numSamples == 0) {
IOUtils::SaveCamera("colorRenderbuffer.mip",resultColor);
IOUtils::SaveCamera("depthRenderbuffer.mip", resultDepth);
}
glfFramebufferObject::BlitColorBuffer(&sourceFbo, &targetFbo, GL_LINEAR);
glfFramebufferObject::Blit(&sourceFbo, &targetFbo, GL_DEPTH_BUFFER_BIT);
GLF_THROW_ON_OPENGL_ERROR;
IOUtils::SaveCamera("colorAfterBlit.mip",resultColor);
IOUtils::SaveCamera("depthAfterBlit.mip", resultDepth);
return -1;
}
}