代码之家  ›  专栏  ›  技术社区  ›  lennsa

光滑的纹理加载器。getTexture无法解析为类型

  •  0
  • lennsa  · 技术社区  · 6 年前

    我认为这只是图书馆的错误实现,但我不知道如何解决它。

    funktion

    似乎类纹理(org.newdawn.slick.opengl.Texture)不起作用或者。。。

    导入工作。。。

    导入组织。纽道恩。滑溜的opengl。纹理 导入组织。纽道恩。滑溜的opengl。TextureLoader;

    我真的不知道发生了什么事。

    package Main.graphics;
    
    import static org.lwjgl.opengl.GL11.*;
    import static org.lwjgl.opengl.GL15.*;
    import static org.lwjgl.opengl.GL20.*;
    import static org.lwjgl.opengl.GL30.*;
    
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.nio.FloatBuffer;
    import java.nio.IntBuffer;
    import java.util.ArrayList;
    import java.util.List;
    
    import org.lwjgl.BufferUtils;
    import org.newdawn.slick.opengl.Texture;
    import org.newdawn.slick.opengl.TextureLoader;
    
    import Main.models.Model;
    
    public class ModelLoader {
    
        // nach Thin Matrix
    
        private List<Integer> vaos = new ArrayList<Integer>();
        private List<Integer> vbos = new ArrayList<Integer>();
        private List<Integer> textures = new ArrayList<Integer>();
    
        public Model loadToVAO(float[] positions, int[] indices) {
            int vaoID = createVAO();
            bindIndicesBuffer(indices);
            storeDataInAttribList(0, positions);
            unbindVAO();
            return new Model(vaoID, indices.length);
        }
    
        public void destroyAll() {
            for (int vao : vaos) {
                glDeleteVertexArrays(vao);
            }
            for (int vbo : vbos) {
                glDeleteBuffers(vbo);
            }
            for (int texture : textures) {
                glDeleteTextures(texture);
            }
        }
    
        public int loadTexture(String textureReference) {
            Texture texture = null; // <--- light blue (seen as variable name?)
            try {
                texture = new TextureLoader.getTexture("PNG", new FileInputStream("res/" + textureReference + ".png"));
            } catch (FileNotFoundException e) { // ^ TextureLoader.getTexture cannot be resolved to a type
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            int textureID = texture.getTextureID();
            textures.add(textureID);
            return textureID;
        }
    
        private int createVAO() {
            int vaoID = glGenVertexArrays();
            vaos.add(vaoID);
            glBindVertexArray(vaoID);
            return vaoID;
        }
    
        private void unbindVAO() {
            glBindVertexArray(0);
        }
    
        private void bindIndicesBuffer(int[] indices) {
            int vboID = glGenBuffers();
            vbos.add(vboID);
            glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboID);
            IntBuffer buffer = storeDataInIntBuffer(indices);
            glBufferData(GL_ELEMENT_ARRAY_BUFFER, buffer, GL_STATIC_DRAW);
        }
    
        private void storeDataInAttribList(int attribNumber, float[] data) {
            int vboID = glGenBuffers();
            vbos.add(vboID);
            glBindBuffer(GL_ARRAY_BUFFER, vboID);
            FloatBuffer buffer = storeDataInFloatBuffer(data);
            glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW);
            glVertexAttribPointer(attribNumber, 3, GL_FLOAT, false, 0, 0);
            glBindBuffer(GL_ARRAY_BUFFER, 0);
        }
    
        private IntBuffer storeDataInIntBuffer(int[] data) {
            IntBuffer buffer = BufferUtils.createIntBuffer(data.length);
            buffer.put(data);
            buffer.flip();
            return buffer;
        }
    
        private FloatBuffer storeDataInFloatBuffer(float[] data) {
            FloatBuffer buffer = BufferUtils.createFloatBuffer(data.length);
            buffer.put(data);
            buffer.flip();
            return buffer;
        }
    
    }
    
    0 回复  |  直到 6 年前