i using tao framework work opengl. i`m trying load texture , show on form. image seems load correctly (texture id generated , no errors occure) not shown correctly.
here code loading texture
public static class texturemanager { static texturemanager() { il.ilinit(); il.ilenable(il.il_origin_set); } public static int loadtexture(string url) { int texobject = -1; int imageid; il.ilgenimages(1, out imageid); il.ilbindimage(imageid); if (il.illoadimage(url)) { int width = il.ilgetinteger(il.il_image_width); int height = il.ilgetinteger(il.il_image_height); gl.glgentextures(1, out texobject); gl.glpixelstorei(gl.gl_unpack_alignment, 1); gl.glbindtexture(gl.gl_texture_2d, texobject); gl.gltexparameteri(gl.gl_texture_2d, gl.gl_texture_wrap_s, gl.gl_repeat); gl.gltexparameteri(gl.gl_texture_2d, gl.gl_texture_wrap_t, gl.gl_repeat); gl.gltexparameteri(gl.gl_texture_2d, gl.gl_texture_mag_filter, gl.gl_linear); gl.gltexparameteri(gl.gl_texture_2d, gl.gl_texture_min_filter, gl.gl_linear); gl.gltexenvf(gl.gl_texture_env, gl.gl_texture_env_mode, gl.gl_replace); gl.glteximage2d(gl.gl_texture_2d, 0, gl.gl_rgb, width, height, 0, gl.gl_rgb, gl.gl_unsigned_byte, il.ilgetdata()); il.ildeleteimages(1, ref imageid); } return texobject; } }
and code drawing it:
gl.glclear(gl.gl_color_buffer_bit | gl.gl_depth_buffer_bit); gl.glclearcolor(255, 255, 255, 1); gl.glloadidentity(); gl.glenable(gl.gl_texture_2d); gl.glbindtexture(gl.gl_texture_2d, mgltextureobject); gl.glpushmatrix(); gl.gltranslated(0, -1, -10); gl.glrotated(rot, 0, 1, 0); gl.glbegin(gl.gl_quads); gl.glnormal3f(0, 0, 1); gl.gltexcoord2f(0, 0); gl.glvertex3d(0, 0, 0); gl.gltexcoord2f(1, 0); gl.glvertex3d(1, 0, 0); gl.gltexcoord2f(1, 1); gl.glvertex3d(1, 1, 0); gl.gltexcoord2f(0, 1); gl.glvertex3d(0, 1, 0); gl.glend(); gl.glpopmatrix(); gl.gldisable(gl.gl_texture_2d); ant.invalidate();
the form blank. if enable lightning here showed:
the image loading simple bmp image 100x100 created in paint.
the problem appeared because image in incorrect size. size of images should 64x64, 128x128 or 256x256. changed size 128x128 , worked fine.
Comments
Post a Comment