Exception in thread "LWJGL Application" youtube tut with link to video - java

i been following this tutorial : http://www.youtube.com/watch?v=LSblkR4K1LU and
i have a problem everytime i run this background image here is what comes up in the console
if someone can help me out... i dont know if im missing something or what it is. i thought it was the image that couldnt be found but i tried to fix it by making the file again and making sure i typed everything correctly.
error i get:
`Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Texture width and height must be powers of two: 1920x1080
at com.badlogic.gdx.graphics.GLTexture.uploadImageData(GLTexture.java:241)
at com.badlogic.gdx.graphics.Texture.load(Texture.java:145)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:133)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:112)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:104)
at com.universal.game.Assets.load(Assets.java:15)
at com.universal.game.MyGame.create(MyGame.java:11)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:136)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:114)`
GameScreen.java
package com.universal.game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public class GameScreen implements Screen {
MyGame game;
OrthographicCamera camera;
SpriteBatch batch;
public GameScreen(MyGame game){
this.game = game;
camera = new OrthographicCamera();
camera.setToOrtho(false,1920,1080);
batch = new SpriteBatch();
}
#Override
public void render(float delta) {
Gdx.gl.glClearColor(1F, 1F, 1F, 1F);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
camera.update();
}
#Override
public void show() {
}
#Override
public void pause() {
}
#Override
public void resume() {
}
#Override
public void dispose() {
}
#Override
public void resize(int width, int height) {
}
#Override
public void hide() {
}
}
MyGame.java
package com.universal.game;
import com.badlogic.gdx.Game;
public class MyGame extends Game{
public GameScreen game_screen;
#Override
public void create() {
Assets.load();
game_screen = new GameScreen(this);
setScreen(game_screen);
}
}
Assets.java
package com.universal.game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.Sprite;
public class Assets {
public static Texture texture_back;
public static Sprite sprite_back;
public static void load(){
texture_back = new Texture(Gdx.files.internal("menu/back.png"));
texture_back.setFilter(TextureFilter.Linear, TextureFilter.Linear);
sprite_back = new Sprite(texture_back);
sprite_back.flip(false, true);
}
}
Main.java
package com.universal.game;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
public class Main {
public static void main(String[] args) {
LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
cfg.title = "Z-Angel";
cfg.useGL20 = true;
cfg.width = 480;
cfg.height = 320;
new LwjglApplication(new MyGame(), cfg);
}
}

"Texture width and height must be powers of two"
In GameScreen.java,
camera.setToOrtho(false,1920,1080);
The 1080 and 1920 is not a legitimate value. You must use one of these values: 1024, 2048, 4096

Related

Java libGdx: FreeTypeFontGenerator is not working (Black screen)

I added in a custom font Aller_light.ttf and when I try to run the program with the font drawn with no errors the screen is black, so I'm not sure if its rendering somewhere else off screen or its not rendering at all.
If you could give your 2 cents that would be of great value to me.
EDIT
Now it's saying i have a nullPointerExeption
Exception in thread "LWJGL Application" java.lang.NullPointerException
at com.mygdx.finis.states.MenuState.draw(MenuState.java:43)
at com.mygdx.finis.states.GameStateManager.draw(GameStateManager.java:31)
at com.mygdx.finis.Main.render(Main.java:36)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:215)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:120)
This is what should be happening:
MenuState Class
package com.mygdx.finis.states;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL30;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
import com.mygdx.finis.Assets;
import com.mygdx.finis.Main;
public class MenuState extends GameState{
private SpriteBatch sb;
private BitmapFont font;
private int currentItem;
private String[] menuItems;
protected MenuState(GameStateManager gsm) {
super(gsm);
}
public void init() {
sb = new SpriteBatch();
FreeTypeFontGenerator gen = new FreeTypeFontGenerator(
Gdx.files.internal(null));
font = gen.generateFont(20);
menuItems = new String[]{
"Play"
};
}
public void update(float dt) {
handleInput();
}
public void draw() {
sb.setProjectionMatrix(Main.cam.combined);//*** This is where the null pointer starts *********
sb.begin();
font.draw(sb, "Quack", Main.WIDTH / 2, Main.HEIGHT / 2);//*** This does not work *******************
sb.end();
}
public void handleInput() {
}
public void dispose() {
}
}
Main Class
package com.mygdx.finis;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL30;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.mygdx.finis.states.GameStateManager;
public class Main implements ApplicationListener{
public static int WIDTH;
public static int HEIGHT;
public static OrthographicCamera cam;
private GameStateManager gsm;
public void create(){
WIDTH = Gdx.graphics.getWidth();
HEIGHT = Gdx.graphics.getHeight();
cam = new OrthographicCamera(WIDTH, HEIGHT);
cam.translate(WIDTH / 2, HEIGHT / 2);
cam.update();
gsm = new GameStateManager();
}
public void render(){
Gdx.gl.glClearColor(0.1f, 0.1f, 0.1f, 1);
Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT);
gsm.update(Gdx.graphics.getDeltaTime());
gsm.draw();//****** THIS IS WHERE THE ISSUE ENDS ******
}
public void resize(int width, int height){}
public void pause(){}
public void resume(){}
public void dispose(){}
}
It seems most likely that your SpriteBatch sb is null. Are you absolutely sure init() is being called?
The only other alternative is that Main.cam is null.
It has to be one of those.
Incidentally, this looks odd to me...
Gdx.files.internal(null));
Why are you doing that?

