LibGDX基本阶段绘制错误

时间:2015-10-22 14:26:09

标签: java libgdx

我正在尝试创建游戏,但我的代码一直给我错误:

Exception in thread "LWJGL Application" java.lang.IllegalArgumentException: no uniform with name 'u_projModelView' in shader
at com.badlogic.gdx.graphics.glutils.ShaderProgram.fetchUniformLocation(ShaderProgram.java:287)
at com.badlogic.gdx.graphics.glutils.ShaderProgram.fetchUniformLocation(ShaderProgram.java:277)
at com.badlogic.gdx.graphics.glutils.ShaderProgram.setUniformMatrix(ShaderProgram.java:507)
at com.badlogic.gdx.graphics.glutils.ShaderProgram.setUniformMatrix(ShaderProgram.java:498)
at com.badlogic.gdx.graphics.glutils.ImmediateModeRenderer20.flush(ImmediateModeRenderer20.java:147)
at com.badlogic.gdx.graphics.glutils.ImmediateModeRenderer20.end(ImmediateModeRenderer20.java:160)
at com.badlogic.gdx.graphics.glutils.ShapeRenderer.end(ShapeRenderer.java:1104)
at com.badlogic.gdx.graphics.glutils.ShapeRenderer.check(ShapeRenderer.java:1092)
at com.badlogic.gdx.graphics.glutils.ShapeRenderer.rect(ShapeRenderer.java:389)
at com.badlogic.gdx.scenes.scene2d.ui.Table.drawDebugRects(Table.java:1224)
at com.badlogic.gdx.scenes.scene2d.ui.Table.drawDebug(Table.java:1204)
at com.badlogic.gdx.scenes.scene2d.Group.drawDebugChildren(Group.java:156)
at com.badlogic.gdx.scenes.scene2d.Group.drawDebug(Group.java:139)
at com.badlogic.gdx.scenes.scene2d.Stage.drawDebug(Stage.java:169)
at com.badlogic.gdx.scenes.scene2d.Stage.draw(Stage.java:132)
at net.lukshe.lukshegame2.screens.MainMenu.render(MainMenu.java:71)
at com.badlogic.gdx.Game.render(Game.java:46)
at net.lukshe.lukshegame2.LuksheGame.render(LuksheGame.java:23)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:215)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:120)

MainMenu.java:

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL30;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;

public class MainMenu implements Screen {

private Stage stage; //done
private TextureAtlas atlas; //done
private Skin skin; //done
private Table table; //done
private TextButton buttonplay, buttonexit;
private BitmapFont white; //done
private Label heading;

@Override
public void show() {
    stage = new Stage();

    atlas = new TextureAtlas("ui/button.pack");
    skin = new Skin(atlas);
    table = new Table(skin);
    table.setBounds(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    white = new BitmapFont(Gdx.files.internal("font/white.fnt"), false);

    //Set the button style
    TextButtonStyle textButtonStyle = new TextButtonStyle();
    textButtonStyle.up = skin.getDrawable("buttonup");
    textButtonStyle.down = skin.getDrawable("buttondown");
    textButtonStyle.pressedOffsetX = 1;
    textButtonStyle.pressedOffsetY = -1;
    textButtonStyle.font = white;
    textButtonStyle.fontColor = Color.BLACK;

    //Creating exit button
    buttonexit = new TextButton("Exit", textButtonStyle);
    buttonexit.pad(20);

    //Add button to the table
    table.add(buttonexit);

    //Debug
    table.debug();

    //Add table to the stage
    stage.addActor(table);

}

@Override
public void render(float delta) {
    //OpenGL settings
    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT);

    //Render at the speed of delta
    stage.act(delta);

    //Draw stage
    stage.draw();

}

LuksheGame.java:

public class LuksheGame extends Game {

public static final String NAME = "Lukse game (LibGDX)", VERSION = "Pre-Alpha 0.0.0.2";

@Override
public void create() {
    setScreen(new Splash());
}

@Override
public void dispose() {     
    super.dispose();
}

@Override
public void render() {
    super.render();
}

@Override
public void resize(int width, int height) {     
    super.resize(width, height);
}

@Override
public void pause() {
    super.pause();
}

@Override
public void resume() {      
    super.resume();
}

}

如果有人可以帮助我,请帮忙。

编辑: 从Splash.java调用MainMenu.java。在Splash类中,我使用Tween引擎来增加和减少初始屏幕的不透明度。 Splash.java:

public class Splash implements Screen {

private SpriteBatch batch;
private Sprite splash;
private TweenManager twm;


@Override
public void show() {
    batch = new SpriteBatch();
    twm = new TweenManager();
    Tween.registerAccessor(Sprite.class, new SpriteAccessor());

    Texture splashtexture = new Texture(Gdx.files.internal("images/splash.png"));
    splash = new Sprite(splashtexture);
    splash.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

    Tween.set(splash, SpriteAccessor.alpha).target(0).start(twm);
    Tween.to(splash, SpriteAccessor.alpha, 2).target(1).repeatYoyo(1, 2).setCallback(new TweenCallback() {
        @Override
        public void onEvent(int type, BaseTween<?> source) {
            ((Game) Gdx.app.getApplicationListener()).setScreen(new MainMenu());
        }
    }).start(twm);
}

@Override
public void render(float delta) {
    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT);

    twm.update(delta);

    batch.begin();
    splash.draw(batch);
    batch.end();

}

@Override
public void resize(int width, int height) {

}

@Override
public void pause() {

}

@Override
public void resume() {

}

@Override
public void hide() {

}

@Override
public void dispose() {
    batch.dispose();
    splash.getTexture().dispose();
}

}

0 个答案:

没有答案
相关问题