Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Java Game APIs & Engines / J2ME / Re: Skybox and textures on: 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
2  Java Game APIs & Engines / J2ME / Skybox and textures on: 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 ?
Pages: [1]
 

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

The first screenshot will be displayed as a thumbnail.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (19 views)
2014-09-24 16:12:06

Grunnt (43 views)
2014-09-23 14:38:19

radar3301 (25 views)
2014-09-21 23:33:17

BurntPizza (62 views)
2014-09-21 02:42:18

BurntPizza (32 views)
2014-09-21 01:30:30

moogie (37 views)
2014-09-21 00:26:15

UprightPath (50 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!