PDA

View Full Version : Ortho View Scrolling/Panning



Bunkai.Satori
02-27-2011, 08:34 AM
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.nStri de;
glVertexAttribPointer(GameViewEngine.PlayerGameVie w.DisplayManager.nPosition, 4, GL_FLOAT, GL_FALSE, GameViewEngine.PlayerGameView.DisplayManager.nStri de, (const void*)offset);

offset += (sizeof(float) * (GameViewEngine.PlayerGameView.DisplayManager.VERT EX_POS_SIZE));
glVertexAttribPointer(GameViewEngine.PlayerGameVie w.DisplayManager.nUV, 2, GL_FLOAT, GL_FALSE, GameViewEngine.PlayerGameView.DisplayManager.nStri de, (const GLvoid*)offset);

glm::mat4 matOrtho2D = glm::ortho<float>(-320.0f, 320.0f, -480.0f, 480.0f);
glUniformMatrix4fv(GameViewEngine.PlayerGameView.D isplayManager.nOrthoProjectionID, 1, 0, glm::value_ptr(matOrtho2D));
//glUniformMatrix4fv(GameViewEngine.PlayerGameView.D isplayManager.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.Display Manager.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.

Bunkai.Satori
02-28-2011, 06:51 AM
Not to let this question become forgotten, does anybody anything to say on this topic?

dukey
02-28-2011, 07:51 AM
i'd just suggest learning the basics of opengl .. before worrying about shaders etc

Bunkai.Satori
02-28-2011, 05:43 PM
Hi dukey,

sometimes things look more difficult than they really are.

I applied LookAt() matrix with model matrix, and futher multiplied it with projection matrix to receive ModeViewProjection Matrix.

This ModelViewProjection matrix was moved to the shader as uniform variable and every vertex was multiplied by it.

Things work for me as expected now. I thought, there was something special with Ortho projection, as it was different kind of projection. However, i realized, that because view projection is applied to model projection, it is independent from both ortho and perspective projections.