Full screen troubles.

I’m using slick2d, but I want fullscreen without literally stretching the display to the point where it’s ugly and unrecognizable…the resolution is 600x500(Strange I know), but I need it to take up the whole screen, seeing as I’m entering this in a contest, and a game that can’t go fullscreen won’t look so hot.

Anyway, any thoughts? I’m so far in, editing all of the values for the menu select and what-not is relatively out of the question; unless I would have to edit the ENTIRE thing, which would take longer than I’d like to spend.

A quick goolging lead me to this:
http://slick.javaunlimited.net/viewtopic.php?p=6057
Is that what you’re looking for.

Not exactly.
But it’s more than perfect, thank you very much.

Not that i’ve really ever used slick properly, but i’d encourage you to literally just type what you want to find out into google, I almost always find something useful and plus it saves you a heap of time asking people.

I never had any trouble, setting the window resolution to my monitors resolution, with the fullscreen flag set to true. Ofcourse, that would require some tinkering, since not everyone is using the same resolution.

try {
Display.setInitialBackground(1, 1, 1);

         JFrame frame = new JFrame("Nusarium");
         frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

         CanvasGameContainer container;
         container = new CanvasGameContainer(new Game());
         container.setPreferredSize(new Dimension(800, 600)); //NOTE: Usable 640x480
         container.getContainer().setTargetFrameRate(60);
         container.getContainer().setShowFPS(false);
         frame.getContentPane().add(container);
         frame.pack();
         frame.setLocationRelativeTo(null);
         frame.setResizable(true);
         frame.setMinimumSize(new Dimension(800, 600));
         frame.setVisible(true);
         container.start();
         
         frame.addWindowListener(new WindowAdapter(){
        	  public void windowClosing(WindowEvent we, CanvasGameContainer container){
        	  container.getContainer().exit();
        	  System.exit(0);
        	  }
         });

This is what I got, now, I need it to center the Canvas, and also slightly stretch it as well. Is there a way to do this? If not, how do I fully stretch it, and how do I simply center as if I were doing both seperately? Thank you.

[quote]I’m using slick2d, but I want fullscreen without literally stretching the display to the point where it’s ugly and unrecognizable…the resolution is 600x500(Strange I know), but I need it to take up the whole screen, seeing as I’m entering this in a contest, and a game that can’t go fullscreen won’t look so hot.

Anyway, any thoughts? I’m so far in, editing all of the values for the menu select and what-not is relatively out of the question; unless I would have to edit the ENTIRE thing, which would take longer than I’d like to spend.
[/quote]
For convenience, Slick provides a utility class for this purpose: ScalableGame. Check out ScalableGameTest.

For convenience, Slick provides a utility class for this purpose: ScalableGame. Check out ScalableGameTest.
[/quote]
Thank you.
EDIT: The graphics look a little pixel-y in the stretched mode. Is there a way to center the container to the middle of the window when it’s stretched? I’ll add it as an option.
EDIT, EDIT:

try {
			 Display.setInitialBackground(1, 1, 1);
			 
	         JFrame frame = new JFrame("Nusarium");
	         frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

	         CanvasGameContainer container;
	         container = new CanvasGameContainer(new ScalableGame(new Game(), 600, 500));
	         container.setPreferredSize(new Dimension(600, 500)); //NOTE: Usable 640x480
	         container.getContainer().setTargetFrameRate(60);
	         container.getContainer().setShowFPS(false);
	         frame.getContentPane().add(container);
	         frame.pack();
	         frame.setLocationRelativeTo(null);
	         frame.setResizable(true);
	         frame.setMinimumSize(new Dimension(600, 500));
	         frame.setVisible(true);
	         container.start();
	         
	         frame.addWindowListener(new WindowAdapter(){
	        	  public void windowClosing(WindowEvent we, CanvasGameContainer container){
	        	  container.getContainer().exit();
	        	  System.exit(0);
	        	  }
	         });
	    
	         
	      } catch (SlickException ex) {
	         ex.printStackTrace();
	      }

For some reason, the javaw.exe doesn’t shut down when I exit the window. How do I fix that as well?

bump

Why are you using CanvasGameContainer?

Just use ScalableGame with an app container like in ScalableTest.
https://bitbucket.org/kevglass/slick/src/d847f8121469/trunk/Slick/src/org/newdawn/slick/tests/ScalableTest.java

You can’t resize the window to whatever you wish that way, you have to have change it to designated sizes within the code. As when I implement it into an app container, it doesn’t allow me to resize the window.

Is there no way to center the container inside the window though? That’s really all I need to do at this point…along with the proper shutdown of javaw.exe.

Solution:

package slicktests;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;

import org.newdawn.slick.BasicGame;
import org.newdawn.slick.CanvasGameContainer;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;

public class CanvasGameTest extends BasicGame {
   private GameContainer container;

   public CanvasGameTest () {
      super("Canvas Game Test");
   }

   public static final int GAME_WIDTH = 800;
   public static final int GAME_HEIGHT = 600;

   public void init (GameContainer container) throws SlickException {
      this.container = container;
   }

   public void update (GameContainer container, int delta) throws SlickException {
   }

   public void render (GameContainer container, Graphics g) throws SlickException {
	   g.setColor(Color.red);
	   g.fillRect(0, 0, GAME_WIDTH, GAME_HEIGHT);
   }

   public void keyPressed (int key, char c) {
      if (key == Input.KEY_ESCAPE) {
    	  container.exit(); 
    	  System.exit(0);
      }
   }

   public static void main (String[] argv) {
      try {
    	 final CanvasGameContainer container = new CanvasGameContainer(new CanvasGameTest());
         JFrame frame = new JFrame("Test");
         frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
         frame.addWindowListener(new WindowAdapter(){
             public void windowClosing(WindowEvent we){
            	 container.getContainer().exit();
            	 System.exit(0);
             }
         });
         frame.getContentPane().setBackground(java.awt.Color.black);
         Dimension size = new Dimension(GAME_WIDTH, GAME_HEIGHT);
         container.setPreferredSize(size);
         container.setMinimumSize(size);
         container.setMaximumSize(size);
         
         GridBagConstraints c = new GridBagConstraints();
         c.fill = GridBagConstraints.CENTER;
         frame.getContentPane().setLayout(new GridBagLayout());
         frame.getContentPane().add(container, c);
         
         frame.pack();
         frame.setResizable(true);
         frame.setLocationRelativeTo(null);
         container.requestFocusInWindow();
         frame.setVisible(true);
         container.start();
      } catch (SlickException ex) {
         ex.printStackTrace();
      }
   }
}

Thanks. I think it worked.
EDIT:
I’m still having trouble getting javaw.exe to shut off, and turning off the screen disposing just leaves the window up too to add to insult.
EDIT, EDIT:
Fixed by modifying some lines. Here it is for anyone else who may come across this in the future:

frame.addWindowListener(new WindowAdapter(){
	        	  public void windowClosing(WindowEvent we){
	        	  Display.destroy();
	        	  System.exit(0);
	        	  }
	         });

Do that anywhere you plan on turning the game off at, and change this too:

frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

to

frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

How about JFrame.EXIT_ON_CLOSE ? :wink:

I think it would be wise to destroy GL/AL context and clean up resources before quitting JVM. If nothing else, for good practice…

windowClosing is still called when you set that. However, it eliminates the need for you to abruptly end the JVM using System.exit(0);

It doesn’t work. Try it yourself. The window stays open.

No I meant when you use JFrame.EXIT_ON_CLOSE, windowClosing is called right before the JVM ends. This way, you don’t have to use System.exit(0);

Ahh, I see. I’ll keep this in mind in the future. Thanks for the advice.