Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Skybox and textures  (Read 994 times)
0 Members and 1 Guest are viewing this topic.
Offline necroleak

Junior Newbie




Java games rock!


« Posted 2005-02-05 07:22:42 »

Hi, I'm trying to create a SkyBox that will wrap all the gameworld. The SkyBox cube will have six different textures for all its sides, but I currently cannot get how to easily implement this.
I'm creating a cube mesh (VB,IB) and putting it around the game world, but how can I put different texture on each side ?
Offline necroleak

Junior Newbie




Java games rock!


« Reply #1 - Posted 2005-02-10 11:07:46 »

I finally managed to work it out. For those interested here's the piece of code. The 'Group' class was the big thing here.

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  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
  public SkyDome( Image2D[] img, int center_x, int center_y, int center_z, 
                                   int width, int height, int depth )
    {
        
        int   half_width = (width / 2),
              half_height = (height / 2),
              half_depth = (depth / 2);
        
        short posCX = (short)(center_x + half_width), negCX = (short)(center_x - half_width),
              posCY = (short)(center_y + half_height), negCY =(short)(center_y - half_height),
              posCZ = (short)(center_z + half_depth), negCZ  = (short)(center_z - half_depth);
        
        try
        {

            // load textures
            Texture2D[] textures = new Texture2D[6];
            for( int i = 0; i < 6; i++ )
            {
                textures[i] = new Texture2D( img[i] );
                textures[i].setFiltering( Texture2D.FILTER_LINEAR, Texture2D.FILTER_LINEAR );
                textures[i].setWrapping( Texture2D.WRAP_CLAMP, Texture2D.WRAP_CLAMP );
                textures[i].setBlendColor( Texture2D.FUNC_MODULATE );
            }
            

            // front
            short[] vSide1 = { posCX, posCY, posCZ,  negCX, posCY, posCZ, posCX, negCY, posCZ,  negCX, negCY, posCZ };
            // back
            short[] vSide2 = { negCX, posCY, negCZ, posCX, posCY, negCZ, negCX, negCY, negCZ, posCX, negCY, negCZ };
            // left
            short[] vSide3 = { negCX, posCY, posCZ, negCX, posCY, negCZ, negCX, negCY, posCZ, negCX, negCY, negCZ };
            // right                
            short[] vSide4 = { posCX, posCY, negCZ, posCX, posCY, posCZ, posCX, negCY, negCZ, posCX, negCY, posCZ };
            // top
            short[] vSide5 = { posCX, posCY, negCZ, negCX, posCY, negCZ, posCX, posCY, posCZ, negCX, posCY, posCZ };
            // bottom            
            short[] vSide6 = { posCX, negCY, posCZ, negCX, negCY, posCZ, posCX, negCY, negCZ, negCX, negCY, negCZ };
                    

            short[] tex = {  
                1, 0,       0, 0,       1, 1,       0, 1,
            };
            
            Mesh skymesh[] = new Mesh[6];
            skymesh[0] = createFace( vSide1, textures[0], tex );
            skymesh[1] = createFace( vSide2, textures[1], tex );
            skymesh[2] = createFace( vSide3, textures[2], tex );
            skymesh[3] = createFace( vSide4, textures[3], tex );
            skymesh[4] = createFace( vSide5, textures[4], tex );
            skymesh[5] = createFace( vSide6, textures[5], tex );

            // compose skybox mesh as a group of submeshes
            m_groupSkybox = new Group();            
            for( int i = 0; i < 6; i++)
                m_groupSkybox.addChild( skymesh[i] );

            
        }
        catch( Exception e )
        {
            System.out.println( "*** SkyDome::SkyBox Construction Exception **** ");
             e.printStackTrace();
        }
    }

    
    private Mesh createFace( short[] vertices, Texture2D texture, short[] texcoords )
    {
        VertexArray v = new VertexArray( vertices.length / 3, 3, 2 );
        v.set( 0, vertices.length / 3, vertices );
        
        VertexArray t = new VertexArray( texcoords.length / 2, 2, 2 );
        t.set( 0, texcoords.length / 2, texcoords );
        
        VertexBuffer vb = new VertexBuffer();
        vb.setPositions( v, 1.0f, null );
        vb.setTexCoords( 0, t, 1.0f, null );
        
        // create the appearance
        Appearance app = new Appearance();        
        app.setTexture( 0, texture ) ;
      
        PolygonMode poly = new PolygonMode();
        poly.setCulling( PolygonMode.CULL_FRONT );
        app.setPolygonMode( poly );

        
        int strips[] = { 4 };        
        IndexBuffer ib = new TriangleStripArray( 0, strips );
        Mesh meshFlat = new Mesh( vb, ib, app );
        meshFlat.setAppearance( 0, app );
        
        return meshFlat;
    }



Gud luk  Wink
Pages: [1]
  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.

Longarmx (39 views)
2014-10-17 03:59:02

Norakomi (29 views)
2014-10-16 15:22:06

Norakomi (24 views)
2014-10-16 15:20:20

lcass (28 views)
2014-10-15 16:18:58

TehJavaDev (57 views)
2014-10-14 00:39:48

TehJavaDev (56 views)
2014-10-14 00:35:47

TehJavaDev (47 views)
2014-10-14 00:32:37

BurntPizza (64 views)
2014-10-11 23:24:42

BurntPizza (36 views)
2014-10-11 23:10:45

BurntPizza (78 views)
2014-10-11 22:30:10
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

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!