Commit 78f61664 by Kai Westerkamp

FBO start

parent a4b5790c
uniform sampler2D Texture;
varying vec4 qt_TexCoord0;
void main(void)
{
gl_FragColor = texture2D(Texture, qt_TexCoord0.st);
}
attribute vec4 qt_Vertex;
attribute vec4 qt_MultiTexCoord0;
uniform mat4 qt_ModelViewProjectionMatrix;
varying vec4 qt_TexCoord0;
void main(void)
{
gl_Position = qt_ModelViewProjectionMatrix * qt_Vertex;
qt_TexCoord0 = qt_MultiTexCoord0;
}
#include "glview.h" #include "glview.h"
GLView::GLView(Scene *scene,Camera * camera,Controler *controler ) GLView::GLView(Scene *scene,Camera * camera,Controler *controler )
{ {
this->camera = camera; this->camera = camera;
...@@ -29,6 +30,8 @@ void GLView::initializeGL ( ) { ...@@ -29,6 +30,8 @@ void GLView::initializeGL ( ) {
static GLfloat lightPosition[4] = { 0.0, 0.0, 4.0, 1.0 }; static GLfloat lightPosition[4] = { 0.0, 0.0, 4.0, 1.0 };
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
//Shader Setup //Shader Setup
initShader(); initShader();
shader->bind(); shader->bind();
...@@ -49,6 +52,21 @@ void GLView::initShader() ...@@ -49,6 +52,21 @@ void GLView::initShader()
shader->addShader(fragment); shader->addShader(fragment);
if(!shader->link()) if(!shader->link())
qCritical()<< "Linking failed"<<shader->log(); qCritical()<< "Linking failed"<<shader->log();
vertex = new QGLShader(QGLShader::Vertex);
if(!vertex->compileSourceFile(QLatin1String(":/display.vert")))
qCritical()<< "Vertex Shader 2failed"<< vertex->log();
fragment = new QGLShader(QGLShader::Fragment);
if(!fragment->compileSourceFile(QLatin1String(":/display.frag")))
qCritical()<< "Fragment Shader 2 failed"<< fragment->log();
displayShader = new QGLShaderProgram(this);
displayShader->addShader(vertex);
displayShader->addShader(fragment);
if(!displayShader->link())
qCritical()<< "Linking failed"<<displayShader->log();
} }
void GLView::home(){ void GLView::home(){
...@@ -60,9 +78,11 @@ void GLView::home(){ ...@@ -60,9 +78,11 @@ void GLView::home(){
void GLView::paintGL () void GLView::paintGL ()
{ {
// QGLFramebufferObjectFormat format; QGLFunctions functions = QGLFunctions(this->context());
// format.setSamples();
// format.setAttachment(QGLFramebufferObject::); shader->bind();
// functions.glBindFramebuffer(GL_FRAMEBUFFER,fbo);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
...@@ -77,7 +97,6 @@ void GLView::paintGL () ...@@ -77,7 +97,6 @@ void GLView::paintGL ()
shader->setUniformValue("shaded",true); shader->setUniformValue("shaded",true);
//set Projection and Camera Rotation //set Projection and Camera Rotation
camera->setupCamera(aspect); camera->setupCamera(aspect);
...@@ -106,11 +125,85 @@ void GLView::paintGL () ...@@ -106,11 +125,85 @@ void GLView::paintGL ()
glEnd (); glEnd ();
} }
shader->release();
// displayShader->bind();
// functions.glBindFramebuffer(GL_FRAMEBUFFER,fbo);
// glViewport(0,0,this->width(),this->height());
// glMatrixMode (GL_MODELVIEW);
// glLoadIdentity ();
// glMatrixMode (GL_PROJECTION);
// glLoadIdentity ();
// displayShader->setUniformValue("Texture",color);
// glBegin (GL_LINE_LOOP);
// glVertex3i (-1, -1, 0);
// glVertex3i (1, -1, 0);
// glVertex3i (1, 1, 0);
// glVertex3i (-1, 1, 0);
// glEnd ();
// displayShader->release();
} }
void GLView::resizeGL(int width , int height ) void GLView::resizeGL(int width , int height )
{ {
aspect = 1.0*width/height; aspect = 1.0*width/height;
qDebug()<<"Resize:"<<width<<height;
QGLFunctions functions = QGLFunctions(this->context());
functions.glGenFramebuffers(1, &fbo);
functions.glBindFramebuffer(GL_FRAMEBUFFER,fbo);
// Create the color buffer
glGenTextures(1, &color);
glBindTexture(GL_TEXTURE_2D, color);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
// Create the color buffer
glGenTextures(1, &picID);
glBindTexture(GL_TEXTURE_2D, picID);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
// Create the depth buffer
glGenTextures(1, &depth);
glBindTexture(GL_TEXTURE_2D, depth);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, width, height, 0, GL_RED, GL_BYTE, NULL);
functions.glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,color,0);
functions.glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT1,GL_TEXTURE_2D,picID,0);
functions.glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_TEXTURE_2D,depth,0);
GLenum err = functions.glCheckFramebufferStatus(GL_FRAMEBUFFER);
if(err == GL_FRAMEBUFFER_COMPLETE){
qDebug()<<"FBO OK";
} else {
qDebug()<<"FBO ERROR"<<err;
}
functions.glBindFramebuffer(GL_FRAMEBUFFER, 0);
} }
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include <controler.h> #include <controler.h>
#include <camera.h> #include <camera.h>
#include <scene.h> #include <scene.h>
#include <gl/GLU.h>
#include <QGLFunctions>
class GLView : public QGLWidget class GLView : public QGLWidget
{ {
...@@ -34,6 +36,7 @@ public: ...@@ -34,6 +36,7 @@ public:
private: private:
QGLShaderProgram *shader; QGLShaderProgram *shader;
QGLShaderProgram *displayShader;
Scene *scene; Scene *scene;
Controler *controler; Controler *controler;
...@@ -43,6 +46,11 @@ private: ...@@ -43,6 +46,11 @@ private:
GLdouble aspect; GLdouble aspect;
GLuint fbo;
GLuint color;
GLuint picID;
GLuint depth;
void initShader(); void initShader();
}; };
......
...@@ -41,4 +41,6 @@ RESOURCES += \ ...@@ -41,4 +41,6 @@ RESOURCES += \
DISTFILES += \ DISTFILES += \
phong.frag \ phong.frag \
phong.vert phong.vert \
display.frag \
display.vert
...@@ -18,5 +18,7 @@ ...@@ -18,5 +18,7 @@
<file>img/viewports.png</file> <file>img/viewports.png</file>
<file>img/view-single.png</file> <file>img/view-single.png</file>
<file>img/delete.png</file> <file>img/delete.png</file>
<file>display.frag</file>
<file>display.vert</file>
</qresource> </qresource>
</RCC> </RCC>
...@@ -242,7 +242,6 @@ void MainWindow::updateStatusBar() ...@@ -242,7 +242,6 @@ void MainWindow::updateStatusBar()
{ {
QString text = scene->getActive()->getName(); QString text = scene->getActive()->getName();
statusBar->showMessage(text); statusBar->showMessage(text);
qDebug()<<"updateStatusBar()"<<text;
} }
void MainWindow::showSingle(){ void MainWindow::showSingle(){
......
...@@ -30,7 +30,9 @@ void main(void) ...@@ -30,7 +30,9 @@ void main(void)
); );
if(shaded) if(shaded)
gl_FragColor = color; gl_FragData[0] = color;
else else
gl_FragColor = vec4(1,1,0,1); gl_FragData[0] = vec4(1,1,0,1);
gl_FragData[1] = vec4(normal,1);
} }
...@@ -87,6 +87,7 @@ void ScenePrimitive::draw(){ ...@@ -87,6 +87,7 @@ void ScenePrimitive::draw(){
gluDisk( qobj, 0.0 , radius, tesselation, 1); gluDisk( qobj, 0.0 , radius, tesselation, 1);
break; break;
case Cone: case Cone:
gluQuadricOrientation(qobj,GLU_OUTSIDE);
gluCylinder(qobj,radius,0,3,tesselation,tesselation); gluCylinder(qobj,radius,0,3,tesselation,tesselation);
gluQuadricOrientation(qobj,GLU_INSIDE); gluQuadricOrientation(qobj,GLU_INSIDE);
gluDisk( qobj, 0.0, radius, tesselation, 1); gluDisk( qobj, 0.0, radius, tesselation, 1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment