Game Development Community

dev|Pro Game Development Curriculum

fun porting space related resources into T3D

by Jeff Yaskus · 02/18/2012 (1:50 pm) · 21 comments

I've been working on trying to decipher and port over the space related resources ... into T3D v1.2

So far, its been a challenge as the code examples are all 5-10 years old. Since T3D doesn't have a "Sky" object anymore, I started with trying to add the "stars" code into "SkyBox".

The function to loadStars() had to be updated, replacing ResourceManager-> with FileStream:: and its loading the star data file properly now.
(see here for the details: www.garagegames.com/community/resource/view/3252 )

However, I have little experience with the OpenGL graphics and such ... so my version of the code to draw the stars is not working as hoped. In the openGL version, he just displayed an array of points ...

original TGE code ... in Sky::renderObject()
// JL: Draw stars on top of everything else.
   if( mRenderStars )
   {
       // Blend with the background.
       glEnable(GL_BLEND);
       glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );

       // Send, render, clean. Repeat as necessary.
       glEnableClientState( GL_VERTEX_ARRAY );
       glVertexPointer(3, GL_FLOAT, 0, &mStarPoints );
       glEnableClientState( GL_COLOR_ARRAY );
       glColorPointer(4, GL_FLOAT, 0, &mStarColors );

       glDrawArrays( GL_POINTS, 0, mNumStars );

       glDisableClientState( GL_VERTEX_ARRAY );
       glDisableClientState( GL_COLOR_ARRAY );
   }

But couldn't find any example of how it would be done in T3D v1.2 "syntax". Here is my "hack" so far, which ... I'll admit is likely way off.

// STARS >>>
   if( mRenderStars )
   {
       GFXDrawUtil *drawer = GFX->getDrawUtil();  

       const MatrixF &objectMat = getRenderTransform();  
       const Point3F &objectPos = objectMat.getPosition();  

       GFXStateBlockDesc starDesc;
       starDesc.setBlend( true );
       
       if ( mNumStars == 0 )  
         return;        
           
       ColorI pntColor;  
       F32 mPointRenderSize =  0.03f;
       F32 mRadius =  1.0f;
       const Point3F pntSize( mPointRenderSize, mPointRenderSize, mPointRenderSize );  

       // Send, render, clean. Repeat as necessary.
       for ( U32 i = 0; i < mNumStars; i++ )  
       {           
          Point3F pnt;
          pnt.set( mStarPoints[i][0], mStarPoints[i][1], mStarPoints[i][2] );
          
          pntColor.set( (U8) mStarColors[i][0], (U8)mStarColors[i][1], (U8)mStarColors[i][2], (U8)mStarColors[i][3] );

          drawer->drawSphere( starDesc, mRadius, pnt, pntColor, true,true,0);
   }

   // <<< STARS

and dumping to the console, shows the first star info as such;
***  XYZ ( 0.023161,-0.099450,0.994773 ) RGBA( 1.000000,1.000000,1.000000,0.487477 ) ***

I'm not sure if (a) my stars are not being drawn because of errors in my code or (b) they are, but not visible because it needs an "offset" or something ?

ie. all the stars are relatively close to (0,0,0) ... just fractions off from 0.

Has anyone ported any of the space related resources over to T3D yet ?

Encountered these issues when converting stuff to T3D ?

Any help or suggestions would be appreciated.






LINKS to old space related resources ... that might be helpful to this effort;

Space Sim ~ TGE ; posted 2007
www.garagegames.com/community/blogs/view/13214

Space Sim ~ TGE - gravity mods ; posted 2007
www.garagegames.com/community/blogs/view/13221

Skysphere ~ TGE/A ; posted ~2005
www.garagegames.com/community/forums/viewthread/35841

Skysphere code ~ TGE ; posted ~2004
www.garagegames.com/community/resource/view/6644/2#comments

fxStarFieldReplicator ~ TGE ; posted 2003
www.garagegames.com/community/blogs/view/4924

"Stars" code from TGE ; posted ~2002
www.garagegames.com/community/resource/view/3252

About the author

Long time gamer, hacker and programmer. With dreams of making video games -

Page «Previous 1 2
#1
02/18/2012 (4:07 pm)
Got the stars resource working!!

Here is the rendering code ...
// STARS >>>
   if( mRenderStars )
   {
      // define mDots
      GFXVertexBufferHandle<GFXVertexPC> mDots;

      // create point-dots
      if( mDots.isNull() )
      {
         mDots.set(GFX, mNumStars, GFXBufferTypeStatic);

         U32 ndot = 0;
         mDots.lock();
         for(U32 i = 0; i < mNumStars; i++)
         { 
           U32 myAlpha = (256 * mStarColors[i][3]) -1;
           mDots[i].color.set( 255, 255,255, myAlpha  );
           mDots[i].point.x = mStarPoints[i][0];
           mDots[i].point.y = mStarPoints[i][1];
           mDots[i].point.z = mStarPoints[i][2];
         }
         mDots.unlock();
      }

      GFXStateBlockDesc dotdesc;
      dotdesc.setBlend(true, GFXBlendSrcAlpha, GFXBlendInvSrcAlpha);
      dotdesc.setCullMode( GFXCullNone );
      GFXStateBlockRef mDotSB = GFX->createStateBlock( dotdesc );

      GFX->setStateBlock(mDotSB);

      // draw the points.
      GFX->setVertexBuffer( mDots );
      GFX->drawPrimitive( GFXPointList, 0, mNumStars );
   }
   // <<< STARS

before
www.jyaskus.com/images/misc/screenshot_before.png
after
www.jyaskus.com/images/misc/screenshot_after.png
#2
02/18/2012 (4:17 pm)
For anyone interested in using the old "stars" resource in T3D ... first download the original zip file from the resource link.

But instead of using the sky.cc and sky.h, use these updated skybox.cpp and skybox.h;
www.jyaskus.com/downloads/stars_T3D_skybox.zip

Put these source files under Engine->Source->Environment ... regenerate your project and compile.

And put the stars.dat under art or such, then create a new mission / level with a standard "Skybox" and not scatter sky ... go into the properties under "Stars", select the source file and enable it.

Voila! stars should pop up ...
#3
02/19/2012 (12:13 am)
@Jeff: Cool man. Maybe you should put this in as an official resource. Use your blog here to point to the resources and provide updates.

Most community members look first at resources for the ... errr ... resources. 8-}
#4
02/19/2012 (12:54 am)
@Quinton - I'll do that once I get the rest of the pieces working ... still trying to work out the issues with creating a Sky Sphere.

