Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (768)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (854)
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 4875 times)
0 Members and 1 Guest are viewing this topic.
Offline Grunnt

JGO Kernel

Medals: 143
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 Devvie

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: 45
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 Kernel

Medals: 143
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:

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));

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

You can read about LibGDX meshes here:

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:
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

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 Kernel

Medals: 143
Projects: 8
Exp: 5 years

Complex != complicated

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


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  

EgonOlsen (1340 views)
2018-06-10 19:43:48

EgonOlsen (1230 views)
2018-06-10 19:43:44

EgonOlsen (939 views)
2018-06-10 19:43:20

DesertCoockie (1380 views)
2018-05-13 18:23:11

nelsongames (1112 views)
2018-04-24 18:15:36

nelsongames (1374 views)
2018-04-24 18:14:32

ivj94 (2120 views)
2018-03-24 14:47:39

ivj94 (1269 views)
2018-03-24 14:46:31

ivj94 (2286 views)
2018-03-24 14:43:53

Solater (808 views)
2018-03-17 05:04:08
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46 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‑
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!