use of org.lwjgl.LWJGLException in project lwjgl by LWJGL.
the class BackgroundLoadTest method initialize.
private static void initialize(String[] args) {
if (args.length != 1)
argsError();
DisplayMode displayMode = null;
try {
DisplayMode[] modes = Display.getAvailableDisplayModes();
displayMode = chooseMode(modes, 1024, 768);
if (displayMode == null)
displayMode = chooseMode(modes, 800, 600);
if (displayMode == null)
displayMode = chooseMode(modes, 640, 480);
if (displayMode == null)
kill("Failed to set an appropriate display mode.");
System.out.println("Setting display mode to: " + displayMode);
Display.setDisplayMode(displayMode);
Display.setTitle("Background Loading Test");
Display.create(new PixelFormat(8, 24, 0));
} catch (LWJGLException e) {
kill(e.getMessage());
}
glViewport(0, 0, displayMode.getWidth(), displayMode.getHeight());
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45, displayMode.getWidth() / (float) displayMode.getHeight(), 1.0f, 10.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// Setup camera position.
glTranslatef(0.0f, 0.0f, -4.0f);
glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
glPushMatrix();
glClearDepth(1.0f);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glFrontFace(GL_CCW);
glPolygonMode(GL_FRONT, GL_FILL);
glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);
glAlphaFunc(GL_GREATER, 0.0f);
glEnable(GL_ALPHA_TEST);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_BLEND);
glShadeModel(GL_SMOOTH);
final FloatBuffer vectorBuffer = BufferUtils.createFloatBuffer(4);
vectorBuffer.clear();
vectorBuffer.put(0, 1.0f).put(1, 1.0f).put(2, 1.0f).put(3, 1.0f);
glLight(GL_LIGHT0, GL_DIFFUSE, vectorBuffer);
vectorBuffer.put(0, 1.0f).put(1, 1.0f).put(2, 1.0f).put(3, 1.0f);
glLight(GL_LIGHT0, GL_AMBIENT, vectorBuffer);
vectorBuffer.put(0, 1.0f).put(1, 1.0f).put(2, 0.5f).put(3, 1.0f);
glLight(GL_LIGHT0, GL_SPECULAR, vectorBuffer);
// Infinite
vectorBuffer.put(0, -1.0f / 3.0f).put(1, 1.0f / 3.0f).put(2, 1.0f / 3.0f).put(3, 0.0f);
glLight(GL_LIGHT0, GL_POSITION, vectorBuffer);
vectorBuffer.put(0, 0.2f).put(1, 0.2f).put(2, 0.2f).put(3, 1.0f);
glLightModel(GL_LIGHT_MODEL_AMBIENT, vectorBuffer);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
sphere = new Sphere();
if ("PB".equalsIgnoreCase(args[0])) {
backgroundLoader = new BackgroundLoader() {
Drawable getDrawable() throws LWJGLException {
return new Pbuffer(2, 2, new PixelFormat(8, 24, 0), Display.getDrawable());
}
};
} else if ("SD".equalsIgnoreCase(args[0])) {
backgroundLoader = new BackgroundLoader() {
Drawable getDrawable() throws LWJGLException {
return new SharedDrawable(Display.getDrawable());
}
};
} else {
argsError();
}
}
use of org.lwjgl.LWJGLException in project lwjgl by LWJGL.
the class UniqueRendererRTT method init.
// Initialize texture renderer
protected Pbuffer init(final int width, final int height, final int texID) {
Pbuffer pbuffer = null;
try {
final RenderTexture rt = new RenderTexture(true, false, false, false, RenderTexture.RENDER_TEXTURE_2D, 0);
pbuffer = new Pbuffer(width, height, new PixelFormat(16, 0, 0, 0, 0), rt, null);
// Initialise state of the pbuffer context.
pbuffer.makeCurrent();
PbufferTest.initGLState(width, height, 0.5f);
glBindTexture(GL_TEXTURE_2D, texID);
Display.makeCurrent();
} catch (LWJGLException e) {
e.printStackTrace();
System.exit(-1);
}
return pbuffer;
}
use of org.lwjgl.LWJGLException in project lwjgl by LWJGL.
the class ShadersTest method initialize.
private static void initialize(String[] args) {
if (args.length != 1)
argsError();
try {
DisplayMode[] modes = Display.getAvailableDisplayModes();
DisplayMode displayMode;
displayMode = chooseMode(modes, 1024, 768);
if (displayMode == null)
displayMode = chooseMode(modes, 800, 600);
if (displayMode == null)
displayMode = chooseMode(modes, 640, 480);
if (displayMode == null)
kill("Failed to set an appropriate display mode.");
System.out.println("Setting display mode to: " + displayMode);
Display.setDisplayMode(displayMode);
Display.create(new PixelFormat(8, 24, 0));
ShadersTest.displayMode = displayMode;
} catch (LWJGLException e) {
kill(e.getMessage());
}
final ContextCapabilities caps = GLContext.getCapabilities();
if ("NONE".equalsIgnoreCase(args[0])) {
shader = null;
} else if ("VP".equalsIgnoreCase(args[0])) {
if (!caps.GL_ARB_vertex_program)
kill("The ARB_vertex_program extension is not supported.");
shader = new ShaderVP("shaderVP.vp");
} else if ("FP".equalsIgnoreCase(args[0])) {
if (!caps.GL_ARB_vertex_program)
kill("The ARB_vertex_program extension is not supported.");
if (!caps.GL_ARB_fragment_program)
kill("The ARB_fragment_program extension is not supported.");
shader = new ShaderFP("shaderFP.vp", "shaderFP.fp");
} else if ("VSH".equalsIgnoreCase(args[0])) {
if (!caps.GL_ARB_vertex_shader)
kill("The ARB_vertex_shader extension is not supported.");
shader = new ShaderVSH("shaderVSH.vsh");
} else if ("FSH".equalsIgnoreCase(args[0])) {
if (!caps.GL_ARB_vertex_shader)
kill("The ARB_vertex_shader extension is not supported.");
if (!caps.GL_ARB_fragment_shader)
kill("The ARB_fragment_shader extension is not supported.");
shader = new ShaderFSH("shaderFSH.vsh", "shaderFSH.fsh");
} else if ("UNI".equalsIgnoreCase(args[0])) {
if (!(caps.OpenGL31 || caps.GL_ARB_uniform_buffer_object))
kill("Neither OpenGL version 3.1 nor ARB_uniform_buffer_object are supported.");
shader = new ShaderUNI("shaderUNI.vsh");
} else {
argsError();
}
glViewport(0, 0, displayMode.getWidth(), displayMode.getHeight());
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45, displayMode.getWidth() / (float) displayMode.getHeight(), 1.0f, 10.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// Setup camera position.
glTranslatef(0.0f, 0.0f, -4.0f);
glRotatef(15.0f, 1.0f, 0.0f, 0.0f);
glPushMatrix();
glClearDepth(1.0f);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glFrontFace(GL_CCW);
glPolygonMode(GL_FRONT, GL_FILL);
glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);
glAlphaFunc(GL_NOTEQUAL, 0.0f);
glEnable(GL_ALPHA_TEST);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
// Setup lighting for when we have fixed function fragment rendering.
glShadeModel(GL_SMOOTH);
if (shader == null) {
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
}
vectorBuffer.clear();
vectorBuffer.put(1.0f).put(1.0f).put(1.0f).put(1.0f);
vectorBuffer.clear();
glLight(GL_LIGHT0, GL_DIFFUSE, vectorBuffer);
vectorBuffer.put(1.0f).put(1.0f).put(1.0f).put(1.0f);
vectorBuffer.clear();
glLight(GL_LIGHT0, GL_AMBIENT, vectorBuffer);
vectorBuffer.put(1.0f).put(1.0f).put(0.5f).put(1.0f);
vectorBuffer.clear();
glLight(GL_LIGHT0, GL_SPECULAR, vectorBuffer);
// Infinite
vectorBuffer.put(-1.0f / 3.0f).put(1.0f / 3.0f).put(1.0f / 3.0f).put(0.0f);
vectorBuffer.clear();
glLight(GL_LIGHT0, GL_POSITION, vectorBuffer);
vectorBuffer.put(0.2f).put(0.2f).put(0.2f).put(1.0f);
vectorBuffer.clear();
glLightModel(GL_LIGHT_MODEL_AMBIENT, vectorBuffer);
sphere = new Sphere();
}
use of org.lwjgl.LWJGLException in project lwjgl by LWJGL.
the class UniqueRenderer method init.
protected Pbuffer init(final int width, final int height, final int texID) {
Pbuffer pbuffer = null;
try {
pbuffer = new Pbuffer(width, height, new PixelFormat(16, 0, 0, 0, 0), null, null);
// Initialise state of the pbuffer context.
pbuffer.makeCurrent();
PbufferTest.initGLState(width, height, 0.5f);
glBindTexture(GL_TEXTURE_2D, texID);
Display.makeCurrent();
} catch (LWJGLException e) {
e.printStackTrace();
System.exit(-1);
}
return pbuffer;
}
use of org.lwjgl.LWJGLException in project Catacomb-Snatch by Catacomb-Snatch.
the class DesktopLauncher method main.
public static void main(String[] arg) {
System.out.println("Starting game in DESKTOP mode!");
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
// TODO Re-enable if it got fixed on all systems (currently throws a shader error)
// config.useGL30 = true;
config.title = "Catacomb Snatch";
config.width = GAME_WIDTH;
config.height = GAME_HEIGHT;
new LwjglApplication(new CatacombSnatch(new PlatformDependent() {
@Override
public void create() {
// Set game cursor
try {
int size = 16, center = (size / 2);
IntBuffer buffer = BufferUtils.newIntBuffer(size * size);
int x = 0, y = 0;
for (int n = 0; n < buffer.limit(); n++) {
if ((x == center || y == center) && (x < center - 1 || y < center - 1 || x > center + 1 || y > center + 1)) {
buffer = buffer.put(n, 0xFFFFFFFF);
}
x++;
if (x == size) {
x = 0;
y++;
}
}
Mouse.setNativeCursor(new Cursor(size, size, center, center, 1, buffer, null));
} catch (LWJGLException e) {
System.err.print("Error setting native cursor!\n" + e);
}
}
@Override
public Object[] createPlatformObjects() {
throw new UnsupportedOperationException("Unimplemented");
}
@Override
public void dispose() {
}
}), config);
}
Aggregations