我正在画一个茶壶,但画布上没有显示任何内容,当我使用glOrtho()方法时,茶壶显示没有问题。我想使用gluLookAt()方法来查看茶壶。当我使用Frustum和Ortho方法时,对象会变形。
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.media.opengl.*;
import javax.media.opengl.glu.*;
import javax.media.opengl.awt.*;
import com.sun.opengl.util.*;
import com.sun.opengl.util.gl2.*; // abet ama zyad bkayn bo 3D
class ThreeDTemp implements GLEventListener {
JFrame frame;
GLCanvas canvas;
Animator animator;
public ThreeDTemp(){
frame = new JFrame("Open GL");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
canvas = new GLCanvas();
canvas.setSize(1000, 600);
canvas.addGLEventListener(this);
frame.add(canvas);
animator = new Animator(canvas);
animator.start();
frame.pack();
frame.setVisible(true);
frame.requestFocus();
}
public void init(GLAutoDrawable drawable) {
GL2 gl = drawable.getGL().getGL2();
GLU glu = new GLU();
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
//gl.glOrtho(-500,500,-300,300,-300,300);
gl.glFrustum(-1,1,-1,1,1.5,20);
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glEnable(GL2.GL_DEPTH_TEST); // abet amash bnusen bo 3d
}
public void display(GLAutoDrawable drawable) {
GL2 gl = drawable.getGL().getGL2();
GLU glu = new GLU();
GLUT glut= new GLUT();
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);//abet aw depth a zyad bkayn
gl.glColor3f(0f ,0.5f ,0.5f);
gl.glLoadIdentity();
glut.glutWireTeapot(200);
//glu.gluLookAt(5,0,0,0,0,0,0,1,0);
gl.glFlush();
}
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { }
public void dispose(GLAutoDrawable drawable) {}
//Main Method
public static void main(String[] args){
new ThreeDTemp();
}
}