Error with libGdx Screens

I have a problems when I try to compiled this is supuse that will a game.
Exception in thread "LWJGL Application" java.lang.NullPointerException at com.waflesgames.spaceinvader.Screens.PlayScreen.render(PlayScreen.java:35)
at com.badlogic.gdx.Game.render(Game.java:46)
at com.waflesgames.spaceinvader.SpaceInvader.render(SpaceInvader.java:24)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:215)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:120)
This is the PlayScreen.java
package com.waflesgames.spaceinvader.Screens;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
import com.waflesgames.spaceinvader.SpaceInvader;
import javax.xml.soap.Text;
/**
* Created by Diego on 03/10/2015.
*/
public class PlayScreen implements Screen{
public SpaceInvader game;
Texture texture;
private OrthographicCamera gamecam;
private Viewport gamePort;
public PlayScreen(SpaceInvader Game){
this.game = game;
texture = new Texture("badlogic.jpg");
gamecam = new OrthographicCamera();
gamePort = new ScreenViewport(gamecam);
}
#Override
public void show() {
}
#Override
public void render(float delta) {
game.batch.setProjectionMatrix(gamecam.combined);
game.batch.begin();
game.batch.draw(texture,0,0);
game.batch.end();
}
#Override
public void resize(int width, int height) {
gamePort.update(width,height);
}
#Override
public void pause() {
}
#Override
public void resume() {
}
#Override
public void hide() {
}
#Override
public void dispose() {
}
}
and this is the SpaceInvader.java
package com.waflesgames.spaceinvader;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.waflesgames.spaceinvader.Screens.PlayScreen;
public class SpaceInvader extends Game {
public SpriteBatch batch;
#Override
public void create () {
batch = new SpriteBatch();
setScreen(new PlayScreen(this));
}
#Override
public void render () {
super.render();
}
}
you have error here:
public PlayScreen(SpaceInvader Game){
this.game = game;
...
it should be game instead of Game - you are get SpaceInvader instance to Game variable so below you are assigning the this.game to itself what causes nullpointer exception in render method (game is null so you cannot acces its batch)

LibGDX - what do the console errors mean and how can I fix this console error?

Heres the console error I'm getting:
Exception in thread "LWJGL Application" java.lang.NullPointerException
at com.dakotapederson.slingshotsteve.SlingshotSteve.render(SlingshotSteve.java:30)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:206)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:114)
And here is the code:
package com.dakotapederson.slingshotsteve;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
public class SlingshotSteve implements ApplicationListener {
// Creates our 2D images
private SpriteBatch batch;
private TextureRegion backgroundTexture;
private Texture texture;
#Override
public void create() {
Texture texture = new Texture(Gdx.files.internal("background.jpg"));
backgroundTexture = new TextureRegion(texture, 20, 20, 50, 50);
}
#Override
public void render() {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(backgroundTexture, 0, 0);
batch.end();
}
#Override
public void resize(int width, int height) {
}
#Override
public void pause() {
}
#Override
public void resume() {
}
#Override
public void dispose() {
batch.dispose();
texture.dispose();
}
}
What do the console errors exactly mean? Because if theirs an error in the code I need to know what it is. Also, since I'm new at this, please describe the error in the code with as much clarity as possible.
You should read basic tutorial: https://github.com/libgdx/libgdx/wiki/A-simple-game
You are missing this line in create():
batch = new SpriteBatch();

Libgdx Desktop Launcher blank

