Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (541)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (604)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1] 2
  ignore  |  Print  
  Sky generation  (Read 6782 times)
0 Members and 1 Guest are viewing this topic.
Offline Francisco Andrades

Junior Newbie




Java games rock!


« Posted 2004-02-04 16:13:16 »

Hi, I've been monitoring this forum for quite some time and has proven very educative. The demos and examples are a great source to start hacking with Xith3D.

What I have not found is a example on how to create a Sky box. I'm talking about a realistic sky, not backgound color. Does anyone has a small example on this? A pointer to a javadoc or tutorial would be enough.

Thanks
Offline wrightmf

Senior Newbie




Is that on the list?


« Reply #1 - Posted 2004-02-04 16:30:18 »

Just create a cube (or, for the more experienced, a sphere sectional) with a sky-ish texture applied to it. Try searching on google for skybox tutorial and you'll see how it works in other APIs. The same methods would apply in Xith (they would just be easier to implement Grin).

A great writeup of it exists over at GamaSutra. Get an account on http://www.gamasutra.com then go to this article:
http://www.gamasutra.com/features/19981023/bell_01.htm

Offline kevglass

« JGO Spiffy Duke »


Medals: 221
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #2 - Posted 2004-02-04 16:33:38 »

You might also want to use a Background node for this, I know endolf has an example....

Kev

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Java Cool Dude

Senior Devvie




Java forever


« Reply #3 - Posted 2004-02-04 16:45:44 »

/me has an excellent FPS camera class that would make a hell of a skybox demo Grin
Offline Francisco Andrades

Junior Newbie




Java games rock!


« Reply #4 - Posted 2004-02-05 11:59:49 »

Thanks a lot, I thought it had to be that way (using a huge box or sphere) - just wanted to know if Xith3D (or JOGL for this matter) had an artifact for sky rendering.
Offline Java Cool Dude

Senior Devvie




Java forever


« Reply #5 - Posted 2004-02-06 03:57:20 »

Well someone spent few minutes and made you something
Simple SkyBox:


Keys: A,S,D,Q,W,E or left, right, up, down, page up, page down to control camera location.
Mouse to change viewing direction.
Source
Offline Herkules

Senior Devvie




Friendly fire isn't friendly!


« Reply #6 - Posted 2004-02-06 04:06:25 »

Where are the textures from?

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Offline Java Cool Dude

Senior Devvie




Java forever


« Reply #7 - Posted 2004-02-06 04:30:19 »

I found them somewhere on the web, you can get them at the .jnlp base directory though Smiley
Offline Herkules

Senior Devvie




Friendly fire isn't friendly!


« Reply #8 - Posted 2004-02-06 04:47:29 »

Already got them Smiley

BTW, this is the same way FlyingGuns created it's skybox. Creating textures for that is not that simple! Anybody has a good tool?

One small thing: the edges are clearly visible. I thinks this is due to filtering artifacts. This vanishes if you sacrifice 1 texel at each textures border:


1  
2  
3  
4  
5  
6  
7  
      float offset = 1f / 512f;
      float tmin = offset;
      float tmax = 1f - offset;
    TexCoord2f     texCoords[] = new TexCoord2f[]{ new TexCoord2f(tmin, tmax),  //upLeft      0
                                                   new TexCoord2f(tmax, tmax),  //upRight     1
                                                   new TexCoord2f(tmin, tmin),  //bottomLeft  2
                                                   new TexCoord2f(tmax, tmin)}; //bottomRight 3



A second thing: the code does not compile due to a missing Class display.DisplayOptions. I tweaked it a bit.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
      //    int parameters[]    =        new int[7];
        //screenWidth   =     parameters[0];
        //screenHeight  =     parameters[1];
        //canvasWidth   =     parameters[2];
        //canvasHeight  =     parameters[3];
        //refreshRate   =     parameters[4];
        //bitDepth      =     parameters[5];
        //fullScreen    = parameters[6]== 1;

      int                
      screenWidth        =                     0,
      screenHeight       =                     0,
      canvasWidth        =                   800,
      canvasHeight       =                   800,
      bitDepth           =                    32,
      refreshRate        =                     0,
      fps                =                     0;


    int parameters[]    =        new int[] {
        screenWidth,
        screenHeight,
        canvasWidth,
        canvasHeight,
        refreshRate,
        bitDepth,
        fullScreen ? 1 : 0
      };


