1
0
Fork 0

Pouzivat OpenGL 3.3 core profile

master
Dušan Poizl 8 years ago
parent 7e254ba95b
commit 4dda441a50
  1. 2
      aabb.frag
  2. 2
      aabb.geom
  3. 2
      aabb.vert
  4. 25
      glwidget.cpp
  5. 3
      glwidget.h
  6. 7
      main.cpp
  7. 2
      shader.frag
  8. 2
      shader.vert

@ -1,4 +1,4 @@
#version 400
#version 150
uniform vec4 color;

@ -1,4 +1,4 @@
#version 400
#version 150
uniform mat4 ModelViewProjectionMatrix;

@ -1,4 +1,4 @@
#version 400
#version 150
in vec3 min;
in vec3 max;

@ -7,7 +7,7 @@
#include <QTimer>
#include "objmodel.h"
GLWidget::GLWidget() :
GLWidget::GLWidget(QGLFormat &format) : QGLWidget(format),
start(0),
count(1)
{
@ -20,15 +20,28 @@ GLWidget::~GLWidget()
void GLWidget::initializeGL()
{
GLuint vao;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
qDebug() << (char*)glGetString(GL_VERSION);
program = new QOpenGLShaderProgram(this);
program->addShaderFromSourceFile(QOpenGLShader::Vertex, "shader.vert");
program->addShaderFromSourceFile(QOpenGLShader::Fragment, "shader.frag");
program->bindAttributeLocation("vertex", 0);
program->link();
AssImpModel model("mesh.blend");
AssImpModel model("mesh.obj");
auto vertex = model.getVertexs();
auto faces = model.getFaces();
int indx[faces.size()*3];
for(uint i=0;i<faces.size();i++)
{
indx[i*3] = faces[i].a;
indx[i*3+1] = faces[i].b;
indx[i*3+2] = faces[i].c;
}
vt.create();
vt.bind();
@ -37,7 +50,7 @@ void GLWidget::initializeGL()
indices = QOpenGLBuffer(QOpenGLBuffer::IndexBuffer);
indices.create();
indices.bind();
indices.allocate(&faces[0], sizeof(Face)*faces.size());
indices.allocate(indx, sizeof(indx));
obj_count = faces.size()*3;
@ -88,18 +101,18 @@ void GLWidget::paintGL()
glDrawElements(GL_TRIANGLES, obj_count, GL_UNSIGNED_INT, 0);
/*vertex.bind();
vertex.bind();
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(0, 3, GL_FLOAT, false, sizeof(BVH::LinearNode), 0);
glVertexAttribPointer(1, 3, GL_FLOAT, false, sizeof(BVH::LinearNode), (void*)(sizeof(cl_float)*3+sizeof(cl_uint)));
glVertexAttribPointer(1, 3, GL_FLOAT, false, sizeof(BVH::LinearNode), (void*)(sizeof(cl_float)*3));
aabb->bind();
aabb->setUniformValue("ModelViewProjectionMatrix", mat);
aabb->setUniformValue("color", QVector4D(0, 1, 0, 1));
glDrawArrays(GL_POINTS, start, count>3000 ? 3000 : count);
aabb->setUniformValue("color", QVector4D(1, 1, 0, 1));
glDrawArrays(GL_POINTS, start*2+1, count*2);*/
glDrawArrays(GL_POINTS, start*2+1, count*2);
}
void GLWidget::keyPressEvent(QKeyEvent *event)

@ -7,6 +7,7 @@
#include <QKeyEvent>
#include <QOpenGLShaderProgram>
#include <QOpenGLBuffer>
#include <QGLFormat>
#include <QGLWidget>
#include "bvh/tree.h"
@ -25,7 +26,7 @@ class GLWidget : public QGLWidget
void paintGL();
BVH::Tree tree;
public:
GLWidget();
GLWidget(QGLFormat &format);
~GLWidget();
void keyPressEvent(QKeyEvent *event);
public slots:

@ -9,8 +9,11 @@ int main(int argc, char **argv)
{
QApplication app(argc, argv);
//GLWidget glwidget;
//glwidget.show();
QGLFormat format;
format.setVersion(3, 3);
format.setProfile(QGLFormat::CoreProfile);
GLWidget glwidget(format);
glwidget.show();
ImgView imgview(0);
imgview.show();

@ -1,4 +1,4 @@
#version 400
#version 150
void main(void)
{

@ -1,4 +1,4 @@
#version 400
#version 150
in vec4 vertex;
uniform mat4 ModelViewProjectionMatrix;

Loading…
Cancel
Save