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 :
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();
}
}
My renderer which implements GLEventListener and KeyListener
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) {
/*GLContext.getCurrent().makeCurrent();
GL gl = GLContext.getCurrent().getGL();*/
switch (arg0.getKeyChar()) {
case 'p':
//gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE);
}
}
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();
// System.out.println(cpt++);
}
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