当我调用“GL11.glEnd”时,多边形消失。如果我将那一行“GL11.glEnd”留下,那么它就会停留在屏幕上,但是当我把它放进去时,我画的多边形就会消失。
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();
}
}
如果有帮助的话,这是第二节课。
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();
}
}
答案 0 :(得分:1)
删除GL11.glOrtho(-500,500,-281,281,-1,1);来自initGraph()方法。
添加
glMatrixMode(GL11.GL_PROJECTION);
glLoadIdentity();
GL11.glOrtho(-500, 500, -281, 281, -1, 1);
glMatrixMode(GL11.GL_MODELVIEW);
在游戏循环之前。
需要在initGraph之后调用更新 g.initGraph(); Display.update();