java - LWJGL BufferedImage White Picture -
i have problem loading image , rendering lwjgl.
here code loading:
bufferedimage image = imageio.read(file); int[] pixels = new int[image.getwidth() * image.getheight()]; image.getrgb(0, 0, image.getwidth(), image.getheight(), pixels, 0, image.getwidth()); bytebuffer buffer = bufferutils.createbytebuffer(image.getwidth() * image.getheight() * 3); for(int y = 0; y < image.getheight(); y++){ for(int x = 0; x < image.getwidth(); x++){ int pixel = pixels[y * image.getwidth() + x]; buffer.put((byte) ((pixel >> 16) & 0xff)); // red component buffer.put((byte) ((pixel >> 8) & 0xff)); // green component buffer.put((byte) (pixel & 0xff)); // blue component byte red = (byte)((pixel >> 16) & 0xff); byte green = (byte)((pixel >> 8) & 0xff); byte blue = (byte)(pixel >> 8 & 0xff); system.out.println("pixel " + x + "x" + y + " = r:" + red + " g:" + green + " b:" + blue); } } buffer.flip(); textureid = gl11.glgentextures(); gl11.glbindtexture(gl11.gl_texture_2d, textureid); gl11.glteximage2d(gl11.gl_texture_2d, 0, gl11.gl_rgb, image.getwidth(), image.getheight(), 0, gl11.gl_rgb, gl11.gl_unsigned_byte, buffer);
the rgb output looks correct, when render image see white area.
the code rendering:
glbindtexture(gl_texture_2d, image.gettextureid()); glcolor3f(1, 1, 1); glbegin(gl_quads); gltexcoord2f(0, 0); glvertex2i(0, 0); gltexcoord2f(image.getwidth(), 0); glvertex2i(0 + image.getwidth(), 0); gltexcoord2f(image.getwidth(), image.getheight()); glvertex2i(0 + image.getwidth(), 0 + image.getheight()); gltexcoord2f(0, image.getheight()); glvertex2i(0, 0 + image.getheight()); glend();
and how initialize opengl:
glmatrixmode(gl_projection); glloadidentity(); glortho(0, 800, 600, 0, 0, -1); glmatrixmode(gl_modelview); glenable(gl_blend); glblendfunc(gl_src_alpha, gl_one_minus_src_alpha);
i hope can me.
texture coordinates normalized [0, 1]. means (0, 0) in bottom left corner of texture , (1, 1) in top right corner of texture.
so, vertices should this:
gltexcoord2f(0, 0); glvertex2i(0, 0); gltexcoord2f(1, 0); glvertex2i(0 + image.getwidth(), 0); gltexcoord2f(1, 1); glvertex2i(0 + image.getwidth(), 0 + image.getheight()); gltexcoord2f(0, 1); glvertex2i(0, 0 + image.getheight());
Comments
Post a Comment