I am writing a program using LibGDX in Java and I want to update the screen every 10 frames with new pixels on the screen. I have tried using a pixelmaps but it does't seem to work. Here is my code:
package com.mhsjlw.heat;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public class Heat extends ApplicationAdapter {
SpriteBatch batch;
Texture img;
private OrthographicCamera camera;
FlirClient flir = new FlirClient("x.x.x.x.x", 2525);
int[] palette = FlirPalette.IRONBOW_PALETTE;
byte[] frame = new byte[4800];
@Override
public void create() {
flir.run();
camera = new OrthographicCamera();
camera.setToOrtho(false, 80, 60);
Pixmap pixmap = new Pixmap( 80, 60, Format.RGB888);
pixmap.drawPixel(1, 1);
}
@Override
public void render() {
camera.update();
Pixmap pixmap = new Pixmap( 80, 60, Format.RGB888);
while(true) {
frame = flir.getFrame();
for (int row=0; row<60; row++) {
for (int col=0; col<0; col++) {
int ndx = row * 80 + col;
pixmap.drawPixel(col, row, FlirPalette.getRgb888(frame[ndx], palette));
}
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
Whenever I run this it just returns a black screen. Thanks in advance.
There is a problem in your code: You have a
while(true)
inrender
but neverbreak
.That is not the only problem, though. You are drawing a pixels to the
Pixmap
, but you are never rendering thePixmap
itself. You need to create aTexture
from yourPixmap
:I have commented things I've changed (except for the
private
modifiers at the beginning of the class) but left a few problematic parts of your code intact.You should really add a condition for your
while
loop, it's currently infinite. Also, you should really not create a newPixmap
every time the code is run, this is not only bad design but also wasteful.If I missed anything I'll update my answer.