I am working on a new game. This is the first time I make a game with lwjgl.
On my Computer and on some others the Display shows what I expected to see but on some other Computers the Display is black. I actually don’t know what I did wrong.
Here is some code. Maybe it helps you.
This is how I setup my Display:
Display.setDisplayMode(new DisplayMode(960, 640));
Display.create();
Display.setVSyncEnabled(true);
GL11.glViewport(0, 0, 960, 640);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(0, 480, 320, 0, -1, 1);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glDisable(GL11.GL_DEPTH_TEST);
And this is the way I load textures:
public static Texture createTexture(BufferedImage image) {
int width = image.getWidth();
int height = image.getHeight();
int[] pixels = new int[width * height];
image.getRGB(0, 0, width, height, pixels, 0, width);
ByteBuffer buffer = BufferUtils.createByteBuffer(width * height * 4);
for (int y = 0; y < width; y++) {
for (int x = 0; x < height; x++) {
int i = pixels[x + y * width];
buffer.put((byte) ((i >> 16) & 0xFF));
buffer.put((byte) ((i >> 8) & 0xFF));
buffer.put((byte) ((i) & 0xFF));
buffer.put((byte) ((i >> 24) & 0xFF));
}
}
buffer.flip();
int ID = glGenTextures();
glBindTexture(GL_TEXTURE_2D, ID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
Texture texture = new Texture();
texture.width = image.getWidth();
texture.height = image.getHeight();
texture.ID = ID;
return texture;
}
If you need some more information feel free to tell me.
~ pixinator