青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

隨筆 - 5, 文章 - 0, 評論 - 24, 引用 - 0
數(shù)據(jù)加載中……

OpenGL中用FreeImage

FreeImage is an Open Source library project for developers who would like to support popular graphics image formats like PNG, BMP, JPEG, TIFF and others as needed by today's multimedia applications. FreeImage is easy to use, fast, multithreading safe, compatible with all 32-bit versions of Windows, and cross-platform (works both with Linux and Mac OS X).
測試過png,bmp,jpg,tga。

TextureManager.h
//**********************************************
//Singleton Texture Manager class
//Written by Ben English
//benjamin.english@oit.edu
//
//For use with OpenGL and the FreeImage library
//**********************************************

#ifndef TextureManager_H
#define TextureManager_H

#include 
<gl/glew.h>
#include 
"FreeImage.h"
#include 
<map>

class TextureManager
{
public:
    
static TextureManager* Inst();
    
virtual ~TextureManager();

    
//load a texture an make it the current texture
    
//if texID is already in use, it will be unloaded and replaced with this texture
    bool LoadTexture(const char* filename,    //where to load the file from
        const unsigned int texID,            //arbitrary id you will reference the texture by
                                            
//does not have to be generated with glGenTextures
        GLenum image_format = GL_RGB,        //format the image is in
        GLint internal_format = GL_RGB,        //format to store the image in
        GLint level = 0,                    //mipmapping level
        GLint border = 0);                    //border size

    
//free the memory for a texture
    bool UnloadTexture(const unsigned int texID);

    
//set the current texture
    bool BindTexture(const unsigned int texID);

    
//free all texture memory
    void UnloadAllTextures();

protected:
    TextureManager();
    TextureManager(
const TextureManager& tm);
    TextureManager
& operator=(const TextureManager& tm);

    
static TextureManager* m_inst;
    std::map
<unsigned int, GLuint> m_texID;
}
;

#endif

TextureManager.cpp
//**********************************************
//Singleton Texture Manager class
//Written by Ben English
//benjamin.english@oit.edu
//
//For use with OpenGL and the FreeImage library
//**********************************************

#include 
"TextureManager.h"

TextureManager
* TextureManager::m_inst(0);

TextureManager
* TextureManager::Inst()
{
    
if(!m_inst)
        m_inst 
= new TextureManager();

    
return m_inst;
}


TextureManager::TextureManager()
{
    
// call this ONLY when linking with FreeImage as a static library
    #ifdef FREEIMAGE_LIB
        FreeImage_Initialise();
    
#endif
}


//these should never be called
//TextureManager::TextureManager(const TextureManager& tm){}
//TextureManager& TextureManager::operator=(const TextureManager& tm){}
    
TextureManager::
~TextureManager()
{
    
// call this ONLY when linking with FreeImage as a static library
    #ifdef FREEIMAGE_LIB
        FreeImage_DeInitialise();
    
#endif

    UnloadAllTextures();
    m_inst 
= 0;
}


