I have an issue regarding LWJGL and Slick
If I import a texture using Slick while having alpha blending enabled, the display will stop rendering!
Here is the code. Upon start it will simply render a purple square. Once the button T is pressed it will simply import the texture. Although i never actually bind the texture, the screen still turns black!
Here is my code:
import static org.lwjgl.opengl.GL11.GL_BLEND;
import java.io.IOException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;
import org.newdawn.slick.util.ResourceLoader;
public class Game {
public static void main(String[] args) throws Exception {
Display.setDisplayMode(new DisplayMode(800, 600));
Display.create();
Game game = new Game();
while (!Display.isCloseRequested()) {
game.update();
}
game.close();
}
public Game() {
initGL();
}
Texture boxTexture;
public void update() {
clearGL();
// Use the texture!
GL11.glColor3f(0.4f, 0.2f, 0.9f);
GL11.glBegin(GL11.GL_QUADS);
GL11.glVertex2f(100, 100);
GL11.glVertex2f(140, 100);
GL11.glVertex2f(140, 140);
GL11.glVertex2f(100, 140);
GL11.glEnd();
if(Keyboard.isKeyDown(Keyboard.KEY_T))
{
try {
boxTexture = TextureLoader.getTexture("png",
ResourceLoader.getResourceAsStream("res/ps.png"));
} catch (IOException e) {
e.printStackTrace();
}
}
Display.update();
}
public void close() {
Display.destroy();
System.exit(0);
}
public void initGL() {
// Enable Alpha Blending
GL11.glEnable(GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA,GL11.GL_ONE_MINUS_SRC_ALPHA);
// Opengl init
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(0, 500, 0, 500, 1, -1);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
// Enable textures
GL11.glEnable(GL11.GL_TEXTURE_2D);
}
public void clearGL() {
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
GL11.glLoadIdentity();
}
}