
[SL Multitexturing] - Only one texture with gluSphere
Posted Sunday, 22 March, 2009 - 19:11 by Celeron inHi 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:
http://img136.imageshack.us/img136/8042/rmonkey.jpg
The seguent poor result, instead, is produced by my code:
http://img183.imageshack.us/img183/5339/myearthmultitex.jpg
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 :-)
| Attachment | Size |
|---|---|
| SphereMultitexturing.zip | 48.85 KB |


Comments
Re: [SL Multitexturing] - Only one texture with gluSphere
The textures could very well be the problem. Most hardware supports only 409x4096 - anything more and it won't work.
I'd also advise against using gluSphere. It's too inflexible and creating a sphere manually is easy:
Re: [SL Multitexturing] - Only one texture with gluSphere
Thank you very much for the reply.
As soon as possible I'll apply the code posted and will report here the feedback.
Maybe RenderMonkey automatically scales the textures before applying them?
Re: [SL Multitexturing] - Only one texture with gluSphere
Yeah, it probably scales and compresses textures when you add them to the project.
Re: [SL Multitexturing] - Only one texture with gluSphere
Well, after a couple of weeks... here I am :-)
I've appreciated your code, Fiddler, so I've translated the vb example project in C# to use it as best as possible.
Reading this forum and the pletora of OpenGL code found on the web, I've tried to use both VBO and SL. The result is the C# project attached to this post and - most of all - a big, big video driver crash when I run it :-((
Obviously my poor knowledge is The Problem, but I think that is an obliged path.
Well, the crash occurs when I try to draw the VBO using this method:
I'm quite sure that something is missing here. But I didn't understand what.
I've scaled down the textures to 4096x4096 and I've updated them here: http://www.box.net/shared/ntb7akfir5
To use them in the project, simply put in the folder "textures" under the project root.
Thanks in advance.
Re: [SL Multitexturing] - Only one texture with gluSphere
Which is the crashing line?
As far as I can tell, the issue lies in the element array. Since you are using an element array, make sure to:
GL.BufferDataat the place where you create the VBO), andOnce you do that, you can draw the VBO like this:
The last parameter is now an offset from the beginning of the element array - use
IntPtr.Zeroto draw the elements from the beginning. Numelements should be equal or less than the number of items in the element array (not the vertex array!), i.e.indices.Length.This way you don't need to pin anything either. Everything is uploaded to GL memory via the
BufferDatacalls - you simply need to bind the buffers and issue the drawing command (in other words, you don't need to keep theushort[]andVertexP3N3T2[]arrays around).Re: [SL Multitexturing] - Only one texture with gluSphere
Thank you very much :-)
Now the crash is fixed, even if the result is not still impressive as you can see here :-))
http://img231.imageshack.us/img231/4227/vbosl.jpg
The method I use to load the buffers is:
Really don't know what's happening now... Do you have any idea about what to check out?
Thanks for the patience.
Re: [SL Multitexturing] - Only one texture with gluSphere
You're specifying InterleavedArrayFormat.T2fN3fV3f, but your vertex struct is VertexP3N3T2. If you use GL.InterleaveArray(), TexCoord must be the first 2 floats, Normal the following and Position the last 3 floats. If you want to keep the struct as-is, check http://www.opentk.com/node/278
Re: [SL Multitexturing] - Only one texture with gluSphere
Aaarrghh :-)) .. thanks, Inertia.. yeah.. now works (I think). I really must check the viewport, but "something" (not too close to a sphere after all) is painted.
I've changed the "VertexP3N3T2" structure in this way, according to the Interleaved Array Format that I am using:
This is what I've got: http://img155.imageshack.us/img155/4452/vbsl3.jpg
Well, I think that now I have to work on the "Reshape" method; this is what I'm using at the moment:
What I have to change to frame completly the "Earth"? When I tried the "single texture experiment" I easily applied this "SetupViewport" method:
... but now it doesn't seem work any more...
Re: [SL Multitexturing] - Only one texture with gluSphere
Double aspect = w / h; should be Double aspect = w / (double)h; otherwise the division is done with integers and the result is cast to double.
Glu.Perspective(45.0, aspect, 1.0, 90.0); could be a troublemaker aswell, try set the nearplane to 0.1 if the front of the sphere appears clipped.
GL.Viewport(0, 0, _viewportW, _viewportW) contains a typo
I don't quite get what you're doing with GL.Ortho and then multiplying Glu.LookAt with it. GL.Ortho should only be used if you want a orthogonal projection matrix (for 2D) but never with the modelview matrix. If this is some cool hack I'd love to hear about it :)
Re: [SL Multitexturing] - Only one texture with gluSphere
Yeah.. a big cool hack :-)) Really, I'm trying to understand how to play with viewport and projection; it's so hard to study only few hours during the week-end, happily with my two sons.. have mercy on a poor father :-))
I'll check these concepts as soon as possible and I'll report my progress.
Thank you very much for your attention and specially for your patience ;-)