本文介绍了Java LWJGL:当我调用"GL11.glEnd"时,多边形消失了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我调用"GL11.glEnd"时,多边形消失了.如果我把那一行"GL11.glEnd"留在外面,那么它会留在屏幕上,但是当我放进去时,我正在绘制的多边形就会消失.

When I call "GL11.glEnd" the polygon disappears. If I leave that one line "GL11.glEnd" out, then it stays on the screen, but when I put it in, the polygon I was drawing disappears.

package package01;

import org.lwjgl.opengl.GL11;

public class Graph {

    ...


void initGraph(){
    GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 
    GL11.glClearDepth(1.0); 
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
    GL11.glOrtho(-500, 500, -281, 281, -1, 1);
    GL11.glColor3f(0.8f, 0.8f, 1.0f);
    GL11.glBegin(GL11.GL_POLYGON);
        GL11.glVertex3f(-60, 110, 0);   
        GL11.glVertex3f(60, 110, 0);
        GL11.glVertex3f(120, 0, 0);
        GL11.glVertex3f(60, -110, 0);
        GL11.glVertex3f(-60, -110, 0);
        GL11.glVertex3f(-120, 0, 0);
    GL11.glEnd();
    GL11.glFlush();
}
}

这是第二类,如果有帮助的话.

And here is the second class if it would help.

package package01;

...

public class DisplayScreen {
Graph g = new Graph();


void start(){
    try {
        Display.setDisplayMode(new DisplayMode(1000,562));
        Display.create();
        GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

    } catch(LWJGLException e) {
        e.printStackTrace();

    }
    while(!Display.isCloseRequested()){

        Display.update();
        g.initGraph();
    }
    Display.destroy();
}


public static void main(String[] args){

    DisplayScreen ds = new DisplayScreen();
    ds.start();

    }
}

推荐答案

删除GL11.glOrtho(-500,500,-281,281,-1,1);来自initGraph()方法.

remove GL11.glOrtho(-500, 500, -281, 281, -1, 1); from the initGraph() method.

添加

glMatrixMode(GL11.GL_PROJECTION);
glLoadIdentity();
GL11.glOrtho(-500, 500, -281, 281, -1, 1);
glMatrixMode(GL11.GL_MODELVIEW);

在游戏循环之前.

update g.initGraph(); Display.update();

update needs to be called after initGraph g.initGraph(); Display.update();

这篇关于Java LWJGL:当我调用"GL11.glEnd"时,多边形消失了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 06:42