Scrolling Background Texture

I have a background, I want it to scroll from right to left
horizontally.  The background is just a texture.

The background width is the same size as the size of screen, so it
should just wrap around the screen, it's just a field of grass that
keeps repeating.

I have read about tiles but this seems too complex for this simple
application.

Any help, in any programming language using openGL is appreciated.

Thanks in advance.
0
1/26/2004 1:49:30 PM
comp.graphics.api.opengl 7072 articles. 1 followers. Post Follow

5 Replies
1232 Views

Similar Articles

[PageSpeed] 15

"Sally" <womanontheinside@yahoo.com> schrieb im Newsbeitrag
news:3080cb7f.0401260549.4f584b1c@posting.google.com...
> I have a background, I want it to scroll from right to left
> horizontally.  The background is just a texture.
>
> The background width is the same size as the size of screen, so it
> should just wrap around the screen, it's just a field of grass that
> keeps repeating.
>
> I have read about tiles but this seems too complex for this simple
> application.
>
> Any help, in any programming language using openGL is appreciated.
>
> Thanks in advance.

Draw 2 tiles only and get the position with the mod-result of the
screen width:

x_offset = (mousepos_x() % screen_x);

DrawTexture(Background, x_offset           , 0); // Right part
DrawTexture(Background, x_offset - screen_x, 0); // Left part

HTH,

-- 
-Gernot

Post here, don't email. If you feel you have to mail, revert my
forename from:
tonreG.Frisch.at.Dream-D-Sign.de@invalid.com
________________________________________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com





0
Gernot
1/26/2004 2:20:26 PM
just manipulate your texturecoords of your background quad in your scrolling
direction.
something like glTexCoord2f(i+1,0) where i is increased every frame.
of cause for every vertex;-)

in c++:
i>1?i=0.0:i+=0.01;

be sure to set the texture environment to GL_REPEAT (IIRC)

hth psy


0
Sebastian
1/26/2004 2:27:37 PM
womanontheinside@yahoo.com (Sally) wrote in message news:<3080cb7f.0401260549.4f584b1c@posting.google.com>...
> I have a background, I want it to scroll from right to left
> horizontally.  The background is just a texture.
> 
> The background width is the same size as the size of screen, so it
> should just wrap around the screen, it's just a field of grass that
> keeps repeating.
> 
> I have read about tiles but this seems too complex for this simple
> application.
> 
> Any help, in any programming language using openGL is appreciated.
> 
> Thanks in advance.

Just change the matrix mode to GL_TEXTURE. Then do ordinary
glTranslate calls to translate the texture coordinates in the
direction you want. Or maybe it is better to texture both sides of
your background geometry (rectangle) and use glRotate (so you will not
"run out of" texture). Dont forget to change the matrix mode back to
GL_MODELVIEW before drawing the geometry again.
This should work.
0
marcus
1/27/2004 9:15:53 AM
> just manipulate your texturecoords of your background quad in your scrolling
> direction.
> something like glTexCoord2f(i+1,0) where i is increased every frame.
> of cause for every vertex;-)

I do that.  The canvas is 600px wide.  But all I get is a 1px wide
texture scrolling accorss the screen from the right to the left, the
rest is black.  Imagine why:

Initial: 0,0.  600,0. 600,600. 0,600.

Then the next after I decrement (scrolling left):

600,0. 599,0. 599,600. 600,600.

Leaving the exture being shown as just 1px wide on the X axis.

> be sure to set the texture environment to GL_REPEAT (IIRC)

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
0
womanontheinside
1/27/2004 1:18:40 PM
Sally wrote:

>>just manipulate your texturecoords of your background quad in your scrolling
>>direction.
>>something like glTexCoord2f(i+1,0) where i is increased every frame.
>>of cause for every vertex;-)
> 
> 
> I do that.  The canvas is 600px wide.  But all I get is a 1px wide
> texture scrolling accorss the screen from the right to the left, the
> rest is black.  Imagine why:
> 
> Initial: 0,0.  600,0. 600,600. 0,600.
> 
> Then the next after I decrement (scrolling left):
> 
> 600,0. 599,0. 599,600. 600,600.
> 
> Leaving the exture being shown as just 1px wide on the X axis.

Repeat mode only works for power-of-two sized textures in 'standard' 
OpenGL. It may work for the extensions, I don't know.

It sounds like you will need to render two quads -- one for the region 0 
to 'g' on the right, and 'g' to 1.0 on the left. 'g' may be 0 or 1.

--
Andy V

0
Andy
1/28/2004 1:20:02 AM
Reply: