Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (117)
games submitted by our members
Games in WIP (564)
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  
  [probably solved] How to render a huge planet?  (Read 1806 times)
0 Members and 1 Guest are viewing this topic.
Offline Grunnt

JGO Wizard


Medals: 69
Projects: 8
Exp: 5 years


Complex != complicated


« Posted 2013-08-26 17:29:29 »

Hi guys, this is kind of a newbie OpenGL question, so please bear with me.

I'm currently fooling around with LibGDX trying some new things out and building a little 2D lander game. The lander is no problem (its basically 128 x 128 pixels), but I do have an issue with rendering a planet that is comparatively huge compared to the lander (as in, 1000+ * larger):



Edit: forgot to mention, heh, it's 2D

The problem is that I have no idea on how to best approach this. I would guess that I could draw the planet as a circular polygon using a mipmap texture (i.e. a detailed texture when zoomed in, less detailed when zoomed out) repeated over the surface. But I'm curious as to how you guys would approach this. Any ideas would be appreciated!

Offline Several Kilo-Bytes

Senior Member


Medals: 11



« Reply #1 - Posted 2013-08-26 17:59:35 »

I would use noise, since my texture would probably be derived from noise anyways if I had to create it. You can use as much or as little detail as you need without creating repetition.
Offline RobinB

JGO Ninja


Medals: 44
Projects: 1
Exp: 3 years


Spacegame in progress


« Reply #2 - Posted 2013-08-26 18:16:09 »

You need to render detail using an very smart LOD system so you dont eat al resources.
Best thing would be to make an quad tree for all lod levels, and generate these on the fly.
But this is 3D stuff..

With a planet you get really fast at texture limits, so using one texture would only work if you wont zoom in (much).
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Grunnt

JGO Wizard


Medals: 69
Projects: 8
Exp: 5 years


Complex != complicated


« Reply #3 - Posted 2013-08-26 18:21:47 »

@Several KB: good idea, but I have some doubts it will look very nice. But it may be worth a try.

@RobinB: sorry! forgot to mention its 2D in fact. But that may not change anything fundamentally. I'll look into quad trees and see what they can do for me..

Offline pitbuller
« Reply #4 - Posted 2013-08-26 19:30:38 »

Just use simple texture with mipmaps.
Offline davedes
« Reply #5 - Posted 2013-08-27 00:01:57 »

If your planet truly needs to be 100k + pixels and you need to be able to see the entire thing (be it through zooming or panning)... then use a mesh with a repeating planet texture, scale the texcoords accordingly.

Generating the points of a circle looks somewhat like this:
http://codepen.io/anon/pen/orGCD

To determine an approximate number of steps given your radius, you can use something like this:
int steps = (int)(12 * Math.pow(radius/2f, 1/3f));


Alternatively:
int steps = (int)(12 * Math.cbrt(radius/2f));


You can read about LibGDX meshes here:
https://github.com/mattdesl/lwjgl-basics/wiki/LibGDX-Meshes

You can use triangles or triangle fan. Triangle fan is easy; just put a point in the center, then points for each circle segment (just like in the Code Pen). Triangles is not too much more difficult; the benefit of them is that you can place many in the same batch (in this case it doesn't seem necessary, since you've only got one planet).

Texcoords would be calculated kind of like this:
1  
2  
float u = (((x-centerX) / radius) / 2f + 0.5f) * repeatCount;
float v = (((y-centerY) / radius) / 2f + 0.5f) * repeatCount;


Which leads to 0.0 - 1.0 values, multiplied by the number of times you want the texture to repeat. Make sure TextureFilter.Repeat is set! Smiley
https://github.com/mattdesl/lwjgl-basics/wiki/LibGDX-Textures#texture-parameters


If you only ever see the tip of the planet, then forgo the above and just use a half-circle texture that makes the ship look small in comparison (SpriteBatch).

Offline Grunnt

JGO Wizard


Medals: 69
Projects: 8
Exp: 5 years


Complex != complicated


« Reply #6 - Posted 2013-08-28 07:42:52 »

@davedes:

Thanks a lot for the detailed explanation! I can see how this can be done, especially the texture coordinate part is interesting. I'll go and try it out.

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.

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

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

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

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

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

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

BurntPizza (33 views)
2014-09-19 03:14:18

Dwinin (48 views)
2014-09-12 09:08:26

Norakomi (75 views)
2014-09-10 13:57:51

TehJavaDev (108 views)
2014-09-10 06:39:09
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!