Mike's code is a bit old, but like the stars resource -- I'm again stuck trying to decipher the graphics part of it.

specifically ... merging Sky::rendersphere(), Sky::renderSkyBox() and Sky::renderObject ... from his post here;
www.garagegames.com/community/resource/view/6644

... with the existing T3D SkyBox code.
#5
02/19/2012 (8:44 am)
i too have been working on porting some of the older space sim resources. Have not met with much success but i did get the gravity mod working.

as for 'skysphere' instead of 'skybox' , i personally do no this it is a issue at all. here is a couple of shots of my project using the skybox. I think the environment here looks pretty darn good.

shatteredgalaxy.rolanddynamics.com/devrenders/screenshot_001-00000.png
shatteredgalaxy.rolanddynamics.com/devrenders/screenshot_001-00001.png
---

as the images show , for the skybox it is all down to the artist that creates the texture set and how it is chopped up.

i have a software app that specifically does skybox's, and does a awesome job at it. Although i will say it did take a bit of time to get the order right in to the material definition but once i did it turned out great, i have 4 sets of these skybox texture sets now and they all look real good.

---

for the star generator, i have this in both TGE 1.5.2 and TGEA 1.8.1 , it works as expected in TGE with the draw back that it is a bit of a pig on performance. In TGEA, even though i did convert the code to TGEA conventions, i am to this day still getting a 'vertex out of bounds of array' error. Mind you i have not gone back to the code in a long time, i just disabled the calls to the function and moved on to other things at one point.

I would love to have this working though, this would be great. There was another problem i ran into with the star generator, that being that stars WILL render inside vehicles, for example in TGE when i do a fly through in my test space ship, i switch to 'cockpit' view and i see stars rendering inside the cockpit.

so i will download and check out your changes to the code, and hope it does not destroy the performance. *cross fingers that the stars do not render inside the 'cockpit'.

cheers mate keep up the effort.
#6
02/20/2012 (12:02 pm)
Cool how 3 different people will find 5 different ways to get something done. I just made a space skybox and used the waterplane with zero opacity, viscosity, etc., and my Soldier is my spaceship placeholder. I really need a spaceship.....

Anyway, nice work there Jeff. I'll be keeping an eye on this blog.
#7
02/20/2012 (8:45 pm)
Roland@ I played around with different free textures and put together a skycube of the milkyway - with stars included. I see what you mean, it looks great and I don't notice the corners like I had expected to. That ordering in the skycube material.cs file took me awhile as well, until i realized that I had to "rotate" my right and left images 90 degrees or so to get them looking properly.

Odd thing is, now the "stars" are drawn as black dots ... and like you mentioned, they appear "through" everthing ... the sun, planets, objects in front of me even. Its as if it uses the "border" color, to draw the dots ... so when I switch back to a "green grid" for a skymat, it works as normal again.

