Author Topic: Textures on a Terrain  (Read 4458 times)

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Textures on a Terrain
« on: October 16, 2008, 11:57:17 pm »
Another question about terrains.  It looks as though only one texture can be assigned to an Object3D at any given time, so what is the best way to texture a terrain that has many different graphics on it, like grass, dirt, roads, etc?  My thought was to create a texture that is say 1024 width and a super huge height that has all the texture graphics on it, then do a UV map for each polygon to the desired graphic.  I'm not sure what method to use for this though.  PolygonManager.setPolygonTexture( int polyID, TextureInfo tInf ) looks like it will do the job, but I just wanted to make sure that will work in both software and OpenGL modes (assuming I use a single texture that is).

Offline fireside

  • double
  • *****
  • Posts: 605
    • View Profile
Re: Textures on a Terrain
« Reply #1 on: October 17, 2008, 12:19:49 am »
You can use more than one texture on an object3d.  It's  more efficient because you can use texture repeat with smaller textures.  It loads them automatically by name so the texture name has to be less than 8 characters and you have to load them before you load the object and name the texture the same as the name in the 3ds file, even the extension needs to be in the name, I think.  Hmm, that's right, you're not using 3ds files.  Well, I don't know how you do it, then.
« Last Edit: October 17, 2008, 12:23:23 am by fireside »
click here->Fireside 7 Games<-

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Textures on a Terrain
« Reply #2 on: October 17, 2008, 12:28:20 am »
You can use more than one texture on an object3d.  It's  more efficient because you can use texture repeat with smaller textures.  It loads them automatically by name so the texture name has to be less than 8 characters and you have to load them before you load the object and name the texture the same as the name in the 3ds file, even the extension needs to be in the name, I think.
That is one way to get the texture onto the Object3D, you are correct.  However, you can also assign a texture to the Object3D after it is loaded (then you are not limited to the 8 character name length).  The same UV coordinates that were in the 3ds file are used, so no worries there.  That way you can switch out textures as needed (for example using a variety of leaf colors for different coppies of the same tree model).  That is the method I used in the "Camera Orbiter" demo applet for the textures on the tree, and also the method I am using for assigning and switching textures on the terrain in my Map Maker application.

It looks like UV maps can be generated with the TextureInfo class, so I am pretty sure that is the way to do it when you are not starting with an actual .3ds file.

--EDIT--
According to the jPCT JavaDocs, "Multi texturing is supported by the OpenGL renderer only".  Perhaps that only applies to per-polygon though ???  I want to have the option of switching between software and OpenGL modes, so if there is a restriction of one texture per Object3D when in software mode, multiple textures won't work in my situation.
« Last Edit: October 17, 2008, 01:23:16 am by paulscode »

Offline fireside

  • double
  • *****
  • Posts: 605
    • View Profile
Re: Textures on a Terrain
« Reply #3 on: October 17, 2008, 06:27:34 am »
 There are two software renderers, and I think the default uses opengl, so it might not matter.  I know I used multiple textures in software mode. 
click here->Fireside 7 Games<-

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Textures on a Terrain
« Reply #4 on: October 17, 2008, 07:26:47 am »
Come to think of it, I have too (when I load a 3ds file and "merge" all the sub objects into one).  So I guess this isn't an issue after all.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Textures on a Terrain
« Reply #5 on: October 17, 2008, 08:46:45 am »
You are confusing multi-texturing with multiple textures. The former means that you apply more than one texture to one polygon. The software renderer doesn't support this. The latter means that you assign multiple textures to one object but with only one per polygon. All renderers support this.

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Textures on a Terrain
« Reply #6 on: October 17, 2008, 01:34:25 pm »
Cool.  I thought maybe that is what the JavDoc meant, but I wanted to be sure before I got too far into things.