bool TextureManager::LoadTexture(const char* filename, const unsigned int texID, GLenum image_format, GLint internal_format, GLint level, GLint border)
{
    
//image format
    FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
    
//pointer to the image, once loaded
    FIBITMAP *dib(0);
    
//pointer to the image data
    BYTE* bits(0);
    
//image width and height
    unsigned int width(0), height(0);
    
//OpenGL's image ID to map to
    GLuint gl_texID;
    
    
//check the file signature and deduce its format
    fif = FreeImage_GetFileType(filename, 0);
    
//if still unknown, try to guess the file format from the file extension
    if(fif == FIF_UNKNOWN) 
        fif 
= FreeImage_GetFIFFromFilename(filename);
    
//if still unkown, return failure
    if(fif == FIF_UNKNOWN)
        
return false;

    
//check that the plugin has reading capabilities and load the file
    if(FreeImage_FIFSupportsReading(fif))
        dib 
= FreeImage_Load(fif, filename);
    
//if the image failed to load, return failure
    if(!dib)
        
return false;

    
//retrieve the image data
    bits = FreeImage_GetBits(dib);
    
//get the image width and height
    width = FreeImage_GetWidth(dib);
    height 
= FreeImage_GetHeight(dib);
    
//if this somehow one of these failed (they shouldn't), return failure
    if((bits == 0|| (width == 0|| (height == 0))
        
return false;
    
    
//if this texture ID is in use, unload the current texture
    if(m_texID.find(texID) != m_texID.end())
        glDeleteTextures(
1&(m_texID[texID]));

    
//generate an OpenGL texture ID for this texture
    glGenTextures(1&gl_texID);
    
//store the texture ID mapping
    m_texID[texID] = gl_texID;
    
//bind to the new texture ID
    glBindTexture(GL_TEXTURE_2D, gl_texID);
    
//store the texture data for OpenGL use
    glTexImage2D(GL_TEXTURE_2D, level, internal_format, width, height,
        border, image_format, GL_UNSIGNED_BYTE, bits);

    
//Free FreeImage's copy of the data
    FreeImage_Unload(dib);

    
//return success
    return true;
}


bool TextureManager::UnloadTexture(const unsigned int texID)
{
    
bool result(true);
    
//if this texture ID mapped, unload it's texture, and remove it from the map
    if(m_texID.find(texID) != m_texID.end())
    
{
        glDeleteTextures(
1&(m_texID[texID]));
        m_texID.erase(texID);
    }

    
//otherwise, unload failed
    else
    
{
        result 
= false;
    }


    
return result;
}


bool TextureManager::BindTexture(const unsigned int texID)
{
    
bool result(true);
    
//if this texture ID mapped, bind it's texture as current
    if(m_texID.find(texID) != m_texID.end())
        glBindTexture(GL_TEXTURE_2D, m_texID[texID]);
    
//otherwise, binding failed
    else
        result 
= false;

    
return result;
}


void TextureManager::UnloadAllTextures()
{
    
//start at the begginning of the texture map
    std::map<unsigned int, GLuint>::iterator i = m_texID.begin();

    
//Unload the textures untill the end of the texture map is found
    while(i != m_texID.end())
        UnloadTexture(i
->first);

    
//clear the texture map
    m_texID.clear();
}

Main.cpp
/************************************************************************/
/*Brief:  Test all kinds of Textures in OpenGL                          */
/*Author: tiny                                                          */
/*Date:   09/29/2008                                                    */
/************************************************************************/
#include 
"TextureManager.h"
#include 
<gl/glew.h>
#include 
<gl/glut.h>

//全局貼圖ID
GLuint texture[1];

void init()
{
    
//將2D貼圖狀態(tài)打開
    glEnable( GL_TEXTURE_2D );

    
//單件貼圖管理
    
//如果加載帶路徑的文件最好選用.\\這樣的格式
    TextureManager::Inst()->LoadTexture( "OpenGL_his.jpg", texture[0] );

    
//線性過濾一定要放到加載紋理的后面
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);    // 線性濾波
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);    // 線性濾波

    glClearColor( 
0.50.50.50.5 );
}


void display()
{
    glClear( GL_COLOR_BUFFER_BIT 
| GL_DEPTH_BUFFER_BIT );

    
//綁定紋理
    TextureManager::Inst()->BindTexture( texture[0] );

    
//渲染
    glBegin( GL_QUADS );
    glTexCoord2d( 
00 ); glVertex3f( -5.0f-5.0f0.0f );
    glTexCoord2d( 
01 ); glVertex3f( -5.0f5.0f0.0f );
    glTexCoord2d( 
11 ); glVertex3f( 5.0f5.0f0.0f );
    glTexCoord2d( 
10 ); glVertex3f( 5.0f-5.0f0.0f );
    glEnd();
    glFlush();

    glutSwapBuffers();
}


void reshape( int w, int h )
{
    glViewport( 
00, GLsizei( w ), GLsizei( h ) );
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    gluPerspective( 
45, ( GLdouble ) w / ( GLdouble ) h, 1.0f1000.0f );
    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();
    gluLookAt( 
0020000010 );
}


void keyboard( unsigned char key, int x, int y )
{
    
if ( key == 27 )
    
{
        
//釋放掉貼圖,防止內(nèi)存泄露
        TextureManager::Inst()->UnloadTexture( texture[0] );
        exit( 
0 );
    }

        
}



