"Cannot use offsets when Array Buffer Object is disabled" error when attempting to change screen

时间:2016-08-31 18:25:26

标签: libgdx

I have a blue square, and when the blue square is moved to the finish flag, the screen should change to signify that the level is complete. However, when I move the blue square to such position, I get an error message:

Exception in thread "LWJGL Application" org.lwjgl.opengl.OpenGLException: Cannot use offsets when Array Buffer Object is disabled
at org.lwjgl.opengl.GLChecks.ensureArrayVBOenabled(GLChecks.java:77)
at org.lwjgl.opengl.GL20.glVertexAttribPointer(GL20.java:892)
at com.badlogic.gdx.backends.lwjgl.LwjglGL20.glVertexAttribPointer(LwjglGL20.java:847)
at com.badlogic.gdx.graphics.glutils.ShaderProgram.setVertexAttribute(ShaderProgram.java:662)
at com.badlogic.gdx.graphics.glutils.VertexBufferObject.bind(VertexBufferObject.java:202)
at com.badlogic.gdx.graphics.Mesh.bind(Mesh.java:380)
at com.badlogic.gdx.graphics.Mesh.bind(Mesh.java:371)
at com.badlogic.gdx.graphics.Mesh.render(Mesh.java:479)
at com.badlogic.gdx.graphics.Mesh.render(Mesh.java:422)
at com.badlogic.gdx.graphics.glutils.ImmediateModeRenderer20.flush(ImmediateModeRenderer20.java:151)
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:1087)
at com.badlogic.gdx.graphics.glutils.ShapeRenderer.polygon(ShapeRenderer.java:1014)
at com.badlogic.gdx.graphics.glutils.ShapeRenderer.polygon(ShapeRenderer.java:1043)
at com.ian.redsquare.Entities.Walls.render(Walls.java:22)
at com.ian.redsquare.Screens.RedSquareScreen.render(RedSquareScreen.java:65)
at com.badlogic.gdx.Game.render(Game.java:46)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:215)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:120)

here is the screen class in which the blue square moves:

package com.ian.redsquare.Screens;

import ...

public class RedSquareScreen implements Screen{

RedSquareGame game;

Viewport gameViewport;
ShapeRenderer renderer;

RedSquare redSquare;
BlueSquare blueSquare;
FinishSquare finishSquare;
Walls walls;

public RedSquareScreen(RedSquareGame game){
    this.game = game;
}

@Override
public void show() {
    gameViewport = new ExtendViewport(C.WORLD_SIZE, C.WORLD_SIZE, C.WORLD_SIZE, C.WORLD_SIZE);
    renderer = new ShapeRenderer();
    renderer.setAutoShapeType(true);

    finishSquare = new FinishSquare(blueSquare);
    redSquare = new RedSquare();
    blueSquare = new BlueSquare(redSquare);
    walls = new Walls();
}

@Override
public void render(float delta) {
    redSquare.update(delta);
    blueSquare.update(delta);

    if(finishSquare.position.dst(blueSquare.position) <= 0){
        game.showLevelEndScreen();

    }

    gameViewport.apply(true);

    Gdx.gl.glClearColor(C.BACKGROUND_COLOR.r, C.BACKGROUND_COLOR.g, C.BACKGROUND_COLOR.b, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    renderer.setProjectionMatrix(gameViewport.getCamera().combined);
    renderer.begin();

    finishSquare.render(renderer);
    redSquare.render(renderer);
    blueSquare.render(renderer);
    walls.render(renderer);

    renderer.end();


}

@Override
public void resize(int width, int height) {
    gameViewport.update(width, height, true);

}

@Override
public void pause() {

}

@Override
public void resume() {

}

@Override
public void hide() {
    renderer.dispose();

}

@Override
public void dispose() {

}
}

here is screen class which is meant to appear once the blue square reaches the finish square:

package com.ian.redsquare.Screens;

import ...

public class LevelEndScreen extends InputAdapter implements Screen {

RedSquareGame game;
Viewport viewport;
ShapeRenderer renderer;
SpriteBatch batch;

public LevelEndScreen(RedSquareGame game){
    this.game = game;
}

@Override
public void show() {
    viewport = new ExtendViewport(C.LE_WORLD_SIZE, C.LE_WORLD_SIZE);
    renderer = new ShapeRenderer();
    renderer.setAutoShapeType(true);
    batch = new SpriteBatch();

    Gdx.input.setInputProcessor(this);


}

@Override
public void render(float delta) {
    viewport.apply();
    Gdx.gl.glClearColor(C.LE_BACKGROUND_COLOR.r, C.LE_BACKGROUND_COLOR.g, C.LE_BACKGROUND_COLOR.b, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    renderer.setProjectionMatrix(viewport.getCamera().combined);
    renderer.begin(ShapeRenderer.ShapeType.Filled);
    renderer.setColor(C.RESTART_COLOR);
    renderer.rect(C.LE_WORLD_SIZE / 4, C.LE_WORLD_SIZE / 2, C.BUTTON_SIZE, C.BUTTON_SIZE);
    renderer.setColor(C.NEXT_LEVEL_COLOR);
    renderer.rect((C.LE_WORLD_SIZE * (3 / 4)) - C.BUTTON_SIZE, C.LE_WORLD_SIZE / 2, C.BUTTON_SIZE, C.BUTTON_SIZE);

    renderer.end();
}

@Override
public void resize(int width, int height) {
    viewport.update(width, height, true);

}

@Override
public void pause() {

}

@Override
public void resume() {

}

@Override
public void hide() {
    batch.dispose();
    renderer.dispose();
}

@Override
public void dispose() {

}

@Override
public boolean touchDown (int screenX, int screenY, int pointer, int button) {

    Vector2 worldTouch = viewport.unproject(new Vector2(screenX, screenY));
    if(worldTouch.dst2(new Vector2(C.LE_WORLD_SIZE / 4, C.LE_WORLD_SIZE / 2)) == 0){
        game.showRedSquareScreen();
    }
    return true;
}
}

0 个答案:

没有答案