代码之家  ›  专栏  ›  技术社区  ›  Blazing Forrest

不支持显示ContextAttribs和GL11投影矩阵模式-函数

  •  1
  • Blazing Forrest  · 技术社区  · 7 年前

    当我试图将lwjgl程序的矩阵模式设置为gl_投影时,出现了一个错误。

    glMatrixMode(GL_PROJECTION);
    

    错误是:

    线程“main”java.lang.IllegalStateException中的异常:不支持函数 在org.lwjgl.bufferchecks.checkfunctionaddress(bufferchecks.java:58) 网址:org.lwjgl.opengl.gl11.glmatrixmode(gl11.java:2075) ……

    我已经把这个错误追踪到我展示的时候了。当我删除我的contextribs时,我的代码不会显示错误并呈现!(当我注释掉需要contextribs的代码时)

    这是我的代码:

    显示代码:

    Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
    ContextAttribs attribs = new ContextAttribs(3, 2).withProfileCore(true).withForwardCompatible(true);
    Display.create(new PixelFormat().withDepthBits(24).withSamples(4), attribs);
    Display.setTitle(TITLE);
    Display.setInitialBackground(1, 1, 1);
    GL11.glEnable(GL13.GL_MULTISAMPLE);
    GL11.glViewport(0, 0, WIDTH, HEIGHT);
    

    初始化方法:

    glMatrixMode(GL_PROJECTION);
    glOrtho(0, width, height, 0, -1, 1);
    glMatrixMode(GL_MODELVIEW);
    glClearColor(0, 1, 0, 0);
    
    textureID = loadTexture("res/hud.png");
    
    glEnable(GL_TEXTURE_2D);
    

    渲染方法:

    glClear(GL_COLOR_BUFFER_BIT);
    
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    
    glPushMatrix();
    
    glTranslatef(0, 0, 0);
    
    glBindTexture(GL_TEXTURE_2D, textureID);
    
    glBegin(GL_QUADS);
    
    {
            glTexCoord2f(0, 0);
            glVertex2f(0, 0);
    
            glTexCoord2f(1, 0);
            glVertex2f(width, 0);
    
            glTexCoord2f(1, 1);
            glVertex2f(width, height);
    
            glTexCoord2f(0, 1);
            glVertex2f(0, height);
    }
    
    glEnd();
    glPopMatrix();
    

    有人知道我如何让这些代码与contextattribs一起工作吗?

    提前谢谢!

    编辑1:我已经静态导入了gl11中的所有函数和变量。

    1 回复  |  直到 7 年前
        1
  •  1
  •   Rabbid76    7 年前

    首先,用 glBegin / glEnd 序列已经被弃用超过10年了。见 Vertex Specification 一种最先进的渲染方式。

    带着那条线

    ContextAttribs attribs = new ContextAttribs(3, 2).withProfileCore(true).withForwardCompatible(true);
    

    OpenGL core profile Context 具有 Forward compatibility 生成位集。

    在此上下文中,所有不推荐使用的函数 格尔贝京 / 格伦德 序列,矩阵堆栈( glMatrixMode ),则删除标准灯光模型等。这会导致错误。

    也见 Fixed Function Pipeline OpenGL Context

    跳过前向兼容位的设置( .withForwardCompatible(true) )来解决这个问题。