Question

I'm developing a game for Android using libGDX. I implemented "spotlight effect" for highlighting some scene elements in tutorial levels. I did use Pixmap class for implementing this. 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;
    }

Fast explanation - I'm creating a Pixmap filling it with color(0,0,0,0.7f). After this I'm drawing transparent circle using Pixmap.fillCircle() method. And then I'm creating new Texture using this Pixmap. I've tested this code using following devices: HTC One V(480*800), Sony XPeria Neo 15i(480*854), HTC Desire S(480*800) and it works good;

enter image description here

But today I'm found that there are problems on HTC One X(1280*720) and Gamsung Nexus(1280*720) - I'm seeing black screen only.

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

Was it helpful?

Solution

The problematic phones are all fairly large screens. Are you running out of texture memory or something like that? (Assuming you are drawing at full resolution.) You might try rendering to a smaller viewport to see if that fixes the issue.

Now that I know this guess was right, I'm curious if there was any evidence in the app's (or Android's?) logs or in the OpenGL error state that points to this problem now that you know what the cause was.

OTHER TIPS

I'm not sure but i've been having problems with Pixmap filling alpha on my application too. I found that the fillCircle in pixmap just didnt set the alpha correctly. When I looked into it a bit i found that a better approach was to use a FrameBuffer.

I found the details in the following libgdx SpriteBatch render to texture

Some of my code which i've been using 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 give the idea what i've been playing with but it seems to work well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top