RoboticsWar Java2D+LWJGL+JOGL

Because JOGL library has no option to turn off vsync, or perhaps I don’t know how Vorax… Thanks for testing the “hyperspeed” :wink:

So is the Java2D input is right, and LWJGL input is not right or both input is not right EgonOlsen? (both refer Y to Z and Z to Y)
If both not right, so this one not my fault :wink:
If LWJGL not work, perhaps this is my fault OR LWJGL team fault ;D

weston, what do you mean by jittery?
It’s perfect here… Anyone experience the same thing (tile movement is jittery??)

Yup, my game engine offer 3 graphics environments right now, at first ppl could only use the standard Java2D, and when finished, if they think they need more performance, switching to OpenGL using LWJGL or JOGL is really easy, no need to change anything, basically the LWJGL and JOGL only add several megs, for testing better stick with Java2D, for deployment, of course I recommend to switch the graphics to LWJGL or JOGL :slight_smile: Adding several megs to the game for much faster performance is affordable :wink:

ok, I should have turned hyperspeed on :stuck_out_tongue: I was up a bit too late when I posted that last night and I was thinking that since I had chosen to use vsync that you would have run the game at a framerate higher then the refresh rate you set it to (basically I assumed that the refresh rate was at 50, even though I’m not sure thats possible on my computer). So I guess it would have been a bit slow being vsynced at running at only 50fps. I noticed that the effect was much worse on jogl/java2d last night and with the framerate up the problem is pretty much gone completely with lwjgl but is still visible on java2d/jogl (both were run with hyperspeed on). It looks like all the tiles are scrolling forward and then they jump back a little bit and then continue moving forward. The overall effect is that they are jerking back and forth while I’m walking around and the screen is scrolling.

If you don’t notice the effect then I wouldn’t worry about it, I tried to warn you before that I’m probably just being picky :wink: (I’m primarily interested in graphics programming, so thats what I tend to notice most).

edit: I believe the lwjgl version actually is running perfectly, the only way the animation would be improved is by using linear texture filtering, but this may not be possible depending on how the tiles are laid out on your texture (some tiles could have colors from neighboring tiles show up on the borders…).

[quote]Because JOGL library has no option to turn off vsync, or perhaps I don’t know how Vorax… Thanks for testing the “hyperspeed” :wink:
[/quote]
Here is some code for turning off vsync at least on windows. Just put it where ever the LWJGL code is:

if (gl.isExtensionAvailable(“WGL_EXT_swap_control”))
((WGL) gl).wglSwapIntervalEXT(0);
else
System.out.println(“VSync control is unavailable”);

I did that test…it’s exactly the way it is.

great, I’ll add a comment to the keyboard javadoc

Updated, please test it once again.
http://goldenstudios.or.id/products/games/bin/robosick.jnlp

Increased refresh rate and color bitdepth in fullscreen mode, increased fps, fixed get display mode, and other.

weston still feel the movement jittery?

Thanks Vorax, the code for setting vsync in JOGL is works nicely, no need to work around that I usually do for many case :slight_smile: simply works!

And this one another test for my Java2D + LWJGL + JOGL engine :
http://goldenstudios.or.id/products/games/bin/demorpgsick.jnlp

For anyone that like applet :slight_smile:
http://goldenstudios.or.id/products/games/bin/robosick.php

http://goldenstudios.or.id/products/games/bin/demorpgsick.php

The applet game only use Java2D, can’t use OpenGL in applet environment.

PS: if you have played the game before please remove the application first from the Java Web Start to remove the cache

LWJGL version looks very nice, good job :wink: The tiles still appear to jerk on java2d/jogl, sorry don’t know what the problem is :frowning:

why can’t opengl be used in an applet? Lwjgl can’t right now cause it doesn’t use awt, but whats stopping someone from using jogl in an applet as long as the jars are signed? I’m curious cause I’ve thought about doing this myself.

RoboticsWar testcase:
Here is my story. I would use Java2D here, then LWJGL with optional mouse cursor warning. JOGL was unplayable on all configs.

Win2k/256MB, Matrox Millennium G400
JDK1.5.0 and JDK1.4.2_04 available. Dont know which one
is being used in the game.

