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).]

Similar Threads

  1. scrolling normal maps to scrolling bump map
    By Johnathon332 in forum OpenGL: GLSL
    Replies: 1
    Last Post: 04-28-2013, 06:48 PM
  2. Background scrolling of rendered landscape
    By walter.weber-gross in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 10-19-2002, 02:30 AM
  3. Scrolling stars / background?
    By CharredSoul in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 06-12-2002, 10:49 PM
  4. 2D Scrolling in OpenGL
    By nebrown1 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 05-08-2001, 07:09 AM
  5. Stars
    By monson in forum OpenGL: Basic Coding
    Replies: 53
    Last Post: 11-29-2000, 08:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean