Stars

I am trying to create a space scene (planets, stars… etc), everything is great except the stars, I can’t seem to get the right visuals (like the ones you see in space simulators). I tried a texture mapped sphere, looked horrible. tried a list (or array) of small bitmapped squares, No luck, can’t even see them. I’m new to openGL so this alone might be the problem.

Does anyone know of a good tutorial on the subject or maybe some source code I can learn from. Any help is appreciated, thanks

Probably I shouldn’t post an answer, because I don’t know resources. But, if you search the web for “skybox” or something similar, you’ll most probably get a tutorial for that technique.
A Skybox is simply a box, textured with 6 textures, that are somehow wrapped to make the impression of a real 360 degrees panorama.

I’ve had the same problem. I tried doing a “skydome” thing with a low-resolution gluSphere but mine looked like crap too. Even when I used REALLY high-res texutres (1024x1024) and each star was just one to four pixels in size. So I know what you mean. I guess you’d have to do a “skybox” thing and then tile your textures on each side of the cube.

maybe use inward-facing, blended, textured quads? you could make them neat shapes, that way. and making stars bigger than one another would be easy, too. you could use an oop approach as well, and then dump all the stars into a display list and forget about them.

what doesn’t go right when using the texture map? too blurry or what?

What about using billboarded squares with a texturemap of a star on it?

Kiyoshi

The textured skybox/skydome is too blurry and I don’t wanna use bitmaps that are too large and tiling looks fake (unless someone has a cool idea). It seemed to me that the OOP approach was the best but the problem is for some reason I cannot see any stars (remember I am novice when it comes to openGL) when I try that. the other problem is figuring out which way their Normals should point (actually I got it!! normalize then inverse the world coord of the star). but then I would have to scale them in such a way that if the camera gets gets closer they won’t look bigger (guess I would solve that if the camera is the centre of the “stardome”… Too much work for something that should be simple… Gonna try a few more things…

Does anyone know what approach is used in games like Starlancer or Wing Commander…

I’d say they use GL_POINTS in a star sphere for ‘normal’ stars, then use quads for bigger stars.

At the risk of sounding stupid… (new in openGL) how would you use GL_POINTS? an example would be great… Thanks :stuck_out_tongue:

Oh yeah and is there an opengl.hlp file anywhere?

[This message has been edited by monson (edited 11-16-2000).]

The problem, at least with mine, isn’t a problem with using large stars and smaller stars… I think the OOP approach would be unneccissarily slow since, if you wanted a reasonably dense starfield, you’d have to use WAY too many quads or billboards (how do you use billboards in OpenGL anyway?) so I think the most reasonable idea is the skybox or skydome. Only problem with that is that you have to use too large of a texture or tile the stars which looks fake. I’ve implemented a skydome (inward facing gluSphere) using a REALLY large texture (1024x1024) and it still looks hokey. The stars still look way too big and too blurry and it’s just plain wierd looking. I can’t describe it. I’m wanting a very basic starfield effect as seen in just about any 3D space combat game. I’m not even asking for big nebulas (although that would be cool) or anything like that.

glBegin ( GL_POINTS );
  glVertex3f ( 0.0, 0.0, -2.0 );
  ...
  ...
glEnd ( );

Simple as that! You can draw and lots of points very quickly as long as texturing and lighting is turned off. Mix a few random GL_QUADs with nice star textures (don’t make them huge, small ones will do), maybe add a Homeworld style untextured nebula in the background - very nice!

Originally posted by Pauly:
[b][quote]

glBegin ( GL_POINTS );
  glVertex3f ( 0.0, 0.0, -2.0 );
  ...
  ...
glEnd ( );

Simple as that! You can draw lots and lots of points very quickly as long as texturing and lighting is turned off. Mix a few random GL_QUADs with nice star textures (don’t make them huge, small ones will do), maybe add a Homeworld style untextured nebula in the background - very nice![/b][/QUOTE]

Umm, now that really wasn’t supposed to happen

Thanks Pauly! (sorry about the stupid question), So I tried it with 100 stars (only GL_POINTS, no Quads), my FPS went down from 60 to 50-55, even lower at times (30FPS). I looks good but the performance hit is high especially for only 100 points. Still it’s better than nothing for now. Thanks a lot, appreciate it

What 3d card are you using?

Remember to make sure to call glPointSize ( 1.0 ); and have point smoothing off for optimal performance.

Try 1000 stars and see if it slows down anymore…

How’s the best way to plot those points “around” your view? Basically, how’s the best way to quickly place them in a “sphere” around the camera?

I have a RIVA TNT2 16MB, I think the GL_SMOOTH is on what the points are drawing.I thinks I still have to clean and optimize the code some more. I’m at work now, but I’ll try what you suggest and let you know.
Punchey, the stars don’t have to be in a sphere, as long as they are always relative to where the camera is. This is sort of what I am using now, I still have to clean my code and maybe use linked lists. Let me know if this helps, maybe I’ll arrange to put an exe file on a site when I’m done It would be cool each other’s work.

void InitStars()
{
for (int i=0; i<100; i++)
{ // this results in a number between -7 and 7
star[i].x = ((float)(rand()%14000)/1000)-7;
star[i].y = ((float)(rand()%14000)/1000)-7;
star[i].z = ((float)(rand()%14000)/1000)-7;
}
}
void DrawStars()
{
DisableAll(); //Disables texture, lights, (gonna add smooth … Everything, as pauly suggests)
glColor3f(1,1,1); //set star color to white
glBegin(GL_POINTS);
for (int i=0; i<100; i++)
{
glVertex3f(star[i].x,star[i].y, star[i].z);
}
glEnd();
EnableAll; //Enables everything
}

void GLDrawScene(); // GONNA USE PSEUDOCODE FOR THIS PART
{
ClearBuffer();
Rotate Cameraview
DrawStars;
TRanslate to Planet coordinates
DrawPlanet



}

Thanks for the code! I havn’t tried your code yet but wouldn’t it sometimes place a star between you and the planet since the coordinate generated could be something between -7 and 7? Since the viewpoint sits at 0,0,0 isn’t it possible the it could place a star at, say, 0,0,1? And if the edge of a planet was at 0,0,2 then you’d see the star in front of the planet?

The best way to do it is use some trig. to randomly generate your stars (or read them from a file if you’re feeling fancy and want real star data) in big sphere. Compile this into a display list.

Whereever you move you viewpoint, move the stars so you never catch up with them.

Actually I admit it is a poor algo for generating stars, but at the time I just wanted to see how they would visually look. another way is to do this.

radius=radius of the stardome (for example, 50)
alpha = random number between 0 and 360 degrees
beta = another random number 0-360 deg; //elevation angle
x=(float)radiuscos(alpha);
y=(float)radius
sin(beta);
z=(float)radius*sin(alpha);

This uses the point on sphere representation using 2 angles and a radius (as I remember it, I’ll have to check that one)

For some reason, I can’t get any points to display. I’m using the same code (fixed up a bit) as was posted in this thread. I’m disableing texturing and lighting and then doing glBegin(GL_POINTS)and then glVertex3f(…) but to no avail! I’ve had this problem before and I never resolved it then either… So I’ve basically never gotten points to work for me. Anyone know why?