Java Code Examples for org.lwjgl.LWJGLException#printStackTrace()

The following examples show how to use org.lwjgl.LWJGLException#printStackTrace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LwJglRenderingEngine.java    From Gaalop with GNU Lesser General Public License v3.0 7 votes vote down vote up
/**
 * Starts the lwjgl engine and shows a window, where the point clouds are rendered
 */
public void startEngine() {
    int width = 800;
    int height = 600;
    
    try {
        Display.setDisplayMode(new DisplayMode(width, height));
        Display.setFullscreen(false);
        Display.setTitle("Gaalop Visualization Window");

        Display.create();
    } catch (LWJGLException e) {
        e.printStackTrace();
        System.exit(0);
    }
    
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glShadeModel(GL11.GL_SMOOTH);
    changeSize(width, height);
    GL11.glDisable(GL11.GL_LIGHTING);


    // init OpenGL
    GL11.glViewport(0, 0, width, height);
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GLU.gluPerspective((float) 65.0, (float) width / (float) height, (float) 0.1, 100);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    
    
}
 
Example 2
Source File: Window.java    From LowPolyWater with The Unlicense 6 votes vote down vote up
protected Window(Context context, WindowBuilder settings) {
	this.fpsCap = settings.getFpsCap();
	try {
		getSuitableFullScreenModes();
		DisplayMode resolution = getStartResolution(settings);
		Display.setInitialBackground(1, 1, 1);
		this.aspectRatio = (float) resolution.getWidth() / resolution.getHeight();
		setResolution(resolution, settings.isFullScreen());
		if (settings.hasIcon()) {
			Display.setIcon(settings.getIcon());
		}
		Display.setVSyncEnabled(settings.isvSync());
		Display.setTitle(settings.getTitle());
		Display.create(new PixelFormat().withDepthBits(24).withSamples(4), context.getAttribs());
		GL11.glViewport(0, 0, resolution.getWidth(), resolution.getHeight());
	} catch (LWJGLException e) {
		e.printStackTrace();
	}
}
 
Example 3
Source File: AppletGameContainer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Start the game container
 * 
 * @throws Exception Failure to create display
 */
public void start() throws Exception {
   Display.setParent(displayParent);
   Display.setVSyncEnabled(true);
   
   try {
      createDisplay();
   } catch (LWJGLException e) {
      e.printStackTrace();
      // failed to create Display, apply workaround (sleep for 1 second) and try again
      Thread.sleep(1000);
      createDisplay();
   }
   
   initGL();
   displayParent.requestFocus();
   container.runloop();
}
 
Example 4
Source File: OpenGL3_TheQuadTextured.java    From ldparteditor with MIT License 6 votes vote down vote up
private void setupOpenGL() {
    // Setup an OpenGL context with API version 3.2
    try {
        PixelFormat pixelFormat = new PixelFormat();
        ContextAttribs contextAtrributes = new ContextAttribs(3, 2)
            .withForwardCompatible(true)
            .withProfileCore(true);
         
        Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
        Display.setTitle(WINDOW_TITLE);
        Display.create(pixelFormat, contextAtrributes);
         
        GL11.glViewport(0, 0, WIDTH, HEIGHT);
    } catch (LWJGLException e) {
        e.printStackTrace();
        System.exit(-1);
    }
     
    // Setup an XNA like background color
    GL11.glClearColor(0.4f, 0.6f, 0.9f, 0f);
     
    // Map the internal OpenGL coordinate system to the entire screen
    GL11.glViewport(0, 0, WIDTH, HEIGHT);
     
    this.exitOnGLError("setupOpenGL");
}
 
Example 5
Source File: VideoHook.java    From malmo with MIT License 6 votes vote down vote up
/**
 * Resizes the window and the Minecraft rendering if necessary. Set renderWidth and renderHeight first.
 */
private void resizeIfNeeded()
{
    // resize the window if we need to
    int oldRenderWidth = Display.getWidth(); 
    int oldRenderHeight = Display.getHeight();
    if( this.renderWidth == oldRenderWidth && this.renderHeight == oldRenderHeight )
        return;
    
    try {
        int old_x = Display.getX();
        int old_y = Display.getY();
        Display.setLocation(old_x, old_y);
        Display.setDisplayMode(new DisplayMode(this.renderWidth, this.renderHeight));
        System.out.println("Resized the window");
    } catch (LWJGLException e) {
        System.out.println("Failed to resize the window!");
        e.printStackTrace();
    }
    forceResize(this.renderWidth, this.renderHeight);
}
 