//    DisplayOptions.showSettingsSelector("Select Screen Mode",
//                                        DisplayOptions.USE_XITH3D_ENGINE,
//                                        parameters);

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Offline Java Cool Dude

Senior Devvie




Java forever


« Reply #9 - Posted 2004-02-06 05:07:25 »

A quick look at the .jnlp source code reveals the location of the missing displayOptions jar file
Here Grin
Nice catch on the edge artifacts thing though Wink
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Herkules

Senior Devvie




Friendly fire isn't friendly!


« Reply #10 - Posted 2004-02-06 05:29:49 »

Ok, just looked at the source.

Meanwhile I recognized that is NOT the way the skybox is made in FlyingGuns!

The problem with this box is, that it has to be HUGE (e.g. as big as the clip distance) in order not to occlude the other, non-skybox geometry.
And I'm sure, when having fog switched on, the skybox is fogged away?

There need to be some interaction with a thing like the Java3Ds Background node. Render the box first, don't touch the Z-Buffer and such.

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Offline Herkules

Senior Devvie




Friendly fire isn't friendly!


« Reply #11 - Posted 2004-02-06 06:01:06 »

Hm hm ... my first look into xith3d code now .....

Lets assume that background geometry is defined within a unit sphere....

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
class CanvasPeerImpl
{
....

private void setViewForBackground(View view) {

        setProjection(view);

        gl.glMatrixMode(GL.GL_PROJECTION);
        view.getBackgroundTransform().get(trans);
        gl.glMultMatrixf(trans);
        gl.glMatrixMode(GL.GL_MODELVIEW);
        gl.glLoadIdentity();

    }


Switch Z-buffer off, farClip =1.0, nearClip=0.1 or so?

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Offline rmdire

Junior Devvie





« Reply #12 - Posted 2004-02-06 06:41:03 »

wow - and again wow - JCD & co. - you're anticipating my needs
thanks for the code.

rmdire Roll Eyes
Offline Herkules

Senior Devvie




Friendly fire isn't friendly!


« Reply #13 - Posted 2004-02-06 13:18:36 »

Experts please comment: is a change in the xith3d backgroundhandling feasable/necessary/useful?

Make it compatible with/similar to Java3D?


Just imagine a skybox in the presence of fog.

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Offline Java Cool Dude

Senior Devvie




Java forever


« Reply #14 - Posted 2004-02-06 14:44:42 »

I put together another demo that combines skybox + heightmap + FPS camera, here's a recent screenshot



I'll be adding noise + lighting to it Smiley
Offline Francisco Andrades

Junior Newbie




Java games rock!


« Reply #15 - Posted 2004-02-08 01:08:16 »

That's great JCD!!

Thanks a lot
Offline wrightmf

Senior Newbie




Is that on the list?


« Reply #16 - Posted 2004-02-08 10:32:03 »

I updated my textured terrian demo to include a skybox. The texture sort of blows, but it employs the basic concept of skyboxing. Also keep in mind that skyboxes look much better on LARGE worlds.

Web Start
Source
Full Jar


Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #17 - Posted 2004-02-08 11:01:24 »

Looks nice, but you've got the texture seams visible along the edges of the skybox - does Xith have a CLAMP_TO_EDGE texture mode yet...?

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline wrightmf

Senior Newbie




Is that on the list?


« Reply #18 - Posted 2004-02-08 16:16:05 »

Quote
Looks nice, but you've got the texture seams visible along the edges of the skybox - does Xith have a CLAMP_TO_EDGE texture mode yet...?


The answer is yes, but the idiot who wrote the demo forgot to put it in there. That guy should be strung up Wink

Anyway, it's fixed now. Download is still in the same place.


Offline swpalmer

JGO Coder


Exp: 12 years


Where's the Kaboom?


« Reply #19 - Posted 2004-02-09 03:05:37 »

I'd love to try this... but it seems JOGL and webstart aren't getting along.

java.lang.UnsatisfiedLinkError: /Users/scottpalmer/Library/Caches/Java Web Start/cache/http/Dusers.xith.org/P80/DMmike/DMXith3DTerrainTest/DMlib/DMjogl/DMmacos/RNjogl-macos.jar/libjogl.jnilib:
     at java.lang.ClassLoader$NativeLibrary.load(Native Method)
     at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1560)
     at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1469)
     at java.lang.Runtime.loadLibrary0(Runtime.java:788)
     at java.lang.System.loadLibrary(System.java:834)
     at net.java.games.jogl.impl.NativeLibLoader$1.run(NativeLibLoader.java:60)
     at java.security.AccessController.doPrivileged(Native Method)
     at net.java.games.jogl.impl.NativeLibLoader.<clinit>(NativeLibLoader.java:46)
     at net.java.games.jogl.impl.GLContext.<clinit>(GLContext.java:51)
     at net.java.games.jogl.impl.macosx.MacOSXGLContextFactory.createGLContext(MacOSXGLContextFactory.java:52)
     at net.java.games.jogl.GLCanvas.<init>(GLCanvas.java:68)
     at net.java.games.jogl.GLDrawableFactory.createGLCanvas(GLDrawableFactory.java:117)
     at net.java.games.jogl.GLDrawableFactory.createGLCanvas(GLDrawableFactory.java:80)
     at com.xith3d.render.jogl.CanvasPeerImpl.<init>(CanvasPeerImpl.java:113)
     at com.xith3d.render.jogl.RenderPeerImpl.makeCanvas(RenderPeerImpl.java:124)
     at com.xith3d.render.jogl.RenderPeerImpl.makeCanvas(RenderPeerImpl.java:104)
     at com.janusresearch.concept.Xith3DTerrainTest.init(Unknown Source)
     at com.janusresearch.concept.Xith3DTerrainTest.main(Unknown Source)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
     at java.lang.reflect.Method.invoke(Method.java:324)
     at com.sun.javaws.Launcher.executeApplication(Launcher.java:844)
     at com.sun.javaws.Launcher.executeMainClass(Launcher.java:804)
     at com.sun.javaws.Launcher.continueLaunch(Launcher.java:682)
     at com.sun.javaws.Launcher.handleApplicationDesc(Launcher.java:397)
     at com.sun.javaws.Launcher.handleLaunchFile(Launcher.java:199)
     at com.sun.javaws.Launcher.run(Launcher.java:167)
     at java.lang.Thread.run(Thread.java:552)

