Jump to content
  • Advertisement

Archived

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

Dotren

starbackground for a space combat game

This topic is 5633 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 all, I''m fairly new to OpenGL and am working on a space combat game. My question is, how do I implement the background of stars in the infinite space area that you can fly in? I can''t just make a "skybox" since could potentially fly out of it. How do you make a nice looking star background that you could fly for an hour and never run into? Thanks, Dotren

Share this post


Link to post
Share on other sites
Advertisement
Use a skybox, but always keep it centered on the camera. So no matter how far you fly or how long you fly towards it, you''ll never ever hit it.

Share this post


Link to post
Share on other sites
In regards to your answer, how could one write the code so that the ''skybox'' is fixed on the center of the camera? I mean, if you''re constantly rotating and translating, then the camera would move, right? Thanx

Share this post


Link to post
Share on other sites
Do you want to fly amongst the stars, or just have a pretty background (skybox)?

Share this post


Link to post
Share on other sites
quote:
Original post by d_a_p_a_n03
In regards to your answer, how could one write the code so that the ''skybox'' is fixed on the center of the camera? I mean, if you''re constantly rotating and translating, then the camera would move, right? Thanx


glLoadIdentity();
glRotatef(... camera rotation ...);
DrawSkyBox();

glLoadIdentity();
glRotatef(... camera rotation ...);
glTranslatef(... camera translation ...);
DrawEverythingElse();


Share this post


Link to post
Share on other sites
The idea is to be able to fly around in a complete 3D environment... like the X-Wing series.

Thanks for the ideas so far, can't wait to try them out.

P.S. on the note of the drawing the skybox to the center of the camera...how do you prevent from popping occuring as objects fly into and out of your "skybox"?

Rendar

[edited by - Dotren on March 31, 2003 11:20:05 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by Dotren
P.S. on the note of the drawing the skybox to the center of the camera...how do you prevent from popping occuring as objects fly into and out of your "skybox"?



You could disable the z-buffer when drawing the skybox. You can use glDepthMask() enable/disable it for writing.

quote:
Original post by circuit

glLoadIdentity();
glRotatef(... camera rotation ...);
DrawSkyBox();

glLoadIdentity();
glRotatef(... camera rotation ...);
glTranslatef(... camera translation ...);
DrawEverythingElse();



Wouldn't this do the same thing...

glLoadIdentity();
glRotatef(... camera rotation ...);

DrawSkyBox();

glTranslatef(... camera translation ...);

DrawEverythingElse();


[edited by - microdot on March 31, 2003 12:48:11 PM]

Share this post


Link to post
Share on other sites
I don't use a starbox, I used a starsphere with billboarded bitmaps. Each star gets a random X, Y and Z position. The position is kept in a vector, which is then normalized and then it is multiplied by the radius of the sphere. Each star or meteor should have its own position, but you should also have an offset vector of some sort. When the game starts the offset vector is 0,0,0, but whenever you update the player position you update the offset vector as well by the exact same amount.
Here is a screen shot of the spaceship flying away from the sphere (just so the user can get a look at the sphere. in the actual game the sphere travels with the player so you never bump into it).
http://www.cprogramming.com/cboard/showthread.php?s=&threadid=36607
I have working code for all of this if you need it.



[edited by - Shadow12345 on March 31, 2003 10:01:37 PM]

[edited by - Shadow12345 on March 31, 2003 10:02:09 PM]

[edited by - Shadow12345 on March 31, 2003 10:03:35 PM]

Share this post


Link to post
Share on other sites
I ended up using some code I found on the forums that generates points on a shere and assigns them random shades of black, grey, and white.

This generates a decent looking starfield and does it in a display list. My problem now is that the starfield moves with the camera so its always the same background...I need the camera''s rotation to be independant of the starfield so it looks like the camera is actually rotating.

Right now I''m using a camera class for mouse look that I found online somewhere (modified it slightly). It uses a gluLookAt with the camera''s position, view, and up vector as arguments and it does this in the display function. The starfield is drawn before this as a display list.

How do I get the starfield to stop the billboarding effect and actually stay independant of the camera''s rotation?

Thanks,
Dotren

Share this post


Link to post
Share on other sites
Stop the billboarding effect? Umm, don''t you want to keep that? You simply add the position of the camera to the star''s point.

Something like:
glTranslatef(Position.x + Player1->CamPos.x, Position.y + Player1->CamPos.y, Position.z + Player1->CamPos.z);

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!