Thinking that perhaps "baked in" stars is a better approach, especially since the stars resource just used dots ... and not stars of different sizes and colors.

Dan@ Always another, possibly better approach right? Thats what I expected to learn from this -- and see if these old resources can add value or not. And trying to make up for my lack of artist ability, with some persistent hacking!

All@ Get spacescape0.3 ... makes some great space cube maps!

#8
02/20/2012 (11:17 pm)
Awesome work! Not something I thought of, but now I know where to get it if I need it. Thanks!
#9
02/21/2012 (10:04 am)
@Jeff Funny you mention Spacescape, lol that is the program i use and yes it does make real nice cube maps.
#10
02/21/2012 (10:54 am)
Yeah I also use spacescape. In fact I noticed someone selling what look to be Spacescape generated skyboxes. :D

That's the height of capitalism right there. Get a free program and make a bunch of skyboxes to sell to the same people who are using that same free program. Ha!
#11
02/22/2012 (7:39 am)
yeah well , lol i thought that too. But i did not want to be the one to say it. :)
#12
02/22/2012 (11:02 am)
All@ Looks like the cat is out of the bag! Giving up the hidden, trade secrets for space sky boxes :O) ... now, I messed around with it a lot last night and had a tough time getting the skybox images to match up properly.

Had to eventually rotates the right,left, back and bottom images ... to get it to map properly. Not sure if its a result of the spacescape export or a t3d "thing" ... but eventually figured out a rotation pattern that worked.

It had to first make a debug version of the images - with words like "this way up" or "this is the left side" on it ... so I could then see how it showed up in the editor and rotate until it fit properly.

Once I had the pattern worked out, applied the same rotations to each of newly generated space maps ... and worked,looked great. In fact, I don't see the common skybox issues even ... no corners are visible and image isn't distorted.
#13
02/23/2012 (11:07 am)
funny i did not have to rotate any of them. here is a sample of one of my skyboxes from spacescape

Singleton CubemapData( refSpaceBox )
{
cubeFace[0] = "art/skies/testspacebox/testspacebox_right1";
cubeFace[0] = "art/skies/testspacebox/testspacebox_left2";
cubeFace[0] = "art/skies/testspacebox/testspacebox_top3";
cubeFace[0] = "art/skies/testspacebox/testspacebox_bottom4";
cubeFace[0] = "art/skies/testspacebox/testspacebox_front5";
cubeFace[0] = "art/skies/testspacebox/testspacebox_back6";
}

Singleton Material( mSpacebox )
{
Cubemap = refSpaceBox;
}

took a bit of time to get the order right, but as you can see from my screenshots above it works a treat.
#14
02/26/2012 (1:38 pm)
Roland@ That explains my issues ... I was trying to create them inside the T3D editor. I mapped them using the names (right, left, etc) ...

new CubemapData(testSkyCubeMap)
{
   cubeFace[0] = "art/skies/test/right1.png";
   cubeFace[1] = "art/skies/test/left2.png";
   cubeFace[2] = "art/skies/test/back5.png"; 		// 6 
   cubeFace[3] = "art/skies/test/front6.png";		// 5
   cubeFace[4] = "art/skies/test/top3.png";		// 3
   cubeFace[5] = "art/skies/test/bottom4.png";		// 4
};

So I had to rotate them to get it to show up correctly ... however, in hind sight ... just putting them in numerical order works much better!

#15
02/27/2012 (7:27 am)
I love this! All I ever wanted was a "right = panel #1, etc.," and now I haves it.

Thanks guys.

@Jeff - Sorry to ugly up your blog like it's some kind of public forum! :D
#16
02/28/2012 (12:09 am)
If it helps -- just posted a full resource on how to create t3d skyboxes using spacescape0.3 ...

Now, everyone gets 'em for free!


Dan@ thanks, you inspired me to put it into a resource.


#17
02/28/2012 (7:52 am)
@jeff yeah i had that too, went by the name (Right, Left, ect ...) which is why it took me a while to get the order right. in hind site i shoulda mapped them in numerical order like spacescape was telling me to do. :)
#18
03/05/2012 (7:34 am)
@Roland Orr:
Quote:
Have not met with much success but i did get the gravity mod working.

care to elaborate on the gravity mod changes?
#19
04/11/2012 (1:11 pm)
@Jeff: The 'star' resource file comes up 404. Can you repost it on Sean's Torque server?

abighole.hngamers.com
#20
04/03/2013 (12:00 pm)
jeff,
can u post the zip file from this resource:
http://www.garagegames.com/community/resource/view/3252
?

" I was trying to create them inside the T3D editor"
i need to control stars from script.
did u have success on that?
Page «Previous 1 2