开发者

How to texture an image onto a sphere without distortion

I have drawn a sphere and I am able to rotate it using java and opengl libraries for an android application. This part works perfectly. Now I am trying to texture a globe image onto the sphere. The image covers the entire sphere but then the continents are compressed and appear as a single line. What do I have to do to get the image properly textured on to my sphere?

For implementing the texture I am using the following code

gl.glEnable(GL10.GL_TEXTURE_2D);
texturesBuffer = IntBuffer.allocate(1);

gl.glGenTextures(1, texturesBuffer);

Bitmap texture = SphereTexture.getTexture(mContext,R.drawable.earth);

gl.glBindTexture(GL10.GL_TEXTURE_2D, texturesBuffer.get(0));
gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_NEAREST);
gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST);
gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE);
gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE);
GLUtils.texImage2D(GL10.GL_开发者_如何学PythonTEXTURE_2D, 0, texture, 0);

texture.recycle();

public static Bitmap getTexture(Context context, int resourceId) {

    Bitmap bitmap = null;
    try {
        bitmap = BitmapFactory.decodeResource(context.getResources(), resourceId);
        return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),  bitmap.getHeight(), yFlipMatrix, false);
    }
    finally {
        if (bitmap != null) {
            bitmap.recycle();
        }
    }
 }


You can do that by XOR the color on both the sides of the line with the color on the otherside taking pixel by pixel.

Nageswara Rao V

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