Android LibGDX Pixmap issue

I am developing an android game using libGDX. I implemented a "spotlight effect" to highlight some of the scene elements in the tutorial levels. I used the Pixmap class to implement it. So I did something like this:

public class ComplexSpotlight implements MoveObserver{

// somewhere in class

    public void update(){
        black.setColor(0, 0, 0, 0.7f);
        black.fill();

        black.setColor(0, 0, 0, 0);

        for(Map.Entry<MoveObservable, Vector2> entry : currentObservablePositions.entrySet()){
            Vector2 position = entry.getValue();

            int x = (int)(Gdx.graphics.getWidth()/2+position.x);
            int y = (int)(Gdx.graphics.getHeight()*1.5f-position.y);

            int radius = 50;

            black.fillCircle(x, y, radius);
            System.out.println("at "+x+" "+y);
        }

        overlay.dispose();
        overlay = new Texture(black);
    }

    public Texture getOverlayTexture(){
        return overlay;
    }

      

Quick explanation. I am creating a Pixmap by filling it with color (0,0,0,0.7f). After that, I draw a transparent circle using the Pixmap.fillCircle () method. And then I create a new texture using this Pixmap. I tested this code using the following devices: HTC One V (480 * 800), Sony XPeria Neo 15i (480 * 854), HTC Desire S (480 * 800) and it works well;

enter image description here

But today I found that there are problems with HTC One X (1280 * 720) and Gamsung Nexus (1280 * 720) - I only see a black screen.

So it would be nice if someone could give me some explanation on this issue. Links, thoughts - anything can be helpful. Thanks in advance!

+3


source to share


2 answers


Problematic phones are pretty big screens. Are you running out of texture memory or something? (Assuming you are drawing at full resolution.) You can try rendering in a smaller viewport to see if that fixes the problem.



Now that I know this assumption was correct, I am curious if there is any evidence in the application logs (or Android?) Or in the OpenGL error state that indicate this problem now that you know what is the cause.

+1


source


I'm not sure, but I had problems populating the Pixmap alpha page in my application. I found that the fillCircle in the pixmap just didn't set the alpha correctly. When I looked into it for a bit, I realized it was better to use FrameBuffer.

I found the details in the following libgdx SpriteBatch Script for Texture

Some of my code that I have used is



public class SplashScreen extends GameScreen {

SpriteBatch batch;
BitmapFont font;

FrameBuffer frmBuff;
TextureRegion frm;
OrthographicCamera frmCam;

int frmSizeX = 256;
int frmSizeY = 256;

public SplashScreen(ReactorApp game) {
    super(game);
    setClearColor(new Color(1,1,1,1));
}

@Override
public void show() {
    // TODO Auto-generated method stub
    super.show();
    batch = new SpriteBatch();
    font = new BitmapFont();

    frmBuff = new FrameBuffer(Format.RGBA8888, frmSizeX, frmSizeY, false);
    frm = new TextureRegion(frmBuff.getColorBufferTexture());
    frmCam= new OrthographicCamera(frmSizeX, frmSizeY);
    frmCam.translate(frmSizeX/2, frmSizeY/2);
}

@Override
public void dispose() {
    // TODO Auto-generated method stub
    super.dispose();
}


public void drawToTexture(){
    frmCam.update();
    ShapeRenderer shape = new ShapeRenderer();
    shape.setProjectionMatrix(frmCam.combined);
    frmBuff.begin();

    Gdx.gl.glClearColor(0, 0, 0, 0);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
    shape.begin(ShapeType.FilledRectangle);
    shape.setColor(Color.BLACK);
    shape.filledRect(0,0,frmSizeX/2, frmSizeY/2);
    shape.end();

    shape.begin(ShapeType.FilledCircle);
    shape.setColor(Color.GREEN);
    shape.filledCircle(MathUtils.random(frmSizeX), MathUtils.random(frmSizeY), 20);
    shape.end();

    frmBuff.end();
}

int pos = 0;

@Override
public void render(float delta) {
    super.render(delta);
    drawToTexture();

    batch.setProjectionMatrix(cam.combined);


    batch.begin();
    batch.draw(frm, pos++, 30,frmSizeX,frmSizeY);
    if(pos>Gdx.graphics.getWidth()-frmSizeX)pos=0;
    font.setColor(Color.RED);
    StringBuilder message = new StringBuilder();
    message.append("Time :"+(int)(delta*1000)+"\n");
    font.drawMultiLine(batch, message.toString(), 10, Gdx.graphics.getHeight());
    batch.end();
}

}

      

this gives an idea of ​​what I was playing with, but seems to work well.

+1


source







All Articles