mirror of
https://github.com/GTNewHorizons/lwjgl3ify.git
synced 2026-11-28 07:56:06 +00:00
Switch to a different fork of lwjglx (still MIT licensed according to comments on top of the files)
This commit is contained in:
1 parent
4fc8be60f5
commit
a59d88da77
17 files changed
+181
-192
No files matched your search
@@ -6,19 +6,20 @@ import java.awt.Desktop;
|
||||
import java.net.URI;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.UIManager;
|
||||
import org.lwjgl.Version;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
public class Sys {
|
||||
|
||||
static {
|
||||
if (!glfwInit()) throw new IllegalStateException("Unable to initialize glfw");
|
||||
if (glfwInit() != true) throw new IllegalStateException("Unable to initialize glfw");
|
||||
}
|
||||
|
||||
public static void initialize() {}
|
||||
|
||||
/** Returns the LWJGL version. */
|
||||
public static String getVersion() {
|
||||
return org.lwjgl.Version.getVersion();
|
||||
return Version.getVersion();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package org.lwjglx.openal;
|
||||
|
||||
import org.lwjgl.openal.ALC10;
|
||||
import java.nio.IntBuffer;
|
||||
import org.lwjglx.BufferUtils;
|
||||
import org.lwjglx.LWJGLException;
|
||||
import org.lwjglx.Sys;
|
||||
|
||||
public class AL {
|
||||
|
||||
public static long alContext = -1;
|
||||
public static ALCdevice alcDevice = null;
|
||||
static ALCdevice alcDevice;
|
||||
|
||||
private static boolean created = false;
|
||||
|
||||
@@ -16,26 +16,27 @@ public class AL {
|
||||
}
|
||||
|
||||
public static void create() throws LWJGLException {
|
||||
if (alContext == -1) {
|
||||
final String defaultDevice = ALC10.alcGetString(0, ALC10.ALC_DEFAULT_DEVICE_SPECIFIER);
|
||||
alcDevice = new ALCdevice(ALC10.alcOpenDevice(defaultDevice));
|
||||
AL.create();
|
||||
|
||||
final int[] attribs = new int[] {
|
||||
org.lwjgl.openal.ALC10.ALC_FREQUENCY,
|
||||
44100,
|
||||
IntBuffer attribs = BufferUtils.createIntBuffer(16);
|
||||
|
||||
org.lwjgl.openal.ALC10.ALC_REFRESH,
|
||||
60,
|
||||
attribs.put(org.lwjgl.openal.ALC10.ALC_FREQUENCY);
|
||||
attribs.put(44100);
|
||||
|
||||
org.lwjgl.openal.ALC10.ALC_SYNC,
|
||||
org.lwjgl.openal.ALC10.ALC_FALSE,
|
||||
attribs.put(org.lwjgl.openal.ALC10.ALC_REFRESH);
|
||||
attribs.put(60);
|
||||
|
||||
0,
|
||||
};
|
||||
attribs.put(org.lwjgl.openal.ALC10.ALC_SYNC);
|
||||
attribs.put(org.lwjgl.openal.ALC10.ALC_FALSE);
|
||||
|
||||
alContext = org.lwjgl.openal.ALC10.alcCreateContext(alcDevice.device, attribs);
|
||||
created = true;
|
||||
}
|
||||
attribs.put(0);
|
||||
attribs.flip();
|
||||
|
||||
long contextHandle = org.lwjgl.openal.ALC10.alcCreateContext(AL.getDevice().device, attribs);
|
||||
|
||||
alcDevice = new ALCdevice(contextHandle);
|
||||
|
||||
created = true;
|
||||
}
|
||||
|
||||
public static boolean isCreated() {
|
||||
@@ -43,9 +44,7 @@ public class AL {
|
||||
}
|
||||
|
||||
public static void destroy() {
|
||||
ALC10.alcDestroyContext(alContext);
|
||||
ALC10.alcCloseDevice(alcDevice.device);
|
||||
alContext = -1;
|
||||
AL.destroy();
|
||||
alcDevice = null;
|
||||
created = false;
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public class AL10 {
|
||||
}
|
||||
|
||||
public static void alSourceStop(java.nio.IntBuffer sources) {
|
||||
org.lwjgl.openal.AL10.alSourceStop(sources.get(0));
|
||||
org.lwjgl.openal.AL10.alSourceStopv(sources);
|
||||
}
|
||||
|
||||
public static void alDeleteSources(java.nio.IntBuffer sources) {
|
||||
|
||||
@@ -50,6 +50,6 @@ public class ALC10 {
|
||||
}
|
||||
|
||||
public static void alcGetInteger(ALCdevice device, int pname, java.nio.IntBuffer integerdata) {
|
||||
integerdata.put(0, org.lwjgl.openal.ALC10.alcGetInteger(device.device, pname));
|
||||
org.lwjgl.openal.ALC10.alcGetIntegerv(device.device, pname, integerdata);
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@
|
||||
package org.lwjglx.openal;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjglx.BufferUtils;
|
||||
|
||||
/**
|
||||
* The ALCcontext class represents a context opened in OpenAL space.
|
||||
|
||||
@@ -4,12 +4,11 @@ import java.lang.reflect.Field;
|
||||
|
||||
public class ContextCapabilities {
|
||||
|
||||
org.lwjgl.opengl.ContextCapabilities cap =
|
||||
org.lwjgl.opengl.GLContext.createFromCurrent().getCapabilities();
|
||||
org.lwjgl.opengl.GLCapabilities cap = org.lwjgl.opengl.GL.getCapabilities();
|
||||
|
||||
public ContextCapabilities() {
|
||||
|
||||
Field[] fields = org.lwjgl.opengl.ContextCapabilities.class.getFields();
|
||||
Field[] fields = org.lwjgl.opengl.GLCapabilities.class.getFields();
|
||||
|
||||
try {
|
||||
for (Field field : fields) {
|
||||
|
||||
@@ -1,43 +1,26 @@
|
||||
package org.lwjglx.opengl;
|
||||
|
||||
import static org.lwjgl.glfw.Callbacks.*;
|
||||
import static org.lwjgl.glfw.GLFW.GLFW_OPENGL_DEBUG_CONTEXT;
|
||||
import static org.lwjgl.glfw.GLFW.GLFW_RELEASE;
|
||||
import static org.lwjgl.glfw.GLFW.GLFW_RESIZABLE;
|
||||
import static org.lwjgl.glfw.GLFW.GLFW_VISIBLE;
|
||||
import static org.lwjgl.glfw.GLFW.glfwCreateWindow;
|
||||
import static org.lwjgl.glfw.GLFW.glfwDefaultWindowHints;
|
||||
import static org.lwjgl.glfw.GLFW.glfwDestroyWindow;
|
||||
import static org.lwjgl.glfw.GLFW.glfwGetPrimaryMonitor;
|
||||
import static org.lwjgl.glfw.GLFW.glfwGetVideoMode;
|
||||
import static org.lwjgl.glfw.GLFW.glfwMakeContextCurrent;
|
||||
import static org.lwjgl.glfw.GLFW.glfwPollEvents;
|
||||
import static org.lwjgl.glfw.GLFW.glfwSetWindowPos;
|
||||
import static org.lwjgl.glfw.GLFW.glfwShowWindow;
|
||||
import static org.lwjgl.glfw.GLFW.glfwSwapBuffers;
|
||||
import static org.lwjgl.glfw.GLFW.glfwSwapInterval;
|
||||
import static org.lwjgl.glfw.GLFW.glfwWindowHint;
|
||||
import static org.lwjgl.glfw.GLFW.glfwWindowShouldClose;
|
||||
import static org.lwjgl.glfw.GLFW.*;
|
||||
import static org.lwjgl.opengl.GL11.GL_FALSE;
|
||||
import static org.lwjgl.opengl.GL11.GL_TRUE;
|
||||
import static org.lwjgl.system.MemoryUtil.NULL;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.glfw.*;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import org.lwjgl.glfw.GLFWCharCallback;
|
||||
import org.lwjgl.glfw.GLFWCursorPosCallback;
|
||||
import org.lwjgl.glfw.GLFWKeyCallback;
|
||||
import org.lwjgl.glfw.GLFWMouseButtonCallback;
|
||||
import org.lwjgl.glfw.GLFWVidMode;
|
||||
import org.lwjgl.glfw.GLFWWindowFocusCallback;
|
||||
import org.lwjgl.glfw.GLFWWindowIconifyCallback;
|
||||
import org.lwjgl.glfw.GLFWWindowPosCallback;
|
||||
import org.lwjgl.glfw.GLFWWindowRefreshCallback;
|
||||
import org.lwjgl.glfw.GLFWvidmode;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjglx.LWJGLException;
|
||||
import org.lwjgl.opengl.GL;
|
||||
import org.lwjgl.system.libffi.FFICIF;
|
||||
import org.lwjglx.BufferUtils;
|
||||
import org.lwjglx.Sys;
|
||||
import org.lwjglx.input.Keyboard;
|
||||
import org.lwjglx.input.Mouse;
|
||||
@@ -46,8 +29,6 @@ public class Display {
|
||||
|
||||
private static String windowTitle = "Game";
|
||||
|
||||
private static org.lwjgl.opengl.GLContext context;
|
||||
|
||||
private static boolean displayCreated = false;
|
||||
private static boolean displayFocused = false;
|
||||
private static boolean displayVisible = true;
|
||||
@@ -76,41 +57,39 @@ public class Display {
|
||||
Sys.initialize(); // init using dummy sys method
|
||||
|
||||
long monitor = glfwGetPrimaryMonitor();
|
||||
ByteBuffer vidmode = glfwGetVideoMode(monitor);
|
||||
GLFWVidMode vidmode = glfwGetVideoMode(monitor);
|
||||
|
||||
int monitorWidth = GLFWvidmode.width(vidmode);
|
||||
int monitorHeight = GLFWvidmode.height(vidmode);
|
||||
int monitorBitPerPixel =
|
||||
GLFWvidmode.redBits(vidmode) + GLFWvidmode.greenBits(vidmode) + GLFWvidmode.blueBits(vidmode);
|
||||
int monitorRefreshRate = GLFWvidmode.refreshRate(vidmode);
|
||||
int monitorWidth = vidmode.width();
|
||||
int monitorHeight = vidmode.height();
|
||||
int monitorBitPerPixel = vidmode.redBits() + vidmode.greenBits() + vidmode.blueBits();
|
||||
int monitorRefreshRate = vidmode.refreshRate();
|
||||
|
||||
desktopDisplayMode = new DisplayMode(monitorWidth, monitorHeight, monitorBitPerPixel, monitorRefreshRate);
|
||||
}
|
||||
|
||||
public static void create(PixelFormat pixel_format, Drawable shared_drawable) throws LWJGLException {
|
||||
public static void create(PixelFormat pixel_format, Drawable shared_drawable) {
|
||||
System.out.println("TODO: Implement Display.create(PixelFormat, Drawable)"); // TODO
|
||||
create();
|
||||
}
|
||||
|
||||
public static void create(PixelFormat pixel_format, ContextAttribs attribs) throws LWJGLException {
|
||||
public static void create(PixelFormat pixel_format, ContextAttribs attribs) {
|
||||
System.out.println("TODO: Implement Display.create(PixelFormat, ContextAttribs)"); // TODO
|
||||
create();
|
||||
}
|
||||
|
||||
public static void create(PixelFormat pixel_format) throws LWJGLException {
|
||||
public static void create(PixelFormat pixel_format) {
|
||||
System.out.println("TODO: Implement Display.create(PixelFormat)"); // TODO
|
||||
create();
|
||||
}
|
||||
|
||||
public static void create() throws LWJGLException {
|
||||
public static void create() {
|
||||
long monitor = glfwGetPrimaryMonitor();
|
||||
ByteBuffer vidmode = glfwGetVideoMode(monitor);
|
||||
GLFWVidMode vidmode = glfwGetVideoMode(monitor);
|
||||
|
||||
int monitorWidth = GLFWvidmode.width(vidmode);
|
||||
int monitorHeight = GLFWvidmode.height(vidmode);
|
||||
int monitorBitPerPixel =
|
||||
GLFWvidmode.redBits(vidmode) + GLFWvidmode.greenBits(vidmode) + GLFWvidmode.blueBits(vidmode);
|
||||
int monitorRefreshRate = GLFWvidmode.refreshRate(vidmode);
|
||||
int monitorWidth = vidmode.width();
|
||||
int monitorHeight = vidmode.height();
|
||||
int monitorBitPerPixel = vidmode.redBits() + vidmode.greenBits() + vidmode.blueBits();
|
||||
int monitorRefreshRate = vidmode.refreshRate();
|
||||
|
||||
desktopDisplayMode = new DisplayMode(monitorWidth, monitorHeight, monitorBitPerPixel, monitorRefreshRate);
|
||||
|
||||
@@ -156,15 +135,45 @@ public class Display {
|
||||
|
||||
Window.windowFocusCallback = new GLFWWindowFocusCallback() {
|
||||
@Override
|
||||
public void invoke(long window, int focused) {
|
||||
displayFocused = focused == GL11.GL_TRUE;
|
||||
public void close() {
|
||||
super.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FFICIF getCallInterface() {
|
||||
return super.getCallInterface();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callback(long ret, long args) {
|
||||
super.callback(ret, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(long l, boolean b) {
|
||||
displayFocused = b == true;
|
||||
}
|
||||
};
|
||||
|
||||
Window.windowIconifyCallback = new GLFWWindowIconifyCallback() {
|
||||
@Override
|
||||
public void invoke(long window, int iconified) {
|
||||
displayVisible = iconified == GL11.GL_FALSE;
|
||||
public void close() {
|
||||
super.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FFICIF getCallInterface() {
|
||||
return super.getCallInterface();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callback(long ret, long args) {
|
||||
super.callback(ret, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(long l, boolean b) {
|
||||
displayVisible = b == false;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -217,7 +226,7 @@ public class Display {
|
||||
displayY = (monitorHeight - mode.getHeight()) / 2;
|
||||
|
||||
glfwMakeContextCurrent(Window.handle);
|
||||
context = org.lwjgl.opengl.GLContext.createFromCurrent();
|
||||
GL.createCapabilities();
|
||||
|
||||
glfwSwapInterval(1);
|
||||
glfwShowWindow(Window.handle);
|
||||
@@ -237,16 +246,12 @@ public class Display {
|
||||
return displayVisible;
|
||||
}
|
||||
|
||||
public static org.lwjgl.opengl.GLContext getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
public static void setLocation(int new_x, int new_y) {
|
||||
System.out.println("TODO: Implement Display.setLocation(int, int)");
|
||||
}
|
||||
|
||||
public static void setVSyncEnabled(boolean sync) {
|
||||
System.out.println("TODO: Implement Display.setVSyncEnabled(boolean)"); // TODO
|
||||
glfwSwapInterval(sync ? 1 : 0);
|
||||
}
|
||||
|
||||
public static long getWindow() {
|
||||
@@ -258,12 +263,8 @@ public class Display {
|
||||
}
|
||||
|
||||
public static void update(boolean processMessages) {
|
||||
try {
|
||||
swapBuffers();
|
||||
displayDirty = false;
|
||||
} catch (LWJGLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
swapBuffers();
|
||||
displayDirty = false;
|
||||
|
||||
if (processMessages) processMessages();
|
||||
}
|
||||
@@ -283,7 +284,7 @@ public class Display {
|
||||
}
|
||||
}
|
||||
|
||||
public static void swapBuffers() throws LWJGLException {
|
||||
public static void swapBuffers() {
|
||||
glfwSwapBuffers(Window.handle);
|
||||
}
|
||||
|
||||
@@ -299,7 +300,7 @@ public class Display {
|
||||
displayCreated = false;
|
||||
}
|
||||
|
||||
public static void setDisplayMode(DisplayMode dm) throws LWJGLException {
|
||||
public static void setDisplayMode(DisplayMode dm) {
|
||||
mode = dm;
|
||||
}
|
||||
|
||||
@@ -307,19 +308,19 @@ public class Display {
|
||||
return mode;
|
||||
}
|
||||
|
||||
public static DisplayMode[] getAvailableDisplayModes() throws LWJGLException {
|
||||
public static DisplayMode[] getAvailableDisplayModes() {
|
||||
IntBuffer count = BufferUtils.createIntBuffer(1);
|
||||
ByteBuffer modes = GLFW.glfwGetVideoModes(GLFW.glfwGetPrimaryMonitor(), count);
|
||||
GLFWVidMode.Buffer modes = GLFW.glfwGetVideoModes(glfwGetPrimaryMonitor());
|
||||
|
||||
DisplayMode[] displayModes = new DisplayMode[count.get(0)];
|
||||
|
||||
for (int i = 0; i < count.get(0); i++) {
|
||||
modes.position(i * GLFWvidmode.SIZEOF);
|
||||
modes.position(i * GLFWVidMode.SIZEOF);
|
||||
|
||||
int w = GLFWvidmode.width(modes);
|
||||
int h = GLFWvidmode.height(modes);
|
||||
int b = GLFWvidmode.redBits(modes) + GLFWvidmode.greenBits(modes) + GLFWvidmode.blueBits(modes);
|
||||
int r = GLFWvidmode.refreshRate(modes);
|
||||
int w = modes.width();
|
||||
int h = modes.height();
|
||||
int b = modes.redBits() + modes.greenBits() + modes.blueBits();
|
||||
int r = modes.refreshRate();
|
||||
|
||||
displayModes[i] = new DisplayMode(w, h, b, r);
|
||||
}
|
||||
@@ -364,7 +365,7 @@ public class Display {
|
||||
}
|
||||
|
||||
public static boolean isCloseRequested() {
|
||||
return glfwWindowShouldClose(Window.handle) == GL_TRUE;
|
||||
return glfwWindowShouldClose(Window.handle) == true;
|
||||
}
|
||||
|
||||
public static boolean isDirty() {
|
||||
@@ -391,12 +392,12 @@ public class Display {
|
||||
return displayResizable;
|
||||
}
|
||||
|
||||
public static void setDisplayModeAndFullscreen(DisplayMode mode) throws LWJGLException {
|
||||
public static void setDisplayModeAndFullscreen(DisplayMode mode) {
|
||||
// TODO
|
||||
System.out.println("TODO: Implement Display.setDisplayModeAndFullscreen(DisplayMode)");
|
||||
}
|
||||
|
||||
public static void setFullscreen(boolean fullscreen) throws LWJGLException {
|
||||
public static void setFullscreen(boolean fullscreen) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@@ -405,19 +406,19 @@ public class Display {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void setParent(java.awt.Canvas parent) throws LWJGLException {
|
||||
public static void setParent(java.awt.Canvas parent) {
|
||||
// Do nothing as set parent not supported
|
||||
}
|
||||
|
||||
public static void releaseContext() throws LWJGLException {
|
||||
public static void releaseContext() {
|
||||
glfwMakeContextCurrent(0);
|
||||
}
|
||||
|
||||
public static boolean isCurrent() throws LWJGLException {
|
||||
return context.isCurrent();
|
||||
public static boolean isCurrent() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void makeCurrent() throws LWJGLException {
|
||||
public static void makeCurrent() {
|
||||
glfwMakeContextCurrent(Window.handle);
|
||||
}
|
||||
|
||||
@@ -464,29 +465,29 @@ public class Display {
|
||||
static GLFWFramebufferSizeCallback framebufferSizeCallback;
|
||||
|
||||
public static void setCallbacks() {
|
||||
glfwSetCallback(handle, keyCallback);
|
||||
glfwSetCallback(handle, charCallback);
|
||||
glfwSetCallback(handle, cursorPosCallback);
|
||||
glfwSetCallback(handle, mouseButtonCallback);
|
||||
glfwSetCallback(handle, windowFocusCallback);
|
||||
glfwSetCallback(handle, windowIconifyCallback);
|
||||
glfwSetCallback(handle, windowSizeCallback);
|
||||
glfwSetCallback(handle, windowPosCallback);
|
||||
glfwSetCallback(handle, windowRefreshCallback);
|
||||
glfwSetCallback(handle, framebufferSizeCallback);
|
||||
GLFW.glfwSetKeyCallback(handle, keyCallback);
|
||||
GLFW.glfwSetCharCallback(handle, charCallback);
|
||||
GLFW.glfwSetCursorPosCallback(handle, cursorPosCallback);
|
||||
GLFW.glfwSetMouseButtonCallback(handle, mouseButtonCallback);
|
||||
GLFW.glfwSetWindowFocusCallback(handle, windowFocusCallback);
|
||||
GLFW.glfwSetWindowIconifyCallback(handle, windowIconifyCallback);
|
||||
GLFW.glfwSetWindowSizeCallback(handle, windowSizeCallback);
|
||||
GLFW.glfwSetWindowPosCallback(handle, windowPosCallback);
|
||||
GLFW.glfwSetWindowRefreshCallback(handle, windowRefreshCallback);
|
||||
GLFW.glfwSetFramebufferSizeCallback(handle, framebufferSizeCallback);
|
||||
}
|
||||
|
||||
public static void releaseCallbacks() {
|
||||
keyCallback.release();
|
||||
charCallback.release();
|
||||
cursorPosCallback.release();
|
||||
mouseButtonCallback.release();
|
||||
windowFocusCallback.release();
|
||||
windowIconifyCallback.release();
|
||||
windowSizeCallback.release();
|
||||
windowPosCallback.release();
|
||||
windowRefreshCallback.release();
|
||||
framebufferSizeCallback.release();
|
||||
keyCallback.free();
|
||||
charCallback.free();
|
||||
cursorPosCallback.free();
|
||||
mouseButtonCallback.free();
|
||||
windowFocusCallback.free();
|
||||
windowIconifyCallback.free();
|
||||
windowSizeCallback.free();
|
||||
windowPosCallback.free();
|
||||
windowRefreshCallback.free();
|
||||
framebufferSizeCallback.free();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ public class GL15x {
|
||||
int size = GL15.glGetBufferParameteri(target, GL15.GL_BUFFER_SIZE);
|
||||
|
||||
PointerBuffer pb = BufferUtils.createPointerBuffer(1);
|
||||
pb.put(0, GL15.glGetBufferPointer(target, pname));
|
||||
GL15.glGetBufferPointerv(target, pname, pb);
|
||||
|
||||
return pb.getByteBuffer(0, size);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ package org.lwjglx.opengl;
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjglx.BufferUtils;
|
||||
|
||||
/** This class represents the state necessary for render-to-texture. */
|
||||
public final class RenderTexture {
|
||||
|
||||
@@ -35,8 +35,6 @@ import static org.lwjgl.opengl.ARBImaging.*;
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
import static org.lwjgl.opengl.GL30.*;
|
||||
|
||||
import org.lwjgl.opengl.GLContext;
|
||||
|
||||
/**
|
||||
* Simple utility class.
|
||||
*
|
||||
@@ -45,8 +43,6 @@ import org.lwjgl.opengl.GLContext;
|
||||
*/
|
||||
public final class Util {
|
||||
|
||||
static org.lwjgl.opengl.GLContext glContext = GLContext.createFromCurrent();
|
||||
|
||||
/** No c'tor */
|
||||
private Util() {}
|
||||
|
||||
@@ -54,9 +50,7 @@ public final class Util {
|
||||
* Throws OpenGLException if glGetError() returns anything else than GL_NO_ERROR
|
||||
*
|
||||
*/
|
||||
public static void checkGLError() throws OpenGLException {
|
||||
glContext.checkGLError();
|
||||
}
|
||||
public static void checkGLError() throws OpenGLException {}
|
||||
|
||||
/**
|
||||
* Translate a GL error code to a String describing the error
|
||||
|
||||
@@ -39,10 +39,10 @@ import static org.lwjgl.opengl.ARBTransposeMatrix.*;
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
import java.nio.FloatBuffer;
|
||||
import org.lwjgl.Version;
|
||||
import org.lwjglx.BufferUtils;
|
||||
import org.lwjglx.LWJGLException;
|
||||
import org.lwjglx.LWJGLUtil;
|
||||
import org.lwjglx.Sys;
|
||||
import org.lwjglx.opengl.Display;
|
||||
import org.lwjglx.opengl.DisplayMode;
|
||||
import org.lwjglx.opengl.GLContext;
|
||||
@@ -201,7 +201,7 @@ public class Gears {
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
|
||||
System.err.println("LWJGL: " + Sys.getVersion() + " / " + LWJGLUtil.getPlatformName());
|
||||
System.err.println("LWJGL: " + Version.getVersion() + " / " + LWJGLUtil.getPlatformName());
|
||||
System.err.println("GL_VENDOR: " + glGetString(GL_VENDOR));
|
||||
System.err.println("GL_RENDERER: " + glGetString(GL_RENDERER));
|
||||
System.err.println("GL_VERSION: " + glGetString(GL_VERSION));
|
||||
|
||||
@@ -34,7 +34,6 @@ package org.lwjglx.test.spaceinvaders;
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import org.lwjglx.LWJGLException;
|
||||
import org.lwjglx.Sys;
|
||||
import org.lwjglx.input.Keyboard;
|
||||
import org.lwjglx.input.Mouse;
|
||||
@@ -211,53 +210,46 @@ public class Game {
|
||||
*/
|
||||
public void initialize() {
|
||||
// initialize the window beforehand
|
||||
try {
|
||||
setDisplayMode();
|
||||
Display.setTitle(WINDOW_TITLE);
|
||||
Display.setFullscreen(fullscreen);
|
||||
Display.create();
|
||||
setDisplayMode();
|
||||
Display.setTitle(WINDOW_TITLE);
|
||||
Display.setFullscreen(fullscreen);
|
||||
Display.create();
|
||||
|
||||
// grab the mouse, dont want that hideous cursor when we're playing!
|
||||
if (isApplication) {
|
||||
Mouse.setGrabbed(true);
|
||||
}
|
||||
|
||||
// enable textures since we're going to use these for our sprites
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
// disable the OpenGL depth test since we're rendering 2D graphics
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
|
||||
glOrtho(0, width, height, 0, -1, 1);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glViewport(0, 0, Display.getFramebufferWidth(), Display.getFramebufferHeight());
|
||||
|
||||
textureLoader = new TextureLoader();
|
||||
|
||||
// create our sound manager, and initialize it with 7 channels
|
||||
// 1 channel for sounds, 6 for effects - this should be enough
|
||||
// since we have a most 4 shots on screen at any one time, which leaves
|
||||
// us with 2 channels for explosions.
|
||||
soundManager = new SoundManager();
|
||||
soundManager.initialize(8);
|
||||
|
||||
// load our sound data
|
||||
SOUND_SHOT = soundManager.addSound("shot.wav");
|
||||
SOUND_HIT = soundManager.addSound("hit.wav");
|
||||
SOUND_START = soundManager.addSound("start.wav");
|
||||
SOUND_WIN = soundManager.addSound("win.wav");
|
||||
SOUND_LOOSE = soundManager.addSound("loose.wav");
|
||||
} catch (LWJGLException le) {
|
||||
System.out.println("Game exiting - exception in initialization:");
|
||||
le.printStackTrace();
|
||||
Game.gameRunning = false;
|
||||
return;
|
||||
// grab the mouse, dont want that hideous cursor when we're playing!
|
||||
if (isApplication) {
|
||||
Mouse.setGrabbed(true);
|
||||
}
|
||||
|
||||
// enable textures since we're going to use these for our sprites
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
// disable the OpenGL depth test since we're rendering 2D graphics
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
|
||||
glOrtho(0, width, height, 0, -1, 1);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glViewport(0, 0, Display.getFramebufferWidth(), Display.getFramebufferHeight());
|
||||
|
||||
textureLoader = new TextureLoader();
|
||||
|
||||
// create our sound manager, and initialize it with 7 channels
|
||||
// 1 channel for sounds, 6 for effects - this should be enough
|
||||
// since we have a most 4 shots on screen at any one time, which leaves
|
||||
// us with 2 channels for explosions.
|
||||
soundManager = new SoundManager();
|
||||
soundManager.initialize(8);
|
||||
|
||||
// load our sound data
|
||||
SOUND_SHOT = soundManager.addSound("shot.wav");
|
||||
SOUND_HIT = soundManager.addSound("hit.wav");
|
||||
SOUND_START = soundManager.addSound("start.wav");
|
||||
SOUND_WIN = soundManager.addSound("win.wav");
|
||||
SOUND_LOOSE = soundManager.addSound("loose.wav");
|
||||
|
||||
// get our sprites
|
||||
gotYou = getSprite("gotyou.gif");
|
||||
pressAnyKey = getSprite("pressanykey.gif");
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
package org.lwjglx.test.spaceinvaders;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjglx.BufferUtils;
|
||||
import org.lwjglx.LWJGLException;
|
||||
import org.lwjglx.openal.AL;
|
||||
import org.lwjglx.openal.AL10;
|
||||
|
||||
@@ -52,7 +52,7 @@ import java.nio.IntBuffer;
|
||||
import java.util.HashMap;
|
||||
import java.util.Hashtable;
|
||||
import javax.swing.ImageIcon;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjglx.BufferUtils;
|
||||
|
||||
/**
|
||||
* A utility class to load textures for OpenGL. This source is based
|
||||
|
||||
@@ -42,7 +42,7 @@ import java.nio.ShortBuffer;
|
||||
import javax.sound.sampled.AudioFormat;
|
||||
import javax.sound.sampled.AudioInputStream;
|
||||
import javax.sound.sampled.AudioSystem;
|
||||
import org.lwjgl.openal.AL10;
|
||||
import org.lwjgl.openal.AL11;
|
||||
|
||||
// import com.sun.media.sound.WaveFileReader;
|
||||
|
||||
@@ -99,7 +99,7 @@ public class WaveData {
|
||||
// WaveFileReader wfr = new WaveFileReader();
|
||||
// return create(wfr.getAudioInputStream(new BufferedInputStream(path.openStream())));
|
||||
} catch (Exception e) {
|
||||
org.lwjgl.system.APIUtil.apiLog("Unable to create from: " + path + ", " + e.getMessage());
|
||||
org.lwjglx.LWJGLUtil.log("Unable to create from: " + path + ", " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -124,7 +124,7 @@ public class WaveData {
|
||||
try {
|
||||
return create(AudioSystem.getAudioInputStream(is));
|
||||
} catch (Exception e) {
|
||||
org.lwjgl.system.APIUtil.apiLog("Unable to create from inputstream, " + e.getMessage());
|
||||
org.lwjglx.LWJGLUtil.log("Unable to create from inputstream, " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -139,7 +139,7 @@ public class WaveData {
|
||||
try {
|
||||
return create(AudioSystem.getAudioInputStream(new BufferedInputStream(new ByteArrayInputStream(buffer))));
|
||||
} catch (Exception e) {
|
||||
org.lwjgl.system.APIUtil.apiLog("Unable to create from byte array, " + e.getMessage());
|
||||
org.lwjglx.LWJGLUtil.log("Unable to create from byte array, " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -164,7 +164,7 @@ public class WaveData {
|
||||
}
|
||||
return create(bytes);
|
||||
} catch (Exception e) {
|
||||
org.lwjgl.system.APIUtil.apiLog("Unable to create from ByteBuffer, " + e.getMessage());
|
||||
org.lwjglx.LWJGLUtil.log("Unable to create from ByteBuffer, " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -183,17 +183,17 @@ public class WaveData {
|
||||
int channels = 0;
|
||||
if (audioformat.getChannels() == 1) {
|
||||
if (audioformat.getSampleSizeInBits() == 8) {
|
||||
channels = AL10.AL_FORMAT_MONO8;
|
||||
channels = AL11.AL_FORMAT_MONO8;
|
||||
} else if (audioformat.getSampleSizeInBits() == 16) {
|
||||
channels = AL10.AL_FORMAT_MONO16;
|
||||
channels = AL11.AL_FORMAT_MONO16;
|
||||
} else {
|
||||
assert false : "Illegal sample size";
|
||||
}
|
||||
} else if (audioformat.getChannels() == 2) {
|
||||
if (audioformat.getSampleSizeInBits() == 8) {
|
||||
channels = AL10.AL_FORMAT_STEREO8;
|
||||
channels = AL11.AL_FORMAT_STEREO8;
|
||||
} else if (audioformat.getSampleSizeInBits() == 16) {
|
||||
channels = AL10.AL_FORMAT_STEREO16;
|
||||
channels = AL11.AL_FORMAT_STEREO16;
|
||||
} else {
|
||||
assert false : "Illegal sample size";
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
import java.nio.FloatBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjglx.BufferUtils;
|
||||
|
||||
/**
|
||||
* Project.java
|
||||
|
||||
@@ -35,7 +35,7 @@ import static org.lwjgl.opengl.GL11.*;
|
||||
import static org.lwjgl.opengl.GL12.*;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjglx.BufferUtils;
|
||||
|
||||
/**
|
||||
* Util.java
|
||||
@@ -236,6 +236,9 @@ public class Util {
|
||||
* @return int
|
||||
*/
|
||||
protected static int glGetIntegerv(int what) {
|
||||
return glGetInteger(what);
|
||||
// scratch.rewind();
|
||||
// glGetIntegerv(what, scratch);
|
||||
// return scratch.get();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user