Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (549)
Games in Android Showcase (137)
games submitted by our members
Games in WIP (594)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [NB]problem with keyLister & GLCanvas  (Read 1086 times)
0 Members and 1 Guest are viewing this topic.
Offline stef784ever

Junior Newbie

Java games rock!

« Posted 2004-04-29 18:24:20 »


 I am NB with OpenGl & Jogl..I have a problems. i have do a classe implement with GLEventListener, KeyListener.  In public void keyPressed(KeyEvent arg0) method, I change a attribut but this no change in display(GLDrawable arg0) method but the attribut is global ( public float[] pos ). If I push 'd' or 'q', this have no effect but another key print "yop".

My source with problems : >

package TestOpen;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.nio.FloatBuffer;


public class MyGLEventListener implements GLEventListener, KeyListener {

     private GL gl;
     private GLU glu;
     private double angle = 0;
     private final double pi = Math.PI;
     private float a = 0;

     public float[] pos = new float[] { 0f, 0f, 0f, 0f, 0f, -1f, 0f, 1f, 0f };

     public void init(GLDrawable arg0) {
           gl = arg0.getGL();
           glu = arg0.getGLU();


           gl = arg0.getGL();
           gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

           gl.glOrtho(0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f);

     public void display(GLDrawable arg0) {
           float b = 0.5f;
           FloatBuffer floatBuffer = BufferUtils.newFloatBuffer(3 * 5);
           floatBuffer.put(new float[] {
                       0.25f, 0.25f, 0f,
                       0.75f, 0.25f, 0f,
                       0.95f, 0.50f, 0f,
                       0.75f, 0.75f, 0f,
                       0.25f, 0.75f, 0f,

           gl.glVertexPointer(3, GL.GL_FLOAT, 0, floatBuffer);

           pos[0] = pos[0] + 0.0001f;

           glu.gluLookAt(      pos[0],      pos[1],      pos[2],      pos[3],      pos[4],      pos[5],      pos[6],      pos[7],      pos[8]);
           gl.glDrawArrays(GL.GL_POLYGON, 0, 5);



     public void reshape(GLDrawable arg0,int arg1,int arg2,      int arg3,int arg4) {

     public void displayChanged(GLDrawable arg0, boolean arg1, boolean arg2) {


     public void keyPressed(KeyEvent arg0) {
           switch (arg0.getKeyChar()) {
                 case 'q' :      pos[0] = pos[0] + 0.0001f;      break;
                 case 'd' :      pos[0] = pos[0] - 0.0001f;      break;
                 default : System.out.println("Yop");

     public void keyReleased(KeyEvent arg0) {      }

     public void keyTyped(KeyEvent arg0) {      }


And my main :

package TestOpen;

import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;


public class MainFrame {

     public static void main(String arg[]) {
           Frame frame = new Frame();

           frame.setSize(400, 300);

           GLCanvas canvas =
                 GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities());

           final Animator animator = new Animator(canvas);
           frame.addWindowListener(new WindowAdapter() {
                 public void windowClosing(WindowEvent e) {

           canvas.addGLEventListener(new MyGLEventListener());
           canvas.addKeyListener(new MyGLEventListener());




thx for all !

I am sorry for my very bad ... :-p
Offline Ken Russell

JGO Coder

Java games rock!

« Reply #1 - Posted 2004-04-29 20:10:31 »

Look at the sources in the jogl-demos workspace (on for examples of how to make key presses and mouse motion interoperate properly with OpenGL rendering.
Offline stef784ever

Junior Newbie

Java games rock!

« Reply #2 - Posted 2004-04-30 03:12:48 »

ok ! Smiley thx very lot

I am sorry for my very bad ... :-p
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.


Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

GamerIDGoesHere (20 views)
2015-01-27 01:23:23

GamerIDGoesHere (20 views)
2015-01-27 01:22:15

CopyableCougar4 (27 views)
2015-01-27 00:34:41

CopyableCougar4 (16 views)
2015-01-26 04:47:56

Olo (14 views)
2015-01-25 21:26:00

Olo (16 views)
2015-01-25 18:44:22

Robo11 (30 views)
2015-01-25 06:14:26

basil_ (27 views)
2015-01-17 22:29:32

wxwsk8er (26 views)
2015-01-16 21:42:21

wxwsk8er (22 views)
2015-01-16 20:44:20
2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!