Rotate Object OpenGL ES 2.0

304 views Asked by At

we are using the following code to plot a BMP image in OpenGL ES 2.0: (x1,y1 is lower left coordinates, and x2,y2 are top right coordinates of the objects on the screen, tempimage data is the pointer to bmp image information stored)

struct
{
  GLuint uiId;
  GLuint uiLowerLeftLoc;
  GLuint uiScaleMatrixLoc;
  GLuint auiLoc[eNumUniforms];
}
m_ShaderProgram;

glUniform2f(m_ShaderProgram.uiLowerLeftLoc, x1, y1);
float afMatrix[4] = { x2 - x1, 0, 0, y2 - y1 };
glUniformMatrix2fv(m_ShaderProgram.uiScaleMatrixLoc, 1, GL_FALSE, afMatrix);
glBindTexture(GL_TEXTURE_2D, m_uiTexForeground);
glTexImage2D(GL_TEXTURE_2D, 0,GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, tempimagedata);
glBindBuffer(GL_ARRAY_BUFFER, m_uiVbo);
glEnableVertexAttribArray(VERTEX_ARRAY);
glVertexAttribPointer(VERTEX_ARRAY, 2, GL_FLOAT, GL_FALSE, 0, 0);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glDisableVertexAttribArray(VERTEX_ARRAY);

I want to rotate the object in terms of angles. How this can be achieved ?

1

There are 1 answers

4
SporreKing On

You should send a rotation/transfom-matrix to the shader you're using before rendering your mesh. Within your vertex shader, multiply the coordinates by the matrix.

This site is good for understanding the basics of rendering with matrices (it uses C++ and GLM): http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/