00030 {
00031
00032 int error;
00033
00034 tex_image = imFileImageLoadBitmap("rain_32x32.png", 0, &error);
00035 int width = tex_image->width;
00036 int height = tex_image->height;
00037 gl_tex_data_RGBA = (unsigned char*) malloc(4*width*height);
00038
00039 gl_tex_data_R = (unsigned char*) malloc(tex_image->size);
00040 gl_tex_data_G = (unsigned char*) malloc(tex_image->size);
00041 gl_tex_data_B = (unsigned char*) malloc(tex_image->size);
00042
00043 imConvertPacking(tex_image->data[0], gl_tex_data_R, tex_image->width, tex_image->height,
00044 tex_image->depth,tex_image->data_type, 0);
00045 imConvertPacking(tex_image->data[1], gl_tex_data_G, tex_image->width, tex_image->height,
00046 tex_image->depth,tex_image->data_type, 0);
00047 imConvertPacking(tex_image->data[2], gl_tex_data_B, tex_image->width, tex_image->height,
00048 tex_image->depth,tex_image->data_type, 0);
00049
00050 int rgba_count = 0;
00051 for(int i=0; i<width; i++)
00052 for(int j=0; j<height; j++)
00053 {
00054 int ch_count = i*width + j;
00055
00056 gl_tex_data_RGBA[rgba_count++] = gl_tex_data_R[ch_count];
00057 gl_tex_data_RGBA[rgba_count++] = gl_tex_data_G[ch_count];
00058 gl_tex_data_RGBA[rgba_count++] = gl_tex_data_B[ch_count];
00059
00060
00061 if ((gl_tex_data_R[ch_count] == 0) &&
00062 (gl_tex_data_G[ch_count] == 0) &&
00063 (gl_tex_data_B[ch_count] == 0))
00064 gl_tex_data_RGBA[rgba_count++] = 0;
00065 else
00066 gl_tex_data_RGBA[rgba_count++] = 255;
00067
00068 }
00069
00070 glGenTextures(1, &tex_id);
00071 glBindTexture(GL_TEXTURE_2D, tex_id);
00072
00073 glTexImage2D(GL_TEXTURE_2D, 0, 4, tex_image->width, tex_image->height, 0, GL_RGBA,
00074 GL_UNSIGNED_BYTE, gl_tex_data_RGBA);
00075 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
00076 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
00077
00078
00079 }