HI…I’m from Russia and my english is not well therefore I beg your pardon…I have a big problem…
I write jogl applet but it is don’t compiling…it is give applet not initialized…can you help me and show my mistake please?
import java.awt.*;
import java.awt.event.*;
import java.util.Random;
import net.java.games.jogl.*;
import net.java.games.jogl.util.GLUT;
import javax.swing.*;
public class OpenglApp extends JApplet {
static Animator animator = null;
static class Renderer
implements GLEventListener, MouseListener, MouseMotionListener
{
private float xrot = 0;
private float yrot = 0;
private float z = -3.8f;
private int prevMouseX, prevMouseY;
public boolean mouseRButtonDown = false;
Random random = new Random();
public float x1 =0.2f;
public float y1 = 0.1f;
public float z1 = 0;
public float n =2;
public float k = 2;
public float l = 2;
public float a1 =0.4f;
public float b1 = 0.1f;
public float c1 = 0.3f; // A0,B0,C0,1,-C-A/B,B
public float A = 1; //random.nextInt(3);
public float B = -l-n/k; // random.nextInt(3);
public float C = k;
public float D = -A*a1-B*b1-C*c1;
public void display(GLDrawable gLDrawable)
{
final GL gl = gLDrawable.getGL();
final GLU glu = gLDrawable.getGLU();
DrawLine drawline = new DrawLine();
DrawPlane drawplane = new DrawPlane();
DrawString drawstring = new DrawString();
DrawAxes drawaxes = new DrawAxes();
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
gl.glTranslatef(0.0f, 0.0f, this.z);
gl.glRotatef(-90, 1.0f, 0.0f, 0.0f);
gl.glRotatef(-100, 0.0f, 0.0f, 1.0f);
gl.glRotatef(15, 0.0f, 1.0f, 0.0f);
gl.glRotatef(xrot, 1.0f, 0.0f, 0.0f);
gl.glRotatef(yrot, 0.0f, 1.0f, 0.0f);
gl.glClearColor(1,1,1,1);
float fLightPos[] = { -100.0f, 100.0f, 50.0f, 1.0f }; // Point source
float fNoLight[] = { 0.0f, 0.0f, 0.0f, 0.0f };
float fLowLight[] = { 0.25f, 0.25f, 0.25f, 1.0f };
float fBrightLight[] = { 0.2f, 0.2f, 0.2f, 0.2f };
gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, fNoLight);
gl.glLightfv(gl.GL_LIGHT0, gl.GL_DIFFUSE, fBrightLight);
gl.glLightfv(gl.GL_LIGHT0, gl.GL_SPECULAR, fBrightLight);
gl.glEnable(gl.GL_LIGHTING);
gl.glEnable(gl.GL_LIGHT0);
gl.glEnable(gl.GL_COLOR_MATERIAL);
gl.glColorMaterial(gl.GL_FRONT, gl.GL_AMBIENT_AND_DIFFUSE);
gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR, fBrightLight);
gl.glLineWidth(1);
drawaxes.Axes(gl,10,1.2f,xrot,yrot);
gl.glColor3f (0.0f, 10.0f, 10.10f);
gl.glLineWidth(1);
drawplane.Plane(gl,0.8f,A,B, C, D);
gl.glLineWidth(2);
gl.glColor3f (110.0f, 0.0f, 0.0f);
drawline.Line(gl, 0.8f ,x1,y1,z1,n,k,l);
gl.glPushMatrix();
gl.glLineWidth(1);
gl.glColor3f (0.0f, 0.0f, 0.0f);
gl.glTranslatef(a1,b1,c1);
gl.glRotatef(yrot, 0.0f, -1.0f, 0.0f);
gl.glRotatef(xrot, -1.0f, 0.0f, 0.0f);
gl.glRotatef(15, 0.0f, -1.0f, 0.0f);
gl.glRotatef(-100, 0.0f, 0.0f, -1.0f);
gl.glRotatef(-90, -1.0f, 0.0f, 0.0f);
drawstring.String(gl, GLUT.STROKE_MONO_ROMAN,0.01f, 0.01f, 0.01f, "M("+ x1+","+y1+","+z1+")");
gl.glPopMatrix();
gl.glPointSize(4f);
gl.glBegin(GL.GL_POINTS);
gl.glVertex3f(a1,b1,c1);
gl.glEnd();
}
public void init(GLDrawable gLDrawable)
{
final GL gl = gLDrawable.getGL();
gLDrawable.addMouseListener((MouseListener) this);
gLDrawable.addMouseMotionListener((MouseMotionListener) this);
}
public void reshape(GLDrawable gLDrawable, int x, int y, int width, int height)
{
final GL gl = gLDrawable.getGL();
final GLU glu = gLDrawable.getGLU();
if (height <= 0)
height = 1;
final float h = (float)width / (float)height;
gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(45.0f, h, 1.0, 20.0);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
}
public void displayChanged(GLDrawable glDrawable, boolean b, boolean b1) {
//To change body of implemented methods use File | Settings | File Templates.
}
public void mouseDragged(MouseEvent e) {
int x = e.getX();
int y = e.getY();
if (mouseRButtonDown) {
xrot = (float)(x - prevMouseX);
yrot = (float)(y - prevMouseY);
} else {
prevMouseX = x;
prevMouseY = y;
}
}
public void mouseMoved(MouseEvent e) {
//To change body of implemented methods use File | Settings | File Templates.
}
public void mouseClicked(MouseEvent e) {
//To change body of implemented methods use File | Settings | File Templates.
}
public void mousePressed(MouseEvent e) {
prevMouseX = e.getX();
prevMouseY = e.getY();
if ((e.getModifiers() & e.BUTTON3_MASK) != 0) {
mouseRButtonDown = true;
}
}
public void mouseReleased(MouseEvent e) {
if ((e.getModifiers() & e.BUTTON3_MASK) != 0) {
mouseRButtonDown = false;
prevMouseX = e.getX();
prevMouseY = e.getY();
}
}
public void mouseEntered(MouseEvent e) {
//To change body of implemented methods use File | Settings | File Templates.
}
public void mouseExited(MouseEvent e) {
//To change body of implemented methods use File | Settings | File Templates.
}
}
public void main()
{
//Frame frame = new Frame("My First Polygon");
GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities());
canvas.addGLEventListener(new Renderer());
JApplet applet = new JApplet();
applet.add(canvas);
applet.setSize(700, 700);
animator = new Animator(canvas);
animator.start();
applet.start();
}
public void start() {
// animator.start();
}
public void stop() {
// animator.stop();
}
}