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

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>
            免费永久网站黄欧美| 亚洲精品视频免费观看| 亚洲天天影视| 99国产精品99久久久久久| 欧美女激情福利| 亚洲伊人久久综合| 午夜精品福利一区二区蜜股av| 国产日韩av高清| 你懂的一区二区| 欧美日韩高清在线| 欧美一级欧美一级在线播放| 欧美在线看片| 91久久久精品| 亚洲女与黑人做爰| 亚洲第一精品影视| 99国产精品久久久久老师| 国产伦一区二区三区色一情| 久久综合九色九九| 欧美日韩国产专区| 久久久久91| 欧美三级中文字幕在线观看| 久久精品成人一区二区三区蜜臀 | 亚洲女女做受ⅹxx高潮| 影音先锋亚洲视频| 一区二区三区 在线观看视| 国产欧美不卡| 亚洲精品免费一二三区| 国产精品久久久久久超碰| 免费成人高清视频| 国产免费观看久久黄| 亚洲国产成人精品女人久久久 | 欧美一级播放| 99re热精品| 久久美女性网| 欧美一区1区三区3区公司| 欧美激情亚洲视频| 另类av导航| 国产视频精品va久久久久久| 亚洲人成网站影音先锋播放| 韩国精品主播一区二区在线观看| 亚洲精品久久久一区二区三区| 国产在线拍揄自揄视频不卡99| 亚洲精品专区| 亚洲精品欧洲| 老司机精品视频网站| 久久精品人人做人人综合| 免费影视亚洲| 欧美成年人视频网站| 国产在线观看一区| 亚洲欧美日韩精品久久亚洲区| 一区二区三区国产精品| 欧美成人69av| 亚洲缚视频在线观看| 亚洲国产精品va在线观看黑人 | 亚洲福利国产精品| 在线国产精品播放| 久久久久久久性| 久久精品一区蜜桃臀影院| 国产精品一区二区久久精品| 日韩一区二区免费高清| 亚洲美女淫视频| 欧美精品一区二区三区在线看午夜| 老司机aⅴ在线精品导航| 国产字幕视频一区二区| 欧美有码视频| 毛片基地黄久久久久久天堂| 一区在线播放| 美女网站在线免费欧美精品| 欧美插天视频在线播放| 91久久精品网| 欧美伦理91| 亚洲视频在线一区| 久久国产黑丝| 亚洲成在线观看| 欧美电影在线播放| 日韩香蕉视频| 羞羞视频在线观看欧美| 国产一区二区三区高清播放| 久久高清福利视频| 欧美福利一区二区| 在线亚洲成人| 国产欧美日韩精品在线| 久久久www成人免费无遮挡大片| 蜜臀久久99精品久久久久久9 | 亚洲黄色有码视频| 亚洲一区二区三区乱码aⅴ蜜桃女 亚洲一区二区三区乱码aⅴ | 午夜日韩av| 伊人久久大香线蕉综合热线| 免费成人av| 亚洲视频欧美视频| 美女国内精品自产拍在线播放| 亚洲国产毛片完整版| 欧美日韩亚洲视频| 久久成人国产| 亚洲开发第一视频在线播放| 羞羞色国产精品| 亚洲精品久久久久久久久| 国产精品国产三级国产专播精品人| 亚洲欧美伊人| 亚洲品质自拍| 久久在线播放| 亚洲自拍偷拍一区| 亚洲高清免费| 国产农村妇女毛片精品久久麻豆 | 日韩午夜视频在线观看| 久久九九热免费视频| 一区二区电影免费观看| 国产在线日韩| 国产精品久久久久久影院8一贰佰 国产精品久久久久久影视 | 91久久精品美女高潮| 国产日韩精品视频一区| 欧美精品国产| 老司机成人网| 久久国产精品久久久久久电车 | 久久久久久久一区| 亚洲尤物影院| 日韩网站在线看片你懂的| 国产在线成人| 国产日产高清欧美一区二区三区| 欧美国产视频一区二区| 久久久久成人精品免费播放动漫| 在线一区二区三区做爰视频网站 | 欧美一区久久| 亚洲无线一线二线三线区别av| 亚洲国产99精品国自产| 国产一区二区精品| 国产精品区一区二区三区| 欧美日韩成人综合在线一区二区 | 国产精品久久夜| 欧美三级在线视频| 欧美日本韩国在线| 欧美韩国日本一区| 欧美成年人网站| 欧美成人精品在线视频| 猫咪成人在线观看| 美女爽到呻吟久久久久| 久久只有精品| 久热成人在线视频| 米奇777超碰欧美日韩亚洲| 久久久夜精品| 久久在线播放| 欧美成人精品在线视频| 欧美成人一区在线| 欧美精品亚洲精品| 欧美日韩精品国产| 欧美午夜一区二区三区免费大片| 欧美日韩第一区日日骚| 欧美日韩在线精品一区二区三区| 欧美日韩国产首页| 国产精品久久久久aaaa| 国产精品美女久久久浪潮软件 | 国产精品地址| 国内外成人免费激情在线视频网站 | 一区二区三区四区蜜桃| 中文精品一区二区三区 | 一区二区不卡在线视频 午夜欧美不卡在| 亚洲国产免费看| av成人免费| 午夜精品久久久久99热蜜桃导演| 欧美一区二区三区在线观看视频 | 国产女主播一区二区三区| 国产综合久久久久久鬼色| 亚洲第一页自拍| 日韩午夜在线播放| 欧美一区二粉嫩精品国产一线天| 久久久777| 亚洲另类在线视频| 欧美一区永久视频免费观看| 久久精品99无色码中文字幕| 免播放器亚洲一区| 国产精品日韩在线播放| 欧美bbbxxxxx| 亚洲日本激情| 亚洲免费视频一区二区| 久久亚洲一区| 欧美三级视频在线播放| 国产在线日韩| 一区二区三区欧美成人| 久久久精品国产免大香伊 | 亚洲欧美日韩一区二区三区在线 | 欧美在线3区| 亚洲国语精品自产拍在线观看| 亚洲一区二区三区四区在线观看 | 麻豆成人av| 欧美三区不卡| 亚洲第一页自拍| 久久国产精品免费一区| 91久久夜色精品国产网站| 午夜在线电影亚洲一区| 男女精品网站| 狠狠久久婷婷| 欧美一级艳片视频免费观看| 亚洲国产成人av好男人在线观看| 亚洲一区在线直播| 欧美精品18+| 亚洲丰满在线| 久久综合亚洲社区| 午夜亚洲性色视频| 欧美性色视频在线| 亚洲视频每日更新|