Sign in to follow this  
kentylarsson

[java] What is best practise when using the 1.4 fullscreen API?

Recommended Posts

Hi! I have never written a game or multimedia application in Java before, but i do have programming experience as well as knowledge of terms such as double buffering (and other screen update methods) and know Swing a bit. I wanted to ask you guys/girls what would be best practise when programming a game which i want to utilize the fullscreen API. I have not found much in the area of tutorials regarding the fullscreen API, BufferedStrategy and such things. My questions are: Which class should i extend in my main game class? At present i extend JFrame which seem to work. Altough i have concerns as i would like the game to start in windowed mode if the fullscreen API is unavailable. What should i think of to make this as easy as possible? I have heard that the timer is unprecise in Java 1.4. What should i use as my timer? I read somewhere that there was a good timer in Java 3D? Or should i go directly to Java 1.5? I would like as many as possible to be able to run the game, but i am willing to sacrifice people with older Java versions than 1.4 as the fullscreen API is not available otherwise. Are there any other things that would be of use for me to know? I basically just want to draw images to a (double buffered) screen and recieve input from the keyboard so that the game can be controlled. Hope that some of you knowledgeable people can find time to help out a poor noob like me. :)

Share this post


Link to post
Share on other sites

I'm using Frame at the moment because I'm using JOGL with a GLCanvas, but I don't see that using JFrame would pose any problems in either fullscreen or windowed mode. I create the Frame and then query if fullscreen is available for the decive. If so, and if fullscreen is requested then I undecorate the window and switch to fullscreen. Seems to work fine in both modes. Heres my setup code:


env = GraphicsEnvironment.getLocalGraphicsEnvironment();
device = env.getDefaultScreenDevice();

oldDisplayMode = device.getDisplayMode();

if (device.isFullScreenSupported())
{
Dimension newDim = new Dimension(modeWidth,modeHeight);
displayMode = findDisplayMode(newDim,oldDisplayMode.getBitDepth(), oldDisplayMode.getRefreshRate());

if (displayMode != null && fullscreen)
{
newDim.width = displayMode.getWidth();
newDim.height = displayMode.getHeight();
frame.setResizable(false);
frame.setUndecorated(true);
device.setFullScreenWindow(frame);
device.setDisplayMode(displayMode);
frame.setLocation(0, 0);
frame.setSize(displayMode.getWidth(), displayMode.getHeight());
canvas.setSize(displayMode.getWidth(), displayMode.getHeight());
}
}


I'm sure there are other ways to do it correctly though.
For your timer needs, you can use the Java3D timer if you want. However, for redistribution purposes, you have to resdistribute the entire Java3D distrib if you want to use any of it at all. I used to use it, now I'm using GageTimer which does the job. A quick google will get a link for you. It fixes up the errors in timing on 1.4 on windows and will use the 1.5 nanotimer if available.

Never used Java2D so I can't help you out there, you might want to consider using LWJGL instead though. Its a binding for OpenGL for java and a sound/input library aswell. Several 2D games have been made using it (www.puppygames.net)

D.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this