droidmachine
droidmachine

Reputation: 577

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

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 ...
}

Upvotes: 0

Views: 634

Answers (1)

Stefan Hanke
Stefan Hanke

Reputation: 3528

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.

Upvotes: 3

Related Questions