Stars

did you make sure you set the color to white (or whatever). use glColor3f(1,1,1); just before glBegin(GL_POINTS), If you can post the code for your “drawStars” function…
Oh Yeah, and make sure that the stars are not outside the view frustrum, start with a stardome radius of 10 or something… Hope this helps

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

Thanks! I got it working… After I got it working, all the stars look so bright and all looked the same so I figured I’d store a color with each star as well. So I did something like this:
float color = 1/((rand()%3) + 1); // gets either a 1 or .5
stars[i].color[0] = color; // indexes of color are r(0) g(1) and b(2)
stars[i].color[1] = color;
stars[i].color[2] = color;

then I render the stars like:
glBegin(GL_POINTS);
for(i=0; i<NUM_STARS; i++)
{
glColor3f(stars[i].color[0],stars[i].color[1],stars[i].color[2]);
glVertex3f(stars[i].x,stars[i].y,stars[i].z);
}
glEnd();

But then all my stars dissapear! If I just put a glColor3f(1,1,1) at the beginning, it works. But if I try and use the generated values, nothing shows up. I can’t see why my generated values would come out at anything other than 1 or .5 and even if it sometimes came out at 0 (which it won’t) there should still be a few visible stars wouldn’t you think? Maybe I just can’t see the forrest for the trees.

That is, because the 1 in the 1/(something) string indicates the compiler to create an integer calculation, wich always ends in 0.0f. Maybe use 1.0f instead like:

float color = 1.0f/((rand()%3) + 1);

Uhmm I think that is the bug, but I don’t know the rand() syntax for sure anymore, since I don’t use it very frequently.

Thanks! Duh! I should have caught that one. I’ll try it now and see if that was it. I’ll bet you’re right though.

DA*N!!! for some reason I cannot get the GL_QUADS to always face the camera (no matter from which angle I am looking) it is always at an angle!! I am trying to use textured quads for the sun and nebulas and stuff… Anyone got any ideas? I know it should be easy, especially since the camera is always at the centre of the star-dome.

Also how can I get the projected 2D screen coordinates of the centre of the quad, in openGL?

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

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

I would be interested to know too

Try searching this message board with the keyword “billboard”. I rann across some billboard stuff on this message board last night but was looking for something else so I didn’t pay attention. You should be able to find the info. On another note, when I implemented your spherical placement of stars algo, I noticed that it actually places the stars in a virtical cylinder. So what I wound up doing was generating random vecors and then normalizing the vectors and multiplying them by the radius. That seems to have worked well with one exception: there is increased star density where the axes’ + and - quadrants converge. It’s hard to explain. But I seriously doubt anyone would ever notice this fact unless you used an EXREMELY dense starfield. Let me know if you find that billboard info and I’d REALLY like to know if and when you find that screen coordinate info. Thanks for all your help!

Now that I think of it, you should be able to precalculate (better performance than render-time calculation for a billboard) the coordinates for a quad that points towards the center of your starsphere. You could, for example, use the method I mentioned for star placement only instead of placing stars, you’re placing coordinates for a quad. Generate four vectors that point out from the center of your starsphere in a rectangular fashion and then simply multiply those coords by the radius of your starsphere and BAM! It should place the quad out along the circumference of your starsphere pointing directly at the center of it (where you will always be). If having the quad too close to other stars is a problem, try adjusting the radius for your quads so they are slightly offset from the stars. Save all of these coords and stars from your initilization, then you’re ready to rock and there’s no “run-time” calculation required like for billboarding. (I know, the init phase is technically run-time also, but it’s done at the start and at a non-time-critical point of the app - not while you’re trying to render so it won’t effect your framerate… only your load time.) I’m sure it wouldn’t be all that hard to write an algo for generating a “rectangular” set of vectors. I’d write one here and now (and probably will when I get home) but it depends on the radius you’re using and consequently, the resolution about the center you desire.

Actually I was working on that one and it was not working, turned out to be a simple syntax mistake (coding after work has its consequences). But yeah, you arrived at the same idea (great minds think alike), and guess what, IT WORKS!!!, what I did though I just calculated 1 point (center of quad) then drew the quad around it, it works for quads that are on the z-axis, but I’ll need to implement your idea for any quad.
About the algo for drawing stars, yes actually that algo seems to draw them in a cylindrical fashion, but if you use 3 different angles it solves the problem (you tend to see a bit more stars at the 0 angles, like you mentioned). I like the algo you presented, i’m thinking of using a variation of that, or simply load a precalculated starmap (maybe an true-life accurate one, it I find one). As for finding the coord of a projected object on screen, no luck yet, lemme know if you find something (I don’t know why openGL is so unfriendly when it comes to that, DX seem to handle this aspect better). Thanks again

Sounds great! Hey, e-mail me at aerotechts@spamsucks.usa.net
(remove the “spamsucks.” from the address. I do this so I won’t get spammed by messageboard crawlers)
I’d like to talk with you more on this stuff 'cause it sounds like we’re doing some of the same stuff and, like you said, good minds think alike so it wouldn’t hurt for us to put those minds together for some of this stuff. This way, we won’t clog up the message board (29 posts on this thread so far!). Later!

No… keep spamming. I’m learning here, too!

x=(float)radiuscos(alpha);
y=(float)radius
sin(beta);
z=(float)radius*sin(alpha);

This will cause problems, i’ve tried something very similar once before and i ended up with some rather large holes at two ends. Tell me if you figure it out though.

wire

