Commit 227f8ace by Kai Westerkamp

bäh

parent a99eeaa6
#version 330
layout(location = 0) in vec4 Position;
layout(location = 0) in vec3 Position;
out vec3 vPosition;
......@@ -7,7 +7,7 @@ uniform mat4x4 VP;
void main(void)
{
vPosition = Position.xyz;
gl_Position = VP * Position;
vPosition = Position;
gl_Position = VP * vec4(Position,1.0);
}
......@@ -30,47 +30,49 @@ void MainWidget::initializeGL(){
animationShader = initShader(QLatin1String(":/animate.frag"),QLatin1String(":/animate.vert"));
m_view = QMatrix4x4();
m_view.lookAt(QVector3D(0.0,1.0,3.0),QVector3D(0.0,0.0,0.0),QVector3D(0.0,1.0,0.0));
m_view.lookAt(QVector3D(2.0,2.0,4.0),QVector3D(0.0,0.0,0.0),QVector3D(0.0,1.0,0.0));
//temp
static const GLfloat g_vertex_buffer_data[] = {
-1.0f,-1.0f,-1.0f,
-1.0f,-1.0f, 1.0f,
-1.0f, 1.0f, 1.0f,
1.0f, 1.0f,-1.0f,
-1.0f,-1.0f,-1.0f,
-1.0f, 1.0f,-1.0f,
1.0f,-1.0f, 1.0f,
-1.0f,-1.0f,-1.0f,
1.0f,-1.0f,-1.0f,
1.0f, 1.0f,-1.0f,
1.0f,-1.0f,-1.0f,
-1.0f,-1.0f,-1.0f,
-1.0f,-1.0f,-1.0f,
-1.0f, 1.0f, 1.0f,
-1.0f, 1.0f,-1.0f,
1.0f,-1.0f, 1.0f,
-1.0f,-1.0f, 1.0f,
-1.0f,-1.0f,-1.0f,
-1.0f, 1.0f, 1.0f,
-1.0f,-1.0f, 1.0f,
1.0f,-1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f,-1.0f,-1.0f,
1.0f, 1.0f,-1.0f,
1.0f,-1.0f,-1.0f,
1.0f, 1.0f, 1.0f,
1.0f,-1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f,-1.0f,
-1.0f, 1.0f,-1.0f,
1.0f, 1.0f, 1.0f,
-1.0f, 1.0f,-1.0f,
-1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
-1.0f, 1.0f, 1.0f,
1.0f,-1.0f, 1.0f
};
static const GLfloat g_vertex_buffer_data[] = {
-1.0f,-1.0f,-1.0f,
-1.0f,-1.0f, 1.0f,
-1.0f, 1.0f, 1.0f,
1.0f, 1.0f,-1.0f,
-1.0f,-1.0f,-1.0f,
-1.0f, 1.0f,-1.0f,
1.0f,-1.0f, 1.0f,
-1.0f,-1.0f,-1.0f,
1.0f,-1.0f,-1.0f,
1.0f, 1.0f,-1.0f,
1.0f,-1.0f,-1.0f,
-1.0f,-1.0f,-1.0f,
-1.0f,-1.0f,-1.0f,
-1.0f, 1.0f, 1.0f,
-1.0f, 1.0f,-1.0f,
1.0f,-1.0f, 1.0f,
-1.0f,-1.0f, 1.0f,
-1.0f,-1.0f,-1.0f,
-1.0f, 1.0f, 1.0f,
-1.0f,-1.0f, 1.0f,
1.0f,-1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f,-1.0f,-1.0f,
1.0f, 1.0f,-1.0f,
1.0f,-1.0f,-1.0f,
1.0f, 1.0f, 1.0f,
1.0f,-1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f,-1.0f,
-1.0f, 1.0f,-1.0f,
1.0f, 1.0f, 1.0f,
-1.0f, 1.0f,-1.0f,
-1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
-1.0f, 1.0f, 1.0f,
1.0f,-1.0f, 1.0f
};
glGenBuffers(1, &vertexbuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
......@@ -104,25 +106,25 @@ QOpenGLShaderProgram* MainWidget::initShader(QString fragSource, QString vertSou
void MainWidget::paintGL(){
qDebug()<<"Paint";
glViewport(0,0,width(),height());
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
animationShader->bind();
QMatrix4x4 VP = m_projection*m_view;
// QMatrix4x4 VP = m_view*m_projection;
//QMatrix4x4 VP = m_view*m_projection;
animationShader->setUniformValue("VP",VP);
animationShader->setUniformValue("MVP",VP);
glEnableVertexAttribArray(positionIndex);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0,(void*)0 // array buffer offset
);
glVertexAttribPointer(positionIndex, 3, GL_FLOAT, GL_FALSE, 0,(void*)0 );
glDrawArrays(GL_TRIANGLES, 0, 12*3); // 12*3 indices starting at 0 -> 12 triangles
glDrawArrays(GL_TRIANGLES, 0, 12*3);
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(positionIndex);
animationShader->release();
}
......@@ -131,7 +133,7 @@ void MainWidget::resizeGL(int width, int height){
qDebug()<<"Resize"<<width<<height;
m_projection = QMatrix4x4();
m_projection.perspective(45.0,width/height,0.01,100.0);
m_projection.perspective(45.0,1.0*width/height,0.01,100.0);
}
......
......@@ -22,6 +22,12 @@ protected:
void resizeGL(int width, int height);
private:
static const int positionIndex = 0;
static const int normalIndex = 1;
static const int uvIndex = 2;
static const int boneIndex = 3;
static const int boneweightIndex = 4;
QOpenGLShaderProgram* animationShader;
QMatrix4x4 m_projection;
QMatrix4x4 m_view;
......
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