mirror of
https://github.com/shadowfacts/lwjgl2-arm64.git
synced 2026-04-06 06:53:59 +00:00
New window sizing & undecorated code
This commit is contained in:
parent
4a513f9329
commit
37262e6727
5 changed files with 312 additions and 27 deletions
|
|
@ -80,6 +80,9 @@ public final class Window {
|
|||
|
||||
/** Fullscreen */
|
||||
private static boolean fullscreen;
|
||||
|
||||
/** Undecorated */
|
||||
private static boolean undecorated;
|
||||
|
||||
/** Tracks VBO state for the window context */
|
||||
private static VBOTracker vbo_tracker;
|
||||
|
|
@ -102,6 +105,24 @@ public final class Window {
|
|||
private Window() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the X coordinate of the window (always 0 for fullscreen)
|
||||
*/
|
||||
public static int getX() {
|
||||
if (!isCreated())
|
||||
throw new IllegalStateException("Cannot get X on uncreated window");
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the Y coordinate of the window (always 0 for fullscreen)
|
||||
*/
|
||||
public static int getY() {
|
||||
if (!isCreated())
|
||||
throw new IllegalStateException("Cannot get Y on uncreated window");
|
||||
return y;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the width of the window
|
||||
*/
|
||||
|
|
@ -326,6 +347,7 @@ public final class Window {
|
|||
if (isCreated())
|
||||
throw new IllegalStateException("Only one LWJGL window may be instantiated at any one time.");
|
||||
Window.fullscreen = true;
|
||||
Window.undecorated = true;
|
||||
Window.x = 0;
|
||||
Window.y = 0;
|
||||
Window.width = Display.getWidth();
|
||||
|
|
@ -352,7 +374,29 @@ public final class Window {
|
|||
* the minimum requirements could not be met satisfactorily
|
||||
*/
|
||||
public static void create(String title, int x, int y, int width, int height, int bpp, int alpha, int depth, int stencil) throws LWJGLException {
|
||||
create(title, x, y, width, height, bpp, alpha, depth, stencil, 0);
|
||||
create(title, x, y, width, height, false, bpp, alpha, depth, stencil);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a window. If the underlying OS does not have "floating" windows, then a fullscreen
|
||||
* display will be created instead. If this fails too then an LWJGLException will be thrown.
|
||||
* If the window is created fullscreen, then its size may not match the specified size
|
||||
* here.
|
||||
* <p>The window created will be set up in orthographic 2D projection, with 1:1 pixel ratio with GL coordinates.
|
||||
* @param title The title of the window
|
||||
* @param x The position of the window on the x axis. May be ignored.
|
||||
* @param y The position of the window on the y axis. May be ignored.
|
||||
* @param width The width of the window's client area
|
||||
* @param height The height of the window's client area
|
||||
* @param undecorated A hint to specify that the window should not have OS decorations such as drag bar and close box
|
||||
* @param bpp Minimum bits per pixel
|
||||
* @param alpha Minimum bits per pixel in alpha buffer
|
||||
* @param depth Minimum bits per pixel in depth buffer
|
||||
* @throws LWJGLException if the window could not be created for any reason; typically because
|
||||
* the minimum requirements could not be met satisfactorily
|
||||
*/
|
||||
public static void create(String title, int x, int y, int width, int height, boolean undecorated, int bpp, int alpha, int depth, int stencil) throws LWJGLException {
|
||||
create(title, x, y, width, height, undecorated, bpp, alpha, depth, stencil, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -377,9 +421,37 @@ public final class Window {
|
|||
*/
|
||||
public static void create(String title, int x, int y, int width, int height, int bpp, int alpha, int depth, int stencil, int samples)
|
||||
throws LWJGLException {
|
||||
|
||||
create(title, x, y, width, height, false, bpp, alpha, depth, stencil, samples);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a window. If the underlying OS does not have "floating" windows, then a fullscreen
|
||||
* display will be created instead. If this fails too then an LWJGLException will be thrown.
|
||||
* If the window is created fullscreen, then its size may not match the specified size
|
||||
* here.
|
||||
* <p>The window created will be set up in orthographic 2D projection, with 1:1 pixel ratio with GL coordinates.
|
||||
* @param title The title of the window
|
||||
* @param x The position of the window on the x axis. May be ignored.
|
||||
* @param y The position of the window on the y axis. May be ignored.
|
||||
* @param width The width of the window's client area
|
||||
* @param height The height of the window's client area
|
||||
* @param undecorated A hint to specify that the window should not have OS decorations such as drag bar and close box
|
||||
* @param bpp Minimum bits per pixel
|
||||
* @param alpha Minimum bits per pixel in alpha buffer
|
||||
* @param depth Minimum bits per pixel in depth buffer
|
||||
* @param stencil Minimum bits per pixel in stencil buffer
|
||||
* @param samples Minimum samples in multisample buffer (corresponds to GL_SAMPLES_ARB in GL_ARB_multisample spec).
|
||||
Pass 0 to disable multisampling. This parameter is ignored if GL_ARB_multisample is not supported.
|
||||
* @throws LWJGLException if the window could not be created for any reason; typically because
|
||||
* the minimum requirements could not be met satisfactorily
|
||||
*/
|
||||
public static void create(String title, int x, int y, int width, int height, boolean undecorated, int bpp, int alpha, int depth, int stencil, int samples)
|
||||
throws LWJGLException {
|
||||
if (isCreated())
|
||||
throw new IllegalStateException("Only one LWJGL window may be instantiated at any one time.");
|
||||
Window.fullscreen = false;
|
||||
Window.undecorated = undecorated;
|
||||
Window.x = x;
|
||||
Window.y = y;
|
||||
Window.width = width;
|
||||
|
|
@ -399,6 +471,7 @@ public final class Window {
|
|||
int width,
|
||||
int height,
|
||||
boolean fullscreen,
|
||||
boolean undecordated,
|
||||
int bpp,
|
||||
int alpha,
|
||||
int depth,
|
||||
|
|
@ -407,7 +480,7 @@ public final class Window {
|
|||
throws LWJGLException;
|
||||
|
||||
private static void createWindow(int bpp, int alpha, int depth, int stencil, int samples) throws LWJGLException {
|
||||
nCreate(title, x, y, width, height, fullscreen, bpp, alpha, depth, stencil, samples);
|
||||
nCreate(title, x, y, width, height, fullscreen, undecorated, bpp, alpha, depth, stencil, samples);
|
||||
context = new Window();
|
||||
makeCurrent();
|
||||
|
||||
|
|
@ -548,5 +621,60 @@ public final class Window {
|
|||
|
||||
private static native void nSetVSyncEnabled(boolean sync);
|
||||
|
||||
/**
|
||||
* Set the window's location. This is a no-op on fullscreen windows.
|
||||
* @param x, y The new window location
|
||||
*/
|
||||
public static void setLocation(int x, int y) {
|
||||
if (!isCreated())
|
||||
throw new IllegalStateException("Cannot move uncreated window");
|
||||
if (fullscreen) {
|
||||
return;
|
||||
}
|
||||
Window.x = x;
|
||||
Window.y = y;
|
||||
nReshape(Window.x, Window.y, Window.width, Window.height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the window's size. This is a no-op on fullscreen windows.
|
||||
* The window's size is clipped to the screen bounds.
|
||||
* @param width, height The new window dimensions
|
||||
*/
|
||||
public static void setSize(int width, int height) {
|
||||
if (!isCreated())
|
||||
throw new IllegalStateException("Cannot resize uncreated window");
|
||||
if (fullscreen) {
|
||||
return;
|
||||
}
|
||||
Window.width = width;
|
||||
Window.height = height;
|
||||
nReshape(Window.x, Window.y, Window.width, Window.height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the window's wounds. This is a no-op on fullscreen windows.
|
||||
* @param x, y The new window location
|
||||
* @param width, height The new window dimensions
|
||||
*/
|
||||
public static void setBounds(int x, int y, int width, int height) {
|
||||
if (!isCreated())
|
||||
throw new IllegalStateException("Cannot reshape uncreated window");
|
||||
if (fullscreen) {
|
||||
return;
|
||||
}
|
||||
Window.x = x;
|
||||
Window.y = y;
|
||||
Window.width = width;
|
||||
Window.height = height;
|
||||
nReshape(Window.x, Window.y, Window.width, Window.height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Native method to reshape the window
|
||||
* @param x, y The new window location
|
||||
* @param width, height The new window dimensions
|
||||
*/
|
||||
private static native void nReshape(int x, int y, int width, int height);
|
||||
|
||||
}
|
||||
|
|
|
|||
109
src/java/org/lwjgl/test/opengl/BouncingWindowTest.java
Normal file
109
src/java/org/lwjgl/test/opengl/BouncingWindowTest.java
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
* Copyright (c) 2002 Lightweight Java Game Library Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'Light Weight Java Game Library' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.lwjgl.test.opengl;
|
||||
|
||||
import org.lwjgl.Display;
|
||||
import org.lwjgl.LWJGLException;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.Window;
|
||||
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
* Tests the windowing functions. ESCAPE quits.
|
||||
*
|
||||
* @author $author$
|
||||
* @version $revision$
|
||||
*/
|
||||
public class BouncingWindowTest {
|
||||
public static void main(String[] args) {
|
||||
|
||||
int x = 0, y = 0, dx = 1, dy = 1;
|
||||
try {
|
||||
Window.create("Bouncing Window Test", 0, 0, 64, 64, true, 16, 0, 16, 8, 0);
|
||||
} catch (LWJGLException e) {
|
||||
e.printStackTrace(System.err);
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
Window.setVSyncEnabled(true);
|
||||
|
||||
float angle = 0.0f;
|
||||
float color = 0.0f;
|
||||
while (!Keyboard.isKeyDown(Keyboard.KEY_ESCAPE) && !Window.isCloseRequested()) {
|
||||
Window.update();
|
||||
x += dx;
|
||||
y += dy;
|
||||
if (x < 0) {
|
||||
x = 1;
|
||||
dx = 1;
|
||||
} else if (x >= Display.getWidth() - Window.getWidth()) {
|
||||
x = Display.getWidth() - Window.getWidth() - 1;
|
||||
dx = -1;
|
||||
}
|
||||
if (y < 0) {
|
||||
y = 1;
|
||||
dy = 1;
|
||||
} else if (y >= Display.getHeight() - Window.getHeight()) {
|
||||
y = Display.getHeight() - Window.getHeight() - 1;
|
||||
dy = -1;
|
||||
}
|
||||
|
||||
Window.setLocation(x, y);
|
||||
angle += 1.0f;
|
||||
if (angle >= 360.0f) {
|
||||
angle = 0.0f;
|
||||
}
|
||||
color += 0.01f;
|
||||
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(Window.getWidth() / 2.0f, Window.getHeight() / 2.0f, 0.0f);
|
||||
GL11.glRotatef(angle, 0.0f, 0.0f, 1.0f);
|
||||
GL11.glColor3f(
|
||||
(float)Math.abs(Math.sin(color)),
|
||||
(float)Math.abs(Math.cos(color)),
|
||||
(float)Math.abs(Math.sin(color) * Math.cos(color))
|
||||
);
|
||||
GL11.glBegin(GL11.GL_QUADS);
|
||||
{
|
||||
GL11.glVertex2f(-20.0f, -20.0f);
|
||||
GL11.glVertex2f(20.0f, -20.0f);
|
||||
GL11.glVertex2f(20.0f, 20.0f);
|
||||
GL11.glVertex2f(-20.0f, 20.0f);
|
||||
}
|
||||
GL11.glEnd();
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue