Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (523)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (592)
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  
  "On-demand" mode modification to tutoria  (Read 4220 times)
0 Members and 1 Guest are viewing this topic.
Offline pahidla

Senior Newbie




Java games rock!


« Posted 2004-12-23 07:38:15 »

How about it?   Smiley
Offline pahidla

Senior Newbie




Java games rock!


« Reply #1 - Posted 2005-01-05 04:16:51 »

If I should give up the hope of seeing this, tell me now!

Then hate me when thou wilt; if ever, now;
Now, while the world is bent my deeds to cross,
Join with the spite of fortune, make me bow,
And do not drop in for an after-loss:
Offline cylab

JGO Ninja


Medals: 55



« Reply #2 - Posted 2005-01-05 06:35:56 »

LOL

sorry, no help, just snicker Wink

Mathias - I Know What [you] Did Last Summer!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline pahidla

Senior Newbie




Java games rock!


« Reply #3 - Posted 2005-01-10 02:14:58 »

I see that nnevatie is back, so there's hope for me. Otherwise, another sad Shakespeare sonnet.
Offline gregof

Junior Devvie




in code we trust


« Reply #4 - Posted 2005-01-10 05:57:05 »

Okey, I have to ask:
what do you mean by: " "On-demand" mode modification to tutoria"?

// Gregof
Offline Tomas

Junior Devvie




Agency9


« Reply #5 - Posted 2005-01-10 07:14:08 »

He probably means that it should run on an IBM server Grin

CTO Agency9
Offline nnevatie

Junior Devvie




It is slightly better to be simple than correct.


« Reply #6 - Posted 2005-01-10 07:35:00 »

Pahidla, you must be referring to this thread:

http://www.java-gaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=jogl;action=display;num=1103394116

...in that case, my bad, sorry - I did promise to deliver a simple example that shows the basic usage of "on-demand" usage of JOGL (manual refreshing of GLDrawables).

The thing is I've been busy with my studies lately - I'm currently working on a 100% Java rigid body dynamics framework/library.

But, if there is any specific question about JOGL, that I could help you with, please do ask without hesitation.


Awards:
- Nobel Prize in Physics for inventing his Doomsday Machine
- Nobel Peace Prize for not using it

http://www.g0dmode.com -- a collection of things not real
Offline pahidla

Senior Newbie




Java games rock!


« Reply #7 - Posted 2005-01-10 18:18:09 »

Funny, rigid bodies is the subject of my research, too. Maybe we can collaborate on that!

For example, I'm thinking right now of how to intelligently add energy dissipation to the rigid body or how to describe it in non-affine coordinates. Will your framework have support for planetary motion of rigid bodies?

As far as on-demand jogl, I just can't figure out how to get things started. How about an application this simple:
When the application starts it shows a triangle.

For me, the init() method does not trigger until I manually resize the parent frame.

Thanks a lot!

Pahidla
Offline GKW

Senior Devvie




Revenge is mine!


« Reply #8 - Posted 2005-01-11 18:36:29 »

On-demand rendering is just calling repaint() on your canvas.  As opposed to using an animator with just calls repaint continuously on it's own thread.  That is why your canvas is initialized when you resize the screen.  Just throw a repaint() call in your mouselistener or keylistener or what ever mechanism you use to change what ever you are visualizing.
Offline pahidla

Senior Newbie




Java games rock!


« Reply #9 - Posted 2005-01-12 05:19:07 »

But how do I make it show anything before the first mouse or key event?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline nnevatie

Junior Devvie




It is slightly better to be simple than correct.


« Reply #10 - Posted 2005-01-12 06:05:49 »

Quote
But how do I make it show anything before the first mouse or key event?


What keeps you from calling glCanvas.repaint() right after you've created it? Smiley

Remember, that repaint method does not cause an immediate refresh of the component but an event that requests the refresh in the AWT thread.

Awards:
- Nobel Prize in Physics for inventing his Doomsday Machine
- Nobel Peace Prize for not using it

http://www.g0dmode.com -- a collection of things not real
Offline pahidla

Senior Newbie




Java games rock!


« Reply #11 - Posted 2005-01-15 05:00:56 »

OK, thanks for all the help!
After simplifying my code things just worked. Here's my on-demand mode demo if anyone finds it useful. Drag to rotate, shift-drag to zoom, double-click to change the presence of perspective, ctrl-drag to change the degree of perspective.

Please comment if I'm doing something wrong.

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import net.java.games.jogl.*;

public class OnDemandDemo {
 public static void main(String[] inArgs) { new OnDemandDemo(); }

