public int load(String imagepath) { BufferedImage bi; try { bi = ImageIO.read(new File(imagepath)); width = bi.getWidth(); height = bi.getHeight(); int[] pixels_raw = new int[width * height * 4]; pixels_raw = bi.getRGB(0, 0, width, height, null, 0, width); ByteBuffer pixels = BufferUtils.createByteBuffer(width * height * 4); for(int i = 0; i < width;i++) { for(int j = 0;j<height;j++) { int pixel = pixels_raw[i*width + j]; pixels.put((byte)((pixel >> 16) & 0xFF)); pixels.put((byte)((pixel >> 8) & 0xFF)); pixels.put((byte)(pixel & 0xFF)); pixels.put((byte)((pixel >> 24) & 0xFF)); } } pixels.flip(); id = glGenTextures(); glBindTexture(GL_TEXTURE_2D, id); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_BYTE, pixels); } catch(IOException e) { e.printStackTrace(); } return id; }
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_BYTE, pixels);