Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  LWJGL DisplayMode Change  (Read 657 times)
0 Members and 1 Guest are viewing this topic.
Offline Seiya02

JGO Coder


Medals: 4
Projects: 4
Exp: 5 years


No Text Here :x


« Posted 2013-10-06 00:05:39 »

Hey, I'm changing the DisplayMode of my Display while rendering (Like in an Options Menu) with Display.setDisplayMode(dm);
The Problem i get from this is, that the Gui I have doesn't get resized so that it fits the Display, it just stays at it's previous size (800x600 by default).
If i set some other DisplayMode at the beginning it works fine but when I change it while the Display is created it just gets messed up.

my init Code:
1  
2  
3  
4  
5  
      GL11.glMatrixMode(GL11.GL_PROJECTION);
      GL11.glLoadIdentity();
      GL11.glOrtho(0, 800, 0, 600, -1, 1);
      GL11.glMatrixMode(GL11.GL_MODELVIEW);
      GL11.glLoadIdentity();


and when i change the displaymode and render a white Quad (0,0,800,600) it shows up like this:


 Any ideas how to fix it?

Edit: after Changing the DisplayMode calling GL11.glViewPort(0,0,Display.getWidth(),Display.getHeight); fixed it Cheesy
Offline Seiya02

JGO Coder


Medals: 4
Projects: 4
Exp: 5 years


No Text Here :x


« Reply #1 - Posted 2013-10-06 00:06:33 »

btw, that blue color is my clear color Cheesy
Offline SHC
« Reply #2 - Posted 2013-10-06 04:22:22 »

I use this and it works fine for me.

1  
2  
3  
4  
5  
if (isKeyDown(KEY_F) && !isKeyDown(KEY_LSHIFT))
    setDisplayMode(1600, 900, true);
       
if (isKeyDown(KEY_F) && isKeyDown(KEY_LSHIFT))
    setDisplayMode(800, 600, false);

And the method
setDisplayMode()
is

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
public static boolean setDisplayMode(int width, int height, boolean fullscreen)
{
    // return if requested DisplayMode is already set
   if ((Display.getDisplayMode().getWidth() == width) && (Display.getDisplayMode().getHeight() == height) && (Display.isFullscreen() == fullscreen))
        return true;

    try
    {
        // The target DisplayMode
       DisplayMode targetDisplayMode = null;

        if (fullscreen)
        {
            // Gather all the DisplayModes available at fullscreen
           DisplayMode[] modes = Display.getAvailableDisplayModes();
            int freq = 0;

            // Iterate through all of them
           for (DisplayMode current: modes)
            {
                // Make sure that the width and height matches
               if ((current.getWidth() == width) && (current.getHeight() == height))
                {
                    // Select the one with greater frequency
                   if ((targetDisplayMode == null) || (current.getFrequency() >= freq))
                    {
                        // Select the one with greater bits per pixel
                       if ((targetDisplayMode == null) || (current.getBitsPerPixel() > targetDisplayMode.getBitsPerPixel()))
                        {
                            targetDisplayMode = current;
                            freq = targetDisplayMode.getFrequency();
                        }
                    }

                    // if we've found a match for bpp and frequency against the
                   // original display mode then it's probably best to go for
                   // this one since it's most likely compatible with the monitor
                   if ((current.getBitsPerPixel() == Display.getDesktopDisplayMode().getBitsPerPixel()) && (current.getFrequency() == Display.getDesktopDisplayMode().getFrequency()))
                    {
                        targetDisplayMode = current;
                        break;
                    }
                }
            }
        }
        else
        {
            // No need to query for windowed mode
           targetDisplayMode = new DisplayMode(width, height);
        }

        if (targetDisplayMode == null)
        {
            System.out.println("Failed to find value mode: " + width + "x" + height + " fs=" + fullscreen);
            return false;
        }

        // Set the DisplayMode we've found
       Display.setDisplayMode(targetDisplayMode);
        Display.setFullscreen(fullscreen);

        System.out.println("Selected DisplayMode: " + targetDisplayMode.toString());

        // Generate a resized event
       instance.resized();

        return true;
    }
    catch (LWJGLException e)
    {
        System.out.println("Unable to setup mode " + width + "x" + height + " fullscreen=" + fullscreen + e);
    }

    return false;
}

Hope this helps.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Seiya02

JGO Coder


Medals: 4
Projects: 4
Exp: 5 years


No Text Here :x


« Reply #3 - Posted 2013-10-06 11:50:58 »

Tested that, didn't work :/ though what is that "instance.resized" ? what does it do?
Offline SHC
« Reply #4 - Posted 2013-10-06 12:12:41 »

Instance is the reference to the game. Resized is a method that is called whenever the display size changes.

Offline Seiya02

JGO Coder


Medals: 4
Projects: 4
Exp: 5 years


No Text Here :x


« Reply #5 - Posted 2013-10-06 12:25:30 »

Can you tell me, what that method does? cause the code without that method isn't working (results in the same)
Offline SHC
« Reply #6 - Posted 2013-10-06 12:46:04 »

It just resets the viewport settings.

Offline Seiya02

JGO Coder


Medals: 4
Projects: 4
Exp: 5 years


No Text Here :x


« Reply #7 - Posted 2013-10-06 12:47:56 »

ah ok, Thx Cheesy
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CogWheelz (15 views)
2014-08-01 22:53:16

CogWheelz (15 views)
2014-08-01 22:51:43

CopyableCougar4 (15 views)
2014-08-01 19:37:19

CogWheelz (19 views)
2014-07-30 21:08:39

Riven (27 views)
2014-07-29 18:09:19

Riven (16 views)
2014-07-29 18:08:52

Dwinin (14 views)
2014-07-29 10:59:34

E.R. Fleming (35 views)
2014-07-29 03:07:13

E.R. Fleming (13 views)
2014-07-29 03:06:25

pw (44 views)
2014-07-24 01:59:36
Resources for WIP games
by CogWheelz
2014-08-01 18:20:17

Resources for WIP games
by CogWheelz
2014-08-01 18:19:50

List of Learning Resources
by SilverTiger
2014-07-31 18:29:50

List of Learning Resources
by SilverTiger
2014-07-31 18:26:06

List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!