Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
GraPa
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kai Westerkamp
GraPa
Commits
78f61664
Commit
78f61664
authored
Nov 23, 2015
by
Kai Westerkamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
FBO start
parent
a4b5790c
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
137 additions
and
9 deletions
+137
-9
display.frag
A2/display.frag
+10
-0
display.vert
A2/display.vert
+11
-0
glview.cpp
A2/glview.cpp
+98
-5
glview.h
A2/glview.h
+8
-0
hellocube.pro
A2/hellocube.pro
+3
-1
hellocube.qrc
A2/hellocube.qrc
+2
-0
mainwindow.cpp
A2/mainwindow.cpp
+0
-1
phong.frag
A2/phong.frag
+4
-2
sceneprimitive.cpp
A2/sceneprimitive.cpp
+1
-0
No files found.
A2/display.frag
0 → 100644
View file @
78f61664
uniform
sampler2D
Texture
;
varying
vec4
qt_TexCoord0
;
void
main
(
void
)
{
gl_FragColor
=
texture2D
(
Texture
,
qt_TexCoord0
.
st
);
}
A2/display.vert
0 → 100644
View file @
78f61664
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
;
}
A2/glview.cpp
View file @
78f61664
#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
)
...
...
A2/glview.h
View file @
78f61664
...
...
@@ -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
();
};
...
...
A2/hellocube.pro
View file @
78f61664
...
...
@@ -41,4 +41,6 @@ RESOURCES += \
DISTFILES
+=
\
phong
.
frag
\
phong
.
vert
phong
.
vert
\
display
.
frag
\
display
.
vert
A2/hellocube.qrc
View file @
78f61664
...
...
@@ -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>
A2/mainwindow.cpp
View file @
78f61664
...
...
@@ -242,7 +242,6 @@ void MainWindow::updateStatusBar()
{
QString
text
=
scene
->
getActive
()
->
getName
();
statusBar
->
showMessage
(
text
);
qDebug
()
<<
"updateStatusBar()"
<<
text
;
}
void
MainWindow
::
showSingle
(){
...
...
A2/phong.frag
View file @
78f61664
...
...
@@ -30,7 +30,9 @@ void main(void)
);
if
(
shaded
)
gl_Frag
Color
=
color
;
gl_Frag
Data
[
0
]
=
color
;
else
gl_FragColor
=
vec4
(
1
,
1
,
0
,
1
);
gl_FragData
[
0
]
=
vec4
(
1
,
1
,
0
,
1
);
gl_FragData
[
1
]
=
vec4
(
normal
,
1
);
}
A2/sceneprimitive.cpp
View file @
78f61664
...
...
@@ -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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment