Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (577)
games submitted by our members
Games in WIP (498)
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  
  Texture Blending  (Read 3099 times)
0 Members and 1 Guest are viewing this topic.
Offline joeyanny

Senior Newbie





« Posted 2010-08-17 14:38:27 »

I am developing a landscape editor in JOGL. I can place the textures in the scene but there is a sharp line where two textures join. I want the edge of the textures to blend together.

Can someone please suggest a method to do this?
Offline Orangy Tang

JGO Kernel


Medals: 51
Projects: 11


Monkey for a head


« Reply #1 - Posted 2010-08-17 15:20:13 »

That'll depend heavily on what your landscape looks like (eg. heightmap vs. model), how you're texturing it (procedural vs. tiles) and how your rendering it (multipass vs. texture spatting vs. megatexture). Basically you'll have to give us a lot more info if you want a useful answer.

These days I'd suggest looking at either texture splatting or megatexture approaches if you want nice results.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline joeyanny

Senior Newbie





« Reply #2 - Posted 2010-08-17 20:03:27 »

My texture code:

Texture rock;
Texture grass;

rock = TextureIO.newTexture(new File("rock.jpg"),false);
grass = TextureIO.newTexture(new File("grass.jpg"),false);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT);

//Drawing quad with rock texture
gl.glEnable(GL.GL_TEXTURE_2D);
TextureCoords rockCoords = rock.getImageTexCoords();
rock.bind();
gl.glBegin(GL.GL_QUADS);
gl.glTexCoord2f(rockCoords.left(), rockCoords.top());
gl.glVertex3d(0,0,0);
gl.glTexCoord2f(rockCoords.right(), rockCoords.top());
gl.glVertex3d(1,0,0);
gl.glTexCoord2f(rockCoords.right(), rockCoords.bottom());
gl.glVertex3d(1,1,0);
gl.glTexCoord2f(rockCoords.left(), rockCoords.bottom());
gl.glVertex3d(0,1,0);
gl.glEnd();
gl.glDisable(GL.GL_TEXTURE_2D);

//Drawing quad with grass texture
gl.glEnable(GL.GL_TEXTURE_2D);
TextureCoords grassCoords = grass.getImageTexCoords();
grass.bind();
gl.glBegin(GL.GL_QUADS);
gl.glTexCoord2f(grassCoords.left(), grassCoords.top());
gl.glVertex3d(1,0,0);
gl.glTexCoord2f(grassCoords.right(), grassCoords.top());
gl.glVertex3d(2,0,0);
gl.glTexCoord2f(grassCoords.right(), grassCoords.bottom());
gl.glVertex3d(2,1,0);
gl.glTexCoord2f(grassCoords.left(), grassCoords.bottom());
gl.glVertex3d(1,1,0);
gl.glEnd();
gl.glDisable(GL.GL_TEXTURE_2D);

I want to blend the rock and grass together where the textures touch
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Orangy Tang

JGO Kernel


Medals: 51
Projects: 11


Monkey for a head


« Reply #3 - Posted 2010-08-18 01:38:07 »

Ugh, so much wrong with this.

1. Use tga or png for textures, as jpeg artifacts are horribly obvious when on textures. Alternatively if you want compression use the various DXT formats.
2. Don't use quads, you're just making extra work for the driver as they'll be split into two tris anyway. Use indexed triangle lists.
3. Don't use immediate mode, use Vertex Buffer Objects (VBOs) or at least vertex arrays.
4. Don't submit your geometry as doubles since it'll get converted to float precision anyway, all you're doing is wasting bandwidth and adding extra processing time.
5. Don't draw every tile in it's own batch, you'll kill the performance.
6. Pack your tiles into a single texture so you can submit the whole terrain in one batch.

If you just want to hardcode a transition you could just add some extra geometry and do the cross fade by setting the vertex alpha as appropriate, but it'd be pretty inefficient. I'd again suggest that you google "texture splatting", but I suspect you're not going to bother.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline Nate

