Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (568)
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  
  Applying a texture to a sphere, using QUAD_STRIPS  (Read 1304 times)
0 Members and 1 Guest are viewing this topic.
Offline ajmas

Junior Member




Miles away from here!


« Posted 2007-10-27 21:57:19 »

I have a method for drawing a sphere:

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  
    static public void drawSphere(GL gl, double radius, int lats, int longs) {
        /*
         * This algorithm moves along the z-axis, for PI radians and then at
         * each point rotates around the z-axis drawing a QUAD_STRIP.
         *
         * If you you start i at a non-zero value then you will see an open
         * end along the z-axis. If you start j at a none zero-axis then you
         * will see segements taken out.
         */

        gl.glEnable(GL.GL_TEXTURE_GEN_S);                          // Enable Texture Coord Generation For S (NEW)
       gl.glEnable(GL.GL_TEXTURE_GEN_T);                          // Enable Texture Coord Generation For T (NEW)


        for ( int i = 0; i <= lats; i++) {
            double lat0 = Math.PI * (-0.5 + (double) (i - 1) / lats);
            double z0 = Math.sin(lat0) * radius;
            double zr0 = Math.cos(lat0) * radius;

            double lat1 = Math.PI * (-0.5 + (double) i / lats);
            double z1 = Math.sin(lat1) * radius;
            double zr1 = Math.cos(lat1) * radius;

            gl.glBegin(GL.GL_QUAD_STRIP);
            for ( int j = 0; j <= longs; j++) {
                double lng = 2 * Math.PI * (double) (j - 1) / longs;
                double x = Math.cos(lng) *radius;
                double y = Math.sin(lng) *radius;
               
                gl.glNormal3d(x * zr0, y * zr0, z0);
                gl.glVertex3d(x * zr0, y * zr0, z0);
               
                gl.glNormal3d(x * zr1, y * zr1, z1);
                gl.glVertex3d(x * zr1, y * zr1, z1);
            }
            gl.glEnd();
        }

        gl.glDisable(GL.GL_TEXTURE_GEN_S);                      
        gl. glDisable(GL.GL_TEXTURE_GEN_T);      
    }


I now want to modify this to allow for applying a texture around the globe. If I had split the sphere into QUADs, then I would probably have applied the texture as a percentage of the rotation, but I am not sure how I would do this with a quad strip?

I would like the texture to wrap around the object, like a map around a globe, rather than repeat.
Offline turquoise3232

Junior Member




Java (games) rock!


« Reply #1 - Posted 2007-10-28 12:11:49 »

Hi, to map a rectangle texture of earth onto a quad you have to disable the automatic texture coordinates generation and provide yourself the texture coordinates of you vertex defining your quads mesh. It's quite easy using latitude and longitude...

I think that i have the code somewhere on my hard drive but it's quite a good exercise to do it yourself.

Hope it helps.
Offline cylab

JGO Ninja


Medals: 50



« Reply #2 - Posted 2007-10-28 12:59:46 »

First google hit for "spherical mapping": http://local.wasp.uwa.edu.au/~pbourke/texture_colour/spheremap/. Haven't read it, but from the pictures it appears to be what you want Wink

Mathias - I Know What [you] Did Last Summer!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ajmas

Junior Member




Miles away from here!


« Reply #3 - Posted 2007-10-28 15:30:55 »

Thanks, looks like what I was looking for Smiley

BTW Google is great, but you just need to know the right search terms.
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.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (20 views)
2014-09-24 16:12:06

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

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

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

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

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

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

BurntPizza (54 views)
2014-09-19 03:14:18
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!