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

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>
            欧美www视频在线观看| 国产人成一区二区三区影院| 久久久精品网| 国产欧美日韩综合一区在线播放| 亚洲国内精品| 欧美www视频在线观看| 在线一区二区三区四区| 欧美日韩国产一区二区三区地区 | 欧美日韩一区二区三区在线 | 美女精品一区| 国产视频欧美视频| 久久精品91| 欧美视频日韩视频| 久久九九全国免费精品观看| 欧美日韩二区三区| 亚洲黄一区二区| 在线观看成人一级片| 亚洲视频精品| 欧美成人精品高清在线播放| 亚洲美女毛片| 一区二区三区黄色| 尤妮丝一区二区裸体视频| 老牛影视一区二区三区| 欧美不卡高清| 亚洲欧美日韩天堂| 久久国产精品99精品国产| 国产农村妇女毛片精品久久麻豆| 亚洲天堂av在线免费| 美女亚洲精品| 亚洲日本一区二区三区| 欧美一级理论片| 欧美一区日本一区韩国一区| 欧美性大战久久久久| 亚洲欧美视频一区二区三区| 欧美日韩国产在线播放| 91久久亚洲| 一区二区不卡在线视频 午夜欧美不卡在 | 红桃视频一区| 午夜老司机精品| 老司机午夜精品视频| 国产日韩一区在线| 久久婷婷丁香| 亚洲伊人一本大道中文字幕| 国产精品亚洲人在线观看| 亚洲精品日韩一| 亚洲人成久久| 欧美好吊妞视频| 欧美激情第三页| 狠狠色狠狠色综合日日五| 久久夜色精品国产| 亚洲一区二区三区在线视频| 欧美伊人久久| 亚洲精品在线二区| 国产精品国产三级国产aⅴ9色| 亚洲欧美精品在线观看| 久久se精品一区二区| 性视频1819p久久| 羞羞答答国产精品www一本| 亚洲欧美不卡| 亚洲欧美日韩国产中文| 亚洲午夜久久久久久尤物 | 欧美日本韩国在线| 免费观看成人| 欧美激情国产高清| 国产精品av一区二区| 欧美不卡视频| 欧美日韩免费精品| 欧美日韩成人一区二区三区| 欧美福利一区二区三区| 久久夜色精品国产欧美乱极品| 久久人人爽人人爽爽久久| 久久蜜桃资源一区二区老牛 | 欧美日韩国产91| 欧美色道久久88综合亚洲精品| 欧美日韩免费观看一区三区| 国产精品黄视频| 国产午夜精品美女视频明星a级| 好吊妞**欧美| 欧美亚洲综合久久| 一本一本久久a久久精品综合麻豆| 亚洲视频免费在线| 欧美日本在线播放| 亚洲精品一区在线| 亚洲成色999久久网站| 欧美国产一区二区| 亚洲视频欧美在线| 欧美激情综合色| 一色屋精品视频在线观看网站| aa级大片欧美三级| 免费在线一区二区| 欧美与欧洲交xxxx免费观看 | 亚洲国产成人91精品| 久久精品亚洲一区| 亚洲欧美日韩国产一区二区| 欧美精品一区三区| 99精品欧美一区二区蜜桃免费| 久久人人97超碰国产公开结果| 99av国产精品欲麻豆| 免费日韩视频| 亚洲日本成人网| 亚洲精品小视频在线观看| 欧美成人中文| 一区二区国产在线观看| 亚洲精品资源| 国产精品v欧美精品v日韩精品 | 玖玖国产精品视频| 欧美一区午夜精品| 精品69视频一区二区三区| 久久综合伊人77777麻豆| 午夜精品久久久久久久久久久| 国产精品一区二区三区四区| 久久国产精品久久久久久久久久| 欧美一级片一区| 亚洲国产精品一区二区www在线| 亚洲第一主播视频| 国产精品美女在线观看| 久久综合色婷婷| 欧美日韩无遮挡| 蜜桃久久av| 国产精品免费一区二区三区在线观看 | 精品69视频一区二区三区| 女同一区二区| 国产精品日韩一区二区| 欧美刺激性大交免费视频| 欧美日韩三级一区二区| 久久婷婷国产综合国色天香| 欧美日韩成人一区| 欧美3dxxxxhd| 狠狠入ady亚洲精品| 亚洲一区二区三区精品在线| 亚洲精品少妇30p| 美国成人直播| 欧美高清在线播放| 激情综合色综合久久| 亚洲欧美伊人| 久久激情中文| 国产手机视频一区二区| 亚洲天堂av在线免费| 亚洲午夜激情免费视频| 欧美精品不卡| 日韩亚洲视频在线| 亚洲一区网站| 国产日韩欧美一区二区| 欧美一区二区三区四区视频| 久久电影一区| 在线观看不卡| 欧美高清视频一区| 99国产精品久久| 久久精品免视看| 亚洲国产一区二区三区高清| 免费中文字幕日韩欧美| 亚洲韩国青草视频| 亚洲尤物精选| 国内精品久久久久久久果冻传媒| 欧美永久精品| 亚洲精品视频二区| 久久久久在线| 一区二区av在线| 黄色成人在线网站| 欧美亚洲第一区| 狼人社综合社区| 亚洲欧美日韩国产一区二区| 欧美国产一区在线| 亚洲欧美激情一区二区| 尤物九九久久国产精品的特点 | 亚洲在线视频网站| 亚洲高清久久网| 国产日韩欧美精品在线| 欧美成人首页| 久久激情五月婷婷| 亚洲天堂成人| 99视频在线观看一区三区| 欧美激情视频一区二区三区在线播放 | 一区二区三区久久网| 裸体一区二区三区| 久久久久国产精品麻豆ai换脸| 亚洲综合精品一区二区| 夜夜爽av福利精品导航 | 国产精品永久免费观看| 国产精品久久一区主播| 国产精品国产三级国产aⅴ9色| 欧美精品在线观看一区二区| 免费观看日韩| 欧美黄污视频| 国产精品xxxxx| 国产精品欧美日韩一区| 国产精品有限公司| 在线欧美日韩| 日韩视频一区二区在线观看| 亚洲精品专区| 午夜亚洲激情| 久热国产精品| 99精品视频免费观看视频| 午夜免费电影一区在线观看| 久久精品一二三| 欧美性感一类影片在线播放| 国产视频一区在线观看| 亚洲伦理在线免费看| 久久久久久久久久久久久女国产乱 | 欧美国产精品日韩|