您好我试图创建一个OOA OpenGL项目,我有两个类Mainproject和地面(心灵地面不是地面但是一个线圈)我不能因为某些原因把它调到主项目上,我得到的只是一个黑色屏
MainProject类
package cg;
import cg.ground;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCanvas;
import javax.media.opengl.GLEventListener;
import com.sun.opengl.util.Animator;
public class MainProject implements GLEventListener {
private ground g = new ground();
public MainProject(ground ground)
{
this.g = ground;
}
@Override
public void display(GLAutoDrawable drawable) {
GL gl = drawable.getGL();
// Clear the drawing area
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
g.display(drawable);
// Flush all drawing operations to the graphics card
}
@Override
public void displayChanged(GLAutoDrawable arg0, boolean arg1, boolean arg2) {
}
@Override
public void init(GLAutoDrawable drawable) {
GL gl = drawable.getGL();
// Enable VSync
gl.setSwapInterval(1);
// Setup the drawing area and shading mode
gl.glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
gl.glShadeModel(GL.GL_SMOOTH); // try setting this to GL_FLAT and see what happens.
}
@Override
public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3, int arg4) {
// TODO Auto-generated method stub
}
public static void main(String[] args) {
Frame frame = new Frame("Simple JOGL Application");
GLCanvas canvas = new GLCanvas();
// canvas.addGLEventListener(new MainProject());
frame.add(canvas);
frame.setSize(640, 480);
final Animator animator = new Animator(canvas);
//add an anonymous WindowListener for the AWT Frame to stop the animator
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
// Run this on another thread than the AWT event queue to
// make sure the call to Animator.stop() completes before
// exiting
new Thread(new Runnable() {
public void run() {
animator.stop();
System.exit(0);
}
}).start();
}
});
frame.setLocationRelativeTo(null);
frame.setVisible(true);
animator.start();
}
}
接地
package cg;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCanvas;
import javax.media.opengl.GLEventListener;
public class ground implements GLEventListener{
public static void main(String[] args) {
}
public void init(GLAutoDrawable drawable) {
}
@Override
public void display(GLAutoDrawable drawable) {
GL gl = drawable.getGL();
// Clear the drawing area
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
gl.glColor3f(1.0f, 0.0f, 1.0f); // Set the current drawing color to red
gl.glBegin(GL.GL_LINE_STRIP);
for (int deg = 0; deg <= 360; deg++) {
double rad = Math.toRadians(deg);
double x = 0.95*Math.cos(rad);
double y = 0.95*Math.sin(rad);
gl.glVertex2d(x, y);
}
gl.glEnd();
// Flush all drawing operations to the graphics card
gl.glFlush();
}
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
}
public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
}
}