Example 6
Source File: DisplayManager.java    From OpenGL-Animation with The Unlicense 6 votes vote down vote up
public static void createDisplay() {
	try {
		Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
		ContextAttribs attribs = new ContextAttribs(3, 2).withProfileCore(true).withForwardCompatible(true);
		Display.create(new PixelFormat().withDepthBits(24).withSamples(4), attribs);
		Display.setTitle(TITLE);
		Display.setInitialBackground(1, 1, 1);
		GL11.glEnable(GL13.GL_MULTISAMPLE);
	} catch (LWJGLException e) {
		e.printStackTrace();
		System.err.println("Couldn't create display!");
		System.exit(-1);
	}
	GL11.glViewport(0, 0, WIDTH, HEIGHT);
	lastFrameTime = getCurrentTime();
}
 
Example 7
Source File: Sonics.java    From AnyaBasic with MIT License 5 votes vote down vote up
public Sonics()
{
    // Initialize OpenAL and clear the error bit.
    try
    {
        AL.create();
    }
    catch (LWJGLException e)
    {
        e.printStackTrace();
        return;
    }
    AL10.alGetError();

}
 
Example 8
Source File: Window.java    From LowPolyWater with The Unlicense 5 votes vote down vote up
public void setResolution(DisplayMode resolution, boolean fullscreen) {
	try {
		Display.setDisplayMode(resolution);
		this.resolution = resolution;
		if (fullscreen && resolution.isFullscreenCapable()) {
			Display.setFullscreen(true);
			this.fullScreen = fullscreen;
		}
	} catch (LWJGLException e) {
		e.printStackTrace();
	}
}
 
Example 9
Source File: NativeCursor.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
public NativeCursor(GLIntImage image_16_1, int offset_x_16_1, int offset_y_16_1,
					GLIntImage image_32_1, int offset_x_32_1, int offset_y_32_1,
					GLIntImage image_32_8, int offset_x_32_8, int offset_y_32_8) {
	org.lwjgl.input.Cursor native_cursor = null;
	int caps = Cursor.getCapabilities();
	
	int alpha_bits = 0;
	if ((caps & Cursor.CURSOR_8_BIT_ALPHA) != 0)
		alpha_bits = 8;
	else if ((caps & Cursor.CURSOR_ONE_BIT_TRANSPARENCY) != 0)
		alpha_bits = 1;

	int max_size = Cursor.getMaxCursorSize();
		
	try {
		if (max_size < 32 && max_size >= 16 && alpha_bits >= 1)
			native_cursor = new org.lwjgl.input.Cursor(image_16_1.getWidth(), image_16_1.getHeight(), offset_x_16_1, offset_y_16_1, 1, image_16_1.createCursorPixels(), null);
		else if (max_size >= 32) {
			if (alpha_bits == 8)
				native_cursor = new org.lwjgl.input.Cursor(image_32_8.getWidth(), image_32_8.getHeight(), offset_x_32_8, offset_y_32_8, 1, image_32_8.createCursorPixels(), null);
			else if (alpha_bits == 1)
				native_cursor = new org.lwjgl.input.Cursor(image_32_1.getWidth(), image_32_1.getHeight(), offset_x_32_1, offset_y_32_1, 1, image_32_1.createCursorPixels(), null);
		}
	} catch (LWJGLException e) {
		e.printStackTrace();
	}
	cursor = native_cursor;
}
 
Example 10
Source File: Game.java    From FEMultiplayer with GNU General Public License v3.0 5 votes vote down vote up
public void init(int width, int height, String name) {
	time = System.nanoTime();
	
	windowWidth = width*scaleX;
	windowHeight = height*scaleY;

	try {
		Display.setDisplayMode(new DisplayMode(windowWidth, windowHeight));
		Display.create();
		Display.setTitle(name);
		Keyboard.create();
		Keyboard.enableRepeatEvents(true);
		Mouse.create();
		glContextExists = true;
	} catch (LWJGLException e) {
		e.printStackTrace();
		System.exit(0);
	}
	
	//init OpenGL
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);
	glEnable(GL_ALPHA_TEST);
	glAlphaFunc(GL_GREATER, 0.01f);
	glEnable(GL_TEXTURE_2D);
	glShadeModel(GL_SMOOTH);
	glClearDepth(1.0f);
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glViewport(0, 0, windowWidth, windowHeight);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0, windowWidth/scaleX, windowHeight/scaleY, 0, 1, -1);		//It's basically a camera
	glMatrixMode(GL_MODELVIEW);
	
	keys = new ArrayList<KeyboardEvent>();
	mouseEvents = new ArrayList<MouseEvent>();
}
 
