Paweł
Paweł

Reputation: 2234

Upload part of Pixmap into GPU

I would like to upload part of Pixmap (specified Rectangle of it) to Texture in GPU (at specified position).

What i would like to achieve is

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

Should i use glTexSubImage2D ? I'm still learning opengl ;/

Upvotes: 1

Views: 107

Answers (2)

Rinnion
Rinnion

Reputation: 99

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);


    }
}

Upvotes: 0

Daahrien
Daahrien

Reputation: 10320

You can use Texture#draw to get a pixmap into a Texture. Like this:

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

Upvotes: 1

Related Questions