 private GLCanvas myGLCanvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities());

 private double myTheta = Math.PI/2;
 private double myPhi   = -Math.PI/2;
 private double myZoom  = 2.0;
 private double myPerspAngle = Math.PI/3;
 private boolean myPerspectivePresent = true;

 public OnDemandDemo() {
   super();

   MouseListeners il = new MouseListeners();
   myGLCanvas.addMouseListener(il);
   myGLCanvas.addMouseMotionListener(il);
   myGLCanvas.addGLEventListener(new OnScreenGLEventListener());
   myGLCanvas.setSize(400, 400);
   myGLCanvas.repaint();

   javax.swing.JFrame frame = new javax.swing.JFrame("On Demand Mode Demonstration");
   frame.getContentPane().add(myGLCanvas);
   frame.pack();
   frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
   frame.setVisible(true);
 }

 public class OnScreenGLEventListener implements GLEventListener {
   public void init(GLDrawable inDrawable) {
     GL gl = inDrawable.getGL();

     gl.glClearColor(1f, 1f, 1f, 1f);

     gl.glEnable(GL.GL_DEPTH_TEST);
     gl.glEnable(GL.GL_POLYGON_OFFSET_FILL);
     gl.glEnable(GL.GL_POLYGON_OFFSET_LINE);

     gl.glEnable(GL.GL_LIGHTING);
     gl.glLightModelfv(GL.GL_LIGHT_MODEL_AMBIENT, new float[] { 1f, 1f, 1f, 1f });

     gl.glDisable(GL.GL_CULL_FACE) ;
     gl.glLightModeli(GL.GL_LIGHT_MODEL_TWO_SIDE, GL.GL_TRUE) ;
   }

   public void display(GLDrawable drawable, boolean modeChanged, boolean deviceChanged) {}
   public void displayChanged(GLDrawable inDrawable, boolean inWhat, boolean inWhen) {}
   public void reshape(GLDrawable drawable, int x, int y, int width, int height) {}

   public void display(GLDrawable inDrawable) {
     GL gl = inDrawable.getGL();
     gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

     pSetView(inDrawable, false);

     gl.glColor3d(0, 0, 0);
     gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE);
     gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_EMISSION, new float[] { 0f, 0f, 0f } );
     gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT_AND_DIFFUSE, new float[] { 0f, 0f, 0f });
     gl.glBegin(GL.GL_LINE_LOOP);
     gl.glVertex3d( 1, -1, -1);
     gl.glVertex3d( 1, -1,  1);
     gl.glVertex3d(-1, -1,  1);
     gl.glVertex3d(-1, -1, -1);
     gl.glEnd();

     gl.glBegin(GL.GL_LINE_LOOP);
     gl.glVertex3d( 1, 1, -1);
     gl.glVertex3d( 1, 1,  1);
     gl.glVertex3d(-1, 1,  1);
     gl.glVertex3d(-1, 1, -1);
     gl.glEnd();

     gl.glFlush();
   }
 }

 public void pSetView(GLDrawable inDrawable, boolean inFlip) {
   pSetView( (double) myGLCanvas.getSize().width / myGLCanvas.getSize().height, inDrawable, inFlip);
 }

 public void pSetView(double inAspect, GLDrawable inDrawable, boolean inFlip) {
   GL gl = inDrawable.getGL();
   GLU glu = inDrawable.getGLU();

   gl.glMatrixMode(GL.GL_PROJECTION);
   gl.glLoadIdentity();

   double dim = myZoom;
   if (myPerspectivePresent) {
     glu.gluPerspective(myPerspAngle*180/Math.PI, inAspect, .1, 100000.0);
     dim = myZoom/Math.tan(myPerspAngle/ 2);
   }
   else
     gl.glOrtho(-myZoom*inAspect, myZoom*inAspect, -myZoom, myZoom, -10.0, 100.0);

   gl.glMatrixMode(GL.GL_MODELVIEW);
   gl.glLoadIdentity();
   double upOrDown = 1 - 2 * (int) (gMod(myTheta, 2*Math.PI)/Math.PI);
   glu.gluLookAt(dim*Math.sin(myTheta)*Math.cos(myPhi),
                 dim*Math.sin(myTheta)*Math.sin(myPhi),
                 dim*Math.cos(myTheta),
                 0.0, 0.0, 0.0,
                 0.0, 0.0, (!inFlip)?upOrDown:-upOrDown);
 }

 public static double gMod(double inA, double inM) {
   while (inA > inM) inA -= inM;
   while (inA < 0) inA += inM;
   return inA;
 }

 private class MouseListeners implements MouseListener, MouseMotionListener {
   private int myLastX, myLastY;
   public void mousePressed(MouseEvent inME) {
     if (inME.getButton() == MouseEvent.BUTTON1) {
       myLastX = inME.getX();
       myLastY = inME.getY();
     }
   }

   public void mouseDragged(MouseEvent inME) {
     if ((inME.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) == 0) return;

     if ((inME.getModifiersEx() & MouseEvent.SHIFT_DOWN_MASK) != 0 )
       myZoom += (inME.getY() - myLastY)/30.0;
     else if ((inME.getModifiersEx() & MouseEvent.CTRL_DOWN_MASK) != 0 )
       myPerspAngle += -(inME.getY() - myLastY)/600.0;
     else {
       myPhi   += -(inME.getX() - myLastX)/300.0;
       myTheta += -(inME.getY() - myLastY)/300.0;
     }
     myLastX = inME.getX();
     myLastY = inME.getY();

     myGLCanvas.display();
   }

   public void mouseMoved(MouseEvent inME) { }
   public void mouseReleased(MouseEvent inME) { }

   public void mouseClicked(MouseEvent inME) {
     if (inME.getButton() == MouseEvent.BUTTON1 && inME.getClickCount() == 2)
       myPerspectivePresent = !myPerspectivePresent;
     myGLCanvas.display();
   }
   public void mouseEntered(MouseEvent e) { }
   public void mouseExited(MouseEvent e) { }
 }
}
Offline pdjensen

