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

Shuffy

不斷的學(xué)習(xí),不斷的思考,才能不斷的進(jìn)步.Let's do better together!
posts - 102, comments - 43, trackbacks - 0, articles - 19

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

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)繞,紋理過(guò)濾,紋理模式的參數(shù)。

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

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

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

2,加載紋理對(duì)象。

//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,加入控制紋理映射效果的各個(gè)菜單項(xiàng)及其事件處理程序

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/    

本文版權(quán)歸作者和博客園共有,歡迎轉(zhuǎn)載,但未經(jīng)作者同意必須保留此段聲明,且在文章頁(yè)面明顯位置給出原文連接,否則保留追究法律責(zé)任的權(quán)利。
原文鏈接: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>
            亚洲在线视频一区| 欧美日韩中文另类| 欧美v日韩v国产v| 亚洲国产成人久久综合| 欧美国产精品日韩| 亚洲色图制服丝袜| 久久久噜噜噜久久狠狠50岁| 亚洲电影免费| 欧美日韩在线第一页| 亚洲影音一区| 欧美激情第六页| 亚洲午夜精品在线| 国内视频精品| 欧美日韩亚洲一区二区三区在线观看| 亚洲欧美电影院| 欧美大片在线观看| 午夜欧美电影在线观看| 亚洲高清资源| 国产精品视频免费| 麻豆精品一区二区av白丝在线| 99riav国产精品| 久久字幕精品一区| 亚洲一区二区在线看| 激情另类综合| 欧美性猛交一区二区三区精品| 久久精品九九| 9人人澡人人爽人人精品| 久久只精品国产| 亚洲欧美日韩国产综合在线| 亚洲国产导航| 国产日韩三区| 欧美日韩一区综合| 美女国产一区| 西西裸体人体做爰大胆久久久| 91久久久久久国产精品| 久久av一区二区三区漫画| 日韩视频三区| 在线观看日韩av| 国产精品青草久久| 欧美日韩国产在线| 欧美超级免费视 在线| 欧美中文字幕精品| 亚洲影视在线| 一本色道精品久久一区二区三区 | 欧美中文在线视频| 99国产精品| 亚洲国产欧美另类丝袜| 国产性做久久久久久| 欧美三日本三级少妇三99| 久久综合久久美利坚合众国| 欧美一区二区三区四区夜夜大片| 日韩一二三区视频| 亚洲激情欧美| 欧美黄色日本| 欧美成人影音| 噜噜噜噜噜久久久久久91 | 久久综合给合久久狠狠狠97色69| 性欧美超级视频| 亚洲欧美久久久| 亚洲午夜国产一区99re久久| 99成人在线| 日韩视频在线你懂得| 亚洲精品国产视频| 最新成人av在线| 亚洲日本在线观看| 亚洲欧洲日本国产| 亚洲国产日韩美| 最新日韩精品| 日韩视频中文字幕| 日韩图片一区| 亚洲视频在线观看| 亚洲一级黄色| 香蕉视频成人在线观看| 欧美影片第一页| 久久精品国产一区二区三区| 久久天天综合| 免费久久99精品国产| 欧美国产国产综合| 欧美日本韩国| 国产精品蜜臀在线观看| 国产麻豆综合| 伊人春色精品| 亚洲卡通欧美制服中文| 亚洲视频免费观看| 性色av一区二区三区在线观看| 午夜精品久久久久久久男人的天堂 | 亚洲福利视频网| 亚洲精品视频免费观看| 亚洲视频专区在线| 欧美一区二区在线| 美日韩精品视频| 欧美日韩国产片| 国产欧美日韩专区发布| 狠色狠色综合久久| 亚洲另类视频| 午夜日韩av| 免费欧美在线视频| 99精品热视频只有精品10| 亚洲欧美日韩综合aⅴ视频| 久久久久久9| 欧美日韩一区自拍| 国内精品伊人久久久久av影院| 亚洲国产欧美日韩另类综合| 一本一道久久综合狠狠老精东影业 | 久久亚洲一区二区| 欧美高清在线| 国产欧美精品日韩区二区麻豆天美| 国产一区二区三区久久精品| 亚洲日本黄色| 欧美一区二区三区视频免费| 女人色偷偷aa久久天堂| 一区二区三区精品视频在线观看| 欧美影院精品一区| 欧美日韩精品高清| 国内精品视频在线播放| 亚洲少妇在线| 久久久久久久999精品视频| 亚洲激情在线| 久久爱www.| 欧美视频观看一区| 在线观看视频一区二区| 亚洲综合丁香| 亚洲国产精品高清久久久| 亚洲一区二区不卡免费| 男女视频一区二区| 国产午夜精品一区二区三区视频 | 国产精品嫩草99a| 亚洲黄色精品| 久久精品视频亚洲| 一本一本久久a久久精品综合妖精| 久久精品视频在线| 国产精品入口麻豆原神| 日韩视频久久| 欧美成在线观看| 欧美在线播放高清精品| 国产精品v欧美精品v日本精品动漫| 亚洲丁香婷深爱综合| 欧美中文字幕久久| 99精品视频免费在线观看| 你懂的视频欧美| 尤物yw午夜国产精品视频明星| 欧美一级视频免费在线观看| 亚洲精品孕妇| 欧美高清在线视频观看不卡| 在线观看欧美一区| 久久一本综合频道| 欧美一二三区在线观看| 国产精品欧美在线| 亚洲自拍16p| 一区二区精品在线| 欧美日韩亚洲综合一区| 妖精视频成人观看www| 亚洲国产日韩欧美在线图片| 麻豆av一区二区三区久久| 在线播放日韩专区| 免费观看一级特黄欧美大片| 久久久久久久久久码影片| 激情综合电影网| 免费观看在线综合| 久久综合精品国产一区二区三区| 狠狠色综合网| 欧美1区3d| 你懂的网址国产 欧美| 亚洲激情视频在线| 亚洲国产另类 国产精品国产免费| 久久久久久久久久久久久9999| 国产一区二区三区电影在线观看| 久久精品女人天堂| 久久久久成人网| 亚洲第一黄色| 亚洲国产精品久久久久秋霞影院 | 欧美激情一区二区三区在线视频观看 | 久久久免费av| 亚洲三级影片| 99精品国产高清一区二区| 国产精品青草久久| 久久久久久久久久久成人| 久久久亚洲成人| 日韩视频在线一区二区三区| 日韩午夜激情av| 国产精品无码永久免费888| 久久久久久尹人网香蕉| 久久这里有精品视频| 日韩天堂av| 亚洲免费视频网站| 精品动漫3d一区二区三区免费| 免费亚洲婷婷| 欧美日韩一区二区欧美激情 | 久久亚洲精品欧美| 一本色道久久综合精品竹菊 | 在线日韩精品视频| 亚洲精品一区二区在线观看| 国产精品成人观看视频免费| 久久久久久欧美| 欧美激情综合| 久久国产精品久久久久久| 美女精品网站| 午夜精品视频一区| 乱码第一页成人| 午夜精品久久久久久久99樱桃|