JGO Kernel


Medals: 128
Projects: 3
Exp: 14 years


Esoteric Software


« Reply #4 - Posted 2010-08-18 03:47:07 »

/hugs Orangy Tang

Offline joeyanny

Senior Newbie





« Reply #5 - Posted 2010-08-18 10:07:33 »

Thanks for your advice, I have researched texture splatting since you mentioned it.

What do you mean by "Don't draw every tile in it's own batch" and "Pack your tiles into a single texture"?
Offline Nate

JGO Kernel


Medals: 128
Projects: 3
Exp: 14 years


Esoteric Software


« Reply #6 - Posted 2010-08-18 11:05:22 »

What do you mean by "Don't draw every tile in it's own batch" and "Pack your tiles into a single texture"?
Look into VBOs and this should become apparent. You want to draw your entire terrain in one call. All your vertices and texture coords should be in one big buffer. This means all your texture coords will reference the same texture, so you need a single texture that has all your tiles.

Offline joeyanny

Senior Newbie





« Reply #7 - Posted 2010-08-18 14:16:36 »

Thanks for the explanation  Smiley
Offline teletubo
« League of Dukes »

JGO Ninja


Medals: 48
Projects: 6
Exp: 8 years



« Reply #8 - Posted 2010-08-18 15:38:15 »

Thanks for the explanation  Smiley

+1

I am myself learning openGL and now I'm trying to optimize my code, this info will surely help .

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 605
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #9 - Posted 2010-08-18 16:53:19 »

I don't really get it. All your points are valid, but he has a problem, that is hard enough in itself (at least requiring multipass, multitexturing with register combiners or shaders).

You just exploded the magnitude of his problem. I expect he'll have a lot of work on each and every step, and step 6 invalidates GL_REPEAT which he uses, multiple images in one texture only really works for sprites, not terrain tiles. Worst: after he did all that work, he will face exactly the same problem: the surface types don't have smooth transitions. My advise would be: give multi-pass a try. Don't care about performance, first try to achieve the results you're after.

'Make it work, make it faster.'

Everything else is premature optimization, making it much harder for yourself.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline joeyanny

Senior Newbie





« Reply #10 - Posted 2010-08-18 17:51:37 »

thanks for the advice Riven, I was just looking for techniques to research and included the code to try to further explain the situation. I've got some smooth transitions for the edges from the advice given. I'll do some code optimisation next.

Im a female btw  Tongue
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 605
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #11 - Posted 2010-08-18 18:01:04 »

thanks for the advice Riven, I was just looking for techniques to research and included the code to try to further explain the situation. I've got some smooth transitions for the edges from the advice given. I'll do some code optimisation next.
Good to hear. Once you get comfortable with OpenGL I'd advice you to skip all the 'old' ways, and start toying with shaders as soon as possible.


Im a female btw  Tongue
'he' was obviously a typo, normally I always refer to programmers as females. persecutioncomplex

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline joeyanny

Senior Newbie





« Reply #12 - Posted 2010-08-18 18:07:09 »

Can you suggest any good websites to look at or books to buy?
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 605
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #13 - Posted 2010-08-18 18:09:30 »

http://www.lighthouse3d.com/opengl/glsl/index.php?shaders

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
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.

xsi3rr4x (23 views)
2014-04-15 18:08:23

BurntPizza (18 views)
2014-04-15 03:46:01

UprightPath (32 views)
2014-04-14 17:39:50

UprightPath (16 views)
2014-04-14 17:35:47

Porlus (32 views)
2014-04-14 15:48:38

tom_mai78101 (58 views)
2014-04-10 04:04:31

BurntPizza (116 views)
2014-04-08 23:06:04

tom_mai78101 (216 views)
2014-04-05 13:34:39

trollwarrior1 (183 views)
2014-04-04 12:06:45

CJLetsGame (190 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
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!