有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java将Pixmap的一部分上传到GPU

我想上传一部分Pixmap(它的指定矩形)到GPU中的纹理(在指定位置)

我想实现的是

void updateTextureFromPixmap(sourcePixmap,sourceRectangle,destTexture, destRectangle) {  
    destTexture.fill(copyfrom(sourcePixmap),copyarea(SourceRectangle),newArea(destRectangle));
}

我应该使用glTexSubImage2D吗?我还在学习opengl/


共 (2) 个答案

  1. # 1 楼答案

    public class PixmapHelper {
    
        static Pixmap fullGraphics ;
        static Pixmap miniObject;
    
        public static void  Initialize()
        {
    
             fullGraphics =AssetLoader.GetPixmap(Settings.TEX_MAP_OBJECTS);
    
    
    
            miniObject=new Pixmap(8,8, Pixmap.Format.RGBA8888);
        }
    
        static void Draw(TextureRegion textureRegion,Texture dstTexture,int dstX,int dstY)
        {
    
           miniObject.drawPixmap(fullGraphics, 0,0,   textureRegion.getRegionX(),textureRegion.getRegionY(),
    textureRegion.getRegionWidth(),textureRegion.getRegionHeight());
    
    
             dstTexture.draw(miniObject,dstX,dstY);
    
    
        }
    }
    
  2. # 2 楼答案

    可以使用Texture#draw将pixmap绘制到纹理中。像这样:

    Pixmap imgA = new Pixmap(Gdx.files.internal("mypng"));
    Texture texture = new Texture(200, 200, Pixmap.Format.RGBA8888); 
    texture.draw(imgA, 0, 0);