#### Archived

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.

## 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 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 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 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 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];	glNewList(STAR_LIST,GL_COMPILE);	glDisable(GL_TEXTURE_2D);	rho = 1.65f;	glBegin(GL_POINTS);	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;		}							glPointSize(size);		glColor3fv(color);		glVertex3f(x,y,z);	}	glEnd();	glEnable(GL_TEXTURE_2D);	glEndList();}// 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]

1. 1
Rutin
25
2. 2
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 14
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631757
• Total Posts
3002126
×