我尝试创建具有xpos,ypos,type和存储在其中的modelInstance的3D立方体。当我尝试运行程序时,我收到此错误:
线程“LWJGL Application”中的异常org.lwjgl.opengl.OpenGLException:禁用数组缓冲区对象时无法使用偏移量
如何启用它?
以下是我收到错误的课程:
package com.me.the_unknown;
import java.util.ArrayList;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
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.materials.Material;
import com.badlogic.gdx.graphics.g3d.materials.TextureAttribute;
import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder;
public class Blocks {
public static ArrayList<Float> blockX = new ArrayList<Float>();
public static ArrayList<Float> blockY = new ArrayList<Float>();
public static ArrayList<Integer> blockType = new ArrayList<Integer>();
public static ArrayList<ModelInstance> blockModelInstance = new ArrayList<ModelInstance>();
public static ModelBatch modelBatch;
private static ModelBuilder modelBuilder;
//Textures
public static Texture stonebrick = new Texture("data/blocks/stonebrick.png");
public static Texture gravel = new Texture("data/blocks/gravel.png");
public static void addBlock(int xpos, int ypos, int type) {
blockX.add((float) xpos * 5);
blockY.add((float) ypos * 5);
blockType.add(type);
updateBlocks();
}
private static void updateBlocks() {
blockModelInstance.clear();
for(int counter = 0; counter < blockX.size(); counter++){
Model model = null;
ModelInstance instance;
if(blockType.get(counter) == 1)
model = modelBuilder.createBox(5f, 5f, 5f, new Material(TextureAttribute.createDiffuse(stonebrick)), Usage.Position | Usage.Normal | Usage.TextureCoordinates | Usage.Generic);
if(blockType.get(counter) == 2)
model = modelBuilder.createBox(5f, 5f, 5f, new Material(TextureAttribute.createDiffuse(gravel)), Usage.Position | Usage.Normal | Usage.TextureCoordinates | Usage.Generic);
instance = new ModelInstance(model);
blockModelInstance.add(instance);
model.dispose();
}
}
public static void create() {
modelBuilder = new ModelBuilder();
updateBlocks();
}
}
答案 0 :(得分:6)
您正在创建一个Model,然后创建一个ModelInstance,然后处理Model,它实际上使ModelInstance不可用,因为它依赖于Model。
确保模型超过依赖它的ModelInstances,因为它管理其资源。在你的情况下,ModelInstance将是无效的,因为它依赖的Mesh通过调用model.dispose()来处理,导致你得到的错误。
同时尝试避免静态,当应用关闭然后重新启动时,它可能会导致设备出现问题。