In C++, OpenGL, Glut, how to bind image.c to a texture, where image.c comes from Gimp>Export>C source code -


so i've spent past 2 days looking through different kinds of 'solutions' question via google, there aren't many , ones i've find don't seem work.

i'm exporting small test image .c resource file gimp, it's size 64x64 , has alpha channel. looks like:

    static const struct {     unsigned int     width;     unsigned int     height;     unsigned int     bytes_per_pixel; /* 2:rgb16, 3:rgb, 4:rgba */      char            *comment;     unsigned char    pixel_data[64 * 64 * 4 + 1];     } ship = {     64, 64, 4,     (char*) 0,     "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"     "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"     "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"     "\0\0\0\0\0\0\0\0\237\237\237\377\237\237\237\377\237\237\237\377\237\237"     "\237\377\237\237\237\377\237\237\237\377\237\237\237\377vzi\0vzi\0vzi\0\0"     "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" 

and goes on quite while, might expect, until ending with

    "\237\237\377\237\237\237\377\237\237\237\377",     }; 

so how can use resource file? if provide example, bare minimum needed create square texture stamped on it, i'd appreciative.

looking @ reference page glteximage2d, done (from here) :

gluint texname1 = 0;  glgentextures(1, &texname1); glbindtexture(gl_texture_2d, texname1); glpixelstorei(gl_unpack_alignment, 1); gltexparameteri(gl_texture_2d, gl_texture_wrap_s, gl_repeat); gltexparameteri (gl_texture_2d, gl_texture_wrap_t, gl_repeat); gltexparameteri (gl_texture_2d, gl_texture_mag_filter, gl_linear); gltexparameteri (gl_texture_2d, gl_texture_min_filter, gl_linear); gltexenvf(gl_texture_env, gl_texture_env_mode, gl_modulate); glteximage2d(gl_texture_2d, 0, ship.bytes_per_pixel, ship.width, ship.height, 0, getdataformat(), getdatatype(), ship.pixel_data);  glcolor3f(1, 1, 0); glbindtexture(gl_texture_2d, texname1); glbegin(gl_quads);     gltexcoord2f (0.0, 0.0);     glvertex3f (0.0, 0.0, -5.0f);     gltexcoord2f (1.0, 0.0);     glvertex3f (.5, 0.0, -5.0f);     gltexcoord2f (1.0, 1.0);     glvertex3f (.5, .5, -5.0f);     gltexcoord2f (0.0, 1.0);     glvertex3f (0.0, .5, -5.0f); glend(); 

the key line :

glteximage2d(gl_texture_2d, 0, ship.bytes_per_pixel, ship.width, ship.height, 0, getdataformat(), getdatatype(), ship.pixel_data); 

you need implement getdataformat() , getdatatype() yourself, , returns data format , type.

one possible implementation :

glenum getdataformat(){   return  gl_bgra; } glenum getdatatype(){   return  gl_unsigned_byte; } 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -