Textures aren't rendering properly

Anything libgdx related goes here!

Textures aren't rendering properly

Postby samxcr » Mon May 13, 2019 1:04 am

I implemented a basic lighting system (https://stackoverflow.com/questions/45595319/transparent-circle-black-around/45598754#45598754) to my game and now some of my textures won't render. Here's my main render method:
Code: Select all
@Override
public void render(float delta) {

update(delta);

frameBuffer.begin();

Gdx.gl.glClearColor(CLEAR, CLEAR, CLEAR, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

batch.setProjectionMatrix(camera.combined);
batch.setBlendFunction(GL20.GL_ONE, GL20.GL_ONE);
batch.begin();

// render lights
currentMap.lightsController.render(batch);

batch.end();

frameBuffer.end();

batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
batch.begin();

// render map and its entities (including player)
currentMap.render(camera, batch);

batch.end();

batch.setProjectionMatrix(batch.getProjectionMatrix().idt());
batch.setBlendFunction(GL20.GL_ZERO, GL20.GL_SRC_COLOR);
batch.begin();
batch.draw(frameBuffer.getColorBufferTexture(), -1, 1, 2, -2);
batch.end();
}

When I run the game, the light is rendered and the TiledMap from the currentMap object is rendered, however my other entities such as the player and buildings are not. The currentMap.render() method looks like this:
Code: Select all
tiledMapRenderer.setView(camera);
tiledMapRenderer.render();

for(Entity e : entities) {
    e.render(batch);
}

// render player LAST
player.render(batch);

I'm guessing it is something to do with the SpriteBatch being set up incorrectly as the player and entities use the batch and don't render while the TiledMap doesn't use it and does render.

To try and figure it out I created a basic Sprite and rendered it by calling batch.draw(sprite, 0, 0); just before my currentMap.render() line, but that is just rendered as a white rectangle.

What would be causing this?
Code: Select all
samxcr
 
Posts: 6
Joined: Mon May 13, 2019 1:02 am

Re: Textures aren't rendering properly

Postby shatterblast » Mon May 13, 2019 3:52 am

I am just taking a guess, but make sure they are all in the same SpriteBatch? Like... make sure that everything fits between batch.begin() and batch.end() while only having ONE of each? While it is okay to have more than one SpriteBatch, containing your stuff to just a single full stretch is important for troubleshooting. This is just something I do, but if I have different stretches of SpriteBatch objects, I give them different variable names. Otherwise, it gives an opportunity for something to be over-written and lost that you might have wanted when you begin() and end() multiple times with some single lonely SpriteBatch that wonders, "What the heck is going on?" In other words, your render() method should only contain batch.begin() and batch.end() once.
shatterblast
 
Posts: 414
Joined: Sun Jul 06, 2014 1:14 pm


Return to Libgdx

Who is online

Users browsing this forum: Google [Bot] and 1 guest