1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
#include "glview.h"
GLView::GLView(QWidget *parent)
:QGLWidget(parent),
QOpenGLFunctions(),
rotationAngle(0.)
{
makeCurrent();
initializeOpenGLFunctions();
if(parent == 0)
{
this-> resize(100,100);
}
else
{
this->resize(parent->size());
}
//intitialisation statique des données
IndiceArray = new GLuint[36]{
0,1,2,2,1,3,
4,5,6,6,5,7,
3,1,5,5,1,7,
0,2,6,6,2,4,
6,7,0,0,7,1,
2,3,4,4,3,5
};
Vertices = new GLfloat[48]{
1.0f, 0.0f, 0.0f, -1.0f, 1.0f, -2.0f,
1.0f, 0.0f, 1.0f, -1.0f, -1.0f, -2.0f,
1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 0.0f,
0.0f, 0.0f, 1.0f, -1.0f, -1.0f, 0.0f,
0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f,
0.0f, 1.0f, 1.0f, 1.0f, -1.0f, 0.0f,
1.0f, 1.0f, 0.0f, 1.0f, 1.0f, -2.0f,
1.0f, 1.0f, 1.0f, 1.0f, -1.0f, -2.0f
};
VBO = new GLuint[2]();
initializeGL();
}
GLView::~GLView()
{
glDeleteBuffers(2,VBO);
delete IndiceArray;
delete Vertices;
delete VBO;
}
void GLView::initializeGL()
{
glViewport(0,0,this->width(),this->height());
glGenBuffers( 2, VBO );
glBindBuffer(GL_ARRAY_BUFFER,VBO[0]);
glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, VBO[1]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(IndiceArray), IndiceArray, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
glBindBuffer(GL_ARRAY_BUFFER,0);
}
void GLView::resizeGL(int w, int h)
{
this->resize(w,h);
glViewport(0,0,w,h);
}
void GLView::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.,0.,0.,1.);
glBindBuffer(GL_ARRAY_BUFFER, VBO[0]);
glVertexPointer( 3, GL_FLOAT, 6 * sizeof(float), ((float*)NULL + (3)) );
glColorPointer( 3, GL_FLOAT, 6 * sizeof(float), 0 );
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, VBO[1]);
glEnableClientState( GL_VERTEX_ARRAY );
glEnableClientState( GL_COLOR_ARRAY );
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
glDisableClientState( GL_COLOR_ARRAY );
glDisableClientState( GL_VERTEX_ARRAY );
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
glBindBuffer(GL_ARRAY_BUFFER,0);
glFlush();
}
void GLView::setAngle(double angle)
{
this->rotationAngle = angle;
}
double GLView::getAngle() const
{
return this->rotationAngle;
} |
Partager