Just starting Libgdx and java game development. Got a little bit of code to try and write a sprite sheet moving animation person, just started it so not finished by when i try an run it the single sprite drawing is not running, nothing is the desktop appliction is just black.
Desktop Launcher:
package com.mkgame.game1.desktop;
import com.MKgames.OptionScreen;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.mkgame.game1.Game1;
public class DesktopLauncher extends Game1{
public static void main (String[] arg) {
LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
cfg.title = "Game1";
cfg.width = 960;
cfg.height = 540;
new LwjglApplication(new Game1 (), cfg);
}
}
Main java class 'Game1':
package com.mkgame.game1;
import com.MKgames.FarmerAsset;
import com.MKgames.OptionScreen;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public class Game1 extends ApplicationAdapter {
public OptionScreen game_screen;
public void create() {
FarmerAsset.load();
}
}
Game screen:
package com.MKgames;
import sun.java2d.loops.DrawGlyphListAA.General;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public class OptionScreen implements Screen{
GameMain game;
OrthographicCamera camera;
SpriteBatch batch;
int farmerX;
public OptionScreen(GameMain game){
this.game = game;
camera = new OrthographicCamera();
camera.setToOrtho(true, 1920, 1080);
batch = new SpriteBatch();
farmerX = 960-85;
}
#Override
public void render(float delta) {
Gdx.gl.glClearColor(0.95F, 0.95F, 0.95F, 0.95F);
camera.update();
generalUpdate();
batch.setProjectionMatrix(camera.combined);
batch.begin();
batch.draw(FarmerAsset.farmer1, farmerX, 200);
batch.end();
}
public void generalUpdate() {
if(Gdx.input.isKeyPressed(Keys.A)||Gdx.input.isKeyPressed(Keys.LEFT)){
farmerX -= 5;
}
else if(Gdx.input.isKeyPressed(Keys.D)||Gdx.input.isKeyPressed(Keys.RIGHT)){
farmerX += 5;
}
}
#Override
public void show() {
}
#Override
public void pause() {
}
#Override
public void resume() {
}
#Override
public void dispose() {
}
#Override
public void resize(int width, int height) {
}
#Override
public void hide() {
}
}
Change
public class Game1 extends ApplicationAdapter {
to
public class Game1 extends Game {
Create an instance of OptionScreen in Game:
public OptionScreen game_screen;
public void create() {
FarmerAsset.load();
game_screen = new OptionScreen(this);
setScreen(game_screen);
}
And it should be good to go.

importing an object with extension md2 in libgdx

i'm new in java game programing i want to import an md2 object i used this tuto http://code.google.com/p/libgdx-users/wiki/MD2_Keyframe_Animation
but the probleme is that i cant instanciate an instance from class KeyframedModelViewer this is my code
package com.ELISA.ELISAgame.Screens;
import com.ELISA.ELISAgame.ELISA;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.assets.loaders.ModelLoader;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.PerspectiveCamera;
import com.badlogic.gdx.graphics.g3d.Material;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.graphics.g3d.ModelInstance;
/*import com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute;*/
import com.badlogic.gdx.graphics.g3d.loader.ObjLoader;
import com.badlogic.gdx.graphics.g3d.utils.CameraInputController;
public class Game implements ApplicationListener, Screen {
ELISA game;
PerspectiveCamera cam;
CameraInputController camController;
ModelBatch modelBatch;
ModelLoader loader;
AssetManager assets;
Model model;
Material material;
ModelInstance instance;
public Game(ELISA game) {
this.game = game;
}
public void create() {
}
#Override
public void render(float delta) {
camController.update();
Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(),
Gdx.graphics.getHeight());
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
modelBatch.begin(cam);
modelBatch.render(instance);
modelBatch.end();
}
#Override
public void resize(int width, int height) {
}
#Override
public void show() {
//new JoglApplication(new KeyframedModelViewer("data/antigene.md2", "data/antigene.png"), "KeframedModel Viewer", 800, 480, false);
modelBatch = new ModelBatch();
cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(),Gdx.graphics.getHeight());
cam.position.set(0f, 6f, 11.5f);
cam.lookAt(0, 0, 0);
cam.near = 0.8f;
cam.far = 300f;
cam.update();
loader = new ObjLoader();
//model = loader.loadModel(Gdx.files.internal("data/labo.obj"));
instance = new ModelInstance(model);
Material material = new Material("material", new TextureAttribute(texture, 0, "s_tex"));
model.setMaterial(material);
camController = new CameraInputController(cam);
Gdx.input.setInputProcessor(camController);
}
#Override
public void hide() {
}
#Override
public void pause() {
}
#Override
public void resume() {
}
#Override
public void dispose() {
modelBatch.dispose();
model.dispose();
}
}
That wiki, "libgdx-users" is highly outdated. MD2 is not supported right now, this is how 3d animations are handled now:
https://github.com/libgdx/libgdx/wiki/3D-animations-and-skinning
"When using fbx-conv https://github.com/libgdx/fbx-conv to convert your model from FBX to G3DB/G3DJ, animations are automatically converted along with it. Just like FBX, G3DB/G3DJ files can contain multiple animations in a single file along with the other model data. Animations applied to nodes which are not present in the source FBX file, will not be converted. So make sure to select all the nodes and animations when exporting to FBX."

Categories

Resources