I haven’t exactly been keeping up with this topic and am also new to OpenGL but inorder to plot the stars randomly, have any of you guys tried using the “GL_POINTS” but with plotting a fractal type function? Maybe that might help to generate the stars a little better…I could however be very wrong but it’s just a thought! Take Care…and Merry Christmas if you celebrate it or Happy New Year!

Hey wire, actually if you use 3 different angles it solves the problem (well almost, you’ll find a few more stars at the 0 angles but it still looks good), ie,:
x=(float)radiuscos(alpha);
y=(float)radius
sin(beta);
z=(float)radius*sin(theta); //diff angle
or you can also go with Punchey’s suggestion which is great too (above), actually I’ll probably switch to that idea too.
I suggest you guys read the whole post if you are doing this kind of stuff (space simulation), some very good ideas are presented. feel free to ask if you have more questions
yoda, your fractal function idea is interesting. Oh yeah, and Merry Xmas and Happy New year

the simple way to generate a regular distribution of random sphere is to generate them into a cubic space, then discard them if they’re outside the enclosed sphere.
then you normalize, and you’re done, like this:

#define SQUARED_LEN_3(v) (v.xv.x+v.yv.yv.zv.z)

Tdmyvert3f p;
float dd;

do {

// this will generate a point into a 2x2x2 cube, centered at 0,0,0
p.x= rand()*2.0/RAND_MAX-1.0;
p.y= rand()*2.0/RAND_MAX-1.0;
p.z= rand()*2.0/RAND_MAX-1.0;

dd= SQUARED_LEN_3(p)

} while( dd>1.0 );

// normalize
dd= 1.0/sqrt(dd);

p.x*= dd;
p.y*= dd;
p.z*= dd;

now we have a point on the surface of the unit sphere.

say we generate 20000 points, maybe in three different chunks: one for the faintest stars, one for the normal and the other for the brightest, to say.

you can render them by the use of glVertex.

i found that a fast way (i think the fastest, since this way you can see if a star is visible with only 3 mults and 2 adds, and in case it is not visible, you cull it away before sending it to the pipeline) is to do this:

float mv[16];

glGetFloatv(GL_MODELVIEW_MATRIX,mv);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

for( ) {
Tdmyvert3f v;
v.z= rotate_solve_for_z // dot product of star location and 3rd column of mv matrix (3 mults, 2 adds)
if(v.z>=THRESHOLD) continue; // gl have negative z running into the screen
v.x= rotate_solve_for_x
v.y= rotate_solve_for_y
glVertex((float *)&v);
}

THRESHOLD is a value wich depends on your current fov and aspect ratio.
but don’t bother about the math, set it to -0.7 and you should be quite good.

DMY

oh, i tried also another way, similar to the skybox approach.

let’s talk about heavy gear 2: there are some missions on the asteroids, where you can clearly see stars surrounding the scene.

i liked very much that star glittering when you smoothly change the view: a common aliasing artifact, but wich in this case looks good.

so i tried to recreate that.
the fact is that if i enclosed the scene into a skybox, then i would have to build a texture wich resolution is very high, compared to the projected size of a pixel (to produce aliasing)

so i tried to tile it: bad!
the skybox is a box, not a sphere, so near the corners of the box can be seen dense clusters of stars (with aliasing, ok) but near the center… no aliasing at all.

i would need a way to keep aliasing mostly constant over the surface of the quads.

so, i splitted every face of the box into more quads (actually 6, if i remember) and assigned directly texture coords to the new verts created.

the texture coords function must map the 3D vertex position to a 2D location on the surface of a sphere (approx works good the same)

i implemented it in a small demo, available here:

earth demo

sorry, but the demo is not compilable, unless i share all the developement system… quite big.

however, the skybox code is all there.

email me if it doesn’t work!

DMY

[This message has been edited by dmy (edited 11-26-2000).]

Just in case: I got that aliasing effect already in a 512512 texture, where the stars still are not only one pixel great, at a resolution of 640x480. Uhmmm, so if you make the stars a bit smaller 44 or even 2*2 texels, it should work for higher resolutions as well.

yep, but you still have aliasing incoherency between the center and the corners of the quads… the stars don’t glitter the same in any direction, is what i mean, and the nature of the skybox is revealed, wich is bad for the observer imo.

also, a grayscale 8-bit 512x512 texture is 256k, and depending how you want to make the background appear, you’ll need 2 to 6 of them.

instead, by using a single tile (seamless is best) of say, 256x256 pixels, you obtain a fairly good background for the scene, with only 64k of texture space.
also you don’t have to switch textures.

then, you could add some other bits of graphics to increase the quality, but still you have that nice glittering.

but as always, it’s a matter of taste

DMY

That’s a good idea you’ve got, dmy. I’ll have to try it out. BTW, I know this is a stupid question that I should already know, but using C++, I’m trying to seed the rand() function so that I get the same starfield every time. I don’t use rand() often and I’ve forgotten how to seed it properly. I’ve done what my documentation says to do and used srand() but when I use it, all my points are placed in the same place. This would make sense if my seed value was set each time before my rand() call, but srand() is only called once and then I call rand() several times after that. Anyone know why I’d be getting the same results every time rand() is called? Anyway, I also like the fractal idea. You could easily combine the box to sphere method with the fractal method by replacing the rand() calls with afractal algo.

[This message has been edited by Punchey (edited 11-27-2000).]

Pass a time value to the srand() so that you seed the random number generator differently each time based on the current time. There are a couple of ways you could do this…

srand(time(NULL)); // Must #include <time.h>

Or in Windows…

srand(timeGetTime()); // Must #include <mmsystem.h>