线程"main"中的异常org.lwjgl.opengl.OpenGLException:无效的操作(1282)-LWJGL [英] Exception in thread "main" org.lwjgl.opengl.OpenGLException: Invalid operation (1282) - LWJGL

查看:117
本文介绍了线程"main"中的异常org.lwjgl.opengl.OpenGLException:无效的操作(1282)-LWJGL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用lwjgl来创建游戏.我做错了什么,下面有错误.我该如何解决?它实际上意味着什么?

I tried to use lwjgl to create a game. I did something wrong and got error below. How I can fix it? What it actually means?

Exception in thread "main" org.lwjgl.opengl.OpenGLException: Invalid operation (1282)
at org.lwjgl.opengl.Util.checkGLError(Util.java:59)
at org.lwjgl.opengl.GL20.glUniform1f(GL20.java:338)
at com.base.engine.Shader.setUniformf(Shader.java:119)
at com.base.engine.Game.update(Game.java:63)
at com.base.engine.MainComponent.run(MainComponent.java:85)
at com.base.engine.MainComponent.start(MainComponent.java:38)
at com.base.engine.MainComponent.main(MainComponent.java:131)
Java Result: 1

推荐答案

来自 OpenGL 3.3参考页面:

如果没有当前程序对象,则生成GL_INVALID_OPERATION.

GL_INVALID_OPERATION is generated if there is no current program object.

您将着色器程序绑定到 Game render()方法中:

You bind your shader program in the render() method of Game:

public void render()
{
    shader.bind();
    mesh.draw();
}

但是,如 教程11中的> MainComponent 类:

However, as seen in the MainComponent class from Tutorial 11:

private void run()
{
    // ...
        while(unprocessedTime > frameTime)
        {
            // ...
            game.update();
            // ...
        }
        if(render)
        {
            render();
            frames++;
        }
        // ...
}

private void render()
{
    RenderUtil.clearScreen();
    game.render();
    Window.render();
}

此处 game.update() render()(因此,因此 game.render())之前被调用.

Here game.update() gets called before render() (and therefore game.render()).

因为着色器程序仅绑定在 game.render()中,所以在第一次调用 game.update()时没有绑定程序,这意味着 GL_INVALID_OPERATION .

Because the shader program is only bound in game.render(), at the first call of game.update() there is no program bound, which means GL_INVALID_OPERATION is thrown.

这并不是真正的问题,因为从程序的第二帧开始就已绑定,因此所有程序都可以从那里正常工作.但是,您可能已打开调试模式,这意味着LWJGL不会默默地忽略OpenGL错误,而是抛出异常.

This isn't really an issue because from the second frame on the program is bound and so all will be working perfectly from there. However, you probably have debug mode switched on, which means LWJGL won't silently ignore OpenGL errors, instead throwing exceptions.

所以您可以关闭调试模式,或者,我建议在 Game 构造函数的末尾绑定着色器程序一次,而不是每帧绑定一次.只要只有一个着色器程序,它就可以完美运行.

So you can either switch debug mode off or, what I would recommend, bind your shader program once at the end of the Game constructor instead of every frame. As long as you only have one shader program, it will work perfectly.

这篇关于线程"main"中的异常org.lwjgl.opengl.OpenGLException:无效的操作(1282)-LWJGL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