OpenGl with C++ - Textures -


i'm trying map textures in opengl face of cube. but, when run program texture doesn't appear. have block of code:

        glenable(gl_texture_2d);         glbindtexture(gl_texture_2d,texture[1]);          glpushmatrix();          glbegin(gl_quads);                                  // begin drawing color cube 6 quads                                                             // top face (y = 1.0f)                                                             // define vertices in counter-clockwise (ccw) order normal pointing out         //glcolor3f(0.0f, 1.0f, 0.0f);     // green         glvertex3f( 1.0f+i*2, -2.0f+y*2, -1.0f+j*2);         glvertex3f(-1.0f+i*2, -2.0f+y*2, -1.0f+j*2);         glvertex3f(-1.0f+i*2, -2.0f+y*2,  1.0f+j*2);         glvertex3f( 1.0f+i*2, -2.0f+y*2,  1.0f+j*2);                                                              // bottom face (y = -1.0f)         //glcolor3f(1.0f, 0.5f, 0.0f);     // orange         glvertex3f( 1.0f+i*2, -4.0f+y*2,  1.0f+j*2);         glvertex3f(-1.0f+i*2, -4.0f+y*2,  1.0f+j*2);         glvertex3f(-1.0f+i*2, -4.0f+y*2, -1.0f+j*2);         glvertex3f( 1.0f+i*2, -4.0f+y*2, -1.0f+j*2);                                                              // front face  (z = 1.0f)         //glcolor3f(1.0f, 0.0f, 0.0f);     // red         gltexcoord2f(0.0f,0.0f);  glvertex3f( 1.0f+i*2,  -2.0f+y*2, 1.0f+j*2);         gltexcoord2f(10.0f,0.0f); glvertex3f(-1.0f+i*2,  -2.0f+y*2, 1.0f+j*2);         gltexcoord2f(10.0f,10.0f); glvertex3f(-1.0f+i*2, -4.0f+y*2, 1.0f+j*2);         gltexcoord2f(0.0f,10.0f); glvertex3f( 1.0f+i*2, -4.0f+y*2, 1.0f+j*2);                                                              // face (z = -1.0f)         //glcolor3f(1.0f, 1.0f, 0.0f);     // yellow         glvertex3f( 1.0f+i*2, -4.0f+y*2, -1.0f+j*2);         glvertex3f(-1.0f+i*2, -4.0f+y*2, -1.0f+j*2);         glvertex3f(-1.0f+i*2,  -2.0f+y*2, -1.0f+j*2);         glvertex3f( 1.0f+i*2,  -2.0f+y*2, -1.0f+j*2);                                                              // left face (x = -1.0f)         //glcolor3f(0.0f, 0.0f, 1.0f);     // blue         glvertex3f(-1.0f+i*2,  -2.0f+y*2,  1.0f+j*2);         glvertex3f(-1.0f+i*2,  -2.0f+y*2, -1.0f+j*2);         glvertex3f(-1.0f+i*2, -4.0f+y*2, -1.0f+j*2);         glvertex3f(-1.0f+i*2, -4.0f+y*2,  1.0f+j*2);                                                              // right face (x = 1.0f)         //glcolor3f(1.0f, 0.0f, 1.0f);     // magenta         glvertex3f(1.0f+i*2,  -2.0f+y*2, -1.0f+j*2);         glvertex3f(1.0f+i*2,  -2.0f+y*2,  1.0f+j*2);         glvertex3f(1.0f+i*2, -4.0f+y*2,  1.0f+j*2);         glvertex3f(1.0f+i*2, -4.0f+y*2, -1.0f+j*2);         glend();                                            // end of drawing color-cube          glpopmatrix();          gldisable(gl_texture_2d); 

my init function this:

void initgl() {      glclearcolor(0.0f, 0.0f, 0.0f, 1.0f);                       // set background color black , opaque      glshademodel(gl_smooth);                                    // enable smooth shading      cria_texturas(); glenable(gl_texture_2d);      //glcleardepth(1.0f);                                         // set background depth farthest      glenable(gl_depth_test);                                    // enable depth testing z-culling      //gldepthfunc(gl_lequal);                                     // set type of depth-test      //glhint(gl_perspective_correction_hint, gl_nicest);          // nice perspective corrections } 

to load texture have written code uses premade class loads image:

glgentextures(1, &texture[0]); glbindtexture(gl_texture_2d, texture[1]); gltexenvf(gl_texture_env, gl_texture_env_mode, gl_decal); gltexparameteri(gl_texture_2d, gl_texture_mag_filter, gl_linear); gltexparameteri(gl_texture_2d, gl_texture_min_filter, gl_linear); gltexparameteri(gl_texture_2d, gl_texture_wrap_s, gl_repeat); gltexparameteri(gl_texture_2d, gl_texture_wrap_t, gl_repeat); imag.loadbmpfile("chao.bmp"); glteximage2d(gl_texture_2d, 0, 3,              imag.getnumcols(),              imag.getnumrows(), 0, gl_rgb, gl_unsigned_byte,              imag.imagedata()); 

so don't understand why texture doesn't appear in face of cube. can me?

when using immediate mode (glbegin, glend) call of glvertex finishing build of 1 single vertex. glvertex coalescing attributes have been placed in other attribute "registers" , sends buffer.

in code have following:

    gltexcoord2f(0.0f,0.0f);  glvertex3f( 1.0f+i*2,  -2.0f+y*2, 1.0f+j*2);     gltexcoord2f(10.0f,0.0f); glvertex3f(-1.0f+i*2,  -2.0f+y*2, 1.0f+j*2);     gltexcoord2f(10.0f,10.0f); glvertex3f(-1.0f+i*2, -4.0f+y*2, 1.0f+j*2);     gltexcoord2f(0.0f,10.0f); glvertex3f( 1.0f+i*2, -4.0f+y*2, 1.0f+j*2);                                                          // face (z = -1.0f)      glvertex3f( 1.0f+i*2, -4.0f+y*2, -1.0f+j*2); 

only last of these gltexcoord calls has effect, other ones set register, value gets overwritten following calls.

the way use immediate mode is

foreach vertex in model:     glcolor     glnormal     gltexcoord     ...     glvertex // must last call specifying vertex! 

you can not group glcolor, glnormal , other calls. but should not use immediate mode anyway! has been deprecated since 1996, when opengl-1.1 did introduce vertex arrays. insist on using technology has been outdated 20 years?


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -