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

Shuffy

不斷的學習,不斷的思考,才能不斷的進步.Let's do better together!
posts - 102, comments - 43, trackbacks - 0, articles - 19

     本文在9篇文章的基礎上,為立方體加入紋理映射的功能。

Texture Mapping

Texture Mapping in OpenGL is a fairly straightforward concept. Every texture is nothing but an image of some sort. Texture mapping is basically applying a texture to a surface. Textures can be 1D, 2D or even 3D. A 1D texture is an image with either a width or a height, not both. They are not very useful. 2D textures have both width and height and are very useful. 3D textures are called Volume textures and are used in medical imaging applications for viewing CAT, MRI, and other 3D scans. We will look at using 2D textures in OpenGL as they are the most widely used in 3D Graphics.

Windows Bitmap Files

Images in Windows are typically stored in bitmap files. These images can be used as textures that will be applied to OpenGL surfaces. But before use them for texture mapping applications we should convert them to an OpenGL format. So we essentially have to read a Windows Bitmap into an OpenGL image. We can use the Auxiliary library to do so. It takes care of all the trouble involved in performing this conversion. Once a texture map is read into memory, the individual elements are called texels, just like an image's individual elements are called pixels. We wouldn't be dealing with these texels as we would be using the Aux library routine auxDIBImageLoadA to perform the conversion for us. Also, we need to make sure that the image dimensions are a power of 2. OpenGL images that we are going to use as a texture must have dimensions of a power of 2. Thus 32X32, 64X64, 128X64 etc. are all valid image sizes to be used as texture maps.

Defining 2D Textures

To define a 2D texture image in OpenGL we call glTexImage2D (when we are not using Mipmapping).

Mipmapping

When texture mapping is used with animation scaling of images cause some visual artifacts. This can be avoided by generating textures of various sizes from a large original texture and letting OpenGL automatically switch between the textures of various sizes. This technique is called Mipmapping and the individual textures are called Mipmaps. We can use the function gluBuild2DMipMaps to construct a series of mipmaps.

Texture Modes

OpenGL defines three texturing modes for different types of rendering. The first is GL_MODULATE, which modulates the current lighting and color information with the texture image. GL_DECAL is the second mode which only uses the texture image. Color and Lighting information will not affect the texture's appearance. The last mode is GL_BLEND, in which the texture image is blended with the current texture color and the current lighting and color information.

Texture Filters

OpenGL uses texture filters to interpolate between the texture pixels. It provides two types of texture filters: the minification filter (GL_TEXTURE_MIN_FILTER) for polygons smaller than the texture image and the magnification filter (GL_TEXTURE_MAG_FILTER) for polygons that are larger than the texture image. We'll look at how we will use these later in the tutorial.

Texture Coordinates

Texture Coordinates associate a particular location in the texture image with vertices in a polygon. These coordinates determine how the texture is mapped onto the polygon. Texture coordinates lie between 0.0 and 1.0 in case of 2D textures.

Texture Wrapping

When texture coordinates go outside the range of 0.0 to 1.0, they are either clamped to the surface or repeated. This can be specified by setting the GL_TEXTURE_WRAP_* parameter appropriately, to either GL_CLAMP or GL_REPEAT.

Texture Objects

Texture objects are a way of loading and maintaining multiple textures in memory without loading them each time before they are used. They are an optimization feature introduced recently in OpenGL.

1,CCY457OpenGLView類中加入下列變量,分別代表紋理環(huán)繞,紋理過濾,紋理模式的參數(shù)。

    GLdouble m_texWrap, m_texFilter, m_texMode;  
    
//All Texture Names
     GLuint m_Texture[3]; //保存紋理對象的名稱

 并在構造函數(shù)中加入:

CCY457OpenGLView::CCY457OpenGLView()
{
    m_xRot 
= 0.0f;
    m_yRot 
= 0.0f;
    m_texWrap 
= GL_CLAMP;
    m_texMode 
= GL_DECAL;
    m_texFilter 
= GL_NEAREST;
}

2,加載紋理對象。

//Texture Mapping Functions
void CCY457OpenGLView::LoadGLTextures()
{
    
//Create Texture Names
    glGenTextures(3, m_Texture);
    LoadTexture(
"Apple.bmp",0);
    LoadTexture(
"Fauve.bmp",1);
    LoadTexture(
"Flower.bmp",2);
}
void CCY457OpenGLView::LoadTexture (CString fileName, int texName)
{
    
//Load Texture
    AUX_RGBImageRec* m_texture;
    m_texture 
= auxDIBImageLoad((const char*)fileName);
    
if(!m_texture)
    {
        MessageBox(
"Picture could not be loaded");
        exit(
1);
    }
    glBindTexture(GL_TEXTURE_2D, m_Texture[texName]);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, m_texWrap);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, m_texWrap);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, m_texFilter);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, m_texFilter);
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, m_texMode);
    gluBuild2DMipmaps(GL_TEXTURE_2D, 
3, m_texture->sizeX,m_texture->sizeY, GL_RGB, GL_UNSIGNED_BYTE, m_texture->data);
}

 3,加入控制紋理映射效果的各個菜單項及其事件處理程序