Senior Newbie





« Reply #12 - Posted 2005-02-13 22:39:35 »

Thanks for the demo - I've been looking for something like this!

I see two problems on a Mac PowerBook with a Radeon 9600.

- maximizing the window does not resize the canvas, although resizing the window usually does. The result is the figures are cropped to their previous window size and ocassionally there is junk in the rest of the window. I also see some occasional shards during resize. It's as if the adjusted viewport sometimes lags behind the window changes.

- The application hangs. I can't find a simple trigger, but resizing, rotating, maximizing, restoring to the previous size when repeated for a while (10 seconds to a few minutes) cause a hang. Here's a thread dump:

    pdj

Quote

> suspend
All threads suspended.
> threads
Group system:
 (java.lang.ref.Reference$ReferenceHandler)0xdf Reference Handler cond. waiting
 (java.lang.ref.Finalizer$FinalizerThread)0xde  Finalizer         cond. waiting
 (java.lang.Thread)0xdd                         Signal Dispatcher running
 (java.lang.Thread)0x403                        Java2D Disposer   cond. waiting
Group main:
 (java.lang.Thread)0x221                        AWT-AppKit        cond. waiting
 (java.lang.Thread)0x39d                        AWT-Shutdown      cond. waiting
 (java.awt.EventDispatchThread)0x3a6            AWT-EventQueue-0  cond. waiting
 (java.lang.Thread)0x3bf                        DestroyJavaVM     running
> wherei all
Signal Dispatcher:
Finalizer:
 [1] java.lang.Object.wait (native method)
 [2] java.lang.ref.ReferenceQueue.remove (ReferenceQueue.java:111), pc = 44
 [3] java.lang.ref.ReferenceQueue.remove (ReferenceQueue.java:127), pc = 2
 [4] java.lang.ref.Finalizer$FinalizerThread.run (Finalizer.java:159), pc = 3
Reference Handler:
 [1] java.lang.Object.wait (native method)
 [2] java.lang.Object.wait (Object.java:429), pc = 2
 [3] java.lang.ref.Reference$ReferenceHandler.run (Reference.java:115), pc = 46
AWT-AppKit:
 [1] java.lang.Object.wait (native method)
 [2] java.lang.Object.wait (Object.java:429), pc = 2
 [3] apple.awt.CToolkit.invokeAndWait (CToolkit.java:1,021), pc = 40
 [4] apple.awt.ComponentModel.handlePaint (ComponentModel.java:344), pc = 28
AWT-Shutdown:
 [1] java.lang.Object.wait (native method)
 [2] java.lang.Object.wait (Object.java:429), pc = 2
 [3] sun.awt.AWTAutoShutdown.run (AWTAutoShutdown.java:259), pc = 32
 [4] java.lang.Thread.run (Thread.java:552), pc = 11
AWT-EventQueue-0:
 [1] java.lang.Object.wait (native method)
 [2] java.lang.Object.wait (Object.java:429), pc = 2
 [3] java.awt.EventQueue.getNextEvent (EventQueue.java:339), pc = 89
 [4] java.awt.EventDispatchThread.pumpOneEventForHierarchy (EventDispatchThread.java:195), pc = 9
 [5] java.awt.EventDispatchThread.pumpEventsForHierarchy (EventDispatchThread.java:184), pc = 26
 [6] java.awt.EventDispatchThread.pumpEvents (EventDispatchThread.java:178  ), pc = 4
 [7] java.awt.EventDispatchThread.pumpEvents (EventDispatchThread.java:170), pc = 3
 [8] java.awt.EventDispatchThread.run (EventDispatchThread.java:100), pc = 9
DestroyJavaVM:
Java2D Disposer:
 [1] java.lang.Object.wait (native method)
 [2] java.lang.ref.ReferenceQueue.remove (ReferenceQueue.java:111), pc = 44
 [3] java.lang.ref.ReferenceQueue.remove (ReferenceQueue.java:127), pc = 2
 [4] sun.java2d.Disposer.run (Disposer.java:116), pc = 3
 [5] java.lang.Thread.run (Thread.java:552), pc = 11
>
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.

Gibbo3771 (12 views)
2014-11-24 19:59:16

trollwarrior1 (35 views)
2014-11-22 12:13:56

xFryIx (74 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50

digdugdiggy (46 views)
2014-11-12 21:10:15

digdugdiggy (40 views)
2014-11-12 21:09:33

kovacsa (66 views)
2014-11-07 19:57:14

TehJavaDev (70 views)
2014-11-03 22:04:50

BurntPizza (68 views)
2014-11-03 18:54:52

moogie (83 views)
2014-11-03 06:22:04
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

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
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!