GLvoid LoadGLTextures() { // Загрузка картинки AUX_RGBImageRec *texture1; AUX_RGBImageRec *texture2; AUX_RGBImageRec *texture3; texture1 = auxDIBImageLoad("Data/CRATE.bmp"); texture2 = auxDIBImageLoad("Data/trava.bmp"); texture3 = auxDIBImageLoad("Data/metka.bmp"); // Создание текстуры glGenTextures(1, &texture[0]); glBindTexture(GL_TEXTURE_2D, texture[0]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, 3, texture1->sizeX, texture1->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, texture1->data); glGenTextures(1, &texture[1]); glBindTexture(GL_TEXTURE_2D, texture[1]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, 3, texture2->sizeX, texture2->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, texture2->data); glGenTextures(1, &texture[2]); glBindTexture(GL_TEXTURE_2D, texture[2]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, 3, texture3->sizeX, texture3->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, texture3->data); }
// подготовка текстуры void LoadPic1() { int i, j; AUX_RGBImageRec *image; short *pImage = NULL; #ifdef UNICODE image = auxDIBImageLoad( (LPCWSTR) "nebo.bmp"); #else image = auxDIBImageLoad( (LPCSTR) "nebo.bmp"); #endif if (image == NULL) { return; } glPixelStorei(GL_UNPACK_ALIGNMENT, 1) ; gluBuild2DMipmaps(GL_TEXTURE_2D, 3, image->sizeX, image->sizeY, GL_RGB, GL_UNSIGNED_BYTE, image->data); 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, GL_RGBA, image->sizeX, image->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, image->data); //0, GL_RGB, GL_UNSIGNED_BYTE, pic1); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); glEnable(GL_TEXTURE_2D); }
void LoadTextures(void) { sun = gluNewQuadric(); earth = gluNewQuadric(); moon = gluNewQuadric(); gluQuadricTexture(sun, GL_TRUE); gluQuadricTexture(earth, GL_TRUE); gluQuadricTexture(moon, GL_TRUE); texRec[0] = auxDIBImageLoad("sun.bmp"); texRec[1] = auxDIBImageLoad("earth.bmp"); texRec[2] = auxDIBImageLoad("moon.bmp"); glGenTextures(3, texID); for (int i = 0; i < 3; i++){ glBindTexture(GL_TEXTURE_2D, texID[i]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, 3, texRec[i]->sizeX, texRec[i]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, texRec[i]->data); glEnable(GL_TEXTURE_2D); } for (int i = 0; i < 3; i++){ if (texRec[i]->data) free(texRec[i]->data); free(texRec[i]); } }
int CglResouce::LoadGLTextures(int level){ int SucessAmount = 0; // 纹理载入成功的数目 char s[30]; AUX_RGBImageRec *TextureImage[IMG_SUM]; // Create Storage Space For The Texture sprintf_s(s,"texture/%d Wall.bmp",level); TextureImage[ 0 ]=auxDIBImageLoad( s ); // 墙 sprintf_s(s,"texture/%d Ceiling.bmp",level); TextureImage[ 1 ]=auxDIBImageLoad( s ); // 天花板 sprintf_s(s,"texture/%d Ground.bmp",level); TextureImage[ 2 ]=auxDIBImageLoad( s ); // 地板 glGenTextures(IMG_SUM, texture); // Create The Texture for( int i=0; i<IMG_SUM; i++ ){ // 检查所有纹理是否载入成功,并生成纹理 if( TextureImage[i] && TextureImage[i]->data){ SucessAmount++; // 成功载入一个纹理 glBindTexture(GL_TEXTURE_2D, texture[i]); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[i]->sizeX, TextureImage[i]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[i]->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[i]->sizeX, TextureImage[i]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[i]->data); free(TextureImage[i]->data); // Free The Texture Image Memory free(TextureImage[i]); // Free The Image Structure }// if }// for return (SucessAmount == IMG_SUM); // Return The Status }
GLuint LoadTextureWithAlphaMask(char *texname, char *maskname) { GLuint texID; AUX_RGBImageRec *tex = auxDIBImageLoad(texname); AUX_RGBImageRec *mask = auxDIBImageLoad(texname); if(tex->sizeX!=mask->sizeX || tex->sizeY!=mask->sizeY){ MessageBox(NULL, "Texture doesn't match the mask!", "Error", MB_OK); return 0; } UCHAR *data = new UCHAR[4*tex->sizeX*tex->sizeY]; ZeroMemory(data, 4*tex->sizeX*tex->sizeY); for(int i=0;i<tex->sizeX*tex->sizeY;i++){ data[i*4] = tex->data[i*3]; data[i*4+1] = tex->data[i*3+1]; data[i*4+2] = tex->data[i*3+2]; data[i*4+3] = mask->data[i*3]; } glGenTextures(1, &texID); glBindTexture(GL_TEXTURE_2D, texID); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex->sizeX, tex->sizeY, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); delete [] data; delete [] tex->data; delete [] mask->data; return texID; }
// Load texture void CHOpenGLView::loadTextureBMP(char *file, GLuint *p_texture) { FILE *p_File = fopen(file, "r"); m_TEXTURE_OK = false; if (p_File) { AUX_RGBImageRec *p_Bitmap = auxDIBImageLoad(file); glBindTexture(GL_TEXTURE_2D, *p_texture); //부여받은 이름으로 texture object를 만들고 해당 texture와 묶은 후 사용함 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, p_Bitmap->sizeX, p_Bitmap->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, p_Bitmap->data); //texture 정보 설정 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); //texture mapping 후 가로축 여분의 공간 Clamping glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); //texture mapping 후 세로축 여분의 공간 Clamping glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); //Magnification, pixel의 중심에서 가장 가까운 texel을 사용 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); //Minification, pixel의 중심에서 가장 가까운 texel을 사용 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); // texture의 모드를 DECAL로 하여 물체의 속성 안 받게함 fclose(p_File); m_TEXTURE_OK = true; } return; }
void CLoad3DS::CreateTexture(UINT textureArray[], LPSTR strFileName, int textureID) { AUX_RGBImageRec *pBitmap = NULL; if(!strFileName) return; pBitmap = auxDIBImageLoad(strFileName); if(pBitmap == NULL) exit(0); glGenTextures(1, &textureArray[textureID]); glPixelStorei (GL_UNPACK_ALIGNMENT, 1); glBindTexture(GL_TEXTURE_2D, textureArray[textureID]); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pBitmap->sizeX, pBitmap->sizeY, GL_RGB, GL_UNSIGNED_BYTE, pBitmap->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR); if (pBitmap) { if (pBitmap->data) free(pBitmap->data); free(pBitmap); } }
int Terrain::LoadGLTextures(GLuint *texture, char *filename) { bool Status = true; AUX_RGBImageRec *TextureImage = NULL; if ( TextureImage = auxDIBImageLoad(filename) ) { glGenTextures( 1, texture); glBindTexture(GL_TEXTURE_2D, texture[0]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, TextureImage->sizeX, TextureImage->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage->data); } else { Status = false; } if(TextureImage) { if(TextureImage->data) { delete TextureImage->data; } delete TextureImage; TextureImage = NULL; } return Status; }
void CBitmap::LoadBMP(string filename) { AUX_RGBImageRec *TextureImage=auxDIBImageLoad(filename.c_str()); if (TextureImage){ xsize=TextureImage->sizeX; ysize=TextureImage->sizeY; mem=new unsigned char[xsize*ysize*4]; for(int y=0;y<ysize;++y){ for(int x=0;x<xsize;++x){ mem[(y*xsize+x)*4+0]=TextureImage->data[((ysize-y-1)*xsize+x)*3]; mem[(y*xsize+x)*4+1]=TextureImage->data[((ysize-y-1)*xsize+x)*3+1]; mem[(y*xsize+x)*4+2]=TextureImage->data[((ysize-y-1)*xsize+x)*3+2]; mem[(y*xsize+x)*4+3]=255; } } #undef free if (TextureImage->data) { free(TextureImage->data); } free(TextureImage); } else { xsize=1; ysize=1; mem=new unsigned char[4]; } }
GLuint* LnR::LoadTexture(const char *filename) { glEnable(GL_TEXTURE_2D); GLuint *texture = new GLuint; AUX_RGBImageRec *TextureImage[1]; memset(TextureImage,0,sizeof(void *)*1); TextureImage[0]=auxDIBImageLoad(L"tex.BMP"); glGenTextures(1, texture); glBindTexture(GL_TEXTURE_2D, *texture); 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 texture; }
void GLManager::loadTextures() { for(int i = 0; i < SIZE; i++) { AUX_RGBImageRec *texImage; string texFile = stars[i]->getFileName(); GLuint& textureID = stars[i]->getTextureID(); texImage = auxDIBImageLoad(texFile.c_str()); printf("%s: %d\n", texFile.c_str(), texImage->sizeX); // 创建一个纹理 glGenTextures(1, &textureID); /*printf("%s's id: %d\n", textureID);*/ // 绑定纹理到对应的id glBindTexture(GL_TEXTURE_2D, textureID); // 设置纹理信息 glTexImage2D(GL_TEXTURE_2D, 0, 3, texImage->sizeX, texImage->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, texImage->data); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); if (texImage) { if (texImage->data) { free(texImage->data); } free(texImage); } } }
bool LoadGLTextures() // Load Bitmaps And Convert To Textures { bool ret = false; AUX_RGBImageRec * TextureImage = 0; // Create Storage Space For The Texture // Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit if (TextureImage = auxDIBImageLoad(g_logo.c_str())) { glGenTextures(1, &g_texture); // Create The Texture // Typical Texture Generation Using Data From The Bitmap glBindTexture(GL_TEXTURE_2D, g_texture); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage->sizeX, TextureImage->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage->data); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); ret = true; } SAFE_DELETE(TextureImage->data); // Free The Texture Image Memory SAFE_DELETE(TextureImage); // Free The Image Structure return ret; }
bool MTexture::CreateFromBMP(UINT *textureID, LPSTR strFileName) { AUX_RGBImageRec *pBitmap = NULL; FILE *pFile = NULL; // The File Handle we will use to read the bitmap if(!strFileName) // Return from the function if no file name was passed in return false; fopen_s(&pFile, strFileName,"r"); // Check To See If The File Exists if(pFile) // If we have a valid file pointer we found the file { pBitmap = auxDIBImageLoad(strFileName); // Load the bitmap and store the data } else // If we can't find the file, quit! { // Prompt the error message MessageBox(NULL, "Couldn't find a texture!", "Error!", MB_OK); exit(0); } // Generate a texture with the associative texture ID stored in the array glGenTextures(1, textureID); // This sets the alignment requirements for the start of each pixel row in memory. glPixelStorei (GL_UNPACK_ALIGNMENT, 1); // Bind the texture to the texture arrays index and init the texture glBindTexture(GL_TEXTURE_2D, *textureID); // Build Mipmaps (builds different versions of the picture for distances - looks better) gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pBitmap->sizeX, pBitmap->sizeY, GL_RGB, GL_UNSIGNED_BYTE, pBitmap->data); // Lastly, we need to tell OpenGL the quality of our texture map. GL_LINEAR_MIPMAP_LINEAR // is the smoothest. GL_LINEAR_MIPMAP_NEAREST is faster than GL_LINEAR_MIPMAP_LINEAR, // but looks blochy and pixilated. Good for slower computers though. glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // The default GL_TEXTURE_WRAP_S and ""_WRAP_T property is GL_REPEAT. // We need to turn this to GL_CLAMP_TO_EDGE, otherwise it creates ugly seems // in our sky box. GL_CLAMP_TO_EDGE does not repeat when bound to an object. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // Now we need to free the bitmap data that we loaded since openGL stored it as a texture if (pBitmap) // If we loaded the bitmap { if (pBitmap->data) // If there is texture data { free(pBitmap->data); // Free the texture data, we don't need it anymore } free(pBitmap); // Free the bitmap structure } return true; }
bool CTexture::MakeAlphaTextureBind(char* TextureFileName) { bool status = true; AUX_RGBImageRec* Image = NULL; unsigned char* alpha = NULL; if (Image = auxDIBImageLoad(TextureFileName)) { alpha = new uint8[4 * Image->sizeX * Image->sizeY]; for (int32 a = 0; a < Image->sizeX * Image->sizeY; a++) { alpha[4 * a] = Image->data[a * 3]; alpha[4 * a + 1] = Image->data[a * 3 + 1]; alpha[4 * a + 2] = Image->data[a * 3 + 2]; alpha[4 * a + 3] = (alpha[4 * a + 0] < alpha[4 * a + 1]) ? alpha[4 * a + 0] : alpha[4 * a + 1]; if (alpha[4 * a + 2] < alpha[4 * a + 3])alpha[4 * a + 3] = alpha[4 * a + 2]; } glGenTextures(1, &m_nTxt); glBindTexture(GL_TEXTURE_2D, m_nTxt); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA8, Image->sizeX, Image->sizeY, GL_RGBA, GL_UNSIGNED_BYTE, alpha); delete[] alpha; } else { status = false; } if (Image) { if (Image->data) delete Image->data; delete Image; Image = NULL; } return status; }
bool Image2D::LoadBMP2(const char* filename) { if(!filename) { return false; } FILE* file = NULL; file = fopen(filename, "r"); //Does file exists? if(file) { fclose(file); //Closing handle wchar_t* temp = (wchar_t*)filename; this->texture = auxDIBImageLoad(filename); if(this->texture != NULL && this->texture->data != NULL) { glGenTextures(1, &this->ID); glBindTexture(GL_TEXTURE_2D, this->ID); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, 3, this->texture->sizeX, this->texture->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, this->texture->data); free(texture); } else { return false; } } else { return false; } return true; }
bool CMesh :: LoadHeightmap( char* szPath, float flHeightScale, float flResolution ) { // Error-Checking FILE* fTest = fopen( szPath, "r" ); // Open The Image if( !fTest ) // Make Sure It Was Found return false; // If Not, The File Is Missing fclose( fTest ); // Done With The Handle // Load Texture Data m_pTextureImage = auxDIBImageLoad( szPath ); // Utilize GLaux's Bitmap Load Routine // Generate Vertex Field m_nVertexCount = (int) ( m_pTextureImage->sizeX * m_pTextureImage->sizeY * 6 / ( flResolution * flResolution ) ); m_pVertices = new CVec[m_nVertexCount]; // Allocate Vertex Data m_pTexCoords = new CTexCoord[m_nVertexCount]; // Allocate Tex Coord Data int nX, nZ, nTri, nIndex=0; // Create Variables float flX, flZ; for( nZ = 0; nZ < m_pTextureImage->sizeY; nZ += (int) flResolution ) { for( nX = 0; nX < m_pTextureImage->sizeX; nX += (int) flResolution ) { for( nTri = 0; nTri < 6; nTri++ ) { // Using This Quick Hack, Figure The X,Z Position Of The Point flX = (float) nX + ( ( nTri == 1 || nTri == 2 || nTri == 5 ) ? flResolution : 0.0f ); flZ = (float) nZ + ( ( nTri == 2 || nTri == 4 || nTri == 5 ) ? flResolution : 0.0f ); // Set The Data, Using PtHeight To Obtain The Y Value m_pVertices[nIndex].x = flX - ( m_pTextureImage->sizeX / 2 ); m_pVertices[nIndex].y = PtHeight( (int) flX, (int) flZ ) * flHeightScale; m_pVertices[nIndex].z = flZ - ( m_pTextureImage->sizeY / 2 ); // Stretch The Texture Across The Entire Mesh m_pTexCoords[nIndex].u = flX / m_pTextureImage->sizeX; m_pTexCoords[nIndex].v = flZ / m_pTextureImage->sizeY; // Increment Our Index nIndex++; } } } // Load The Texture Into OpenGL glGenTextures( 1, &m_nTextureId ); // Get An Open ID glBindTexture( GL_TEXTURE_2D, m_nTextureId ); // Bind The Texture glTexImage2D( GL_TEXTURE_2D, 0, 3, m_pTextureImage->sizeX, m_pTextureImage->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, m_pTextureImage->data ); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // Free The Texture Data if( m_pTextureImage ) { if( m_pTextureImage->data ) free( m_pTextureImage->data ); free( m_pTextureImage ); } return true; }
AUX_RGBImageRec* LoadBitmap(String filePath) // Loads A Bitmap Image { if(filePath.empty()) // Make Sure A Filename Was Given { return nullptr; // If Not Return NULL } return auxDIBImageLoad(filePath.c_str()); // Load The Bitmap And Return A Pointer }
AUX_RGBImageRec* OpenGLGame::loadBMPFile( const char* szFileName ) { if ( !szFileName ) { return NULL; } return auxDIBImageLoad( szFileName ); }
void GR_DLAttribTexture::SetTexture(LPCTSTR lpszFilePath) { if(m_pBytes) ::free(m_pBytes); AUX_RGBImageRec* pRGBImageRec = auxDIBImageLoad(lpszFilePath); m_iWidth = pRGBImageRec->sizeX; m_iHeight = pRGBImageRec->sizeY; m_pBytes = pRGBImageRec->data; }
// Load A BMP AUX_RGBImageRec *LoadBMP(LPCWSTR Filename) // Loads A Bitmap Image { if (!Filename) // Make Sure A Filename Was Given { return NULL; // If Not Return NULL } return auxDIBImageLoad(Filename); // Load The Bitmap And Return A Pointer }
/*load bmp file*/ AUX_RGBImageRec* ctexture::load_bmp(const char* filename) { FILE* file = NULL; if(!filename) return NULL; file = fopen(filename ,"r"); if(file){ fclose(file); return auxDIBImageLoad(filename); } return NULL; }
GLvoid LoadGLTextures() { AUX_RGBImageRec *texture1; texture1 = auxDIBImageLoad(L"svb.bmp"); glGenTextures(1, &texture[0]); glBindTexture(GL_TEXTURE_2D, texture[0]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, 3, texture1->sizeX, texture1->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, texture1->data); }
AUX_RGBImageRec *LoadBMP(std::string Filename)//teksturki { FILE *File; File = fopen(Filename.c_str(), "r");//sprawdz czy istnieje if (File) { fclose(File); return auxDIBImageLoad(Filename.c_str()); } return nullptr; }
AUX_RGBImageRec *LoadBMP(char *Filename) { FILE *File=NULL; if (!Filename) return NULL; File=fopen(Filename,"r"); if (File) { fclose(File); return auxDIBImageLoad(Filename); } return NULL; }
void Object3DS::createTexture(UINT textureArray[], LPSTR strFileName, int textureID) { AUX_RGBImageRec *pBitmap = NULL; TGAImage *tgaImage = NULL; FILE *pFile = NULL; // The File Handle we will use to read the bitmap if(!strFileName) // Return from the function if no file name was passed in return; pFile = fopen(strFileName,"r"); // Check To See If The File Exists setTextureType(strFileName); if(pFile) { if (textureType == TEXTURE_BMP) { pBitmap = auxDIBImageLoad(strFileName); // Load the bitmap and store the data } else if (textureType == TEXTURE_TGA) { tgaImage = new TGAImage(); tgaImage->loadTGA(strFileName); } else { exit(0); } } else // If we can't find the file, quit! { // Prompt the error message printf("Couldn't find a texture!\n"); exit(0); } glGenTextures(1, &textureArray[textureID]); glPixelStorei (GL_UNPACK_ALIGNMENT, 1); glBindTexture(GL_TEXTURE_2D, textureArray[textureID]); if (textureType == TEXTURE_BMP) { gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pBitmap->sizeX, pBitmap->sizeY, GL_RGB, GL_UNSIGNED_BYTE, pBitmap->data); } else if (textureType == TEXTURE_TGA) { gluBuild2DMipmaps(GL_TEXTURE_2D, 3, tgaImage->imageWidth, tgaImage->imageHeight, tgaImage->texFormat, GL_UNSIGNED_BYTE, tgaImage->imageData); } glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); if (pBitmap) { if (pBitmap->data) free(pBitmap->data); // Free the texture data, we don't need it anymore free(pBitmap); // Free the bitmap structure } }
AUX_RGBImageRec* CLineComputeView::LoadBMP(TCHAR * filename) { if(!PathFileExists(filename)) { MessageBox(_T("加载位图失败"), MsgCaption); return false; } else { return auxDIBImageLoad(filename); } }
bool CTexture::MakeTextureBind(char* TextureFileName,bool bLinear,bool bMip) { bool status=true; AUX_RGBImageRec *Image=NULL; if (Image=auxDIBImageLoad(TextureFileName)) { glGenTextures(1, &m_nTxt); glBindTexture(GL_TEXTURE_2D, m_nTxt); if(bLinear) { if(bMip) { glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR); gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB8, Image->sizeX, Image->sizeY, GL_RGB, GL_UNSIGNED_BYTE, Image->data); } else { glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, Image->sizeX, Image->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, Image->data); } } else { if(bMip) { glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST_MIPMAP_NEAREST); gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB8, Image->sizeX, Image->sizeY, GL_RGB, GL_UNSIGNED_BYTE, Image->data); } else { 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, GL_RGB8, Image->sizeX, Image->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, Image->data); } } } else status=false; if (Image) { if (Image->data) delete Image->data; delete Image; } return status; }
//========================================================= // loadbmp // - load a bitmap using aux library //========================================================= AUX_RGBImageRec *LoadBitmap(char *filename) { FILE *f=fopen(filename,"r"); // open the image file for reading // check for the file if (f) { fclose(f); // Close the handel return auxDIBImageLoad(filename); // load using the glaux lib } // end of the if return NULL; } // end of the function
//----------------------------------------------------------------------------- void GameWorld::_test_load() //----------------------------------------------------------------------------- { AUX_RGBImageRec *texture; texture = auxDIBImageLoad(texture_box_path); glGenTextures(1, &texture_box); glBindTexture(GL_TEXTURE_2D, texture_box); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, 3, texture->sizeX, texture->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, texture->data); }
bool Texture::LoadTexture(TCHAR *Filename) { FILE *File=NULL; // File Handle if (!Filename) // Make Sure A Filename Was Given { //textureImage = NULL; return false; // If Not Return NULL } textureImage = auxDIBImageLoad(Filename);// Load The Bitmap And Return A Pointer if(!textureImage) return false; return true; }