java - OpenGL Mipmap Texture_2D -
i new in opengl , utilize lwjgl.
i not know how see if "mipmaps working"
this how load image (64x64) :
private int loadpngtexture(string filename) { bytebuffer buf = null; int twidth = 0; int theight = 0; seek { inputstream in = new fileinputstream(classloader.getsystemresource(filename).getpath()); decoder = new pngdecoder(in); twidth = decoder.getwidth(); theight = decoder.getheight(); buf = bufferutils.createbytebuffer(4 * decoder.getwidth() * decoder.getheight()); decoder.decode(buf, decoder.getwidth() * 4, pngdecoder.format.rgba); buf.flip(); in.close(); } grab (ioexception e) { e.printstacktrace(); system.exit(-1); } int texid = gl11.glgentextures(); gl13.glactivetexture(gl13.gl_texture0); gl11.glbindtexture(gl11.gl_texture_2d, texid); gl11.glpixelstorei(gl11.gl_unpack_alignment, 1); gl11.glteximage2d(gl11.gl_texture_2d, 0, gl11.gl_rgb, twidth, theight, 0, gl11.gl_rgba, gl11.gl_unsigned_byte, buf); gl30.glgeneratemipmap(gl11.gl_texture_2d); gl11.gltexparameteri(gl11.gl_texture_2d, gl11.gl_texture_wrap_s, gl11.gl_repeat); gl11.gltexparameteri(gl11.gl_texture_2d, gl11.gl_texture_wrap_t, gl11.gl_repeat); gl11.gltexparameteri(gl11.gl_texture_2d, gl11.gl_texture_mag_filter, gl11.gl_linear); gl11.gltexparameteri(gl11.gl_texture_2d, gl11.gl_texture_min_filter, gl11.gl_linear_mipmap_linear); homecoming texid; }
and how draw image :
public void drawgl() { gl11.glpushmatrix(); gl11.glbindtexture(gl11.gl_texture_2d, playertextures[0]); gl11.glbegin(gl11.gl_triangle_strip); gl11.gltexcoord2f(1, 0); gl11.glvertex2f(decoder.getwidth(), 0); gl11.gltexcoord2f(1, 1); gl11.glvertex2f(decoder.getwidth(), decoder.getwidth()); gl11.gltexcoord2f(0, 0); gl11.glvertex2f(0, 0); gl11.gltexcoord2f(0, 1); gl11.glvertex2f(0, decoder.getwidth()); gl11.glend(); gl11.glpopmatrix(); }
the draw correct, can see image if alter displaymode (from 800x600 1280x960), image not growing up. problem need image grow scale resolution.
java opengl lwjgl mipmaps
No comments:
Post a Comment