int LoadGLTextures() /* * 这是6面是一个图片的贴图源程序,怎么修改才能使之6面显示不同的贴图呢? */ // Load Bitmaps And Convert To Textures { int Status=FALSE; // Status Indicator AUX_RGBImageRec *TextureImage[1]; // Create Storage Space For The Texture memset(TextureImage,0,sizeof(void *)*1); // Set The Pointer To NULL // Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit if (TextureImage[0]=LoadBMP("Data/NeHe.bmp")) { Status=TRUE; // Set The Status To TRUE glGenTextures(1, &texture[0]); // Create The Texture // Typical Texture Generation Using Data From The Bitmap glBindTexture(GL_TEXTURE_2D, texture[0]); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); } if (TextureImage[0]) // If Texture Exists { if (TextureImage[0]->data) // If Texture Image Exists { free(TextureImage[0]->data); // Free The Texture Image Memory } free(TextureImage[0]); // Free The Image Structure } return Status; // Return The Status } /* 这是在http://iask.sina.com.cn/search_engine/snapshot.php?key=nehe&url=http%3A%2F%2Fzhidao.baidu.com%2Fquestion%2F76146098.html&snapid=100352606&snap=nehe看到的所谓实现6面不同纹理贴图的代码,没看明白,不知道6个纹理贴图在程序中是如何实 的,就看到一个循环6次的for循环。 */ int LoadGLTextures() { int Status=FALSE; AUX_RGBImageRec *TextureImage[1]; //创建纹理储存空间 memset(TextureImage,0,sizeof(void*)*1); ///////////////////////////////// //增加图片的路径 char name1[20]; char name2[20]; glGenTextures(6,&texture[0]); //告诉GL我们即将创建六个纹理,并将其保存在以0开始的texture数组中 for(int i=0;i<6;i++) { //图片路径的处理 strcpy(name1,"Images/雪花啤酒"); itoa(i+1,name2,10); strcat(name2,".bmp"); strcat(name1,name2); if(TextureImage[0]=LoadBMP(name1)) { Status=TRUE; //glGenTextures(6,&texture[0]); //创建六个纹理 //使用来自位图的数据创建Nearest滤波贴图 glBindTexture(GL_TEXTURE_2D,texture[i]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexImage2D(GL_TEXTURE_2D,0,3,TextureImage[0]->sizeX,TextureImage[0]->sizeY,0,GL_RGB,GL_UNSIGNED_BYTE,TextureImage[0]->data); } else { Status=FALSE; } } if(TextureImage[0]) { if(TextureImage[0]->data) { free(TextureImage[0]->data); } free(TextureImage[0]); } return Status; } // Return The Status
应该就是这个啊
那data文件夹里面的6张图片怎么命名呢?
/*
* 这是6面是一个图片的贴图源程序,怎么修改才能使之6面显示不同的贴图呢?
*/
// Load Bitmaps And Convert To Textures
{
int Status=FALSE; // Status Indicator AUX_RGBImageRec *TextureImage[1]; // Create Storage Space For The Texture memset(TextureImage,0,sizeof(void *)*1); // Set The Pointer To NULL // Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
if (TextureImage[0]=LoadBMP("Data/NeHe.bmp"))
{
Status=TRUE; // Set The Status To TRUE glGenTextures(1, &texture[0]); // Create The Texture // Typical Texture Generation Using Data From The Bitmap
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
} if (TextureImage[0]) // If Texture Exists
{
if (TextureImage[0]->data) // If Texture Image Exists
{
free(TextureImage[0]->data); // Free The Texture Image Memory
} free(TextureImage[0]); // Free The Image Structure
} return Status; // Return The Status
}
/*
这是在http://iask.sina.com.cn/search_engine/snapshot.php?key=nehe&url=http%3A%2F%2Fzhidao.baidu.com%2Fquestion%2F76146098.html&snapid=100352606&snap=nehe看到的所谓实现6面不同纹理贴图的代码,没看明白,不知道6个纹理贴图在程序中是如何实
的,就看到一个循环6次的for循环。
*/
int LoadGLTextures()
{
int Status=FALSE;
AUX_RGBImageRec *TextureImage[1]; //创建纹理储存空间
memset(TextureImage,0,sizeof(void*)*1); /////////////////////////////////
//增加图片的路径
char name1[20];
char name2[20];
glGenTextures(6,&texture[0]); //告诉GL我们即将创建六个纹理,并将其保存在以0开始的texture数组中
for(int i=0;i<6;i++)
{
//图片路径的处理
strcpy(name1,"Images/雪花啤酒");
itoa(i+1,name2,10);
strcat(name2,".bmp");
strcat(name1,name2); if(TextureImage[0]=LoadBMP(name1))
{
Status=TRUE;
//glGenTextures(6,&texture[0]); //创建六个纹理
//使用来自位图的数据创建Nearest滤波贴图
glBindTexture(GL_TEXTURE_2D,texture[i]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D,0,3,TextureImage[0]->sizeX,TextureImage[0]->sizeY,0,GL_RGB,GL_UNSIGNED_BYTE,TextureImage[0]->data);
}
else
{
Status=FALSE;
}
}
if(TextureImage[0])
{
if(TextureImage[0]->data)
{
free(TextureImage[0]->data);
}
free(TextureImage[0]);
}
return Status;
} // Return The Status