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();
};
main()
{
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)
{
star.Draw();
star.Move();
if (!star.IsVisible())
{
stars.remove(star);
}
}
}
}
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:
- 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
- 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.
- 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.