HowTo: Create a texture coordinates buffer (floatbuffer) for a sphere?

Hi Artists,



I will make it quick :wink: :

How do I create a texture coordinates buffer for a sphere?



I already know how to do this with a Quad:


        FloatBuffer tex1 = BufferUtils.createVector2Buffer(4);
        for (int x = 0; x < 4; x++)
            tex1.put(1.0f).put(0.0f);
        q.setTextureCoords(new TexCoords(tex1), 1);
       
        FloatBuffer tex2 = BufferUtils.createVector2Buffer(4);
        for (int x = 0; x < 4; x++)
            tex2.put(0.0f).put(1.0f);
        q.setTextureCoords(new TexCoords(tex2), 2);



I need this for the parallax shader to bumpmap a sphere. Like in the TestFragmentProgramState.class but now with a sphere. My search in the forum and in the www was not that successfuly.

Thank you for your time and help!

If you use jME's primitives, they generate their own texture coordinates. Take a look at the Sphere class.

And how do I use it for the parallax shader?



Sorry I am very new to jME, maybe I'm looking in the wrong tree (with wrong terms) to do what I need to do with jME.



In other words:



How do I bump map a sphere using the parallax shader seen in the TestFragmentProgramState.class?


The parallax shader creates a quad right? So all you need to do is to replace "new Quad(…)" with "new Sphere(…)" and you have the parallax shader on a sphere.

I already did that, with no success … I need more input please!  :smiley:



I thought it's because of the float buffer and the setTextureCoord() method which doesn't work with a sphere that I did not use while testing it with a sphere.


  1. So is it right than, that I don't need to create a float buffer for the sphere cause this class already has one?
  2. If so, how do I can access this buffer?
  3. Do I need to change the texture coordinates of the sphere like I have to do it with the quad (see first post) to get the parallax shader working?
  4. And if so, how do I change them?



    I tested my 3 textures (color, normal map, specular map) with the Fragment test case on a quad and they all worked very well, but when I apply this shader to a sphere they are only be overlayed on the sphere without bump mapping.






Here is what I've learned so far:



1+2. Spatials do have their own texture coordinate buffer. You can access it with getTextureCoords() and setTextureCoords().

3. You don't have to!



If you want to apply a parallax shader, or any other, to a spatial (i.e. a sphere), use the GLSLShaderObjectsState instead of trying to do it like in the TestFragmentProgramState.java described. Especially if you don't have any idea what's going on in the used shader files .vp and .fp for this example. (I think they do work only for quads!?)



How to use a GLSLShaderObjectsState, for a normalmap or parallax shader, is well described in the jmetest/renderer/loader/TestNormalmap.java



I hope this will help other beginners too!  :wink: