Sky generation

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.

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.

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

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.

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.

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.

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 :slight_smile:

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();

`

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.

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

[quote]You might also want to use a Background node for this, I know endolf has an example…

Kev
[/quote]
Do you know where that example might be? Ive searched the site and Google to no avail

I can see that it uses a background node. But reading that code and the Background.java code in Xith3D I can’t see any indication that its disabling the depth test before writing the background geometry.

Hi
Sorry about the delay in responding.

Ok, Java3d does disable the z buffer and draw a one unit background (in my case a sphere), xith doesn’t (yet?), so you have to draw a huge cube to do it. The way I have done it for darkvoid is to create an ac3d model with the starfield texture applied that is 280 metres across (not big enough for propper play, but ok for now, corners at -140,-140,-140 to 140,140,140). This then has the texture applied to the inside of it. I use my ac3d loader to load it into xith and place it in the background. I hope that helps a little, but it’s just summing up what others have said.

I’d like to see the z disabled for background nodes and a one unit size like java3d did, maybe when I’ve sorted a few things out here I’ll look into it if no-one gets there first :slight_smile:

Cheers

Endolf

[quote]But reading that code and the Background.java code in Xith3D I can’t see any indication that its disabling the depth test before writing the background geometry.
[/quote]
Isn’t that what I asked before?

It seems that background stuff is rendered first. So theres hope that a skybox e.g. isn’t fogged away. But it still has to be a large box taking the Z-clipping into account when setting up the geometry?

Sorry to bring up this old thread but I was wondering if anyone had looked into this anymore/worked out how to get it working?

It’s just that it fits into something I’m thinking about at the moment, a kinda space simulation with a starfield in the background similar by the sound of it to the effect endolf wanted to create.

Cheers,
Dan.

I did, and noticed a strange thing.
First of all, the thing that almost every 3D tutorial seem to be forgotting about skyboxes is that you have to disable the depth buffer when drawing them around the camera, to ensure that the scene will be drawn on top of the skybox instead of partially (of totally) behind the sky geometry.

This is the rather ugly code for a skybox proto-demo. It is working correctly only if you use vertex colouring for the skybox. If you enable the texture it seems to make ignore the DepthBufferEnabled flag.
I’m doing something wrong, I hope.


import javax.vecmath.*;

import java.awt.*;
import java.awt.event.*;

// Xith3D
import com.xith3d.scenegraph.*;
import com.xith3d.test.*;
import com.xith3d.loaders.texture.*;

// use Jogl
import com.xith3d.render.*;
import com.xith3d.render.jogl.*;

public class SkyBox implements KeyListener {
    TransformGroup sbTG, cubeTG;
    Transform3D sbT, cubeT, v;
    Shape3D cube;
    Shape3D box;
    Vector3f eyeLoc = new Vector3f(0, 0, 10);
    View view;
    float angle;
    float speed = 0.02f;
    boolean db;
    
    public static void main (String args[]) {
        new SkyBox();
    }
    
    public SkyBox() {
        db = false;
        
        // create the virtual universe
        VirtualUniverse universe = new VirtualUniverse();
        
        // add a view to the universe
        view = new View();
        universe.addView(view);
        
        // add a locale
        Locale locale = new Locale();
        universe.addLocale(locale);
        
        // create a BranchGroup
        BranchGroup scene = new BranchGroup();
        locale.addBranchGraph(scene);
        
        //loads texture for the skybox
        Texture2D skyTex;
        TextureLoader tl = new TextureLoader();
        tl.registerPath(".");
        skyTex = (Texture2D)tl.getMinMapTexture("sky.png");
        
        sbTG = new TransformGroup();
        cubeTG = new TransformGroup();
        scene.addChild(sbTG);
        scene.addChild(cubeTG);
        
        //Cube geometry
        Geometry g1 = Cube.createCubeViaTriangles(0, 0, 0, 1, true);
        cube = new Shape3D(g1, new Appearance());
        
        //Skybox geometry
        
        //sets renderingattributes to not use depthbuffer for the skybox
        RenderingAttributes ra = new RenderingAttributes();
        ra.setDepthBufferEnable(false);
        Appearance boxApp = new Appearance();
        boxApp.setRenderingAttributes(ra);
        
        
        //Enable this to have a blue working skybox
        boxApp.setColoringAttributes(
            new ColoringAttributes(
            new Color3f(0.0f, 0.0f, 1.0f), ColoringAttributes.NICEST));
        
        //using this call broke the setRenderingAttributes!
        //boxApp.setTexture(skyTex);
        
        Geometry g2 = Cube.createCubeViaTriangles(0, 0, 0, 10, false);
        box = new Shape3D(g2, boxApp);
        
        sbTG.addChild(box);
        cubeTG.addChild(cube);
        sbT = new Transform3D();
        cubeT = new Transform3D();
        v = new Transform3D();
        v.setTranslation(eyeLoc);
        sbT.setTranslation(eyeLoc);
        sbTG.setTransform(sbT);
        
        //ensure the cube to be OVER the Skybox to illustrate 
        //the disabling of the depth buffer for the skybox rendering
        cubeT.setTranslation(new Vector3f(0f, 0f, -12f));
        cubeTG.setTransform(cubeT);
        
        //Window creation lingo.
        RenderPeer rp = new RenderPeerImpl();
        CanvasPeer cp = rp.makeCanvas(null, 640, 480, 32, false);
        Canvas3D canvas = new Canvas3D();
        canvas.set3DPeer(cp);
        Toolkit.getDefaultToolkit().addAWTEventListener(
            new EventListener(),   AWTEvent.KEY_EVENT_MASK);
        
        //Place camera
        view.addCanvas3D(canvas);
        view.getTransform().lookAt(eyeLoc,   // location of eye
            new Vector3f( 0, 0, 0),   // center of view
            new Vector3f( 0, 1, 0));  // vector pointing up
        
        while(true) {
            view.renderOnce();
        }
    }
    
    public void keyPressed(KeyEvent e) {
        if (e.getKeyCode() == e.VK_LEFT) {
            angle = (angle + speed) % 360;
            v.setTranslation(new Vector3f (0, 0, 0));
            v.rotY(angle);
            v.setTranslation(eyeLoc);
            view.setTransform(v);
            sbT.setTranslation(eyeLoc);
            sbTG.setTransform(sbT);
        }
        
        if (e.getKeyCode() == e.VK_RIGHT) {
            angle = (angle - speed) % 360;
            v.setTranslation(new Vector3f (0, 0, 0));
            v.rotY(angle);
            v.setTranslation(eyeLoc);
            view.setTransform(v);
            sbT.setTranslation(eyeLoc);
            sbTG.setTransform(sbT);
        }        
    }
    
    public void keyTyped(KeyEvent e) {
        
    }
    
    public void keyReleased(KeyEvent e) {
        
    }
    
    class EventListener implements AWTEventListener {
        public void eventDispatched(AWTEvent event) {
            if(event instanceof KeyEvent) {
                KeyEvent e = (KeyEvent) event;
                switch(e.getID()) {
                    case KeyEvent.KEY_TYPED: keyTyped(e); break;
                    case KeyEvent.KEY_PRESSED: keyPressed(e); break;
                    case KeyEvent.KEY_RELEASED: keyReleased(e); break;
                }
            }
        }
    }
}

Comments?

Hi,

don’t know if this has been mentioned in this thread so far:

Terragen is a nice tool to create images for backgrounds and skyboxes.

You can find it here: www.planetside.co.uk

Besides it’s a very nice tool to play with (even for beginners). See www.terradreams.de for examples from skilled terragen users.

Somewhere on the terragen site is a skybox tutorial including a script. This tutorial tells you how to create 6 images for your cube.

That’s nice, if only Xith3D will retain depth buffer settings on the cube once textured :slight_smile:

I also noticed that if the cube is set too large (around 50000 seem to broke in my machine) the texture binded to the cube will not show up at all.

wow! Terragen has come a LONG way since I last used at it four years ago. Thanks for prompting me to check it out again.

Will.

found some:
http://www.delphigl.de/tutorials/skybox.html
http://www.blitzcoder.com/cgi-bin/articles/show_article.pl?f=gamejoseph03212002.html
http://www.blitzbasic.com/Community/posts.php?topic=25359

First one looks good.

Will.