http://GameProgrammer.Com

Programming

GP Mailing List
     Thread Index
     Date Index

ATXGPSIG List
     Thread Index
     Date Index

Google
>

Home

Wise2Food



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

GP: Java, DirectX, and hwnd's



Hello,

	I'm attempting to write a simple 2D graphics library to be used
for gaming purposes.  I dislike how disorganized and unmanageable C/C++
code can be, but at the same time, it's the only high-level language that
is fairly portable and can give me direct access to hardware resources.
On the other hand, Java's a language that's much more organized and easy
to code in, but it's pretty slow and you can't access hardware directly.
So I thought about the possibility of using the Java Native Interface with
platform-specific C code to create this gaming library--the C code can be
used for hardware access (routing abstract function calls to DirectX,
Xlib, Allegro, etc) as well as any speed-critical code, and the Java can
be used to code the game logic, as a sort of scripting engine.

	I found an article on Gamasutra that talks about the issues
involved in doing something like this... There seem to be two routes to
take with this idea: making a Java application that interfaces with a
shared library (a DLL, in the case of Windows) for native code, or making
a C/C++ application that launches a Java Virtual Machine as an embedded
system.  From a conceptual standpoint, the Java app would seem to be the
most flexible way to go, for a number of reasons that I won't explain
right now, but my main problem with this on the Windows platform is the
issue of window handles (HWND's).  In a native win32 app, the WinMain()
function is always passed a window handle by the operating system.  For
DirectX to operate in full-screen mode, it needs to call a function
that sets the cooperative level (SetCooperativeLevel()); that function
requires a non-null window handle as a parameter.  Because JNI is
completely platform-independent, there's no way for me to get any kind of
window handle here (e.g., I can't use the AWT or Swing to get one).

	Is there any Windows API call that can give me such a window
handle, or can it only be given to a native win32 app?  If not, I guess
I'll have to make a win32 app that launches an embedded JVM.  If I
end up making it a Java application, I hope I don't run into this
kind of problem on another platform.  Thanks for your input, and if
you've ever done any work with JNI and would like to give me any tips, it
would be very helpful too.

			Atul

P.S. -- No, I'm not using MS J++'s interface to COM to access DirectX...
For one thing, I don't have J++, and I'd also like to make this as
cross-platform as possible, which MS is not well-known for.

=================================================================
To SUBSCRIBE or UNSUBSCRIBE please visit
http://gameprogrammer.com/mailinglist.html