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

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類中加入下列變量,分別代表紋理環繞,紋理過濾,紋理模式的參數。

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

 并在構造函數中加入:

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()中加入如下調用:

    //加載紋理
    LoadGLTextures();

5,繪制函數修改如下:

void CCY457OpenGLView::RenderScene ()
{
//繪制函數
        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/    

本文版權歸作者和博客園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,否則保留追究法律責任的權利。
原文鏈接: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亚洲v| 一区二区亚洲精品国产| 在线综合欧美| 日韩午夜免费视频| 欧美系列电影免费观看| 亚洲欧美电影院| 午夜精品久久久久久久99热浪潮 | 国产色综合天天综合网| 久久精品一区| 免费成人高清在线视频| 一区二区三区精品在线| 亚洲一区二区三区乱码aⅴ蜜桃女| 国产精品chinese| 欧美亚洲综合网| 开元免费观看欧美电视剧网站| 亚洲黄色三级| 亚洲一区二区成人| 在线不卡视频| 一区二区欧美日韩| 激情欧美一区二区| 亚洲日本中文字幕区| 国产精品v亚洲精品v日韩精品| 久久精品九九| 欧美激情中文字幕在线| 午夜精品久久久久久久蜜桃app| 久久av二区| 一区二区三区成人精品| 欧美亚洲视频| 亚洲一二三四久久| 久久久噜噜噜| 欧美一级网站| 欧美精品综合| 久久综合久久久久88| 欧美视频精品在线| 欧美成人免费观看| 国产精品一二三视频| 亚洲娇小video精品| 国产综合色精品一区二区三区| 亚洲毛片一区| 亚洲福利视频二区| 亚洲欧美日韩国产一区二区| 亚洲精品一级| 久久爱www.| 亚洲专区在线视频| 欧美激情aⅴ一区二区三区| 久久久久久色| 国产精品一区亚洲| 99riav1国产精品视频| 亚洲人成人99网站| 久久夜色精品国产欧美乱| 欧美中文在线观看| 国产精品av久久久久久麻豆网| 欧美大片第1页| 激情综合网激情| 久久av一区二区三区亚洲| 亚洲欧美bt| 欧美性天天影院| 夜夜狂射影院欧美极品| 亚洲精品乱码久久久久久黑人 | 一本色道久久综合亚洲精品高清 | 国产精品一二三四区| 亚洲毛片一区| 一区二区精品| 欧美日韩国产欧| 亚洲品质自拍| 一区二区三区四区五区在线 | 久久久精品日韩欧美| 久久精品国语| 激情综合在线| 久久亚洲精品视频| 亚洲成人在线视频播放 | 欧美日韩综合不卡| 亚洲麻豆视频| 亚洲欧美变态国产另类| 国产精品久久中文| 先锋a资源在线看亚洲| 欧美一区二视频| 国产日韩欧美在线播放| 欧美一区二区三区在线观看视频| 久久精品道一区二区三区| 国产裸体写真av一区二区| 欧美一区二区播放| 欧美va天堂在线| 日韩视频不卡中文| 欧美视频在线视频| 午夜免费日韩视频| 能在线观看的日韩av| 亚洲免费成人av| 国产精品一区二区三区久久| 欧美呦呦网站| 欧美激情一区二区三区蜜桃视频 | 亚洲性色视频| 国产日韩一区二区三区| 久久夜色精品亚洲噜噜国产mv| 欧美黑人国产人伦爽爽爽| 亚洲最新视频在线播放| 国产精品一卡二| 久久精品在线观看| 亚洲剧情一区二区| 久久久久国内| 一区二区三区四区蜜桃| 国产欧美一区二区三区在线看蜜臀 | 欧美资源在线观看| 亚洲日韩欧美视频| 国产精品亚洲人在线观看| 久久久中精品2020中文| 亚洲精品视频免费观看| 久久精品亚洲一区二区| 亚洲欧洲一区二区天堂久久| 国产精品视频自拍| 欧美jizzhd精品欧美巨大免费| 亚洲视频专区在线| 欧美国产日韩一区二区| 欧美一区2区视频在线观看| 91久久中文字幕| 国产一区二区日韩| 欧美午夜理伦三级在线观看| 久久综合综合久久综合| 亚洲欧美在线一区二区| 日韩视频久久| 欧美电影在线观看| 久久免费高清| 欧美一区二区三区免费观看视频| 日韩亚洲欧美一区| 亚洲电影毛片| 国内精品美女在线观看| 国产精品视频yy9299一区| 欧美日本韩国一区二区三区| 久久夜色撩人精品| 久久精品国产亚洲aⅴ| 亚洲一区国产视频| 一本色道88久久加勒比精品| 亚洲欧洲日产国产综合网| 蘑菇福利视频一区播放| 久久久综合激的五月天| 欧美在线免费视频| 午夜宅男欧美| 午夜精品久久久久久久99樱桃| 一区二区av在线| 一本色道久久综合狠狠躁篇的优点| 在线观看视频免费一区二区三区| 国产亚洲欧洲| 韩国v欧美v日本v亚洲v| 国产一区二区三区久久| 国产一区二区日韩精品欧美精品| 国产日韩免费| 狠狠色综合色综合网络| 国内精品久久久久久 | 亚洲电影有码| 亚洲国产欧美在线人成| 亚洲黄色影院| 日韩视频免费大全中文字幕| 99精品欧美一区| 亚洲少妇自拍| 欧美在线观看一区二区| 久久精品麻豆| 免费观看成人网| 亚洲国产美女久久久久| 亚洲精品国久久99热| 一区二区电影免费观看| 亚洲一区二区三区在线播放| 性感少妇一区| 蜜桃av一区二区| 欧美日韩三区四区| 国产精品视频九色porn| 黄色小说综合网站| 亚洲九九精品| 欧美一级二区| 欧美 日韩 国产在线| 91久久夜色精品国产九色| 亚洲福利视频网| 亚洲午夜精品一区二区三区他趣| 亚洲综合色噜噜狠狠| 久久五月天婷婷| 欧美日韩国产综合网| 国产三级精品在线不卡| 在线精品观看| 亚洲影院免费观看| 久久亚洲图片| 日韩一区二区免费看| 欧美一区二区三区免费看| 美女精品在线观看| 国产精品久久久久久福利一牛影视| 国内自拍亚洲| 亚洲一区图片| 欧美岛国在线观看| 亚洲欧美国产三级| 欧美精品一区二区在线观看| 国产乱肥老妇国产一区二| 亚洲欧洲精品一区二区精品久久久| 亚洲夜晚福利在线观看| 嫩草国产精品入口| 亚洲欧美另类久久久精品2019| 嫩模写真一区二区三区三州| 国产精品日韩一区| 99视频超级精品| 老鸭窝91久久精品色噜噜导演| 亚洲私人影院在线观看| 欧美电影在线观看| 尤物精品国产第一福利三区|