int main( int argc, char *argv[] )
{
    glutInit( 
&argc, argv );
    glutInitDisplayMode( GLUT_DOUBLE 
| GLUT_RGBA | GLUT_DEPTH );
    glutInitWindowPosition( 
300300 );
    glutInitWindowSize( 
400300 );
    glutCreateWindow( 
"OpenGL Texture Test" );
    init();
    glutReshapeFunc( reshape );
    glutKeyboardFunc( keyboard );
    glutDisplayFunc( display );
    glutMainLoop();

    
return 0;
}
bmp效果圖:

tga效果圖:

jpg效果圖:

png效果圖:

有的圖的效果不是想要的,可能和RGB的順序有關(guān)。

posted on 2008-09-29 13:14 brilyf 閱讀(4429) 評論(5)  編輯 收藏 引用

評論

# re: OpenGL中用FreeImage  回復(fù)  更多評論   

不要意思,png和tga都是帶有alpha通道的,必須指定象素格式類型,如下:
TextureManager::Inst()->LoadTexture( "snowman.png", texture[0], GL_BGRA );
2008-09-29 13:48 | brilyf

# re: OpenGL中用FreeImage  回復(fù)  更多評論   

有人在嗎?究竟怎樣弄才能的到你這個效果呢?
2009-05-08 20:44 | hello opengl

# re: OpenGL中用FreeImage  回復(fù)  更多評論   

當(dāng)我載入多個紋理時 只有1個有用...!!!!!!!!!!!
2012-01-27 11:15 | hrlqqq

# re: OpenGL中用FreeImage  回復(fù)  更多評論   

載入多個紋理時 只有一個有用...

代碼有問題??
2012-01-27 11:15 | hrlqqq

# re: OpenGL中用FreeImage  回復(fù)  更多評論   

是的,我也是驗證了很久,載入多個紋理時,只有最后載入的那個紋理才有用,前面的都無法使用。texture[i]沒有意義,無法通過使用texture[i]來bind指定的那個紋理
2012-05-17 12:27 | LHZorro

