QGLTexture2D Texture not showing up
-
Trying to get some simple textureing working in Qt5.2 ( OpenGL )
I have a quad ( drawn as two triangles ) and i am just trying to apply a texture to it but all i ever see is solid color.
I have drawn the quad as wire frame to test that the data in the VBOs is OK. I'm pretty sure the texture coords are also OK as it's just a quad so starting at (0,0) to (1,1) to map the whole texture.
I read in the texture like this;
@QImage textureImage ( 1024, 1024, QImage::Format_ARGB32 );
if ( textureImage.load ( "Resources\Data\Images\texture.png" ) ) {
textureImage = QGLWidget::convertToGLFormat ( textureImage ); // Need this?
m_texture = new QGLTexture2D;
m_texture->setImage ( textureImage );@Then later on i bind it before drawing;
@m_texture->bind();
glDrawElements ( GL_TRIANGLES, m_numIndices, GL_UNSIGNED_SHORT, 0 );
...@But i'm not seeing anything that looks like the texture, just solid color.
The shaders are simple. The Vertex shader;
@#version 330
layout (location = 0) in vec3 VertexPosition;
layout (location = 1) in vec3 VertexColor;
layout (location = 2) in vec2 VertexTexCoord;out vec3 VPosition;
out vec3 VColor;
out vec2 VTexture;uniform mat4 ModelViewMatrix;
uniform mat3 NormalMatrix;
uniform mat4 ProjectionMatrix;void main() {
VColor = VertexColor;
VTexture = VertexTexCoord;
mat4 MVP = ProjectionMatrix * ModelViewMatrix;
VPosition = vec3(ModelViewMatrix * vec4( VertexPosition, 1.0) );
gl_Position = MVP * vec4( VertexPosition, 1.0 );
}@Fragment shader
@#version 330
uniform sampler2D myTexture;
in vec3 VPosition;
in vec3 VColor;
in vec2 VTexCoord;layout( location = 0 ) out vec4 FragColor;
void main() {
FragColor = texture( myTexture, VTexCoord );
}@Any help much appreciated.