Programming => Lightweight Java Gaming Library => Topic started by: zpixel on October 13, 2003, 13:35:14

Title: Question about mouse input
Post by: zpixel on October 13, 2003, 13:35:14
Hi people!

First hello to all - this is my first post on this forum.

I'm a kind of a newbie both to this forum & to lwjgl; so I have some questions - hope someone have patience to read & maybe answer =).

lwjgl seems promising to me; it's quite easy and little api, so I like it so long, especially since I'm looking for api that depends as little as possible on awt & swing.
For now I have done just those simple nehe demos that comes with lwjgl and wrote some own simple demos to learn more about lwjgl

but since I have mostly been programming on a bit higher level of abstraction I have a little problem to understand some details especially about polling mouse =) - ehm; so here is my question:

1) how do u use mouse? since lwjgl Mouse gives you input as a change in coordinates since last time - how can I get position in window? I want to program some widgets and will need to develop some techinque for picking, so I need to understand how can I convert deltas to some coordinates either relative to Window or to screen coordinates. I know this is lame newbie question but I really don't understand what ones get from mouse dx & dy. For example when mouse enters lwjgl window - I must somehow get coordinates to start tracking from - so how do I get those? Does mouse track in lwjgl window coordinates or screen coordinates .... ehh - by now you probably understan what I don't understand =)

I have some other questions too:

2) is anyone tried to use awtevents with lwjgl? Is there anyway to add some event listeners and dispatchers to lwjgl? Theoretically it should be possible, to develop some kind of "container" or "component" (not those that comes with awt, but to develop such from scratch for use with lwjgl) and add a listener to it and later use it with lwjgl window.

3) what is procedure for compiling lwjgl &what are other dependences to java features?
I would like to compile lwjgl with gcj (hard to guess :) ). as I saw from the forum, not anyone seems to done it yet. since lwjgl doesn't depend on awt or swing it should be possible to do that at least in theory. libjava has nio implemented, awt event and supports jni calls.
So where do I start compiling lwjgl?  Even if I compile just with javac how do u guys compile lwjgl ... It would be nice if someone wrote a few words how to do that.
Title: Question about mouse input
Post by: elias on October 13, 2003, 15:17:13
1)  When you create the mouse it will be captured within the window and the cursor will be hidden. And the deltas are just that - deltas since last Mouse.poll(). That mode is common in FPS genre where you don't want to look around only to be stopped because your cursor hits the window border. However, to support cursor oriented games like RTS, you have another mode of operation:

a) create a org.lwjgl.input.Cursor
b) call Mouse.setNativeCursor

now, the cursor appears with your custom image, but you still only have the deltas. How is that possible? Native cursors are implemented such that when they are first enabled with Mouse.setNativeCursor, the cursor is reset to the bottom left corner of the window (changed in CVS version to the middle). You can use that information along with the deltas to precisely track the cursor location. There's no leave/enter window events though.

There's a NativeCursor example in the examples part of LWJGL.

2) I'm not exactly sure what you mean there. Something like JOGL maybe?

3) As far as I know, the gcj implementation of nio is not yet complete. But if it is, you should be able to compile lwjgl applications. There's a guy on the javagaming.org board that tried it. With a standard SUN java, you can jsut use

javac -cp lwjgl.jar <javafile>

After getting the lwjgl.jar and native libs from lwjgl.org. Runing lwjgl applications is done with

java -Djava.library.path=. -cp lwjgl.jar:. <classfile>

where . is directory containing the native libs (liblwjgl.so an libopenal.so for linux, lwjgl.dll and lwjglaudio.dll for windows)

Hope that helps.

 - elias
Title: Question about mouse input
Post by: zpixel on October 14, 2003, 00:23:47
thnks for fast answer

yes it helps; I have got the thing about mouse input  :D

for 2)
I was just thinking about possibility of using awtevents for communication between different components; I'm going to develop some vidgets for drawing uml diagrams (and probably some ordinary widgets for ui) as part of a schoolwork. I would like to make them opengl accelerated - just for fun  :shock:
it would be nice to make them talk through java events so that I can skip programming that part

for this purpose jogl is better suited - it is working with both awt & swing already - but I like to make things myself; and as I said - would like to get it compile with gcj - so I will skip graphical part of awt (and thus jogl) at least for a while

3) I ment rather how to compile lwjgl itself - I already know how to compile and run lwjgl applications, I guess I expressed myself bad (english is not my first lang - nor second for that matter  :oops:  ).

thnks for help man
Title: Question about mouse input
Post by: elias on October 14, 2003, 08:00:37
You can probably use AWT events, although lwjgl is not going to help you there.  You have to create a class that fetches input from the input classes and create events itself. Shouldn't be too hard though - in fact, that's what we do in our game. The good part about doing it yourself is getting rid of those overrated threads.

About compiling LWJGL - you have to fetch the sources from cvs through the instructions at lwjgl.org->cvs. Then you can compile lwjgl.jar and lwjgl_examples.jar with ant package (assuming you installed ant). Then to compile the native part on linux you'll cd to src/native and do ./autogen.sh && ./configure (maybe append --configure-debug) && make. Compiling on win32 is more complicated.

 - elias
Title: Question about mouse input
Post by: thinker on October 14, 2003, 20:29:38
Quote from: "elias"

There's a NativeCursor example in the examples part of LWJGL.

examples? I downloaded version 0.7 and i don't see any examples or lwjgl_examples.jar. Are the examples only available from CVS?
Title: Question about mouse input
Post by: Matzon on October 15, 2003, 05:35:40
it's called lwjgl_test.jar :)
Title: Question about mouse input
Post by: zpixel on October 16, 2003, 23:38:00
thnks elias

that is what I roughly ment;
I already tried to make some tests with awt events and it seems to be possible - I didn't get it right yet - but I did get something (wierd) , which is alwayz better then noting  :shock:

thnks for info about compiling lwjgl - that was what I wanted to know.