Java LWJGL: Display.create() schlägt fehl

T

T0B3Y

Gast
Hi,

ich bin grad dabei das erste mal mit LWJGL zu arbeiten. Java verwende ich schon länger. Nachdem ich einigen Code hinzugefügt hatte, ging das Programm einfach nicht mehr. Was ich am entsprechenden Teil geändert hatte, weiß ich leider nicht mehr. Durch etwas probieren fand ich raus, dass sich das Programm bei der Display.create() Methode einfach schließt. Fehlermeldung gibts keine.

Code:
package main;

import static org.lwjgl.opengl.GL11.GL_BLEND;
import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
import static org.lwjgl.opengl.GL11.GL_DEPTH_TEST;
import static org.lwjgl.opengl.GL11.GL_ONE_MINUS_SRC_ALPHA;
import static org.lwjgl.opengl.GL11.GL_SRC_ALPHA;
import static org.lwjgl.opengl.GL11.glBlendFunc;
import static org.lwjgl.opengl.GL11.glClear;
import static org.lwjgl.opengl.GL11.glClearColor;
import static org.lwjgl.opengl.GL11.glDisable;
import static org.lwjgl.opengl.GL11.glEnable;
import static org.lwjgl.opengl.GL11.glViewport;

import graphics.SpriteBatch;
import graphics.Texture;
import graphics.TextureRegion;

import java.awt.Toolkit;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;

public class Main {

	public static final boolean VSYNC = false;

	public static final int WIDTH = Toolkit.getDefaultToolkit().getScreenSize().width;
	public static final int HEIGHT = Toolkit.getDefaultToolkit()
			.getScreenSize().height;

	public static final boolean FULLSCREEN = true;
	private SpriteBatch batch;

	protected boolean running = false;

	Texture grassSheet;
	TextureRegion grass1;

	public static void main(String[] args) {
		
		try {
			new Main().start();
		} catch (LWJGLException e) {
		}
	}

	public void start() throws LWJGLException {

		

		Display.setTitle("Flime");
		Display.setResizable(true);
		Display.setDisplayMode(new DisplayMode(1366, 768));

		Display.setVSyncEnabled(VSYNC);

		DisplayMode[] modes = Display.getAvailableDisplayModes();
		
		for(DisplayMode m: modes) {
			System.out.println(m.getHeight());
			System.out.println(m.getWidth());
			System.out.println("");
		}
		Display.create();

		create();

		resize();

		batch = new SpriteBatch(WIDTH * HEIGHT);
		running = true;

		while (running && !Display.isCloseRequested()) {
			if (Display.wasResized())
				resize();

			if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE))
				running = false;

			tick();
			render();

			Display.update();
			Display.sync(60);
		}

		dispose();
		Display.destroy();
	}

	public void exit() {
		running = false;
	}

	protected void create() {

		glDisable(GL_DEPTH_TEST);

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

		glClearColor(0f, 0f, 0f, 0f);

		// ... initialize resources here ...

		try {
			grassSheet = new Texture(new URL("\res/grass.png"));
		} catch (Exception e) {
			grassSheet = null;
			e.printStackTrace();
		}
		grass1 = new TextureRegion(grassSheet, 0, 0, 64, 64);

	}

	protected void render() {
		glClear(GL_COLOR_BUFFER_BIT);

		batch.begin();

		batch.draw(grass1, 50, 50);

		batch.end();
	}

	protected void resize() {
		glViewport(0, 0, Display.getWidth(), Display.getHeight());
		// ... update our projection matrices here ...
	}

	protected void dispose() {
		// ... dispose of any textures, etc ...
	}

	protected void tick() {
		System.out.println("adsfasdfafasdf");

	}

}

Danke schonmal ;)

MfG
 
Du könntest (sortiert nach Aussicht auf Erfolg, absteigend):
  1. Debuggen
  2. Ein kompilierendes Beispiel hochladen (d.h. inkl. dependencies)
  3. Hoffen, dass ein LWJGL-Gott vorbeikommt
  4. Hoffen, dass jemand seine hellseherischen Fähigkeiten versucht
 
OK, ich hab das Problem grad gelöst. Was es war - keine Ahnung... ich hab einfach lwjgl neu runtergeladen, dann gings
 
Zurück
Oben