void CCY457OpenGLView::OnTexturewrapGlclamp() 
{
    m_texWrap 
= GL_CLAMP;
    LoadGLTextures();
    InvalidateRect(NULL,FALSE);    
}
void CCY457OpenGLView::OnUpdateTexturewrapGlclamp(CCmdUI* pCmdUI) 
{
    
if(m_texWrap == GL_CLAMP)
        pCmdUI
->SetRadio();
    
else
        pCmdUI
->SetRadio(FALSE);    
}
void CCY457OpenGLView::OnTexturewrapGlrepeat() 
{
    m_texWrap 
= GL_REPEAT;
    LoadGLTextures();
    InvalidateRect(NULL,FALSE);
}
void CCY457OpenGLView::OnUpdateTexturewrapGlrepeat(CCmdUI* pCmdUI) 
{
    
if(m_texWrap == GL_REPEAT)
        pCmdUI
->SetRadio();        
    
else
        pCmdUI
->SetRadio(FALSE);
}
void CCY457OpenGLView::OnTexturefilterGlnearest() 
{
    m_texFilter 
= GL_NEAREST;
    LoadGLTextures();
    InvalidateRect(NULL,FALSE);        
    
}
void CCY457OpenGLView::OnUpdateTexturefilterGlnearest(CCmdUI* pCmdUI) 
{
    
if(m_texFilter == GL_NEAREST)
        pCmdUI
->SetRadio();    
    
else
        pCmdUI
->SetRadio(FALSE);    
}
void CCY457OpenGLView::OnTexturefilterGllinear() 
{
    m_texFilter 
= GL_LINEAR;
    LoadGLTextures();
    InvalidateRect(NULL,FALSE);        
}
void CCY457OpenGLView::OnUpdateTexturefilterGllinear(CCmdUI* pCmdUI) 
{
    
if(m_texFilter == GL_LINEAR)
        pCmdUI
->SetRadio();    
    
else
        pCmdUI
->SetRadio(FALSE);    
}
void CCY457OpenGLView::OnTexturemodeGlmodulate() 
{
    m_texMode 
= GL_MODULATE;
    LoadGLTextures();
    InvalidateRect(NULL,FALSE);
}
void CCY457OpenGLView::OnUpdateTexturemodeGlmodulate(CCmdUI* pCmdUI) 
{
    
if(m_texMode == GL_MODULATE)
        pCmdUI
->SetRadio();                
    
else
        pCmdUI
->SetRadio(FALSE);    
}
void CCY457OpenGLView::OnTexturemodeGldecal() 
{
    m_texMode 
= GL_DECAL;
    LoadGLTextures();
    InvalidateRect(NULL,FALSE);
}
void CCY457OpenGLView::OnUpdateTexturemodeGldecal(CCmdUI* pCmdUI) 
{
    
if(m_texMode == GL_DECAL)
        pCmdUI
->SetRadio();                
    
else
        pCmdUI
->SetRadio(FALSE);
}
void CCY457OpenGLView::OnTexturemodeGlblend() 
{
    m_texMode 
= GL_BLEND;
    LoadGLTextures();
    InvalidateRect(NULL,FALSE);
}
void CCY457OpenGLView::OnUpdateTexturemodeGlblend(CCmdUI* pCmdUI) 
{
    
if(m_texMode == GL_BLEND)
        pCmdUI
->SetRadio();                
    
else
        pCmdUI
->SetRadio(FALSE);
}

4,在InitializeOpenGL()中加入如下調(diào)用:

    //加載紋理
    LoadGLTextures();

5,繪制函數(shù)修改如下:

