c++ - DevIL image not rendering correctly -
i using opengl, can load tga files properly, reason when render jpg files, not see them correctly.
this image supposed like--
and looks like.. why stretched? because of coordinates?
here code using drawing.
void renderer::drawjpg(gluint tex, int xi, int yq, int width, int height) const { glbindtexture(gl_texture_2d, tex); glbegin(gl_quads); gltexcoord2i(0, 0); glvertex2i(0+xi, 0+xi); gltexcoord2i(0, 1); glvertex2i(0+xi, height+xi); gltexcoord2i(1, 1); glvertex2i(width+xi, height+xi); gltexcoord2i(1, 0); glvertex2i(width+xi, 0+xi); glend(); }
this how loading image...
imagename=s; ilboolean success; ilinit(); ilgenimages(1, &id); ilbindimage(id); success = illoadimage((const ilstring)imagename.c_str()); if (success) { success = ilconvertimage(il_rgb, il_unsigned_byte); /* convert every colour component unsigned byte. if image contains alpha channel can replace il_rgb il_rgba */ if (!success) { printf("image conversion failed."); } glgentextures(1, &id); glbindtexture(gl_texture_2d, id); width = ilgetinteger(il_image_width); height = ilgetinteger(il_image_height); glteximage2d(gl_texture_2d, 0, ilgetinteger(il_image_bpp), ilgetinteger(il_image_width), ilgetinteger(il_image_height), 0, ilgetinteger(il_image_format), gl_unsigned_byte, ilgetdata()); gltexparameteri(gl_texture_2d, gl_texture_wrap_s, gl_repeat); // linear filtered gltexparameteri(gl_texture_2d, gl_texture_wrap_t, gl_repeat); // linear filtered gltexparameteri(gl_texture_2d, gl_texture_mag_filter, gl_linear); gltexparameteri(gl_texture_2d, gl_texture_min_filter, gl_linear);
i should mention this, images did rendered properly, thought because width != height. not case, images width != height loaded fine. other images still problem.
you need call
glpixelstorei(gl_unpack_alignment, 1);
before uploading texture data glteximage2d
.
from reference pages:
gl_unpack_alignment
specifies alignment requirements start of each pixel row in memory. allowable values 1 (byte-alignment), 2 (rows aligned even-numbered bytes), 4 (word-alignment), , 8 (rows start on double-word boundaries).
the default value alignment 4 , image loading library returns pixel data byte-aligned rows, explains why of images ok (when width multiple of four).
Comments
Post a Comment