Java – fixed incompatibility between lwjgl 3 and slick util

What I want to do is map the texture to the OpenGL model in lwjgl I know that lwjgl 3 and slick util sometimes work together, but sometimes they can't In my case, it worked a little, and then tried to access a method in OpenGL. Lwjgl 3 no longer exists My post is not necessarily trying to fix this error, but to find a way around it I have tried to downgrade / run lwjgl 2 instead of lwjgl 3, which is very bad. I have also tried several different PNG decoders to get what I want, but I can't figure them out In addition, I have obtained "lwjgl 3 compatible slick util", but it doesn't have any classes / methods I need It would be lovely if someone could fix my code for me or tell me how to fix it myself

This is an error:

Mon Feb 15 18:38:13 EST 2016 INFO:Use Java PNG Loader = true
Exception in thread "main" java.lang.NoSuchMethodError: org.lwjgl.opengl.GL11.glGetInteger(ILjava/nio/IntBuffer;)V
    at org.newdawn.slick.opengl.renderer.ImmediateModeOGLRenderer.glGetInteger(ImmediateModeOGLRenderer.java:194)
    at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:317)
    at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:254)
    at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:200)
    at org.newdawn.slick.opengl.TextureLoader.getTexture(TextureLoader.java:64)
    at org.newdawn.slick.opengl.TextureLoader.getTexture(TextureLoader.java:24)
    at Graphics.Loader.loadTexture(Loader.java:37)
    at Graphics.LaunchWindow.loop(LaunchWindow.java:116)
    at Graphics.LaunchWindow.run(LaunchWindow.java:43)
    at Graphics.LaunchWindow.main(LaunchWindow.java:155)

This is the launchwindow class:

package Graphics;

import org.lwjgl.glfw.*;
import org.lwjgl.opengl.*;
import org.lwjgl.util.Display;

import Controls.KeyParser;
import Controls.KeyboardInput;
import Controls.MouseInput;
import Controls.MouseParser;
import Graphics.Shaders.StaticShader;
import Controls.Cursor;
import Models.Model1;
import Models.RawModel;
import Models.TexturedModel;
import Textures.ModelTexture;

import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.system.MemoryUtil.*;

import java.nio.ByteBuffer;