Offline wrightmf

Senior Newbie




Is that on the list?


« Reply #20 - Posted 2004-02-09 09:02:25 »

swpalmer, have you tried downloading the jar and compiling/running it manually? The bundled MacOSX libraries worked for the guys at the office (except for texture handling from the jar subdirectory, which shouldn't be an issue if you compile/run manually). Please give it a try and let me know.

Offline swpalmer

JGO Coder


Exp: 12 years


Where's the Kaboom?


« Reply #21 - Posted 2004-02-09 11:52:33 »

Grabbed the JAR and a JOGL distribution that should work.. the linker error is gone (I think it is a webstart thing), but now I get:

Adding light [26 sec, 54mb/63mb]
2004-02-09 09:40:01.297 java[1135] invalid context
2004-02-09 09:40:01.299 java[1135] invalid context
net.java.games.jogl.GLException: Error creating nsContext
       at net.java.games.jogl.impl.macosx.MacOSXOnscreenGLContext.create(MacOSXOnscreenGLContext.java:137)
       at net.java.games.jogl.impl.macosx.MacOSXOnscreenGLContext.makeCurrent(MacOSXOnscreenGLContext.java:150)
       at net.java.games.jogl.impl.GLContext.invokeGL(GLContext.java:162)
       at net.java.games.jogl.impl.macosx.MacOSXOnscreenGLContext.invokeGL(MacOSXOnscreenGLContext.java:76)
       at net.java.games.jogl.GLCanvas.displayImpl(GLCanvas.java:182)
       at net.java.games.jogl.GLCanvas.display(GLCanvas.java:82)
       at com.xith3d.render.jogl.CanvasPeerImpl.render(CanvasPeerImpl.java:941)
       at com.xith3d.scenegraph.View.renderOnce(View.java:722)
       at com.xith3d.scenegraph.View.renderOnce(View.java:655)
       at com.janusresearch.concept.Xith3DTerrainTest.runTest(Unknown Source)
       at com.janusresearch.concept.Xith3DTerrainTest.init(Unknown Source)
       at com.janusresearch.concept.Xith3DTerrainTest.main(Unknown Source)


Which appears to be a OS X thing.  Is there no JOGL build out there that actually works for OS X?  I used one from Gerard Ziemski's home page and it should work as it clearly had a folder named 142, and I'm running the newly released 1.4.2 JRE for OS X.

Offline wrightmf

Senior Newbie




Is that on the list?


« Reply #22 - Posted 2004-02-09 12:11:41 »

swpalmer, can you run other Xith demos or is mine the only one that is problematic on your system?

Offline swpalmer

JGO Coder


Exp: 12 years


Where's the Kaboom?


« Reply #23 - Posted 2004-02-09 16:43:04 »

I used to be able to run Xith demos ... but alas 'tis hosed completely now.

Thread 11 Crashed:
0   libobjc.A.dylib                0x90831388 objc_msgSend_stret + 0x8
1   libjogl.jnilib                 0x0a26a904 createContext + 0x3c
2   libjogl.jnilib                 0x0a1ff6a4 Java_net_java_games_jogl_impl_macosx_CGL_createContext + 0x18


I think your code is fine, though perhaps the Xith3D/JOGL referenced in your JNLP file is not working with OS X 10.3.2 JRE 1.4.2

We really need a central place to put working stable builds of these frameworks for WebStart users to reference as an extension or somthing.

Offline wrightmf

Senior Newbie




Is that on the list?


« Reply #24 - Posted 2004-02-09 16:50:51 »

Quote

We really need a central place to put working stable builds of these frameworks for WebStart users to reference as an extension or somthing.

Agreed. Of course, I don't think this would have run on your machine anyway as I use a textures subdirectory inside the jar and I have seen problems with this from Mac users where I work. I guess I should move the textures to the root of the jar to be more flexible.

Offline swpalmer

JGO Coder


Exp: 12 years


Where's the Kaboom?


« Reply #25 - Posted 2004-02-09 18:23:33 »

That subdir in Jar problem is very odd.  The Jar code in the JRE is mostly pure Java isn't it?  It seems strange for that to fail in the Mac port... but I guess anything is possible.  I know that I use graphics in subdirs for my swing apps and they load fine with getResource...

odd.

Offline gregorypierce

Senior Devvie




I come upon thee like the blue screen of death....


« Reply #26 - Posted 2004-02-10 01:21:25 »

The source for the skybox demo is dine. I've built this and used the JOGL on my own site and everything works fine. Its the libraries that are included on the JOGL site. I can contribute a working version is someone tells me where to upload it for Xith3D.

Currently I'm the OSX keeper Smiley

http://www.gregorypierce.com

She builds, she builds oh man
When she links, she links I go crazy
Cause she looks like good code but she's really a hack
I think I'll run upstairs and grab a snack!
Offline kaffiene
« Reply #27 - Posted 2004-02-17 07:29:30 »

As Hurkules mentioned, this isn't the usual way to do skyboxes in OpenGL.  Usually you turn the ZBuffer and fogging off and render a small box around the camera.

Something like this:

       glPushAttrib(GL_ENABLE_BIT | GL_DEPTH_BUFFER_BIT);

       glDisable(GL_LIGHTING);
           glDisable(GL_CULL_FACE);
           glDisable(GL_DEPTH_TEST);
           glDisable(GL_BLEND);
           glDisable(GL_FOG);

            glEnable(GL_TEXTURE_2D);
       glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
     
       glPushMatrix();
       glTranslatef((cam->location.x), (cam->location.y), (cam->location.z));

       glBindTexture(GL_TEXTURE_2D, skyTex->texId);
       
       
       glBegin(GL_QUADS);
           // +z
           glTexCoord2f(0,0); glVertex3f(-10, -10, 10);
           glTexCoord2f(0,1); glVertex3f(-10,  10, 10);
           glTexCoord2f(1,1); glVertex3f( 10,  10, 10);
           glTexCoord2f(1,0); glVertex3f( 10, -10, 10);
           // -z
           glTexCoord2f(0,0); glVertex3f(-10, -10, -10);
           glTexCoord2f(1,0); glVertex3f( 10, -10, -10);
           glTexCoord2f(1,1); glVertex3f( 10,  10, -10);
           glTexCoord2f(0,1); glVertex3f(-10,  10, -10);            
           // +y
           glTexCoord2f(0,0); glVertex3f(-10,  10, -10);
           glTexCoord2f(1,0); glVertex3f( 10,  10, -10);            
           glTexCoord2f(1,1); glVertex3f( 10,  10,  10);
           glTexCoord2f(0,1); glVertex3f(-10,  10,  10);            
           // -y
           glTexCoord2f(0,0); glVertex3f(-10, -10, -10);
           glTexCoord2f(0,1); glVertex3f(-10, -10,  10);            
           glTexCoord2f(1,1); glVertex3f( 10, -10,  10);
           glTexCoord2f(1,0); glVertex3f( 10, -10, -10);            
           // +x
           glTexCoord2f(0,0); glVertex3f(10, -10,  10);
           glTexCoord2f(1,0); glVertex3f(10,  10,  10);              
           glTexCoord2f(1,1); glVertex3f(10,  10, -10);
           glTexCoord2f(0,1); glVertex3f(10, -10, -10);
         
           // -x
           glTexCoord2f(0,0); glVertex3f(-10, -10, -10);
           glTexCoord2f(1,0); glVertex3f(-10,  10, -10);
           glTexCoord2f(1,1); glVertex3f(-10,  10,  10);
           glTexCoord2f(0,1); glVertex3f(-10, -10,  10);
       glEnd();

       glPopMatrix();

       glPopAttrib();

Offline kaffiene
« Reply #28 - Posted 2004-02-17 07:36:57 »

As Hurkules mentioned, this isn't the usual way to do skyboxes in OpenGL.  Usually you turn the ZBuffer and fogging off and render a small textured box around the camera.

If you set the skybox to a very large size (as is done in the code examples in this thread) there are several potential problems:

(1) Efficiency - it means you have to write to every position in the Z buffer which you don't if the ZBuffer is off and your objects don't cover the whole screen (anywhere with a sky).  More importantly, if you are using fog, you have fog calculations applied for every pixel in the screen rather than just those with foreground objects.

(2) Z-Buffer fighting - if you put your skybox out in the wild blue yonder you are placing it where the ZBuffer precision is very low and risk ZBuffer fighting for distant objects, or even worse, distant objects disapearing behind the background!

Its much better for the background to be really in the background by not appearing in the ZBuffer at all.

Any ideas how this could be achieved?

TIA

Peter.
Offline kevglass

« JGO Spiffy Duke »


Medals: 221
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #29 - Posted 2004-02-17 07:53:20 »

Presumably this is what the "Background" node type is for. Whether it has (or will have) this functionality I don't know, have to check the source.

Kev

Pages: [1] 2
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

BurntPizza (9 views)
2014-12-27 22:38:51

Mr.CodeIt (13 views)
2014-12-27 04:03:04

TheDudeFromCI (17 views)
2014-12-27 02:14:49

Mr.CodeIt (25 views)
2014-12-23 03:34:11

rwatson462 (56 views)
2014-12-15 09:26:44

Mr.CodeIt (46 views)
2014-12-14 19:50:38

BurntPizza (92 views)
2014-12-09 22:41:13

BurntPizza (113 views)
2014-12-08 04:46:31

JscottyBieshaar (86 views)
2014-12-05 12:39:02

SHC (97 views)
2014-12-03 16:27:13
How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!