Celeron's picture

[SL Multitexturing] - Only one texture with gluSphere

Hi again,
after my first newbie post ( http://www.opentk.com/node/719 , sorry again... ) I've done my homeworks using RenderMonkey to check the vertex/fragment shader syntax.
Well, the result is acceptable as you can see here:

The seguent poor result, instead, is produced by my code:

It seems like only one texture (day) is available and for sure something in my code is going wrong ;-)
A question: does gluSphere support multitexturing? If so, how can I accomplish this task? Reading some examples with Google, I didn't found any reference to this.

For all those wishing help me to understand, I've posted the VB.Net 2005 project that implements - better say "tries to implement" :-) - SL sphere multitexturing.
In the project is included vertex/fragment code (as it appears in the Orange Book - ch. #10), but - obviously - not the textures. These ones are 7200x3600 px jpegs; after all, to compile and run the project, it is possible to use any image you have; the problem - I think - isn't in the textures because they went well in RenderMonkey :-(

Thanks in advance for any help :-)

SphereMultitexturing.zip48.85 KB


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
objarni's picture

Celeron: the way I do matrix setup 99% of the time is this:

1. In resize of window:
GL.MatrixMode( projection ); // don't know the enum by heart
GL.LoadIdentity(); // clear any "history"
GL.Ortho(0, 10, 0, 10, -1, 1); // change 10 with what you prefer the right/top border of the window to be in 2d coordinates
GL.Viewport(0, 0, Width, Height); // Width/Height of window (from GameWindow or GLControl, whichever you use)

2. In paint:
GL.MatrixMode( modelview );
GL.LoadIdentity(); // clear any "history"
GL.Transform/Rotate etc.

Celeron's picture

Thank you, Objarni. will apply your stuff when i'll be back from work. Stay tuned :-))

Inertia's picture

It wasn't my intent to insult you, in theory you could use the GL.Ortho command to do a GL.Scale and GL.Translate in a single command and by that save one matrix multiplication.

Celeron's picture
"Inertia" wrote:

It wasn't my intent to insult you

You really did not ... instead you made me smiling :-)
Thanks to all; I'm really finding a little bit of time to apply the indications you gave me. I'll report ;-)

Celeron's picture

After a "complete mind refresh" about sphere geometrical concepts, I can't understand why my "Sphere Class" paints only the top sector :-(
As I said in some posts over, I used the code posted by Fiddler regarding the way how calculate vertices and indices. I read it more and more without find any hidden mistake (obviously mine, since I haven't done copy-and-past, but I re-typed it all just to deeply understand what I was doing).
Attached you can find both Geometries.cs file that holds "Sphere Class" and the terrifying sphere sector image that it generates :-)

Thanks for patience ;-)

Geometries.cs9.79 KB
HorribleSphere.jpg20.5 KB
Celeron's picture

To help someone to help me :-), I'd like to post all my little exercise-application.
The issue is still present and I guess I'm not able to solve without any suggestion. The strange thing is that, if I use glutSphere using the same matrixmode/viewport setup, the Earth is drawn; if I use the sphere vertices/elements generation through VBO, I'm able to render just a sector of the sphere.
And, for the very few things I think to have understand, this sounds very strange.
So far as I can read, the Fiddler's sphere code is ok.

This is what I get:
The strange sphere
I really appreciate your help :-)

VboAndShaders.zip50 KB
the Fiddler's picture

I'm not at my PC now, so I can't test this, but maybe have you tried changing the limits of the two for-loops, i.e. 2 * Math.PI instead of Math.PI or something similar? I wrote the code from memory and it's quite possible I've messed up the limits.

Celeron's picture

Yeah... something changes if I change phi limit according to:
double phi = (y / (rings - 1)) * 2 * Math.PI;

...but still the sphere isn't complete. It misses the south sector, even if is a smaller part. Here you can see:

This is the image link for a larger view: http://img133.imageshack.us/img133/112/vboandshaders2.jpg
More: the clouds and the gloss map textures seem not to be still visible... one issue at the time :-))

I really appreciate your help.

Edit: forgot to mention that the sphere on this last image uses: radius:1.0, height:1.0, segments:256, rings:256

2nd Edit: maybe something is clarifying.
The vertices data array in your code is declared in this way:
var data = new VertexP3N3T2[rings * segments];

The element array is instead declared in this way:
var data = new ushort[segments * rings * 6];

Trying to change the vertices declaration in:
var data = new VertexP3N3T2[rings * segments * 6];
The sphere is now completely drawn, even if has still some errors, but I think that are related to the sphere setup (expecially rings and segments).

What is the best sphere setup about number of rings and segments?
And what do you think about the invisibility of clouds and gloss map?

the Fiddler's picture

Two suggestions:

  1. Add the following code to verify that the indices are correct:
                // Verify that we don't access any vertices out of bounds:
                foreach (int index in data)
                    if (index >= segments * rings)
                        throw new IndexOutOfRangeException();
  2. Try with fewer segments/rings.

I just tested here and the code seems to work fine (I'm using it for a skydome/skysphere). While I can't find any difference with the code in my previous post, I'm attaching my version for good measure.

The number of segments/rings is a tradeoff between quality and speed. Something like 30/30 should work fine for most usages (I am using just 12/5 for skydome and you can't really notice it).

skysphere.cs2.72 KB
Celeron's picture

Point 1:
well, seems that I'm loosing something - I'm so optimist :-).. My data array is of type:

            /// <summary>
            /// Vertex Structure for vec3 position, vec3 normals, vec2 textcoord
            /// </summary>
            [StructLayout(LayoutKind.Sequential, Pack = 1)]
            public struct VertexT2N3P3
                public Vector2 TexCoord;
                public Vector3 Normal;
                public Vector3 Position;
                public VertexT2N3P3(Vector2 texCoord, Vector3 normal, Vector3 position)
                    this.TexCoord = texCoord;
                    this.Normal = normal;
                    this.Position = position;

The question is: how I can test an int value while cycling data array of this type?

Point 2.:
The following link is what now I'm drawing (segments:12, rings:5):

Playing with LookAt and Rotate I've "discovered" - this really makes me smile :-) - the "lost sector".
Really don't know why. What to check?

Now I know how a child feels reading for the very first time :-)