@SuppressWarnings("unused")
public class LaunchWindow {

private GLFWErrorCallback errorCallback;
private GLFWKeyCallback   keyCallback;
private GLFWMouseButtonCallback mouseButtonCallback;
private GLFWCursorPosCallback cursorPosCallback;

public int width = 1024;
public int height = 600;
public String title = "Duplicity";
public long fullscreen = NULL;
public long window;
private Cursor cursor;

public void run() {

    try {
        init();
        loop();
        glfwDestroyWindow(window);
        keyCallback.release();
    } finally {
        glfwTerminate();
        errorCallback.release();
    }
}

private void init() {

    glfwSetErrorCallback(errorCallback = GLFWErrorCallback.createPrint(System.err));

    KeyboardInput.initiate();
    MouseInput.initiateMouse();

    if ( glfwInit() != GLFW_TRUE )
        throw new IllegalStateException("Unable to initialize GLFW");

    if(fullscreen == NULL){
        glfwDefaultWindowHints();
        glfwWindowHint(GLFW_VISIBLE,GLFW_FALSE);
        glfwWindowHint(GLFW_RESIZABLE,GLFW_TRUE);
    }

    window = glfwCreateWindow(width,height,title,fullscreen,NULL);
    if (window == NULL)
        throw new RuntimeException("Failed to create the GLFW window");

    glfwSetKeyCallback(window,keyCallback = new GLFWKeyCallback() {
        @Override
        public void invoke(long window,int key,int scancode,int action,int mods) {
            if ( key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE )
                glfwSetWindowShouldClose(window,GLFW_TRUE);
        }
    });

    GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
    glfwSetWindowPos(window,(vidmode.width() - width) / 2,(vidmode.height() - height) / 2);
    glfwMakeContextCurrent(window);
    glfwSwapInterval(1);
    glfwShowWindow(window);

    keyCallback = GLFWKeyCallback.create(KeyboardInput::glfw_key_callback);
    keyCallback.set(window);

    mouseButtonCallback = GLFWMouseButtonCallback.create(MouseInput::glfw_mouse_button_callback);
    mouseButtonCallback.set(window);

    cursorPosCallback = GLFWCursorPosCallback.create(MouseInput::glfw_cursor_pos_callback);
    cursorPosCallback.set(window);

    cursor = new Cursor(Cursor.Standard.ARROW);
    glfwSetCursor(window,cursor.getCursor());

    GL.createCapabilities();
}

public void updateinput() {
    KeyboardInput.update();
    MouseInput.update();
    glfwPollEvents();
}

public void loop() {

    Loader loader = new Loader();
    Render render = new Render();
    Model1 model1 = new Model1();
    Display display = new Display();
    StaticShader shader = new StaticShader();

    RawModel model = loader.loadToVAO(model1.Model1Vertices(),model1.Model1Indices());
    ModelTexture texture = new ModelTexture(loader.loadTexture("marble"));
    TexturedModel texturedModel = new TexturedModel(model,texture);

    GL.createCapabilities();
    //glClearColor(0.0f,0.0f,0.0f);

    if(width != 1024 && height != 600){
        System.out.println("resized");
    }

    while ( glfwWindowShouldClose(window) == GLFW_FALSE ) {
        render.prepare();
        shader.start();
        render.render(texturedModel);
        shader.stop();

        //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glfwSwapBuffers(window); 
        glfwPollEvents();
        try {
            new KeyParser().checkKeyState();
            new MouseParser().checkMouseState();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    shader.cleanUp();
    loader.cleanUp();
}
public void setCursor(Cursor cursor) {
    this.cursor = cursor;
    glfwSetCursor(window,cursor.getCursor());
}

public Cursor getCursor() {
    return cursor;
}

public static void main(String[] args) {
    new LaunchWindow().run();
}

}

This is the loader:

package Graphics;

import java.io.FileInputStream;
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.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL15;
import org.lwjgl.opengl.GL20;
import org.lwjgl.opengl.GL30;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;

import Models.RawModel;

public class Loader {

private List<Integer> vaos = new ArrayList<Integer>();
private List<Integer> vbos = new ArrayList<Integer>();
private List<Integer> textures = new ArrayList<Integer>();

public RawModel loadToVAO(float[] positions,int[] indices){
    int vaoID = createVAO();
    bindIndicesBuffer(indices);
    storeDataInAttributeList(0,positions);
    unbindVAO();
    return new RawModel(vaoID,indices.length);
}

public int loadTexture(String fileName){
    Texture texture = null;
    try {
        texture = TextureLoader.getTexture("PNG",new FileInputStream("res/" + fileName + ".png"));
    } catch (IOException e) {
        e.printStackTrace();
    }
    int textureID = texture.getTextureID();
    textures.add(textureID);
    return textureID;
}

public void cleanUp(){
    for(int vao:vaos){
        GL30.glDeleteVertexArrays(vao);
    }
    for(int vbo:vbos){
        GL15.glDeleteBuffers(vbo);
    }
    for(int texture:textures){
        GL11.glDeleteTextures(texture);
    }
}

private int createVAO(){
    int vaoID = GL30.glGenVertexArrays();
    vaos.add(vaoID);
    GL30.glBindVertexArray(vaoID);
    return vaoID;
}

private void storeDataInAttributeList(int attNumber,float[] data){
    int vboID = GL15.glGenBuffers();
    vbos.add(vboID);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER,vboID);
    FloatBuffer buffer = storeDataInFloatBuffer(data);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER,buffer,GL15.GL_DYNAMIC_DRAW); //change to static if static model
    GL20.glVertexAttribPointer(attNumber,3,GL11.GL_FLOAT,false,0);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER,0);
}

private void unbindVAO(){
    GL30.glBindVertexArray(0);
}

private void bindIndicesBuffer(int[] indices){
    int vboID = GL15.glGenBuffers();
    vbos.add(vboID);
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER,vboID);
    IntBuffer buffer = storeDataInIntBuffer(indices);
    GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER,GL15.GL_DYNAMIC_DRAW); //change to static of static model
}

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;
}

}

Solution

You can download the slick util compatible with lwjgl3 here: * Click*

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>