बनावट लोड करने के लिए मेरा सरल सी कार्यान्वयन फ़ंक्शन देखें।
GLuint LoadTexture(const char * filename)
{
GLuint texture;
int width, height;
unsigned char * data;
FILE * file;
file = fopen(filename, "rb");
if (file == NULL) return 0;
width = 1024;
height = 512;
data = (unsigned char *)malloc(width * height * 3);
//int size = fseek(file,);
fread(data, width * height * 3, 1, file);
fclose(file);
for(int i = 0; i < width * height ; ++i)
{
int index = i*3;
unsigned char B,R;
B = data[index];
R = data[index+2];
data[index] = R;
data[index+2] = B;
}
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,GL_MODULATE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_REPEAT);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, width, height,GL_RGB, GL_UNSIGNED_BYTE, data);
free(data);
return texture;
}
उपरोक्त फ़ंक्शन बनावट डेटा देता है। चर
GLuint texture
texture= LoadTexture("your_image_name.bmp");
में बनावट डाटा स्टोर अब आप glBindTexture
glBindTexture (GL_TEXTURE_2D, texture);
स्रोत
2012-09-21 03:54:17
+1। – Cosine
यह थ्रेड-असुर – AbiusX
यह बहुत मजेदार है, कभी भी अपना खुद का लेखन नहीं माना जाता है ... –