Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (495)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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 1035 times)
0 Members and 1 Guest are viewing this topic.
Offline stef784ever

Junior Newbie




Java games rock!


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

Hello

 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;

import net.java.games.jogl.GL;
import net.java.games.jogl.GLDrawable;
import net.java.games.jogl.GLEventListener;
import net.java.games.jogl.GLU;
import net.java.games.jogl.util.BufferUtils;

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();

           System.out.println("init");

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

           gl.glMatrixMode(GL.GL_PROJECTION);
           gl.glLoadIdentity();
           gl.glOrtho(0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f);
     }

     public void display(GLDrawable arg0) {
           gl.glClear(GL.GL_COLOR_BUFFER_BIT);
           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.glEnableClientState(GL.GL_VERTEX_ARRAY);
           gl.glVertexPointer(3, GL.GL_FLOAT, 0, floatBuffer);

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

           gl.glLoadIdentity();
           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);

           gl.glFlush();

     }

     public void reshape(GLDrawable arg0,int arg1,int arg2,      int arg3,int arg4) {
           System.out.println("reshape");
           gl.glMatrixMode(GL.GL_MODELVIEW);
     }

     public void displayChanged(GLDrawable arg0, boolean arg1, boolean arg2) {
           System.out.println("displayChanged");

     }

     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;

import net.java.games.jogl.Animator;
import net.java.games.jogl.GLCanvas;
import net.java.games.jogl.GLCapabilities;
import net.java.games.jogl.GLDrawableFactory;

public class MainFrame {

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

           frame.setSize(400, 300);
           //frame.setBackground(Color.white);

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


           final Animator animator = new Animator(canvas);
           frame.addWindowListener(new WindowAdapter() {
                 public void windowClosing(WindowEvent e) {
           
                       animator.stop();
                       System.exit(0);
                 }
           });            

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

           frame.add(canvas);

           frame.show();

           animator.start();
     }
}


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 java.net) 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.

Dwinin (26 views)
2014-09-12 09:08:26

Norakomi (57 views)
2014-09-10 13:57:51

TehJavaDev (71 views)
2014-09-10 06:39:09

Tekkerue (37 views)
2014-09-09 02:24:56

mitcheeb (57 views)
2014-09-08 06:06:29

BurntPizza (41 views)
2014-09-07 01:13:42

Longarmx (27 views)
2014-09-07 01:12:14

Longarmx (34 views)
2014-09-07 01:11:22

Longarmx (34 views)
2014-09-07 01:10:19

mitcheeb (40 views)
2014-09-04 23:08:59
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

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org 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‑gaming.org
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!