Java2D bufferstrategy on, windowed: 100/100 (50/50 after hypspd on/off switch)
ok, this is the winner
Java2D bufferstrategy on, windowed hyperspd: 120/3000
ok
Java2D bufferstrategy off, windowed: 100/100
well, jerky/jittery scrolling due to a bufferstrategy was off

JOGL fullscreen vsync on: crash
white screen of death at the very start. Switched to fullscreen and white screen was here to stay. Mouse moved ok but thats it.
big problems trying to kill the process
JOGL windowed vsync on: 36/100
animation is jittery a lot, unplayable
JOGL windowed vsync off: 36/100
animation is jittery a lot, unplayable
JOGL windowed vsync on, hyperspd: 36/100
animation is jittery a lot, unplayable

LWJGL fullscreen vsync on: 97/100
ok
ALT+TAB to other window and coming back corrupts the graphics
LWJGL windowed vsync on: 97/100,
ok, BUT steals my mouse cursor :frowning:
LWJGL windowed vsycn off: 97/100
ok, but steals my mouse cursor
LWJGL windowed vync on, hyperspd: 174/3000
unplayable jittery animation and steals mouse cursor

that’s funny, I have the keyboard bug in the applet but not in the application version (french keyboard W=Z)

OpenGL can’t be used in applet cos OpenGL is using dll, and applet can’t load dll. Or am I wrong about that? :stuck_out_tongue:

Still jittery? Even in 100 fps? Is the fps drops somewhat in Java2D/JOGL?

That’s alright whome, hiding mouse pointer in LWJGL indeed makes the mouse pointer gone for sure :slight_smile:
In other environment the mouse is not visible too, isn’t it? So what’s wrong?

I guess you need to uinstall all your JDK whome, and install a fresh new one. Looks like your JDK is a bit weird there, very slow, or is that perhaps because of the graphics card?

Well then JOGL still has the most irritating problem so far :frowning:

Huh keyboard bug in applet? Applet use pure Java2D key function. Are you sure?

JOGL and Java2D did not steal a mouse cursor, which is a must for windowed mode.

LWJGL stole a mouse curson even in windowed mode, which is something that should not happen/be done. I don’t know whether its internal LWJGL feature and not an application driven option.

Maybe I should try on offline without a webstart. Do you have a standalone application bundle available. I could then use several JDKs and see how JOGL behaves. And I could even change a JOGL library versions to see results.

[quote]I don’t know whether its internal LWJGL feature and not an application driven option.
[/quote]
Application driven.

[quote]JOGL and Java2D did not steal a mouse cursor, which is a must for windowed mode.
[/quote]
It is? - wonder why all those games got it wrong then…
It should steal the cursor, unless the cursor is of relevance. Nothig more annoying than having a cursor block the view.

JOGL and Java2D use the same core, the Java AWT.
JOGL is only canvas that replace java.awt.Canvas.
So the basic is same. Only set the mouse pointer to 1x1 size transparent.

For why LWJGL steal the mouse cursor in windowed mode, ask the LWJGL team :stuck_out_tongue:

Offline? Download the jar one by one :stuck_out_tongue:
The game
http://goldenstudios.or.id/products/games/bin/robosick.jar

GTGE
http://goldenstudios.or.id/products/games/bin/golden_0_2_1.jar
http://goldenstudios.or.id/products/games/bin/GTGE_add_ons.jar

LWJGL
http://goldenstudios.or.id/products/games/bin/lwjgl.jar
http://goldenstudios.or.id/products/games/bin/lwjgl-windows.jar

JOGL
http://goldenstudios.or.id/products/games/bin/jogl.jar
http://goldenstudios.or.id/products/games/bin/jogl-natives-win32.jar

And run robosick.jar, it should do

[quote] For why LWJGL steal the mouse cursor in windowed mode, ask the LWJGL team
[/quote]
It does so, because you asked it to do it by calling Mouse.setGrabbed(true);

??? So there is another way to hide mouse pointer in LWJGL, I don’t know that?
How to do that?
The problem here is, when in the game (windowed mode), the mouse pointer not shown, but when outside the game window, the mouse pointer shown, just like Java2D.

LWJGL defaults to showing the cursor in windowed mode, and “stealing” it in fullscreen mode.
If you don’t have a cursor when playing in windowed mode, it’s because you called the setGrabbed method - or you set the cursor to a transparent one.

