title: How to construct a cubemap texture using QOpenGLTexture?
body: <p>I want to construct a cubemap texture using QOpenGLTexture using 6 images. I think I have placed them right.</p>
  
  <p>I am using the following code to construct the cubemap</p>
  
  <pre><code>const QImage posx = QImage(":/images/posx.jpg").mirrored().convertToFormat(QImage::Format_RGBA8888);
  const QImage posy = QImage(":/images/posy.jpg").mirrored().convertToFormat(QImage::Format_RGBA8888);
  const QImage posz = QImage(":/images/posz.jpg").mirrored().convertToFormat(QImage::Format_RGBA8888);
  const QImage negx = QImage(":/images/negx.jpg").mirrored().convertToFormat(QImage::Format_RGBA8888);
  const QImage negy = QImage(":/images/negy.jpg").mirrored().convertToFormat(QImage::Format_RGBA8888);
  const QImage negz = QImage(":/images/negz.jpg").mirrored().convertToFormat(QImage::Format_RGBA8888);
  
  d-&gt;environment = new QOpenGLTexture(QOpenGLTexture::TargetCubeMap);
  d-&gt;environment-&gt;create();
  d-&gt;environment-&gt;setSize(posx.width(), posx.height(), posx.depth());
  d-&gt;environment-&gt;setFormat(QOpenGLTexture::RGBA8_UNorm);
  d-&gt;environment-&gt;allocateStorage();
  d-&gt;environment-&gt;setData(0, 0, QOpenGLTexture::CubeMapPositiveX,
                          QOpenGLTexture::RGBA, QOpenGLTexture::UInt8,
                          (const void*)posx.constBits(), 0);
  d-&gt;environment-&gt;setData(0, 0, QOpenGLTexture::CubeMapPositiveY,
                          QOpenGLTexture::RGBA, QOpenGLTexture::UInt8,
                          (const void*)posy.constBits(), 0);
  d-&gt;environment-&gt;setData(0, 0, QOpenGLTexture::CubeMapPositiveZ,
                          QOpenGLTexture::RGBA, QOpenGLTexture::UInt8,
                          (const void*)posz.constBits(), 0);
  d-&gt;environment-&gt;setData(0, 0, QOpenGLTexture::CubeMapNegativeX,
                          QOpenGLTexture::RGBA, QOpenGLTexture::UInt8,
                          (const void*)negx.constBits(), 0);
  d-&gt;environment-&gt;setData(0, 0, QOpenGLTexture::CubeMapNegativeY,
                          QOpenGLTexture::RGBA, QOpenGLTexture::UInt8,
                          (const void*)negy.constBits(), 0);
  d-&gt;environment-&gt;setData(0, 0, QOpenGLTexture::CubeMapNegativeZ,
                          QOpenGLTexture::RGBA, QOpenGLTexture::UInt8,
                          (const void*)negz.constBits(), 0);
  d-&gt;environment-&gt;setWrapMode(QOpenGLTexture::ClampToEdge);
  d-&gt;environment-&gt;setMinificationFilter(QOpenGLTexture::LinearMipMapLinear);
  d-&gt;environment-&gt;setMagnificationFilter(QOpenGLTexture::LinearMipMapLinear);
  </code></pre>
  
  <p>I then bind the environment texture during paintGL() as follows</p>
  
  <pre><code>.....
  d-&gt;environment-&gt;bind(0);
  d-&gt;shader-&gt;setUniformValue("qt_Environment", 0);
  
  const int nrIndicies = d-&gt;torusResolution * d-&gt;tubeResolution * 6;
  glDrawElements(GL_TRIANGLES, nrIndicies, GL_UNSIGNED_INT, (void*)0);
  .....
  </code></pre>
  
  <p>Vertex shader snippet is as follows</p>
  
  <pre><code>....
  varying vec3 v_TexCoord;
  ....
  
  void main(void)
  {
      ....
      v_TexCoord = normalize(v_Normal + v_Position);
      ....
  }
  </code></pre>
  
  <p>The fragment shader snippet is as follows</p>
  
  <pre><code>.....
  varying vec3 v_TexCoord;
  uniform samplerCube qt_Environment;
  .....
  
  vec4 evaluateColor(in vec3 normal, in vec3 texCoord)
  {
      vec3 finalColor ....
      .....
      .....
  
      finalColor += textureCube(qt_Environment, texCoord).rgb;    
      return vec4( finalColor, c_one );
  }
  
  void main(void)
  {
      gl_FragColor = evaluateColor(v_Normal, v_TexCoord);
  }
  </code></pre>
  
  <p>I also have another part of the code which renders the cubemap on a skybox. While I am able to project the 6 images on the skybox and render it properly, I am unable to render the reflection on a torus object in the scene. </p>
  
  <p><a href="http://i.stack.imgur.com/qWRwN.png" rel="nofollow">I am getting a well lit torus, with no reflection.</a></p>
  
  <p>Can somebody help with this please?</p>