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

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>
            欧美电影打屁股sp| 一本色道久久加勒比88综合| 欧美制服第一页| 亚洲欧美清纯在线制服| 国产拍揄自揄精品视频麻豆| 久久久久国内| 欧美二区不卡| 亚洲一区二区三区四区中文| 亚洲欧美欧美一区二区三区| 一区二区视频在线观看| 欧美黄色网络| 国产精品成人一区二区| 久久国产精品99久久久久久老狼| 欧美在线看片| 亚洲青涩在线| 亚洲欧美国产三级| 亚洲黄色尤物视频| 亚洲先锋成人| 在线观看三级视频欧美| 亚洲精品综合| 好看的av在线不卡观看| 亚洲另类在线视频| 国产亚洲视频在线观看| 亚洲三级影院| 国产一区二区三区的电影 | 在线观看视频免费一区二区三区| 亚洲高清123| 国产深夜精品| 日韩视频一区二区在线观看 | 黄色亚洲免费| 亚洲免费观看高清完整版在线观看熊| 国产日韩一区二区| 91久久久一线二线三线品牌| 国产一区白浆| 一卡二卡3卡四卡高清精品视频| 国内成+人亚洲| 亚洲午夜激情网站| 亚洲美女黄网| 久久久久久久久岛国免费| 亚洲欧美变态国产另类| 欧美wwwwww| 免播放器亚洲一区| 国产亚洲欧美一区| 亚洲制服av| 亚洲影音一区| 欧美日韩一区二区视频在线| 欧美国产在线电影| 一区二区三区在线视频观看| 午夜日韩电影| 亚洲欧美第一页| 欧美日韩视频在线一区二区观看视频| 美国十次了思思久久精品导航| 国产精品毛片一区二区三区| 99国产精品自拍| 日韩视频在线一区二区三区| 乱码第一页成人| 美玉足脚交一区二区三区图片| 国产视频一区在线| 亚洲欧美日韩综合一区| 亚洲欧美成人| 国产欧美日韩一级| 亚洲免费观看高清完整版在线观看熊 | 久久久国产精品一区二区三区| 欧美一级片一区| 国产精品免费看| 亚洲一区二区在线| 午夜精品一区二区三区在线播放| 欧美视频1区| 亚洲一区三区视频在线观看| 亚洲性视频网站| 国产精品卡一卡二| 午夜视频精品| 另类尿喷潮videofree| 樱花yy私人影院亚洲| 久久三级视频| 欧美激情第五页| 一片黄亚洲嫩模| 欧美午夜激情视频| 香蕉成人久久| 免费不卡中文字幕视频| 亚洲精品一二三区| 欧美午夜精品久久久久久浪潮| 亚洲一区二区精品视频| 久久久久久久久久久久久久一区| 精品动漫3d一区二区三区| 蜜桃av一区二区| 日韩亚洲在线| 久久久精品国产一区二区三区| 在线观看成人av电影| 欧美日韩国产一区二区三区地区| 99精品福利视频| 久久精品在线观看| 亚洲精品国产欧美| 国产精品女人毛片| 久久综合色8888| 亚洲少妇最新在线视频| 久久一区激情| 亚洲视频在线观看网站| 狠色狠色综合久久| 欧美日韩一卡二卡| 久久精品夜色噜噜亚洲aⅴ| 亚洲第一黄色网| 久久高清国产| 中文av字幕一区| 一色屋精品亚洲香蕉网站| 欧美日韩一区在线视频| 久久婷婷av| 亚洲欧美区自拍先锋| 亚洲日本在线观看| 久久精品最新地址| 日韩亚洲欧美精品| 激情五月***国产精品| 欧美日韩一级片在线观看| 久久中文在线| 香蕉久久国产| 一区二区三区欧美在线| 欧美韩日一区| 久久婷婷av| 午夜一区二区三区在线观看| 日韩网站在线观看| 一区在线免费| 国产主播精品在线| 国产精品久久久久久久app| 欧美成人综合| 麻豆成人在线播放| 久久精品国产在热久久 | 亚洲综合色激情五月| 一区二区三区日韩| 亚洲理伦电影| 亚洲精品久久久久久久久久久久 | 亚洲三级网站| 亚洲国产精品电影在线观看| 蜜桃伊人久久| 久久亚洲综合网| 久久免费99精品久久久久久| 久久成人这里只有精品| 午夜久久资源| 欧美一区二区三区啪啪| 午夜精品福利一区二区蜜股av| 亚洲视频在线观看网站| 亚洲网友自拍| 亚洲图片你懂的| 亚洲一级一区| 亚洲欧美制服另类日韩| 亚洲欧美中文日韩在线| 亚洲欧美制服中文字幕| 欧美一区二区三区四区在线观看| 亚洲欧美另类在线| 欧美在线观看网址综合| 久久精品国产99国产精品澳门| 久久9热精品视频| 久久婷婷蜜乳一本欲蜜臀| 麻豆精品视频在线观看| 欧美成va人片在线观看| 欧美国产日韩一区二区| 亚洲精品美女久久久久| 一本久道综合久久精品| 亚洲欧美日本国产专区一区| 久久精品国产69国产精品亚洲| 久久久久久国产精品一区| 乱码第一页成人| 欧美日一区二区三区在线观看国产免 | 欧美国产第一页| 欧美日韩精品在线视频| 国产精品视频免费一区| 狠狠入ady亚洲精品| 亚洲激情亚洲| 亚洲一区在线免费观看| 久久久久久久综合色一本| 欧美顶级少妇做爰| 日韩亚洲在线| 久久久久久网| 欧美日韩在线看| 国内欧美视频一区二区| 亚洲日本aⅴ片在线观看香蕉| 亚洲一区日韩在线| 麻豆免费精品视频| 一个人看的www久久| 久久久国产精品一区二区中文 | 午夜伦欧美伦电影理论片| 玖玖视频精品| 国产精品羞羞答答| 亚洲日本成人女熟在线观看| 亚洲欧美精品suv| 欧美成人午夜激情| 亚洲欧美日韩国产一区| 欧美国产欧美亚洲国产日韩mv天天看完整 | 欧美日韩在线影院| 一区精品在线| 午夜精品亚洲| 亚洲三级电影在线观看| 久久综合国产精品| 国产欧美高清| 亚洲视频中文| 亚洲大片精品永久免费| 久久精品伊人| 国产日韩在线看片| 亚洲一区三区视频在线观看| 亚洲国产黄色片| 久久国产婷婷国产香蕉|