[quote]??? So there is another way to hide mouse pointer in LWJGL, I don’t know that?
How to do that?
The problem here is, when in the game (windowed mode), the mouse pointer not shown, but when outside the game window, the mouse pointer shown, just like Java2D.
[/quote]
I think what you are after is setting a transparent cursor using org.lwjgl.input.Mouse.setNativeCursor(Cursor cursor).

Yup I setGrabbed both in windowed and fullscreen mode because I don’t want the mouse cursor visible.
But the problem, once again, in windowed mode, even the mouse outside the game window, the cursor still not visible.
In Java2D, when the mouse INSIDE the game window the mouse cursor NOT VISIBLE, BUT OUTSIDE the game window the mouse cursor BACK TO NORMAL (VISIBLE)
In LWJGL, even outside the game window, the mouse cursor still not visible, is there another way to set the mouse cursor not visible in LWJGL instead of setGrabbed method? And makes the mouse cursor only not visible while IN THE GAME WINDOW?

For a better explanation, try out the roboticswar game and see the difference between Java2D/JOGL windowed mode and LWJGL windowed mode mouse cursor.

In the javadoc it said, “if native cursor supported” what that’s suppose to mean? Is it only works in Windows OS?
And how to create the org.lwjgl.input.Cursor? I don’t see image or buffered image in constructor parameter.
Sorry I’m very new to LWJGL, I learn LWJGL plus JOGL starting from two weeks ago.

As I said in the previous post: use Mouse.setNativeCursor. It will change the mouse image when the mouse cursor is inside the lwjgl window. If you set it with a transparent image the mouse cursor will be invisible when it is inside the lwjgl window. When you move it outside it will be visible, showing the cursor the normal way by the os.

Hell, I’ll even give you the some source:

import java.nio.*;
import org.lwjgl.input.Mouse;
import org.lwjgl.input.Cursor;


/**
 * Mouse cursor utility class.
 */
public class MouseCursor {


      /**
       * Makes the native cursor transparent. Does not grab the mouse.
       */
      public static void hideNativeCursor() {
            int minSize = Cursor.getMinCursorSize();
            Cursor cursor = createCursor(new int[minSize*minSize], minSize, minSize, 0, 0);
            enableNativeCursor(cursor);
      }


      /**
       * Sets the native curosr to the image specified by the parameters. The
       * MouseCursor position is set to the middle of the window.
       */
      public static void enableNativeCursor(Cursor cursor) {
            try {
                  if (cursor != null && (Cursor.getCapabilities() & Cursor.CURSOR_ONE_BIT_TRANSPARENCY ) != 0) {
                        Mouse.setNativeCursor(cursor);
                  } else {
                        System.out.println("No HW cursor support!");
                        Mouse.setNativeCursor(null);
                  }
            } catch (Exception e) {
                  System.out.println("Exception setting hardware cursor:"+e.getMessage());
            }
      }


      /**
       * Creates a cursor.
       * @return the created cursor or null if creating failed.
       */
      public static Cursor createCursor(int data[], int w, int h, int x, int y) {
            try {
                  if ((Cursor.getCapabilities() & Cursor.CURSOR_ONE_BIT_TRANSPARENCY ) != 0) {
                        ByteBuffer scratch = ByteBuffer.allocateDirect(4 * data.length);
                        for (int i=0; i<data.length; i++) {
                              if ((data[i]>>>24) > 0) {
                                    scratch.put((byte) 0xff);
                                    scratch.put((byte) ((data[i]>>16) & 0xff));
                                    scratch.put((byte) ((data[i]>>8) & 0xff));
                                    scratch.put((byte) ((data[i]) & 0xff));
                              } else {
                                    scratch.putInt(0);
                              }
                        }
                        
                        scratch.rewind();
                        return new Cursor(w,h, x, y, 1, scratch.asIntBuffer(), null);
                  }
            } catch (Exception e) {
                  System.out.println("Exception creating cursor:"+e.getMessage());
            }

            return null;
      }
}

To use it you:

  1. Do NOT grab the mouse
  2. Call MouseCursor.hideNativeCursor()

I think the code uses Lwjgl 0.95. If you use another version of lwjgl it might not compile because they keep moving stuff around. Then you have to search the javadocs for it.