Monday 15 March 2010

c++ - NPOT support in OpenGL for R8G8B8 texture -



c++ - NPOT support in OpenGL for R8G8B8 texture -

i have created sample application using glew , glut reads dds file , displays it. manually read dds file (npot(886 x 317) file in r8g8b8) , creates info pointer(unsigned char*).

then prepared texture using

void preparetexture(int w, int h, unsigned char* data) { /* create , load texture opengl */ glgentextures(1, &textureid); /* texture name generation */ glbindtexture(gl_texture_2d, textureid); glteximage2d(gl_texture_2d, 0, gl_rgb, w, h, 0, gl_rgb, gl_unsigned_byte, data); glgeneratemipmap(gl_texture_2d); }

in above figure, first 1 shows original dds file , sec 1 rendering result of application wrong. if re-size image 1024 x 512, both images same.

from opengl specification

i.3 non-power-of-two textures restriction of textures power-of-two dimensions has been relaxed texture targets, non-power-of-two textures may specified without generating errors. non-power-of-two textures promoted arb texture non powerfulness of 2 extension.

from understand opengl 2.0 can utilize npot textures , opengl handle this.

i tried using devil image library load dds file end same result. if convert image rgba , and alter internal format , format of glteximage2d gl_rgba right result if dds file npot.

glteximage2d(gl_texture_2d, 0, gl_rgba, w, h, 0, gl_rgba, gl_unsigned_byte, data);

i tried application in pc's nvida card , radeon card , both of them giving same result.

my sample source code can downloaded link

can tell me wrong application? or opengl not allow npot if image in r8g8b8.

this looks alignment issue. add together before glteximage2d() call:

glpixelstorei(gl_unpack_alignment, 1);

this value specifies row alignment of info in bytes. default value 4.

with texture width of 886 , 3 bytes per pixel gl_rgb, each row 886 * 3 = 2658 bytes, not multiple of 4.

with unpack_alignment value @ default, size rounded next multiple of 4, 2660. 2660 bytes read each row, explains increasing shift each row. first row correct, sec 1 2 bytes off, 2nd row 4 bytes off, 3rd row 6 bytes off, etc.

c++ opengl

No comments:

Post a Comment