Dear all,
can I kindly ask for a guidance on how to implement efficient 2D scrolling/panning mechanism in OpenGL ES 2.0? The panning should be as effective as possible.
Will the proposed solution work well with paralax scrolling as well?
To give you information about how I implement orthographic view, here is a regular 2D Render method of one of my game objects:
bool CObjectMyShip::Render( float fInterpolationParam )
{
glBindBuffer(GL_ARRAY_BUFFER, ApplicationEngine.ResourceManager.vVBOs[OBID_MyRocket001].nVertexBufferID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ApplicationEngine.ResourceManager.vVBOs[OBID_MyRocket001].nElementBufferID);
GLint offset = (nFrameNumber * 4) * GameViewEngine.PlayerGameView.DisplayManager.nStride;
glVertexAttribPointer(GameViewEngine.PlayerGameView.DisplayManager.nPosition, 4, GL_FLOAT, GL_FALSE, GameViewEngine.PlayerGameView.DisplayManager.nStride, (const void*)offset);
offset += (sizeof(float) * (GameViewEngine.PlayerGameView.DisplayManager.VERTEX_POS_SIZE));
glVertexAttribPointer(GameViewEngine.PlayerGameView.DisplayManager.nUV, 2, GL_FLOAT, GL_FALSE, GameViewEngine.PlayerGameView.DisplayManager.nStride, (const GLvoid*)offset);
glm::mat4 matOrtho2D = glm::ortho<float>(-320.0f, 320.0f, -480.0f, 480.0f);
glUniformMatrix4fv(GameViewEngine.PlayerGameView.DisplayManager.nOrthoProjectionID, 1, 0, glm::value_ptr(matOrtho2D));
//glUniformMatrix4fv(GameViewEngine.PlayerGameView.DisplayManager.nOrthoProjectionID, 1, 0, matOrthogonal.Pointer());
vec3 vViewPosition = vec3(0.0f, 0.0f, 0.0f);
vViewPosition.x = vPosition.x + (float(fCurrentSpeedRight - fCurrentSpeedLeft ) * fInterpolationParam);
vViewPosition.y = vPosition.y + (float(fCurrentSpeedUp - fCurrentSpeedDown) * fInterpolationParam);
vViewPosition.z = 1;
glUniform3fv(GameViewEngine.PlayerGameView.DisplayManager.nTranslationID, 1, vViewPosition.Pointer());
glDrawElements( GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_SHORT, NULL );
return true;
}
Here is my simple vertex shader:
uniform mat4 uOrthoProjection;
uniform vec3 Translation;
attribute vec4 Position;
attribute vec2 TextureCoord;
varying vec2 TextureCoordOut;
void main()
{
gl_Position = uOrthoProjection * (Position + vec4(Translation, 0));
TextureCoordOut = TextureCoord;
}
Thank you.