0
\$\begingroup\$

Now my Image isn't loading to the screen. I tried to be decorative with the code but since it isn't working I made it just like the video I'm whatching. I don't get any exceptions, but the image doesn't appear still.

My main desktop launcher class:

public class DesktopLauncher {
public static void main (String[] arg) {
    LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
    config.title = " Game Tests ";
    config.width = 500;
    config.height = 400;
    config.useGL30 = true;

    new LwjglApplication(new MyGdxGame(), config);
}
}  

My Game class:

public class MyGdxGame extends Game {

@SuppressWarnings("unused")
private TestScreenA GameScreen;

@Override
public void create () {
    //loads image
    AssetLoaderTest.load();
    GameScreen = new TestScreenA(this);


}

@Override
public void render () {



}
}

My Screen class:

public class TestScreenA implements Screen{

@SuppressWarnings("unused")
private MyGdxGame game;


//Camera 
private OrthographicCamera camera;

//images etc.
private SpriteBatch batch;

public TestScreenA(MyGdxGame game) {
    this.game = game;

    //Camera
    camera = new OrthographicCamera();
    camera.setToOrtho(false, 1920, 1080);

    batch = new SpriteBatch();

}


public void render(float delta) {
    //clears the screen with white
    Gdx.gl.glClearColor(1F, 1F, 1F, 1F);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    camera.update();

    //loads images scaled to camera
    batch.setProjectionMatrix(camera.combined);

    batch.begin();
        batch.draw(AssetLoaderTest.s, 0, 0);
    batch.end();

}


public void resize(int width, int height) {

}


public void show() {

}


public void hide() {

}


public void pause() {

}


public void resume() {

}


public void dispose() {

}

}

My AssetLoaderTest class:

public class AssetLoaderTest {

//Images etc.

public static Texture t;
public static Sprite s;

static void load() {

    t = new Texture(Gdx.files.internal("testImgs/badlogic.jpg"));
    //Automatically scales texture based off of window size
    t.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    //a sprite is pretty much the body and the texture is the texture or image of it
    s = new Sprite(t);
    s.flip(false, true);

}

}
\$\endgroup\$
1
\$\begingroup\$

Your MyGdxGame class' render method doesn't do anything. It should call GameScreen.render() to render.

Some comments about style:

  • Variable names should be lower-case on their first letter (gameScreen not GameScreen)
  • Please fix your formatting next time
  • Suppressing warnings should be done carefully; they're usually indicative of a problem that may bite you.

If you use version control, which you should even if working alone, you can always commit frequently and roll back your changes when you break something -- if you used the LibGDX app maker JAR to make your project, you should have a good, working starting point.

\$\endgroup\$
0
\$\begingroup\$

Not sure, but something really seems odd to me in your code.

In your launcher you have :

config.useGL30 = true;

And then you are doing :

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

But since you want to use GL30, you should probably do :

Gdx.gl30.glClearColor(1F, 1F, 1F, 1F);
Gdx.gl30.glClear(GL30.GL_COLOR_BUFFER_BIT);

As Gdx.gl is a shortcut to GDX.gl20.

\$\endgroup\$
  • \$\begingroup\$ It forces me to use GL20 or higher. I'm not sure why. \$\endgroup\$ – GDX N00B Jul 3 '14 at 20:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.