Example 11
Source File: Window.java    From 3DGameEngine with Apache License 2.0 5 votes vote down vote up
public static void CreateWindow(int width, int height, String title)
{
	Display.setTitle(title);
	try 
	{
		Display.setDisplayMode(new DisplayMode(width, height));
		Display.create();
		Keyboard.create();
		Mouse.create();
	} 
	catch (LWJGLException e) 
	{
		e.printStackTrace();
	}
}
 
Example 12
Source File: DisplayManager.java    From OpenGL-Tutorial-1 with The Unlicense 5 votes vote down vote up
/**
 * Creates a display window on which we can render our game. The dimensions
 * of the window are determined by setting the display mode. By using
 * "glViewport" we tell OpenGL which part of the window we want to render
 * our game onto. We indicated that we want to use the entire window.
 */
public static void createDisplay() {
	ContextAttribs attribs = new ContextAttribs(3, 2).withForwardCompatible(true).withProfileCore(true);
	try {
		Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
		Display.create(new PixelFormat(), attribs);
		Display.setTitle(TITLE);
	} catch (LWJGLException e) {
		e.printStackTrace();
	}
	GL11.glViewport(0, 0, WIDTH, HEIGHT);
}
 
Example 13
Source File: TestUtils.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Initialise the GL display
 * 
 * @param width The width of the display
 * @param height The height of the display
 */
private void initGL(int width, int height) {
	try {
		Display.setDisplayMode(new DisplayMode(width,height));
		Display.create();
		Display.setVSyncEnabled(true);
	} catch (LWJGLException e) {
		e.printStackTrace();
		System.exit(0);
	}

	GL11.glEnable(GL11.GL_TEXTURE_2D);
	GL11.glShadeModel(GL11.GL_SMOOTH);        
	GL11.glDisable(GL11.GL_DEPTH_TEST);
	GL11.glDisable(GL11.GL_LIGHTING);                    
       
	GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);                
       GL11.glClearDepth(1);                                       
       
       GL11.glEnable(GL11.GL_BLEND);
       GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
       
       GL11.glViewport(0,0,width,height);
	GL11.glMatrixMode(GL11.GL_MODELVIEW);

	GL11.glMatrixMode(GL11.GL_PROJECTION);
	GL11.glLoadIdentity();
	GL11.glOrtho(0, width, height, 0, 1, -1);
	GL11.glMatrixMode(GL11.GL_MODELVIEW);
}
 
Example 14
Source File: Renderer.java    From AnyaBasic with MIT License 4 votes vote down vote up
Renderer( int screenWidth, int screenHeight )
{
    try
    {
        Display.setDisplayMode(new DisplayMode(screenWidth, screenHeight));
        Display.create();
        Display.setTitle( "AnyaBasic 0.4.0 beta" );
    }
    catch( LWJGLException e )
    {
        e.printStackTrace();
    }

    this.screenWidth = screenWidth;
    this.screenHeight = screenHeight;

    GL11.glViewport( 0, 0,
            screenWidth, screenHeight );

    GL11.glMatrixMode( GL11.GL_PROJECTION );
    GL11.glLoadIdentity();

    GL11.glOrtho( 0, screenWidth, screenHeight, 0, 1, -1 );
    GL11.glMatrixMode( GL11.GL_MODELVIEW );

    GL11.glLoadIdentity();

    GL11.glShadeModel(GL11.GL_SMOOTH);             //set shading to smooth(try GL_FLAT)
    GL11.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);     //set Clear color to BLACK
    GL11.glClearDepth(1.0f);                       //Set Depth buffer to 1(z-Buffer)
    GL11.glDisable(GL11.GL_DEPTH_TEST);            //Disable Depth Testing so that our z-buffer works

    GL11.glDepthFunc(GL11.GL_LEQUAL);

    GL11.glEnable(GL11.GL_COLOR_MATERIAL);


    GL11.glEnable(GL11.GL_TEXTURE_2D);

    GL11.glEnable( GL11.GL_ALPHA_TEST );
    GL11.glAlphaFunc(GL11.GL_GREATER, 0);

    GL11.glEnable( GL11.GL_BLEND );
    GL11.glBlendFunc( GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA );

    GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);

    GL11.glDisable(GL11.GL_CULL_FACE);

    GL11.glPolygonMode(GL11.GL_FRONT, GL11.GL_FILL);

    GL11.glMatrixMode( GL11.GL_MODELVIEW );
    GL11.glLoadIdentity();
    GL11.glTranslatef( 0.375f, 0.375f, 0 );	// magic trick

}
 
