Scrolling Background Texture

  • Permalink
  • submit to reddit
  • Email
  • Follow


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
Reply womanontheinside (5) 1/26/2004 1:49:30 PM

See related articles to this posting

"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
Reply 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
Reply 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
Reply 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
Reply 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
Reply Andy 1/28/2004 1:20:02 AM
comp.graphics.api.opengl 7135 articles. 24 followers. Post

5 Replies
802 Views

Similar Articles

[PageSpeed] 6

  • Permalink
  • submit to reddit
  • Email
  • Follow


Reply:

Similar Artilces:

Scrolling a texture
Hello guys. I want to do a simple scrolling graph on a texture, which is then rendered to the screen. I want it to move a pixel at a time, and draw a new line of data at the edge. I'm guessing the best way is to move an entire block in texture memory with a single command. Does anybody know the most backward compatible way of doing this, as the only way I can think of is to read the data to CPU memory, move memory around, then shove back to GPU - but that can't be very efficient. Thanks, Dave "Foots" <turn@invalid.com> wrote in message news:z%wh...

Background stops scrolling
Hi, I just made a homepage with a scrolling background using:- <body background="Pictures/stars.gif"> <script type="text/javascript" language="JavaScript"> <!-- Begin var backgroundOffset = 0; var bgObject = eval('document.body'); function scrollBG(maxSize) { backgroundOffset = backgroundOffset + 1; if (backgroundOffset > maxSize) backgroundOffset = 0; bgObject.style.backgroundPosition = "0 " + backgroundOffset; } var ScrollTimer = window.setInterval("scrollBG(256)", 64); // End --> </script&g...

image map with scrolling background
Is there any way to use a scrolling background image as imagemap? please show example. thanks Zurab Zurab Mamasakhlisi wrote: > Is there any way to use a scrolling background image as imagemap? Unless you do not write a lot of code for it, there is not. And unlike image maps it is unreliable since client-side script support may be not present. > please show example. Please code yourself first, this is a discussion group, not a support forum. PointedEars ...

render to texture
Hi all, I want to render a sphere to a texture to map it on thousands of quads to increase performance. All works fine but the background color makes me sick. I set the glClearColor to 1.0,.0,.0,.0 and expected a fully transparent background in my texture after calling glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, viewport_[0], viewport_[1], viewport_[2], viewport_[3], 0); but all I get is a red one. Is there a simple way to achieve what I want or is there another method maybe using GL_LUMINANCE and the stencil buffer and if yes do you have sample how to do such a thing? Thank you very much,...

Repeat Texture as Background Image
Hi, i would like to put a texture file (png or tif) as a background in a figure but keep the proportion of the image and repeat it until it cover all the space. Cheers.. Hi, figure % Plot your data plot(rand(5)) % Load an image load clown % Create a second axes ax=axes('units','normalized', ... 'position',[0 0 1 1],... 'color','none',... 'xtick',[], ... 'ytick',[],... 'box','on',... 'hittest','off'); % Add the replicated image n=5; % You may modify this number image('cda...

Paper texture background to drawings in 2008
How do I get rid of it? I can't find the option. Any help appreciated! Why do Solidworks do this tacky shit anyway. > How do I get rid of it? I can't find the option. Go To TOOLS > OPTIONS > COLORS and TOGGLE ON the USE SPECIFIED COLOR FOR DRAWING PAPER COLOR towards the bottom of the dialog. > Why do Solidworks do this tacky shit anyway. They're called "ENHANCEMENTS" and for the same reason they add all the other tacky bullshit. Then they don't have to focus on all the bugs they should be fixing instead. will wrote: > > Any help appreci...

Generating Texture Bitmaps (Website Backgrounds)
Kinda cool image generator, check it out. Uses cellular texturing algorithm to generate neato bitmap images that can be used as web page backgrounds. http://www.lunchgamer.com ...

How to use content of a DIB as a background texture
How to use content of a DIB created by CreateDIBSection as a background texture in an OpenGL generated scene? Any demo code please? ...

Generating Texture Bitmaps (Website Backgrounds)
Kinda cool image generator, check it out. Uses cellular texturing algorithm to generate neato bitmap images that can be used as web page backgrounds. http://www.lunchgamer.com ...