Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Scrolling stars / background in opengl?

  1. #1

    Scrolling stars / background in opengl?

    Ok so im a beginner at opengl and im starting to make a space game.

    My goal is to have a top-down view of objects/spacecraft ect with stars underneath them. The ships would move like real live (I.E. the old asteroids game) and the stars would scroll under the ships.

    Any ideas on a good way to accomplish this with opengl?

  2. #2
    Junior Member Newbie
    Join Date
    Jan 2002
    Location
    London, England, UK
    Posts
    14

    Re: Scrolling stars / background in opengl?

    I am assuming that your camera moves but does not rotate (to maintain the top-down perspective).

    One way to accomplish this would be to draw a large quad that will fill the whole view and is far enough back to be behind the ships when they are drawn. You could then texture map the quad with a picture of some stars, and translate the texture across slightly every frame. You probably want something like this :

    glEnable(GL_TEXTURE_2D);

    // Translate the texture
    glMatrixMode(GL_TEXTURE_2D);
    glPushMatrix();
    glTranslatef(xTrans, 0.0, 0.0);
    glMatrixMode(GL_MODELVIEW);
    xTrans += 0.05;

    glBindTexture(GL_TEXTURE_2D, stars)

    glPushMatrix();
    // Translate to camera pos but further back
    glTranslatef(cam.x, cam.y, cam.z + 100);

    // Draw the quad
    glBegin(GL_QUAD);
    // Vertex3f & TexCoord2f calls to draw the quad
    glEnd();
    glPopMatrix();

    glMatrixMode(GL_TEXTURE_2D);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);

    glDisable(GL_TEXTURE_2D);

    glEnd();

    I guess that should work (but as I just wrote it off the top of my head I wouldn't bet on it). Hope it helps.

    [This message has been edited by JimmyT (edited 06-13-2002).]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •