Advertisement
Guest User

Untitled

a guest
Oct 21st, 2014
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void TriangleWindow::render()
  2. {
  3.     const qreal retinaScale = devicePixelRatio();
  4.     glViewport(0, 0, width() * retinaScale, height() * retinaScale);
  5.  
  6.     glClear(GL_COLOR_BUFFER_BIT);
  7.  
  8.     m_program->bind();
  9.  
  10.     QMatrix4x4 matrix;
  11.     matrix.perspective(60.0f, 16.0f/9.0f, 0.1f, 100.0f);
  12.     matrix.translate(0, 0, -2);
  13.     matrix.rotate(100.0f * m_frame / screen()->refreshRate(), 0, 1, 0);
  14.  
  15.     m_program->setUniformValue(m_matrixUniform, matrix);
  16.  
  17.     /*GLfloat vertices[] = {
  18.         0.0f, 0.5f,
  19.         -0.5f, -0.5f,
  20.         0.5f, -0.5f
  21.     };*/
  22.  
  23.     GLfloat vertices[] = {
  24.         -0.5f, -0.5f,
  25.          0.5f, -0.5f,
  26.         -0.5f,  0.5f,
  27.          0.5f,  0.5f
  28.     };
  29.  
  30.     GLfloat colors[] = {
  31.         1.0f, 0.0f, 0.0f,
  32.         0.0f, 1.0f, 0.0f,
  33.         0.0f, 0.0f, 1.0f,
  34.         0.5f, 0.5f, 0.5f
  35.     };
  36.  
  37.     glVertexAttribPointer(m_posAttr, 2, GL_FLOAT, GL_FALSE, 0, vertices);
  38.     glVertexAttribPointer(m_colAttr, 3, GL_FLOAT, GL_FALSE, 0, colors);
  39.  
  40.     glEnableVertexAttribArray(0);
  41.     glEnableVertexAttribArray(1);
  42.  
  43.     glDrawArrays(GL_TRIANGLES, 0, 3);
  44.     glDisableVertexAttribArray(1);
  45.     glDisableVertexAttribArray(0);
  46.  
  47.     m_program->release();
  48.  
  49.     ++m_frame;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement