Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Best solution for drawing the space / universe

This topic is 5747 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi people, which is the best way to draw the background of a space game ? A simple sky box with spacy-textures or a "sphere"-box.... which solution looks best ?? Bye, nomore

Share this post

Link to post
Share on other sites
2 very quick ideas:

1.) Call 2 rand(), one for x and one for y, map those coordinates to a sphere, and use this as a constant star backdrop (so you always view this sphere from the inside). This should give you a nice constant star sky.

2.) Do it the homeworld-way. Construct a sphere, apply a bit of "noise" to the sphere's vertices, and give each vertex a random color (of course not completely random, but so that some are black, and there are also patches with nebulas etc.). Looks very real, doesn't require texture mapping, and is very fast.

Ciao, ¡muh!

PS: About 1.: You of course do that for each star, so for 5000 stars you would do something like:

for(i = 0; i < 5000; i++)
// you map the 0 - RAND_MAX range of the rands to

// lat/long coordinates on a sphere in this function:

putStar(rand()/* x-coordinate*/, rand()/* y-coordinate*/);

You can store that in a display list (I only know OpenGL, no idea what this would be for DirectX), so it would be really fast.

[edited by - thebigMuh on October 23, 2002 8:40:33 AM]

[edited by - thebigMuh on October 23, 2002 8:57:20 AM]

Share this post

Link to post
Share on other sites
Actually I think that the most realistic way to render (distant) stars, is also the most straightforward one: as tons of 3D point primitves (eg. GL_POINTS) and small camera aligned billboards, distributed over a sphere around you. This looks *much* better than a background texture, at least than those commonly used lowres ones. Give it a try, with about 5000 to 8000 points (of various intensities and ''star like'' colours) and 100 to 200 billboards, you can get an awesome result.

Share this post

Link to post
Share on other sites
If you want to be really crafty, you can implement what Freespace did and use GL_LINES to draw the stars as blur points between the last frame and the current one.

You just use the old viewpoint and new viewpoint, calculate the star''s position based on these old and new orientations and draw a line.

If the viewpoint barely moved, you just draw them as points.

Use line width and point width functions to anti-alias them.

Share this post

Link to post
Share on other sites
Following up on thebigmuh's first idea:


#define STAR_LIST 200

// somewhere up above: glEnable (GL_POINT_SMOOTH);

void BuildStars()
int i;
float rho, phi ,theta;
float x, y, z;
float size;
int r;
float color[3];



rho = 1.65f;

for (i=0;i<30000;i++)
z = -rho + ((float)rand() / (float)RAND_MAX) * rho * 2;
phi = ((float)rand() / (float)RAND_MAX) * 3.1415965f * 2.0f;
theta = asinf(z / rho);
x = rho * cosf(theta) * cosf(phi);
y = rho * cosf(theta) * sinf(phi);

size = 1.0f + (((float)rand() / (float)RAND_MAX) * 2.0f);
color[0] = color[1] = color[2] = 0.25f + (((float)rand() / (float)RAND_MAX) * 0.75f);

r = rand()%100;
if ((r >= 0) && (r <= 15))
color[0] *= 1.25f;
if ((r > 15) && (r <= 25))
color[0] *= 1.25f;
color[1] *= 1.25f;





// To draw the stars: glCallList(STAR_LIST);

Where rho is the radius of the sphere. At first I had it generating spherical coordinates straight out, but that resulted in bunching up at the poles. After a bit of research I found an alternate way of doing it (shown above) which distributes the points uniformly. I hope this helps.

[edited by - robopaul on October 24, 2002 11:06:14 AM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!