Hello everyone,
I'm new with OpenGL in general and so with JOGL...
My objectives in the excercice i want to realise is simple
"Change the polygon mode when i pressed the 'p' key".
For that i have:
Part1 class like this :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| [size=12pt] import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent;
import javax.media.opengl.GLCanvas; import javax.media.opengl.GLCapabilities; import javax.swing.JFrame;
import com.sun.opengl.util.Animator;
public class Part1 {
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(300, 300);
GLCanvas canvas = new GLCanvas(new GLCapabilities()); frame.add(canvas);
Renderer rend = new Renderer(); canvas.addGLEventListener(rend); canvas.addKeyListener(rend);
final Animator animator = new Animator(canvas); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { animator.stop(); System.exit(0); } }); frame.setVisible(true); animator.start();
} } [/size] |
My renderer which implements GLEventListener and KeyListener
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| import java.awt.event.KeyEvent; import java.awt.event.KeyListener;
import javax.media.opengl.DebugGL; import javax.media.opengl.GL; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLContext; import javax.media.opengl.GLEventListener;
public class Renderer implements GLEventListener, KeyListener { static int cpt = 0;
public void keyPressed(KeyEvent arg0) { switch (arg0.getKeyChar()) { case 'p': } }
public void keyReleased(KeyEvent arg0) { System.out.println("relacher");
}
public void keyTyped(KeyEvent arg0) { System.out.println("typer");
}
public void init(GLAutoDrawable arg0) { GL gl = arg0.getGL(); arg0.setGL(new DebugGL(arg0.getGL())); System.out.println("Init GL is " + gl.getClass().getName()); }
public void display(GLAutoDrawable arg0) { GL gl = arg0.getGL(); gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); gl.glPointSize(2.0f); gl.glClear(GL.GL_COLOR_BUFFER_BIT);
gl.glBegin(GL.GL_POLYGON); gl.glColor3f(1.0f, 0.0f, 0.0f); gl.glVertex2f(-0.5f, -0.5f); gl.glColor3f(0.0f, 1.0f, 0.0f); gl.glVertex2f(0.5f, -0.5f); gl.glColor3f(0.0f, 0.0f, 1.0f); gl.glVertex2f(0.5f, 0.5f); gl.glColor3f(1.0f, 1.0f, 1.0f); gl.glVertex2f(-0.5f, 0.5f);
gl.glEnd(); gl.glFlush();
}
public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3, int arg4) { System.out.println("reshape"); }
public void displayChanged(GLAutoDrawable arg0, boolean arg1, boolean arg2) { System.out.println("ghghgh"); }
} |
My problem is in the keyPressed method where i don't arrive to make the current context
So where can i find information about GL context ?
thank
oliver