只有注冊用戶登錄后才能發(fā)表評論。
網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲国产精品国自产拍av秋霞| 欧美特黄视频| 欧美成人激情视频免费观看| 一色屋精品视频在线观看网站| 久久国产主播精品| 欧美成人tv| 在线视频欧美日韩| 国产精品视频一| 久久国产精品久久久| 欧美大香线蕉线伊人久久国产精品| 亚洲人精品午夜| 国产精品久久国产精麻豆99网站| 亚洲欧美日韩精品一区二区 | 久久噜噜亚洲综合| 永久91嫩草亚洲精品人人| 欧美成人免费在线观看| 一区二区三区高清在线| 久久人人97超碰精品888| 91久久精品美女| 国产精品久久久久91| 久久综合网hezyo| 制服丝袜亚洲播放| 免费成人av在线看| 亚洲一区二区在线看| 国内精品视频一区| 欧美日韩一区二区三区四区在线观看| 亚洲一二三级电影| 欧美激情精品久久久久久大尺度| 欧美三级中文字幕在线观看| 欧美一区二区三区视频免费播放| 亚洲第一网站| 久久精品99国产精品日本| 亚洲精品1234| 欧美在线视频免费播放| 亚洲精品在线观看免费| 久久免费观看视频| 亚洲曰本av电影| 亚洲日韩中文字幕在线播放| 国产欧美一区二区三区沐欲| 欧美激情第六页| 久久久久久电影| 亚洲一区在线播放| 一区二区三欧美| 1024成人网色www| 国产综合欧美| 国产精品美女www爽爽爽视频| 玖玖国产精品视频| 久久国产黑丝| 亚洲欧美一区二区三区极速播放| 99re国产精品| 亚洲精品资源美女情侣酒店| 欧美chengren| 国产午夜精品在线| 国产精品看片资源| 欧美日韩国产在线一区| 欧美99在线视频观看| 久久精品成人欧美大片古装| 午夜精品三级视频福利| 夜夜躁日日躁狠狠久久88av| 亚洲日本一区二区| 亚洲第一天堂无码专区| 麻豆精品国产91久久久久久| 久久久久久久一区二区三区| 香蕉免费一区二区三区在线观看| 在线亚洲免费| 亚洲伊人网站| 亚洲一区二区三区高清不卡| 中国亚洲黄色| 亚洲淫性视频| 亚洲欧美激情一区二区| 亚洲在线一区二区三区| 亚洲香蕉伊综合在人在线视看| 一本色道久久88亚洲综合88| 日韩五码在线| 亚洲午夜黄色| 亚洲欧美日韩专区| 性做久久久久久久免费看| 欧美诱惑福利视频| 欧美在线影院| 麻豆91精品| 欧美国产日韩视频| 亚洲精品美女在线| av成人福利| 午夜视频久久久久久| 欧美永久精品| 美女视频黄a大片欧美| 欧美成人一区二区三区在线观看 | 欧美黄色网络| 欧美视频网址| 国产视频不卡| 亚洲大片av| 一本色道久久综合亚洲精品不 | 性欧美1819性猛交| 久久久久久久999精品视频| 久久综合九色综合久99| 欧美激情第8页| 国产精品亚洲欧美| 久久综合九色综合久99| 欧美精品一区二区三区蜜桃| 国产精品久久久久三级| 国产主播一区二区三区四区| 最新国产成人av网站网址麻豆 | 亚洲精品欧美日韩| 亚洲一区二区四区| 久久久亚洲国产天美传媒修理工| 欧美ab在线视频| 一区二区三区高清| 欧美中文字幕在线观看| 欧美国产成人在线| 国产精品中文字幕欧美| 亚洲国产成人精品女人久久久| 99精品欧美一区| 久久久久久久一区二区三区| 亚洲国产精品精华液2区45| 亚洲已满18点击进入久久| 久久免费视频一区| 国产精品久久久久999| 亚洲精华国产欧美| 欧美一区成人| 亚洲美女在线观看| 久久久av毛片精品| 欧美性色aⅴ视频一区日韩精品| 狠狠做深爱婷婷久久综合一区| 夜夜嗨av一区二区三区四季av| 久久久99免费视频| 99视频在线观看一区三区| 久久国产视频网站| 欧美视频一区二区三区…| 在线观看免费视频综合| 欧美在线3区| 亚洲精品乱码久久久久| 久久婷婷成人综合色| 国产精品一区二区三区免费观看| 亚洲黄色一区二区三区| 久久久久久夜精品精品免费| 一区二区三区免费网站| 欧美 日韩 国产 一区| 国内外成人在线视频| 亚洲综合国产精品| 亚洲精品欧洲精品| 欧美xxx成人| 一区二区三区在线看| 久久成人久久爱| 一区二区三区免费在线观看| 欧美va天堂在线| 在线观看日韩专区| 久久精品在这里| 亚洲一区二区三区四区在线观看 | 国产精品久久网| 一区二区欧美在线观看| 亚洲第一福利社区| 久久夜色精品国产噜噜av| 国产亚洲人成网站在线观看| 午夜免费在线观看精品视频| 亚洲美女免费视频| 欧美剧在线免费观看网站| 亚洲人体大胆视频| 亚洲国产精品一区制服丝袜| 久久综合中文| 亚洲高清视频一区| 欧美成人一二三| 免费高清在线视频一区·| 激情久久五月| 老牛嫩草一区二区三区日本| 欧美一区在线看| 国内自拍视频一区二区三区| 久久福利毛片| 欧美在线视频观看免费网站| 韩国三级电影久久久久久| 久久久亚洲综合| 久久这里有精品15一区二区三区 | 国产精品99久久久久久白浆小说 | 日韩视频免费观看| 欧美日韩精品一区视频| 亚洲午夜精品网| 亚洲专区一二三| 国产麻豆精品久久一二三| 久久国产精品久久久| 久久久天天操| 久久综合久久久久88| 亚洲三级免费电影| 日韩一二三在线视频播| 欧美视频福利| 久久精品在线视频| 老司机精品久久| 欧美国产丝袜视频| 亚洲视频图片小说| 亚洲影院在线观看| 黄色成人在线| 亚洲国产欧美日韩精品| 欧美午夜精品久久久久免费视| 香蕉久久夜色精品国产| 久久性天堂网| 亚洲视频欧美视频| 欧美有码在线视频| av成人毛片| 欧美一级视频| 日韩天堂在线观看| 新67194成人永久网站| 亚洲日本在线观看|