Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am pretty new to Graphics Programming. I am currently using OpenGL. I have got some hands-on in last few days. I have knowledge of Texture Mapping, Cubemap, Multitexturing. But somehow I am not able to bridge the gap between my understanding and actual coding

What I am trying to do is create a demo of a stars coming out of screen. It should look realistic.

Now, my questions are:
1. Is Cubemap capable of doing this?
2. Do I need to write particle engine for this?(Really, don't want to at this stage)
3. This is kinda most needed for me. May I See some code..? In some tutorial / just code would also do.. but i think if its similar to my requirement then only it will Help

share|improve this question

closed as not a real question by Byte56, Jari Komppa, bummzack, Sean Middleditch, Josh Petrie Mar 6 '13 at 16:15

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

If you put two spaces at the end of each line a new line will be created Markdown help - Line breaks – user25712 Mar 4 '13 at 13:13
Try to avoid putting "Thanks in Advance" at the end of your question, see this Should 'Hi', 'thanks,' taglines, and salutations be removed from posts? – user25712 Mar 4 '13 at 13:26
Where to get started questions are best suited for a discussion oriented site, like those listed in the FAQ. – Byte56 Mar 4 '13 at 15:57
You really shouldn't put questions like this here but to give you a nudge in the right direction I would look at #2 first assuming you are trying for the 'flying through stars' look. I cant imagine that you would have to write a particle engine from scratch however as there are packages out there that will do this for you and you simply have to set up the parameters for your particles. – RobCurr Mar 4 '13 at 16:37
I'm not sure how stars coming out of the screen can look "realistic". If you want it to look like star trek or the famous screen saver, that's not realistic. While no one really knows what it would look like, you can imagine it would be pretty warped, just look what it looks like when you're getting close to the speed of light: – Byte56 Mar 4 '13 at 18:01
up vote 0 down vote accepted

What you're asking for is sometimes called the starfield effect, named after the infamous screensaver. That should give you a nice starting point for searching.

A lot of tutorials recommend "faking" the effect in 2D, that is, start by putting a dot near the centre of the screen, then moving them away from the centre and towards the edge. Sometimes an acceleration is included to simulate the perceived motion of stars that are moving almost directly at the camera. This is indeed the "easiest" way, but it is not realistic, and I prefer another:

Use 3D particles

Represent each star as a 3D point, starting from some location in front of the camera, and moving in the general direction of the camera. That is, if the z-axis was forward/backward with respect to the camera, you would generate stars with an initial z coordinate, and random x/y coordinates, and animate the stars by subtracting a constant speed from the z coordinate.

Here's some code to get you started (illustrative purposes only, does not compile, you didn't specify the language, not using best practices):

class Star
    float x, y, z;
    void Move() { z -= STAR_SPEED; }
    void Draw();
    bool IsVisible();

    list<Star> stars;
    for (int i = 0; i < MAX_FRAMES; i++)
        if (i % MAKE_STAR_PERIOD == 0)
            stars.append(Star(random(), random(), INITIAL_Z));
        for (star : stars)
            if (!star.IsVisible())

The advantages of this approach are:

  • Realistic 3D motion (2D approximations suffer from weird motion for very-far-away or very-close stars)
  • Realistic distance modelling (finding the distance to the star is trivial, so you can modify the luminosity of stars based on distance etc)
  • As with all particle systems, you can choose any arbitrary drawing method for each star. Draw nebulae, galaxies!

Finally, to answer your specific questions:

  1. Is Cubemap capable of doing this?
    • I assume you mean using textured surfaces. Yes you can do this, but it won't look good because unless you have many layers of transparent textures, viewers will quickly discern the surfaces themselves, plus it's making the problem harder than it needs to be
  2. Do I need to write particle engine for this?(Really, don't want to at this stage)
    • I recommed the 3D particle approach. Why not? An "engine" is as hard as a string is long.
  3. This is kinda most needed for me. May I See some code..? In some tutorial / just code would also do.. but i think if its similar to my requirement then only it will Help
    • I gave you some code, you can search for more tutorials, really it's just points in 3D space flying in the same axis.
share|improve this answer
It would be good to mention that drawing the stars involve perspective projecting, which in the simplest form is screenX = screenSize / 2 + x * constant / z; and same for y. – msell Mar 5 '13 at 6:14

Not the answer you're looking for? Browse other questions tagged or ask your own question.