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"
GLView::GLView(Scene *scene,Camera * camera,Controler *controler )
{
this->camera = camera;
......@@ -29,6 +30,8 @@ void GLView::initializeGL ( ) {
static GLfloat lightPosition[4] = { 0.0, 0.0, 4.0, 1.0 };
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
//Shader Setup
initShader();
shader->bind();
......@@ -49,6 +52,21 @@ void GLView::initShader()
shader->addShader(fragment);
if(!shader->link())
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(){
......@@ -60,9 +78,11 @@ void GLView::home(){
void GLView::paintGL ()
{
// QGLFramebufferObjectFormat format;
// format.setSamples();
// format.setAttachment(QGLFramebufferObject::);
QGLFunctions functions = QGLFunctions(this->context());
shader->bind();
// functions.glBindFramebuffer(GL_FRAMEBUFFER,fbo);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
......@@ -77,7 +97,6 @@ void GLView::paintGL ()
shader->setUniformValue("shaded",true);
//set Projection and Camera Rotation
camera->setupCamera(aspect);
......@@ -106,11 +125,85 @@ void GLView::paintGL ()
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 )
{
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);
}
......@@ -134,7 +227,7 @@ void GLView::mousePressEvent(QMouseEvent *event )
void GLView::mouseMoveEvent(QMouseEvent *event )
{
controler->mouseMoveEvent(this,event);
controler->mouseMoveEvent(this,event);
}
void GLView::wheelEvent(QWheelEvent *event )
......
......@@ -7,6 +7,8 @@
#include <controler.h>
#include <camera.h>
#include <scene.h>
#include <gl/GLU.h>
#include <QGLFunctions>
class GLView : public QGLWidget
{
......@@ -34,6 +36,7 @@ public:
private:
QGLShaderProgram *shader;
QGLShaderProgram *displayShader;
Scene *scene;
Controler *controler;
......@@ -43,6 +46,11 @@ private:
GLdouble aspect;
GLuint fbo;
GLuint color;
GLuint picID;
GLuint depth;
void initShader();
};
......
......@@ -41,4 +41,6 @@ RESOURCES += \
DISTFILES += \
phong.frag \
phong.vert
phong.vert \
display.frag \
display.vert
......@@ -18,5 +18,7 @@
<file>img/viewports.png</file>
<file>img/view-single.png</file>
<file>img/delete.png</file>
<file>display.frag</file>
<file>display.vert</file>
</qresource>
</RCC>
......@@ -242,7 +242,6 @@ void MainWindow::updateStatusBar()
{
QString text = scene->getActive()->getName();
statusBar->showMessage(text);
qDebug()<<"updateStatusBar()"<<text;
}
void MainWindow::showSingle(){
......
......@@ -30,7 +30,9 @@ void main(void)
);
if(shaded)
gl_FragColor = color;
gl_FragData[0] = color;
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(){
gluDisk( qobj, 0.0 , radius, tesselation, 1);
break;
case Cone:
gluQuadricOrientation(qobj,GLU_OUTSIDE);
gluCylinder(qobj,radius,0,3,tesselation,tesselation);
gluQuadricOrientation(qobj,GLU_INSIDE);
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