Example 15
Source File: Game.java    From FEMultiPlayer-V2 with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Inits the.
 *
 * @param width the width
 * @param height the height
 * @param name the name
 */
public void init(int width, int height, String name) {
	Game.logicalWidth = width;
	Game.logicalHeight = height;
	Game.scale = FEResources.getWindowScale();
	final int windowWidth = Math.round(logicalWidth * scale);
	final int windowHeight = Math.round(logicalHeight * scale);

	try {
		Display.setDisplayMode(new DisplayMode(windowWidth, windowHeight));
		Display.create();
		Display.setTitle(name);
		Keyboard.create();
		Keyboard.enableRepeatEvents(true);
		Mouse.create();
		glContextExists = true;
	} catch (LWJGLException e) {
		e.printStackTrace();
		System.exit(0);
	}
	
	//init OpenGL
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);
	glEnable(GL_ALPHA_TEST);
	glAlphaFunc(GL_GREATER, 0.01f);
	glEnable(GL_TEXTURE_2D);
	glShadeModel(GL_SMOOTH);
	glClearDepth(1.0f);
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glViewport(0, 0, windowWidth, windowHeight);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0, width, height, 0, 1, -1);		//It's basically a camera
	glMatrixMode(GL_MODELVIEW);
	
	keys = new ArrayList<KeyboardEvent>();
	mouseEvents = new ArrayList<MouseEvent>();
}
 
Example 16
Source File: ClientProxy.java    From Fullscreen-Windowed-Minecraft with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void toggleFullScreen(boolean goFullScreen, int desiredMonitor) {

    //Set value if it isn't set already.
    if(System.getProperty("org.lwjgl.opengl.Window.undecorated") == null){
        System.setProperty("org.lwjgl.opengl.Window.undecorated", "false");
    }

    //If we're in actual fullscreen right now, then we need to fix that.
    if(Display.isFullscreen()) {
        fullscreen = true;
    }

    String expectedState = goFullScreen ? "true":"false";
    // If all state is valid, there is nothing to do and we just exit.
    if(fullscreen == goFullScreen
            && !Display.isFullscreen()//Display in fullscreen mode: Change required
            && System.getProperty("org.lwjgl.opengl.Window.undecorated") == expectedState // Window not in expected state
    )
        return;

    //Save our current display parameters
    Rectangle currentCoordinates = new Rectangle(Display.getX(), Display.getY(), Display.getWidth(), Display.getHeight());
    if(goFullScreen && !Display.isFullscreen())
        _savedWindowedBounds = currentCoordinates;

    //Changing this property and causing a Display update will cause LWJGL to add/remove decorations (borderless).
    System.setProperty("org.lwjgl.opengl.Window.undecorated",expectedState);

    //Get the fullscreen dimensions for the appropriate screen.
    Rectangle screenBounds = getAppropriateScreenBounds(currentCoordinates, desiredMonitor);

    //This is the new bounds we have to apply.
    Rectangle newBounds = goFullScreen ? screenBounds : _savedWindowedBounds;
    if(newBounds == null)
        newBounds = screenBounds;

    if(goFullScreen == false && ClientProxy.fullscreen == false) {
        newBounds = currentCoordinates;
        _savedWindowedBounds = currentCoordinates;
    }

    try {
        fullscreen = goFullScreen;
        client.fullscreen = fullscreen;
        if( client.gameSettings.fullScreen != fullscreen) {
            client.gameSettings.fullScreen = fullscreen;
            client.gameSettings.saveOptions();
        }
        Display.setFullscreen(false);
        Display.setResizable(!goFullScreen);
        Display.setDisplayMode(new DisplayMode((int) newBounds.getWidth(), (int) newBounds.getHeight()));
        Display.setLocation(newBounds.x, newBounds.y);

        client.resize((int) newBounds.getWidth(), (int) newBounds.getHeight());
        Display.setVSyncEnabled(client.gameSettings.enableVsync);
        client.updateDisplay();

    } catch (LWJGLException e) {
        e.printStackTrace();
    }

}
 
