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

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精品| 国产日韩欧美成人| 久久久999精品免费| 欧美一级欧美一级在线播放| 国产亚洲一区二区三区在线播放| 久久久五月天| 欧美国产一区视频在线观看| 亚洲午夜一区| 久久精品论坛| 宅男精品视频| 欧美一区三区二区在线观看| 国内精品一区二区三区| 欧美激情综合色| 国产精品久久久久久久久久免费| 欧美一级网站| 女女同性女同一区二区三区91| 在线一区免费观看| 久久久久欧美精品| 日韩一区二区免费高清| 午夜精品久久久久久久久久久| 伊甸园精品99久久久久久| 91久久综合| 国产在线拍揄自揄视频不卡99| 亚洲东热激情| 国产乱肥老妇国产一区二| 欧美xxx成人| 国产精品激情av在线播放| 免费视频一区二区三区在线观看| 欧美三日本三级少妇三2023 | 欧美国产丝袜视频| 亚洲欧美视频在线观看| 久久夜色精品国产| 欧美一区二区啪啪| 欧美日韩蜜桃| 欧美精品在线网站| 久久综合色影院| 国产欧美欧美| 99国产精品自拍| 亚洲精美视频| 久久av一区二区三区| 亚洲欧美另类久久久精品2019| 噜噜噜噜噜久久久久久91| 欧美一站二站| 国产精品乱码人人做人人爱| 亚洲欧洲一区| 亚洲人成网站在线观看播放| 久久成人精品无人区| 欧美一区二区大片| 国产精品手机在线| 亚洲特级毛片| 午夜精品999| 欧美午夜不卡影院在线观看完整版免费| 免费在线成人av| 加勒比av一区二区| 午夜精品国产更新| 久久国产手机看片| 国产欧美日本| 欧美中文字幕第一页| 欧美中文字幕不卡| 国产欧美一区二区三区在线老狼| 在线视频亚洲| 午夜一区二区三区不卡视频| 国产精品色婷婷| 亚洲欧美日本国产专区一区| 欧美亚洲免费高清在线观看| 国产麻豆综合| 久久不射2019中文字幕| 麻豆免费精品视频| 亚洲精品乱码久久久久久| 欧美不卡视频| 亚洲国产小视频| 欧美激情一区在线| 日韩系列欧美系列| 欧美一区在线视频| 在线观看日韩av| 欧美国产一区在线| 一区二区三区不卡视频在线观看| 亚洲欧美日韩视频一区| 国产一区二区精品久久99| 欧美综合国产精品久久丁香| 美女视频黄 久久| 亚洲精品一区二区三区99| 欧美日韩高清在线观看| 亚洲无线观看| 蜜桃av一区二区| 一区二区三区四区在线| 欧美先锋影音| 午夜国产一区| 久久久综合视频| 一区二区精品在线| 国产精品亚洲综合一区在线观看 | 亚洲综合日韩在线| 免费在线看一区| 夜夜夜久久久| 国产模特精品视频久久久久| 老司机午夜免费精品视频| 亚洲日本电影| 久久免费精品视频| 亚洲人成人一区二区在线观看| 欧美视频中文一区二区三区在线观看| 亚洲欧美日本国产专区一区| 欧美 日韩 国产精品免费观看| av成人激情| 国产视频精品xxxx| 欧美日韩国产成人精品| 香蕉免费一区二区三区在线观看| 欧美成人有码| 久久久国产精彩视频美女艺术照福利| 亚洲日本中文字幕| 国产亚洲制服色| 欧美午夜宅男影院| 欧美黑人在线播放| 久久精品一区二区| 亚洲一二三区精品| 亚洲国产美女精品久久久久∴| 国产精品日韩欧美大师| 欧美日韩精品国产| 欧美不卡视频一区发布| 久久精品论坛| 亚洲欧美日韩在线观看a三区| 欧美激情四色 | 欧美一级在线视频| 一区二区av| 日韩午夜视频在线观看| 在线日韩电影| 在线看片第一页欧美| 国产日本精品| 国产午夜亚洲精品不卡| 国产精品久久久久久妇女6080| 欧美人与性动交cc0o| 麻豆成人在线观看| 久久久久高清| 久久久国产精品一区| 亚洲欧美怡红院| 亚洲一区二区三区777| 亚洲小说欧美另类婷婷| av成人黄色| 亚洲一区二区在线免费观看| 日韩亚洲不卡在线| 99国产精品国产精品久久| 亚洲免费av片| 在线亚洲免费| 亚洲欧美国产精品桃花| 日韩视频一区二区三区| 亚洲国产日韩欧美| 99国内精品久久| 亚洲在线视频观看| 欧美一区二区三区精品| 久久久777| 老司机精品视频网站| 免费在线欧美视频| 亚洲第一在线综合网站| 亚洲清纯自拍| 亚洲视频在线观看免费| 亚洲欧美日韩精品久久| 久久成人精品视频| 欧美大片免费看| 欧美性一区二区| 国产一区二区三区免费不卡 | 韩国一区电影| 亚洲国产精品小视频| 亚洲美女中文字幕| 亚洲欧美激情四射在线日| 久久aⅴ国产欧美74aaa| 男女激情久久| 亚洲桃花岛网站| 久久久人成影片一区二区三区观看 | 亚洲美女视频在线免费观看| 亚洲视频欧美在线| 久久激情网站| 亚洲精品久久久久久久久久久久久 | 欧美国产一区二区三区激情无套| 欧美日韩中文在线观看| 国产麻豆综合| 99精品欧美一区二区三区综合在线 | 亚洲欧洲一区二区在线观看| 正在播放欧美一区| 欧美一区在线直播| 亚洲国产精品第一区二区| 亚洲午夜av电影| 欧美成人免费网| 国产一区二区三区久久悠悠色av | 久久精品视频免费| 欧美日韩aaaaa| 亚洲第一区色| 性欧美暴力猛交69hd| 亚洲高清自拍| 欧美与欧洲交xxxx免费观看 | 麻豆精品一区二区av白丝在线| 欧美日韩在线亚洲一区蜜芽| 亚洲成色777777女色窝| 午夜欧美理论片| 亚洲精品在线视频观看| 久久一区亚洲| 国产亚洲欧美日韩美女| 亚洲伊人第一页| 亚洲剧情一区二区| 欧美电影打屁股sp|