What is the appropriate way of drawing background in opengl es?

跟風遠走 提交于 2019-12-11 14:21:25

问题


I have a tile background with 2400x480 pixels.Also one more far layer for parallax effect.Is that drawing background with a for loop logical?

for(int i=0;i<100;i++) {
    //Drawing code like 0+2400*i ...
}

回答1:


I hope this gets you started, but I really don't know...

I assume in the following that the texture is displayed all at once. Due to the size of the texture -- 2400*480 = (3*800)*480 -- I think this may not be correct, but anyway.

For each layer, you have two quads with fixed texture coordinates. Initially, one the first quad is visible; in the course of the animation, the first is moved out of the screen and the second in. The texture border must match, otherwise a crack will be visible.

+-------------++-------------+
|             ||             |
|             ||             |
+-------------++-------------+
^             ^
   visible

... as time progresses ...
+-------------++-------------+
|             ||             |
|             ||             |
+-------------++-------------+
      ^             ^
         visible

You can do this for the bottom layer and the next layer. Use different velocities for layers of different distance. You will need blending when there is more than one layer.

If the first assumption proves to be incorrect, you need to modify texture coordinates during the animation. There is one full-screen quad, and the texture coordinates are setup for one third of the texture. Then, linearly translate all four coordinates in the same direction until the top is hit. At this point you somehow need to begin to show the first third again -- using a second quad for example.



来源:https://stackoverflow.com/questions/10078840/what-is-the-appropriate-way-of-drawing-background-in-opengl-es

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!