Example 17
Source File: Renderer.java    From tribaltrouble with GNU General Public License v2.0 4 votes vote down vote up
private final static void failedOpenGL(LWJGLException e) {
	e.printStackTrace();
	try {
		UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
	} catch(Exception je) {
		je.printStackTrace();
	}

	ResourceBundle bundle = ResourceBundle.getBundle(Renderer.class.getName());
	String title = Utils.getBundleString(bundle, "error_title");
	String message = Utils.getBundleString(bundle, "opengl_error_message");
	int choice = JOptionPane.showConfirmDialog(null, message, title, JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);

	if (choice == JOptionPane.YES_OPTION) {
		String new_uid = (new UID()).toString();
		String uid = readOrSetPreference("uid", new_uid);
		String os_name = System.getProperty("os.name");
		String os_arch = System.getProperty("os.arch");
		String os_version = System.getProperty("os.version");
		String java_version = System.getProperty("java.version");
		String java_vendor = System.getProperty("java.vendor");
		long total_mem = Runtime.getRuntime().maxMemory();
		String adapter_name = Display.getAdapter();
		String adapter_version = Display.getVersion();

		try {
			String url = "http://oddlabs.com/driversupport.php?"
				+ "uid=" + URLEncoder.encode(uid, "UTF-8")
				+ "&raw_os=" + URLEncoder.encode(os_name, "UTF-8")
				+ "&os_version=" + URLEncoder.encode(os_version, "UTF-8")
				+ "&arch=" + URLEncoder.encode(os_arch, "UTF-8")
				+ "&java_version=" + URLEncoder.encode(java_version, "UTF-8")
				+ "&java_vendor=" + URLEncoder.encode(java_vendor, "UTF-8")
				+ "&total_mem=" + URLEncoder.encode("" + total_mem, "UTF-8");
			if (adapter_name != null)
				url += "&adapter_name=" + URLEncoder.encode(adapter_name, "UTF-8");
			if (adapter_version != null)
				url += "&adapter_version=" + URLEncoder.encode(adapter_version, "UTF-8");
			Sys.openURL(url);
		} catch (java.io.UnsupportedEncodingException uee) {
			uee.printStackTrace();
		}
	}

	Main.shutdown();
}
 
Example 18
Source File: Mini2DxOpenALAudio.java    From mini2Dx with Apache License 2.0 4 votes vote down vote up
public Mini2DxOpenALAudio(int simultaneousSources, int deviceBufferCount, int deviceBufferSize) {
	this.deviceBufferSize = deviceBufferSize;
	this.deviceBufferCount = deviceBufferCount;

	registerSound("ogg", Mini2DxOgg.Sound.class);
	registerMusic("ogg", Mini2DxOgg.Music.class);
	registerSound("wav", Mini2DxWav.Sound.class);
	registerMusic("wav", Mini2DxWav.Music.class);
	registerSound("mp3", Mini2DxMp3.Sound.class);
	registerMusic("mp3", Mini2DxMp3.Music.class);

	try {
		AL.create();
	} catch (LWJGLException ex) {
		noDevice = true;
		ex.printStackTrace();
		return;
	}

	allSources = new IntArray(false, simultaneousSources);
	for (int i = 0; i < simultaneousSources; i++) {
		int sourceID = alGenSources();
		if (alGetError() != AL_NO_ERROR)
			break;
		allSources.add(sourceID);
	}
	idleSources = new IntArray(allSources);
	soundIdToSource = new LongMap<Integer>();
	sourceToSoundId = new IntMap<Long>();

	FloatBuffer orientation = (FloatBuffer) BufferUtils.createFloatBuffer(6)
			.put(new float[] { 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f }).flip();
	alListener(AL_ORIENTATION, orientation);
	FloatBuffer velocity = (FloatBuffer) BufferUtils.createFloatBuffer(3).put(new float[] { 0.0f, 0.0f, 0.0f })
			.flip();
	alListener(AL_VELOCITY, velocity);
	FloatBuffer position = (FloatBuffer) BufferUtils.createFloatBuffer(3).put(new float[] { 0.0f, 0.0f, 0.0f })
			.flip();
	alListener(AL_POSITION, position);

	recentSounds = new Mini2DxOpenALSound[simultaneousSources];
	recentSoundIds = new LongArray(simultaneousSources);
}