安卓的OpenGL ES装载2质感的非电力 [英] Android Opengl-es loading a non-power of 2 texture

查看:212
本文介绍了安卓的OpenGL ES装载2质感的非电力的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,我已经多次在Android的播放,它使用OpenGL-ES。

I have an app that I've been repeatedly playing with in android, it uses opengl-es.

目前我从位图加载纹理像这样:

Currently I load textures from a bitmap like so:

//Load up and flip the texture - then dispose the temp
    Bitmap temp = BitmapFactory.decodeResource(Deflecticon.getContext().getResources(), resourceID);
    Bitmap bmp = Bitmap.createBitmap(temp, 0, 0, temp.getWidth(), temp.getHeight(), flip, true);
    temp.recycle();

    //Bind the texture in memory
    gl.glBindTexture(GL10.GL_TEXTURE_2D, id);

    //Set the parameters of the texture.
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);

    //On to the GPU
    GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bmp, 0);

最明显的问题是,我使用的材质必须是2的力量此刻我是pre-在Photoshop中编辑的纹理是2的幂,只是有空的边界。然而,这是一个有点乏味,我希望能够加载它们,因为它们..承认他们是不是2的电源并将其装入一个纹理是。

The obvious issue is that the texture I'm using has to be a power of 2. At the moment I'm pre-editing the textures in photoshop to be a power of 2 and simply have empty borders. However this is a little tedious and I want to be able to load them as they are .. recognise they aren't a power of 2 and load them into a texture that is.

我知道我可以缩放位图成为2大小的力量和简单的伸展纹理,但我不想舒展质感,在某些情况下,可能需要将多个纹理成一个地图集。

I know I could scale the bitmap to become a power of 2 size and simply stretch the texture but I do not wish to stretch the texture and in some cases may want to put several textures into one "atlas".

我知道我可以使用glTexSubImage2D()粘贴到纹理我想要的数据,我想的起源。这是伟大的!

I know I can use glTexSubImage2D() to paste into the texture the data I want at the origin I want. This is great!

不过,我不知道如何在Android中初始化的纹理,没有数据?

However I do not know how in Android to initialise a texture with no data?

在这个问题<一href="http://stackoverflow.com/questions/5073611/possible-to-glteximage2d-an-npot-image-onto-a-pow-2-texture-without-extra-allocat">$p$pviously问的建议是调用glTexImage2D(),没有数据,并再填充它。

In this question previously asked the suggestion was to call glTexImage2D() with no data and to then fill it.

然而,在Android的,当你调用GLUtils.texImage2D(GL10.GL_TEXTURE_2D,0,BMP,0);你不指定宽度/高度。它从位图我想读这个。

However in android when you call "GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bmp, 0);" you do not specify a width / height. It reads this from the bitmap I assume.

什么是做到这一点的最好方法是什么?我可以创建2个大小合适的功率只有空白,没有填充任何数据,并用它来初始化纹理,然后一个新的位图粘贴到使用子图像呢?或者我应该做一个新的位图莫名其妙地复制我想要的像素(不知道你是否可以很容易地做到这一点)到这个新的位图(离开边框),然后就用这个?

What is the best way to do this? Can I create a new bitmap of the right power of 2 size only blank and not filled with any data and use this to initialise the texture then paste into it using subImage? Or should I make a new bitmap somehow copy the pixels I want (not sure if you can do this easily) into this new bitmap (leaving borders) and then just use this?

编辑:澄清,我使用的OpenGL

clarified that I'm using opengl.

推荐答案

我想,如果你尝试创建具有2轴尺寸电源位图,然后添加你的位图它应该只是罚款。也许像

I think if you tried creating a bitmap with the power of 2 axis sizes and then add your bitmap it should work just fine. maybe something like

Bitmap.createBitmap(notPowerOf2Bitmap, offx, offy, xsize, ysize, bitmapFlag)

除此之外,我会说遭受过Photoshop的过程。你有多少图片了?

other than that, I would say suffer through the photoshop process. How many pictures you got?

这篇关于安卓的OpenGL ES装载2质感的非电力的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