void CCY457OpenGLView::RenderScene ()
{
//繪制函數(shù)
        glTranslatef(0.0f,0.0f,-5.0f);
        glRotatef(m_xRot,
1.0f,0.0f,0.0f);
        glRotatef(m_yRot,
0.0f,1.0f,0.0f);
        glEnable(GL_TEXTURE_2D);
        glBindTexture(GL_TEXTURE_2D,m_Texture[
0]);
        
//Front Face
        glBegin(GL_POLYGON);
            glTexCoord2f(
0,0);
            glVertex3f(
-1.0f,-1.0f,0.0f);
            glTexCoord2f(
1,0);
            glVertex3f( 
1.0f,-1.0f,0.0f);
            glTexCoord2f(
1,1);
            glVertex3f( 
1.0f1.0f,0.0f);
            glTexCoord2f(
0,1);
            glVertex3f(
-1.0f1.0f,0.0f);
        glEnd();
        
//Back Face
        glBegin(GL_POLYGON);
            glTexCoord2f(
1,0);
            glVertex3f(
-1.0f,-1.0f,-1.0f);
            glTexCoord2f(
1,1);
            glVertex3f(
-1.0f1.0f,-1.0f);
            glTexCoord2f(
0,1);
            glVertex3f( 
1.0f1.0f,-1.0f);
            glTexCoord2f(
0,0);
            glVertex3f( 
1.0f,-1.0f,-1.0f);
        glEnd();
        glBindTexture(GL_TEXTURE_2D,m_Texture[
1]);
        
//Left Face
        glBegin(GL_POLYGON);
            glTexCoord2f(
1,0);
            glVertex3f(
-1.0f,-1.0f0.0f);
            glTexCoord2f(
1,1);
            glVertex3f(
-1.0f1.0f0.0f);
            glTexCoord2f(
0,1);
            glVertex3f(
-1.0f1.0f,-1.0f);
            glTexCoord2f(
0,0);
            glVertex3f(
-1.0f,-1.0f,-1.0f);
        glEnd();
        
//Right Face
        glBegin(GL_POLYGON);
            glTexCoord2f(
0,0);
            glVertex3f(
1.0f,-1.0f0.0f);
            glTexCoord2f(
1,0);
            glVertex3f(
1.0f,-1.0f,-1.0f);
            glTexCoord2f(
1,1);
            glVertex3f(
1.0f1.0f,-1.0f);
            glTexCoord2f(
0,1);
            glVertex3f(
1.0f1.0f0.0f);
        glEnd();
        glBindTexture(GL_TEXTURE_2D,m_Texture[
2]);
        
//Top Face
        glBegin(GL_POLYGON);
            glTexCoord2f(
0,0);
            glVertex3f(
-1.0f1.0f,  0.0f);
            glTexCoord2f(
0,1);
            glVertex3f( 
1.0f1.0f,  0.0f);
            glTexCoord2f(
1,1);
            glVertex3f( 
1.0f1.0f-1.0f);
            glTexCoord2f(
1,0);
            glVertex3f(
-1.0f1.0f-1.0f);
        glEnd();
        
//Botton Face
        glBegin(GL_POLYGON);
            glTexCoord2f(
0,1);
            glVertex3f(
-1.0f-1.0f,  0.0f);
            glTexCoord2f(
0,0);
            glVertex3f(
-1.0f-1.0f-1.0f);
            glTexCoord2f(
1,0);
            glVertex3f( 
1.0f-1.0f-1.0f);
            glTexCoord2f(
1,1);
            glVertex3f( 
1.0f-1.0f,  0.0f);
        glEnd();
        glDisable(GL_TEXTURE_2D);
}

 

 

作者:洞庭散人

出處:http://phinecos.cnblogs.com/    

