fixed examples to new architexture
This commit is contained in:
parent
deb08476ef
commit
e0a93cdd14
|
@ -34,8 +34,8 @@ package org.lwjgl.examples;
|
||||||
import org.lwjgl.Sys;
|
import org.lwjgl.Sys;
|
||||||
import org.lwjgl.input.Keyboard;
|
import org.lwjgl.input.Keyboard;
|
||||||
import org.lwjgl.openal.AL;
|
import org.lwjgl.openal.AL;
|
||||||
|
import org.lwjgl.opengl.Display;
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
import org.lwjgl.opengl.Window;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* $Id$
|
* $Id$
|
||||||
|
@ -84,10 +84,13 @@ public class Game {
|
||||||
private static void init() throws Exception {
|
private static void init() throws Exception {
|
||||||
// Create a fullscreen window with 1:1 orthographic 2D projection, and with
|
// Create a fullscreen window with 1:1 orthographic 2D projection, and with
|
||||||
// mouse, keyboard, and gamepad inputs.
|
// mouse, keyboard, and gamepad inputs.
|
||||||
Window.create(GAME_TITLE);
|
Display.setTitle(GAME_TITLE);
|
||||||
|
Display.setFullscreen(true);
|
||||||
|
|
||||||
// Enable vsync if we can
|
// Enable vsync if we can
|
||||||
Window.setVSyncEnabled(true);
|
Display.setVSyncEnabled(true);
|
||||||
|
|
||||||
|
Display.create();
|
||||||
|
|
||||||
// Start up the sound system
|
// Start up the sound system
|
||||||
AL.create();
|
AL.create();
|
||||||
|
@ -101,16 +104,16 @@ public class Game {
|
||||||
private static void run() {
|
private static void run() {
|
||||||
while (!finished) {
|
while (!finished) {
|
||||||
// Always call Window.update(), all the time
|
// Always call Window.update(), all the time
|
||||||
Window.update();
|
Display.update();
|
||||||
|
|
||||||
if (Window.isCloseRequested()) {
|
if (Display.isCloseRequested()) {
|
||||||
// Check for O/S close requests
|
// Check for O/S close requests
|
||||||
finished = true;
|
finished = true;
|
||||||
} else if (Window.isActive()) {
|
} else if (Display.isActive()) {
|
||||||
// The window is in the foreground, so we should play the game
|
// The window is in the foreground, so we should play the game
|
||||||
logic();
|
logic();
|
||||||
render();
|
render();
|
||||||
org.lwjgl.Display.sync(FRAMERATE);
|
Display.sync(FRAMERATE);
|
||||||
} else {
|
} else {
|
||||||
// The window is not in the foreground, so we can allow other stuff to run and
|
// The window is not in the foreground, so we can allow other stuff to run and
|
||||||
// infrequently update
|
// infrequently update
|
||||||
|
@ -119,7 +122,7 @@ public class Game {
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
}
|
}
|
||||||
logic();
|
logic();
|
||||||
if (Window.isVisible() || Window.isDirty()) {
|
if (Display.isVisible() || Display.isDirty()) {
|
||||||
// Only bother rendering if the window is visible or dirty
|
// Only bother rendering if the window is visible or dirty
|
||||||
render();
|
render();
|
||||||
}
|
}
|
||||||
|
@ -137,7 +140,7 @@ public class Game {
|
||||||
AL.destroy();
|
AL.destroy();
|
||||||
|
|
||||||
// Close the window
|
// Close the window
|
||||||
Window.destroy();
|
Display.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -33,15 +33,15 @@ package org.lwjgl.examples.spaceinvaders;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.lwjgl.Display;
|
import org.lwjgl.opengl.Display;
|
||||||
import org.lwjgl.DisplayMode;
|
import org.lwjgl.opengl.DisplayMode;
|
||||||
|
import org.lwjgl.opengl.PixelFormat;
|
||||||
import org.lwjgl.LWJGLException;
|
import org.lwjgl.LWJGLException;
|
||||||
import org.lwjgl.Sys;
|
import org.lwjgl.Sys;
|
||||||
import org.lwjgl.input.Controller;
|
import org.lwjgl.input.Controller;
|
||||||
import org.lwjgl.input.Keyboard;
|
import org.lwjgl.input.Keyboard;
|
||||||
import org.lwjgl.input.Mouse;
|
import org.lwjgl.input.Mouse;
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
import org.lwjgl.opengl.Window;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main hook of our game. This class with both act as a manager
|
* The main hook of our game. This class with both act as a manager
|
||||||
|
@ -212,12 +212,10 @@ public class Game {
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
// initialize the window beforehand
|
// initialize the window beforehand
|
||||||
try {
|
try {
|
||||||
if (fullscreen && setDisplayMode()) {
|
setDisplayMode();
|
||||||
Window.create(WINDOW_TITLE, Display.getDepth(), 0, 8, 0, 0);
|
Display.setTitle(WINDOW_TITLE);
|
||||||
Window.setVSyncEnabled(true);
|
Display.setFullscreen(fullscreen);
|
||||||
} else {
|
Display.create();
|
||||||
Window.create(WINDOW_TITLE, 100, 100, width, height, Display.getDepth(), 0, 8, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// grab the mouse, dont want that hideous cursor when we're playing!
|
// grab the mouse, dont want that hideous cursor when we're playing!
|
||||||
Mouse.setGrabbed(true);
|
Mouse.setGrabbed(true);
|
||||||
|
@ -277,14 +275,14 @@ public class Game {
|
||||||
*/
|
*/
|
||||||
private boolean setDisplayMode() {
|
private boolean setDisplayMode() {
|
||||||
// get modes
|
// get modes
|
||||||
DisplayMode[] dm = org.lwjgl.util.Display.getAvailableDisplayModes(800, 600, -1, -1, -1, -1, 60, 60);
|
DisplayMode[] dm = org.lwjgl.util.Display.getAvailableDisplayModes(width, height, -1, -1, -1, -1, 60, 60);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
org.lwjgl.util.Display.setDisplayMode(dm, new String[] {
|
org.lwjgl.util.Display.setDisplayMode(dm, new String[] {
|
||||||
"width=" + width,
|
"width=" + width,
|
||||||
"height=" + height,
|
"height=" + height,
|
||||||
"freq=" + 60,
|
"freq=" + 60,
|
||||||
"bpp=" + org.lwjgl.Display.getDepth()
|
"bpp=" + org.lwjgl.opengl.Display.getDisplayMode().getBitsPerPixel()
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -425,7 +423,7 @@ public class Game {
|
||||||
frameRendering();
|
frameRendering();
|
||||||
|
|
||||||
// update window contents
|
// update window contents
|
||||||
Window.update();
|
Display.update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -447,7 +445,7 @@ public class Game {
|
||||||
|
|
||||||
// update our FPS counter if a second has passed
|
// update our FPS counter if a second has passed
|
||||||
if (lastFpsTime >= 1000) {
|
if (lastFpsTime >= 1000) {
|
||||||
Window.setTitle(WINDOW_TITLE + " (FPS: " + fps + ")");
|
Display.setTitle(WINDOW_TITLE + " (FPS: " + fps + ")");
|
||||||
lastFpsTime = 0;
|
lastFpsTime = 0;
|
||||||
fps = 0;
|
fps = 0;
|
||||||
}
|
}
|
||||||
|
@ -543,7 +541,7 @@ public class Game {
|
||||||
}
|
}
|
||||||
|
|
||||||
// if escape has been pressed, stop the game
|
// if escape has been pressed, stop the game
|
||||||
if (Window.isCloseRequested() || Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
|
if (Display.isCloseRequested() || Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
|
||||||
Game.gameRunning = false;
|
Game.gameRunning = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -593,7 +591,7 @@ public class Game {
|
||||||
private void execute() {
|
private void execute() {
|
||||||
gameLoop();
|
gameLoop();
|
||||||
soundManager.destroy();
|
soundManager.destroy();
|
||||||
Window.destroy();
|
Display.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue