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

隨筆 - 5, 文章 - 0, 評(píng)論 - 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).
測(cè)試過(guò)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] );

    
//線性過(guò)濾一定要放到加載紋理的后面
    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 閱讀(4430) 評(píng)論(5)  編輯 收藏 引用

評(píng)論

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

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

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

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

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

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

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

載入多個(gè)紋理時(shí) 只有一個(gè)有用...

代碼有問(wèn)題??
2012-01-27 11:15 | hrlqqq

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

是的,我也是驗(yàn)證了很久,載入多個(gè)紋理時(shí),只有最后載入的那個(gè)紋理才有用,前面的都無(wú)法使用。texture[i]沒有意義,無(wú)法通過(guò)使用texture[i]來(lái)bind指定的那個(gè)紋理
2012-05-17 12:27 | LHZorro

只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   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>
            国产精品网站视频| 美女脱光内衣内裤视频久久影院| 美国三级日本三级久久99| 午夜精品国产| 午夜精品成人在线| 久久国产综合精品| 久久综合国产精品| 免费一级欧美在线大片| 女人香蕉久久**毛片精品| 欧美不卡激情三级在线观看| 欧美成人精品影院| 亚洲激情第一页| 日韩亚洲不卡在线| 亚洲一区二区三区在线视频| 亚洲国产欧美日韩精品| 亚洲精品在线观看视频| 一区二区三区高清不卡| 亚洲欧美日本在线| 久久久久国内| 欧美激情精品久久久久久久变态| 久久av在线看| 老司机精品久久| 久久久久久一区二区| 香蕉成人伊视频在线观看| 久久精品综合网| 欧美搞黄网站| 国产精品久久久久久影院8一贰佰 国产精品久久久久久影视 | 久久精品国产一区二区三| 亚洲视频网在线直播| 久久成人18免费观看| 免费观看亚洲视频大全| 欧美三级黄美女| 国内成人精品一区| 日韩视频国产视频| 欧美一区二区三区四区在线观看地址 | 一区二区日本视频| 午夜精品久久久| 蜜桃视频一区| 一本色道久久综合亚洲精品婷婷 | 亚洲欧美一区二区三区久久| aa级大片欧美| 一本大道久久精品懂色aⅴ| 亚洲国产一区在线| 亚洲在线1234| 免费亚洲一区二区| 国产日韩欧美精品综合| 亚洲精品国产精品久久清纯直播| 亚洲电影第1页| 亚洲男女自偷自拍| 老色批av在线精品| 日韩网站在线| 9色国产精品| 久久综合五月| 国产欧美视频在线观看| 亚洲精品乱码久久久久久蜜桃麻豆 | 一区精品在线| 亚洲一区在线播放| 久久精品成人一区二区三区| 久久精品av麻豆的观看方式| 亚洲看片网站| 久色成人在线| 国产专区一区| 亚洲欧美制服另类日韩| 久久久久久亚洲精品杨幂换脸| 久久综合狠狠综合久久激情| 免费高清在线一区| 亚洲黄色在线视频| 久久蜜桃精品| 国产老肥熟一区二区三区| 一区二区视频欧美| 日韩亚洲在线观看| 欧美a级片网站| 欧美一级久久| 国产精品久久网| 亚洲图片自拍偷拍| 欧美激情一区二区三区成人| 久久国产精品久久久久久电车| 美女精品自拍一二三四| 国产在线视频不卡二| 亚洲欧美日韩精品久久久| 亚洲美女精品久久| 欧美黄污视频| 亚洲美女色禁图| 欧美激情第4页| 久久伊人一区二区| 欲色影视综合吧| 久久亚洲国产精品一区二区| 亚洲欧美在线免费观看| 国产精品久久国产三级国电话系列 | 欧美成人精品h版在线观看| 欧美一区二区大片| 欧美精品成人| 99re66热这里只有精品4| 亚洲福利在线看| 欧美激情视频在线播放| 日韩特黄影片| 亚洲精品在线二区| 欧美天堂亚洲电影院在线播放 | 午夜免费日韩视频| 国产精品一二三四区| 亚洲欧美制服另类日韩| 亚洲女人小视频在线观看| 国产精品第十页| 午夜精品美女自拍福到在线| 亚洲一区二区高清视频| 国产精品久久网| 欧美怡红院视频一区二区三区| 亚洲国产成人精品视频| 欧美高清在线视频观看不卡| 亚洲欧洲在线播放| 亚洲片区在线| 欧美天天综合网| 亚洲欧美一级二级三级| 午夜在线精品| 狠狠久久婷婷| 欧美怡红院视频| 久久九九热免费视频| 亚洲第一主播视频| 久久亚洲国产成人| 牛人盗摄一区二区三区视频| 99热精品在线| 亚洲一区二区在| 欧美日韩另类视频| 亚洲精品日韩欧美| 99精品热视频| 国产一区二区你懂的| 欧美va亚洲va日韩∨a综合色| 亚洲欧洲av一区二区| 国产综合网站| 久久精品一区二区国产| 久久亚洲欧洲| 亚洲午夜精品久久| 久久精品国亚洲| 99视频+国产日韩欧美| 亚洲在线第一页| 亚洲国产精品久久久久| 9久re热视频在线精品| 亚洲成人直播| 国产精品jizz在线观看美国 | 欧美日韩性生活视频| 香蕉精品999视频一区二区 | 久久九九热免费视频| 免费不卡欧美自拍视频| 亚洲免费视频一区二区| 夜夜夜久久久| 国产精品v日韩精品| 亚洲主播在线观看| 久久国产黑丝| 在线不卡亚洲| 欧美 日韩 国产一区二区在线视频 | 欧美激情第六页| 性欧美8khd高清极品| 老司机精品视频网站| 亚洲精品在线观看免费| 亚洲第一狼人社区| 国产精品亚发布| 久久久www成人免费毛片麻豆| 欧美一级片久久久久久久| 亚洲麻豆国产自偷在线| 欧美在线视频观看免费网站| 一区二区三区高清在线观看| 久久激情五月丁香伊人| 亚洲成色最大综合在线| 一区二区三区精品在线| 亚洲精品久久久久久下一站| 午夜视频在线观看一区二区三区| 国产最新精品精品你懂的| 欧美不卡一卡二卡免费版| 国产精品麻豆va在线播放| 亚洲国产精品www| 黄色一区二区三区四区| 亚洲一区二区三区精品在线| 亚洲精品在线视频| 久久五月激情| 久久精品夜夜夜夜久久| 欧美视频免费看| 亚洲人成绝费网站色www| 影音欧美亚洲| 亚洲伦理一区| 亚洲精品国产欧美| 亚洲性感激情| 在线亚洲国产精品网站| 欧美88av| 欧美黄色网络| 在线免费精品视频| 久久精品国产999大香线蕉| 小辣椒精品导航| 国产精品成人免费| 日韩午夜电影| 夜久久久久久| 欧美激情欧美激情在线五月| 欧美在线www| 国产精品男女猛烈高潮激情| 日韩一级裸体免费视频| 一区二区三区日韩在线观看| 欧美激情在线免费观看| 亚洲国产精品成人久久综合一区| 国产精品毛片高清在线完整版| 免费h精品视频在线播放| 欧美三级第一页|