本文版權歸作者和博客園共有,歡迎轉載,但未經(jīng)作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,否則保留追究法律責任的權利。
原文鏈接:http://www.cnblogs.com/phinecos/archive/2008/11/05/1327646.html
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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| 久久久欧美精品sm网站| 亚洲高清免费| 久久嫩草精品久久久精品| 尤物网精品视频| 欧美黄色aaaa| 欧美日韩视频在线观看一区二区三区| 夜夜狂射影院欧美极品| 夜夜狂射影院欧美极品| 国产精品亚洲片夜色在线| 久久精品国产第一区二区三区最新章节 | 欧美激情第五页| 欧美福利在线| 午夜精品久久久久久久蜜桃app | 亚洲精品自在久久| 国产精品久久婷婷六月丁香| 欧美在线一区二区| 欧美gay视频| 欧美亚洲日本网站| 另类图片综合电影| 亚洲主播在线观看| 久久久91精品国产一区二区精品| 亚洲欧洲日韩综合二区| 亚洲欧美一区二区精品久久久| 在线精品在线| 亚洲视频精选| 亚洲黄色性网站| 亚洲一区久久久| 最新国产成人av网站网址麻豆| 亚洲一区影院| 亚洲美女av网站| 久久精品99国产精品日本| 妖精视频成人观看www| 欧美在线观看视频| 亚洲一区二区三区免费观看| 久久一区精品| 久久国产精品99久久久久久老狼| 欧美国产先锋| 久热精品视频在线免费观看| 国产精品久久国产三级国电话系列| 欧美国产精品人人做人人爱| 国产日韩精品久久久| 亚洲免费不卡| 亚洲精品欧洲精品| 久久激情中文| 久久精品综合| 国产精品色网| 国产精品99久久99久久久二8| 亚洲娇小video精品| 久久久久久久精| 久久xxxx| 国产情人综合久久777777| 一区二区三区高清不卡| 亚洲另类一区二区| 毛片av中文字幕一区二区| 久久久国产精品一区二区三区| 欧美午夜无遮挡| 99re6热只有精品免费观看| 亚洲成人在线网站| 久久深夜福利| 欧美大片一区二区三区| 伊人一区二区三区久久精品| 久久精品国产96久久久香蕉| 久久精品中文| 激情婷婷欧美| 老妇喷水一区二区三区| 免费在线视频一区| 在线欧美日韩国产| 免费观看成人www动漫视频| 欧美r片在线| 亚洲黄色免费网站| 欧美精品国产精品| 亚洲精选一区| 亚洲欧美在线磁力| 国产日韩精品电影| 久久精品国产999大香线蕉| 久久综合九色| 亚洲精品欧美激情| 欧美日韩精品一区二区在线播放 | 久久久久九九视频| 在线观看亚洲a| 麻豆成人在线观看| 亚洲人成在线观看一区二区| 中文在线一区| 国产精品自拍三区| 久久精品一区二区三区四区 | 久久成人精品无人区| 激情久久影院| 欧美精品www| 亚洲手机在线| 免费日韩av| 一本色道88久久加勒比精品| 国产精品一区一区三区| 久久视频精品在线| 亚洲最新合集| 欧美69wwwcom| 亚洲欧美偷拍卡通变态| 精品成人久久| 欧美日韩一区免费| 久久福利影视| 日韩一级精品视频在线观看| 久久久噜噜噜久久狠狠50岁| 亚洲精品中文字| 国产亚洲美州欧州综合国| 欧美不卡一卡二卡免费版| 亚洲一区激情| 亚洲欧洲一区二区三区| 久久国产毛片| 亚洲性视频网址| 亚洲国产成人午夜在线一区| 国产精品久久久91| 欧美精品99| 久久久久成人精品免费播放动漫| 99国产精品| 欧美第十八页| 久久精品免费播放| 亚洲一级片在线观看| 最近中文字幕mv在线一区二区三区四区 | 亚洲一区二区久久| 91久久国产综合久久蜜月精品| 久久久久久9| 亚洲欧美中文日韩在线| 99re热这里只有精品免费视频| 国产一区在线视频| 国产精品羞羞答答xxdd| 欧美全黄视频| 欧美精品v日韩精品v国产精品| 久久久噜噜噜| 久久久精品tv| 久久激情五月激情| 欧美在线视频不卡| 午夜国产精品影院在线观看| 99国产精品99久久久久久粉嫩| 欧美激情视频网站| 免费在线看一区| 免费观看成人鲁鲁鲁鲁鲁视频 | 亚洲日本成人| 亚洲人体影院| 亚洲青色在线| 亚洲美女av在线播放| 亚洲精品久久| 亚洲美女视频网| 日韩视频在线观看免费| 亚洲人成亚洲人成在线观看图片| **性色生活片久久毛片| 亚洲第一色在线| 亚洲国产一区二区精品专区| 亚洲二区在线| 亚洲精品小视频在线观看| 亚洲黄色av| 99在线精品观看| 亚洲香蕉在线观看| 午夜免费在线观看精品视频| 午夜欧美大尺度福利影院在线看| 亚洲欧美亚洲| 久久综合伊人77777蜜臀| 老司机成人网| 亚洲国产精品999| 亚洲美女在线一区| 亚洲男人天堂2024| 久久久亚洲国产天美传媒修理工| 久久综合网hezyo| 欧美日韩国产精品一区二区亚洲| 欧美三级日本三级少妇99| 国产伦精品一区二区三区高清 | 国产精品国色综合久久| 国产精品一区2区| 一区二区三区在线免费视频| 亚洲国产成人精品久久久国产成人一区 | 国产欧美日韩一区二区三区| 国产在线精品成人一区二区三区 | 亚洲国产高清一区| 一区二区三区精品视频在线观看| 亚洲欧美日韩在线高清直播| 久久一区二区三区四区| 亚洲国产婷婷香蕉久久久久久99 | 美日韩精品免费| 日韩亚洲综合在线| 久久久久久9| 欧美午夜精品久久久| 狠狠网亚洲精品| 亚洲少妇诱惑| 美女露胸一区二区三区| 一本色道精品久久一区二区三区 | 亚洲欧美日韩爽爽影院| 欧美成人亚洲成人日韩成人| 国产嫩草一区二区三区在线观看| 亚洲国产精品久久| 欧美伊人久久久久久久久影院 | 久久久久久欧美| 99精品视频免费| 免费成人性网站| 国产日韩欧美黄色| 一区二区三区久久久| 欧美不卡福利| 久久国产欧美| 国产精品视频区| 亚洲深夜激情| 亚洲人成网在线播放| 久久久久国产精品午夜一区|