Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (120)
games submitted by our members
Games in WIP (577)
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  
  need texture help  (Read 729 times)
0 Members and 1 Guest are viewing this topic.
Offline Zorqu

Senior Newbie




Java games rock!


« Posted 2004-08-07 04:52:30 »

Hi all, I'm new to Xith and still fairly new to 3D programming.  Using the tutorials I came up with this simple program.  I'm trying to display texture on a quad instead of the cube used in the tutorial, it changes the quad's color, but the texture doesn't show.  I'm using the glass.png texture from the tutorial:

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  
package xith;

import javax.vecmath.*;

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

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

public class Xith
{
      private int SCREEN_WIDTH = 1024;
      private int SCREEN_HEIGHT = 768;
      private int MAP_WIDTH = 40;
      private int MAP_HEIGHT = 40;
      private int STARTING_VIEW_X = 10;
      private int STARTING_VIEW_Z = 10;
     
      public static void main (String[] args)
      {
            new Xith();
      }
     
      public Xith()
      {
            // Texture and TextureLoader
            Texture2D textureTerrain = null;
            TextureLoader tl = new TextureLoader();
           
            // Specify paths for textures, there can be more than one path
            tl.registerPath("./textures");
           
            //load the texture, program will crash if texture doesn't exist
            textureTerrain = (Texture2D)tl.getMinMapTexture("glass.png");
           
            //create virtual univers
            VirtualUniverse universe = new VirtualUniverse();
           
            // add a view to universe
            View 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);
           
            // draw Terrain
          Point3f[] coords = new Point3f[] {
                      new Point3f(0, 0, 0),
                        new Point3f(MAP_WIDTH, 0, 0),
                        new Point3f(MAP_WIDTH, 0, MAP_HEIGHT),
                        new Point3f(0, 0, MAP_HEIGHT),
          };

          QuadArray g = new QuadArray(coords.length, GeometryArray.COORDINATES);
          g.setCoordinates(0,coords);
           
            Appearance a = new Appearance();
            a.setTexture(textureTerrain);
           
          Shape3D Terrain = new Shape3D(g, a);
            scene.addChild(Terrain);
           
            // turn the scene into a render friendly format
            scene.compile();
           
            //create a canvas for our graphics
            RenderPeer rp = new RenderPeerImpl();
            CanvasPeer cp = rp.makeCanvas(null,SCREEN_WIDTH,SCREEN_HEIGHT,16,false);
            Canvas3D canvas = new Canvas3D();
            canvas.set3DPeer(cp);
           
            //modify our view
            view.addCanvas3D(canvas);
            view.getTransform().lookAt(
                        new Vector3f( STARTING_VIEW_X, 15, STARTING_VIEW_Z),            // location of eye
                        new Vector3f( STARTING_VIEW_X, 0, STARTING_VIEW_Z+3),            // center of view
                        new Vector3f( 0, 1, 0));      // vector pointing up
            view.startView();
           
      }
}
Offline hawkwind

Junior Duke




Java games rock!


« Reply #1 - Posted 2004-08-07 16:45:12 »

I think you need to tell the quad constructor your data contains textures coords

QuadArray quad = new QuadArray(.....
       GeometryArray.COORDINATES |  
       GeometryArray.TEXTURE_COORDINATE_2 |  
       ........

you need to generate some texture coords and add them to the coords array passed to the quad construtor

TexCoord2f[] texCoords = new TexCoord2f[] {
       new TexCoord2f(0f, 0f),
       new TexCoord2f(1f, 0f),
       new TexCoord2f(1f, 1f),
       new TexCoord2f(0f, 1f) };

take a look at  texture tuts on xith.org, comes with pretty pictures and source code....heh heh I know the author.

http://xith.org/tutes/GettingStarted/html/more_fun_with_textures.html#SECTION00071000000000000000
Offline Zorqu

Senior Newbie




Java games rock!


« Reply #2 - Posted 2004-08-07 17:53:53 »

Thanks hawk,  I was trying to use the code from the simple texture tutorial, I guess it doesn't work with the quad.  Here is my working code snippet if anyone else was having this problem:

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  
            // create a BranchGroup
            BranchGroup scene = new BranchGroup();
            locale.addBranchGraph(scene);
           
            // Define Texture coords for a square shape
          TexCoord2f[] texCoords = new TexCoord2f[] {
                      new TexCoord2f(0f, 0f),
                        new TexCoord2f(1f, 0f),
                        new TexCoord2f(1f, 1f),
                        new TexCoord2f(0f, 1f) };
           
            // draw Terrain
          Point3f[] coords = new Point3f[] {
                      new Point3f(0, 0, 0),
                        new Point3f(MAP_WIDTH, 0, 0),
                        new Point3f(MAP_WIDTH, 0, MAP_HEIGHT),
                        new Point3f(0, 0, MAP_HEIGHT),
          };

          QuadArray g = new QuadArray(coords.length, GeometryArray.COORDINATES |
                                                                            GeometryArray.TEXTURE_COORDINATE_2);
          g.setCoordinates(0,coords);
          g.setTextureCoordinates(0,0,texCoords);
           
            Appearance a = new Appearance();
            a.setTexture(textureTerrain);
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 (52 views)
2014-10-17 03:59:02

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

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

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

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

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

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

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

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

BurntPizza (86 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!