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
| #include "windowopengl.h"
WindowOpengl::WindowOpengl(QWidget *parent)
: QGLWidget(parent)
{
setMinimumWidth(200);
minRange = 1.0;
maxRange = 120.0;
distCam = 80.0;
Delta = 0.0;
//program = new QGLShaderProgram;
}
WindowOpengl::~WindowOpengl()
{
}
void WindowOpengl::initializeGL()
{
program = new QGLShaderProgram();
glClearColor(0.1,0.1,0.0,1);
if (!program->addShaderFromSourceCode(QGLShader::Vertex,
"attribute highp vec4 vertex;"
"attribute mediump mat4 matrix;"
"void main(void)"
"{"
" gl_Position = matrix * vertex;"
"}"))
{
QMessageBox::information(this, "Beuglage", "Ya une erreur quequepar, tu es vraiment un Zéros !");
}
if (!program->addShaderFromSourceCode(QGLShader::Fragment,
"uniform mediump vec4 color;"
"void main(void)"
"{"
" gl_FragColor = color;"
"}"))
{
QMessageBox::information(this, "Beuglage", "Ya une erreur quequepar, tu es vraiment un Zéros !");
}
if (!program->link())
{
QMessageBox::information(this, "Beuglage", "Ya une erreur quequepar, tu es vraiment un Zéros !");
}
}
void WindowOpengl::resizeGL(int width, int height)
{
int side = qMin(width, height);
glViewport((width - side) / 2, (height - side) / 2, side, side);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective( 45.0, 1, 0.1, 60.0 );
glMatrixMode(GL_MODELVIEW);
}
void WindowOpengl::paintGL()// draw the scene:
{
glClear(GL_COLOR_BUFFER_BIT );
if (!program->bind())
{
QMessageBox::information(this, "Beuglage", "Ya une erreur quequepar, tu es vraiment un Zéros !");
}
QVector3D triangleVertices[] = {
QVector3D(1.0f, 1.0f, -5.0f),
QVector3D(0.0f, 1.0f, -5.0f),
QVector3D(1.0f, 0.0f, -5.0f)
};
int vertexLocation = program->attributeLocation("vertex");
int colorLocation = program->attributeLocation("color");
int matrixLocation = program->attributeLocation("matrix");
QMatrix4x4 pmvMatrix;
program->enableAttributeArray(vertexLocation);
program->setAttributeArray(vertexLocation, triangleVertices);
program->setUniformValue(matrixLocation, pmvMatrix);
program->setUniformValue(colorLocation, QVector4D(0.5, 0, 0, 1));
glDrawArrays(GL_TRIANGLES, 0, 3);
program->disableAttributeArray(vertexLocation);
program->release();
} |
Partager