Hello,
Here are the code details,
We are writing OpenGL ES 2.0 simple application of loading a texture(.png) on QT 5.10 using QOpenGLWidget.
We are able to build and run in both Windows and Ubuntu version 16.04 Environment, but we are targetting the NXP S32V234 board.
We have QT 5.10, OpenGL ES 2.0, Linux 4.19 version running on NXP S32V234 board, there it fails to load the texture. Pointers would be much appreciated.
Here is the vertex and fragment shader code which are compiled using normal gl functions not the QT's addShaderFromSourceFile function.
//Vertex Shader
#ifdef GL_ES
precision mediump int;
precision mediump float;
#endif
attribute vec3 position;
attribute vec3 color;
attribute vec2 texCoord;
varying vec3 Color;
varying vec2 TexCoord;
uniform mat4 transform;
void main()
{
gl_Position = transform * vec4(position, 1.0);
Color = color;
TexCoord = texCoord;
}
//Fragment Shader
#ifdef GL_ES
precision mediump int;
precision mediump float;
#endif
uniform sampler2D outputTexture;
varying vec3 Color;
varying vec2 TexCoord;
void main()
{
gl_FragColor = texture2D(outputTexture, TexCoord) * vec4(Color, 1.0);
}
Here is the initialization and loading of texture
void MyGL::initializeTextureBuffer()
{
float vertices[] = {
// positions // texture coords
0.0f, 0.3f, 0.0f, 1.0f,0.0f,0.0f, 0.0f, 0.0f, // bottom left /* @pixel (35,57)
0.0f, 0.6f, 0.0f,0.0f,1.0f,0.0f, 0.0f, 1.0f, // top left @pixel (35,27)
0.5f, 0.6f, 0.0f,0.0f,0.0f,1.0f, 1.0f, 1.0f, // top right @pixel (76,27)
0.5f, 0.3f, 0.0f, 1.0f,1.0f,1.0f, 1.0f, 0.0f, // bottom right @pixel (76,57) */
};
glGenBuffers(1, &camTextureBufferObject);
glBindBuffer(GL_ARRAY_BUFFER, camTextureBufferObject);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0); //unbinding
textureQT = loadTexture(":/images/images/CamRedA.PNG");
}
QOpenGLTexture* MyGL::loadTexture(const char * path)
{
QOpenGLTexture* texture;
texture = new QOpenGLTexture(QImage(path).mirrored());
texture->setMinificationFilter(QOpenGLTexture::Nearest);
texture->setMagnificationFilter(QOpenGLTexture::Linear);
texture->setWrapMode(QOpenGLTexture::Repeat);
return texture;
}
Here is the main render loop
void MyGL::paintGL()
{
glClearColor(0.0f, 0.0f, 0.0f, 0.05f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
///********************************* Texture Rendering ********************************************************/
glUseProgram(shaderpgmTexture);
glm::mat4 projection = glm::perspective(glm::radians(camspec.fov), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);
glm::mat4 view = glm::lookAt(camspec.cameraPos, camspec.cameraPos + camspec.cameraFront, camspec.cameraUp);
glm::mat4 model = glm::mat4(1.0f);
glm::mat4 transform = projection * view * model;
glUniformMatrix4fv(glGetUniformLocation(shaderpgmTexture, "transform"), 1, false, &transform[0][0]);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glUniform1i(glGetUniformLocation(shaderpgmTexture, "outputTexture"), 0);
glActiveTexture(GL_TEXTURE0);
textureQT->bind();
glBindBuffer(GL_ARRAY_BUFFER, camTextureBufferObject);
// position attribute
GLint vertexLocation = glGetAttribLocation(shaderpgmTexture,"position");
glEnableVertexAttribArray(vertexLocation);
glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)0);
// color
GLint colorLocation = glGetAttribLocation(shaderpgmTexture, "color");
glEnableVertexAttribArray(colorLocation);
glVertexAttribPointer(colorLocation, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(3 * sizeof(float)));
// texture coord attribute
GLint vertexTex = glGetAttribLocation(shaderpgmTexture, "texCoord");
glEnableVertexAttribArray(vertexTex);
glVertexAttribPointer(vertexTex, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(6 * sizeof(float)));
glDrawArrays(GL_QUADS, 0, 4);
glDisable(GL_BLEND);
glUseProgram(0);
/********************************* Texture Rendering - End ********************************************************/
}