c++ - Rendering Object with Texture in OpenGL -


i'm trying put texture in model, doesn't work, model drawn without texture.

this function loads texture, @ first should working fine, because used in program. i'm calling function @ main function putting result in global variable called modeltexture.

gluint inittexture(char* filename) {    bitmapinfo *info;    glubyte *ptr, *bits, *rgba, *rgbaptr;    gluint texture, temp;    glenum type;    bits = loaddibitmap(filename, &info);    if (bits == (glubyte *)0) {    return null;    }    if (info->bmiheader.biheight == 1)        type = gl_texture_1d;    else    type = gl_texture_2d;    glgentextures(1, &texture);    glbindtexture(type, texture);    gltexparameteri(type, gl_texture_mag_filter, gl_linear);    gltexparameteri(type, gl_texture_min_filter, gl_linear_mipmap_linear);    gltexparameteri(type, gl_texture_wrap_s, gl_repeat);    gltexparameteri(type, gl_texture_wrap_t, gl_repeat);    rgba = (glubyte *)malloc(info->bmiheader.biwidth * info->bmiheader.biheight * 4);    int = info->bmiheader.biwidth * info->bmiheader.biheight;    for(rgbaptr = rgba, ptr = bits;  > 0; i--, rgbaptr += 4, ptr += 3){        rgbaptr[0] = ptr[2];        rgbaptr[1] = ptr[1];        rgbaptr[2] = ptr[0];        rgbaptr[3] = (ptr[0] + ptr[1] + ptr[2])/3;    }    glubuild2dmipmaps(gl_texture_2d, 4, info->bmiheader.biwidth, info->bmiheader.biheight, gl_rgba, gl_unsigned_byte, rgba);    return texture; } 

so, here display callback, draw model.

void rendergl(void){     glclear(gl_color_buffer_bit | gl_depth_buffer_bit);     glenable(gl_depth_test);     glfrontface(gl_cw);     glcullface (gl_back);     glenable(gl_cull_face);     glmatrixmode(gl_projection);     glloadidentity();     gluperspective(angle, aspratio, znear, zfar);     glmatrixmode(gl_modelview); updatecamera();     glpolygonmode(gl_front_and_back, gl_fill); glenable(gl_texture_2d);     glbindtexture(gl_texture_2d, modeltexture);     gltexenvi(gl_texture_env, gl_texture_env_mode, gl_replace);     int i;     (i = 0; < object.numtris; i++){         glbegin(gl_triangles);             glnormal3f(object.tris[i].normal[0].x, object.tris[i].normal[0].y, object.tris[i].normal[0].z);             gltexcoord2f(0.0f, 0.0f);             glvertex3f(object.tris[i].v0.x, object.tris[i].v0.y, object.tris[i].v0.z);             glnormal3f(object.tris[i].normal[1].x, object.tris[i].normal[1].y, object.tris[i].normal[1].z);             gltexcoord2f(0.5f, 1.0f);             glvertex3f(object.tris[i].v1.x, object.tris[i].v1.y, object.tris[i].v1.z);             glnormal3f(object.tris[i].normal[2].x, object.tris[i].normal[2].y, object.tris[i].normal[2].z);             gltexcoord2f(1.0f, 0.0f);             glvertex3f(object.tris[i].v2.x, object.tris[i].v2.y, object.tris[i].v2.z);         glend();     }     gldisable(gl_texture_2d); glutswapbuffers(); } 

so, there i'm doing wrong or forgetting do?


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -