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

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>
            蜜桃av久久久亚洲精品| 亚洲综合清纯丝袜自拍| 久久9热精品视频| 久久亚洲精品视频| 欧美一级片在线播放| 国产精品成人播放| 一本久久综合亚洲鲁鲁五月天| 亚洲国产精品久久久久秋霞影院| 久久久精品动漫| 国产一区二区你懂的| 久久精品国产91精品亚洲| 中国成人黄色视屏| 欧美无乱码久久久免费午夜一区| 一区二区三区四区蜜桃| 亚洲精品孕妇| 你懂的视频一区二区| 在线观看欧美黄色| 欧美激情亚洲另类| 免费观看成人www动漫视频| 国产一区二区三区四区在线观看| 欧美伊人久久| 久久久久这里只有精品| 亚洲国产成人91精品| 欧美大片在线看免费观看| 猫咪成人在线观看| 在线欧美日韩国产| 最新亚洲激情| 欧美亚洲第一区| 欧美一区二区三区免费观看视频| 欧美一区二区三区喷汁尤物| 欧美亚一区二区| 久久国产主播| 美女成人午夜| 一本色道精品久久一区二区三区 | 欧美黑人在线播放| 一区二区冒白浆视频| 亚洲国产精品福利| 欧美午夜欧美| 久久偷看各类wc女厕嘘嘘偷窃| 久久中文在线| 亚洲自拍高清| 久久精品30| 亚洲精品欧美日韩专区| 亚洲午夜伦理| 在线观看欧美| 亚洲网站在线看| 亚洲大胆人体视频| 亚洲韩国精品一区| 国产一区二区三区丝袜| 亚洲国产婷婷| 国产精品永久免费视频| 欧美黑人多人双交| 欧美三级第一页| 美日韩丰满少妇在线观看| 欧美激情视频网站| 久久精品国产亚洲5555| 欧美午夜不卡| 欧美va天堂在线| 国产精品一二一区| 亚洲免费激情| 亚洲国产精选| 欧美一区二区三区啪啪| 一本色道久久综合| 久久综合久久综合久久| 欧美亚洲免费| 国产精品v一区二区三区| 欧美国产精品va在线观看| 国产午夜精品在线观看| 亚洲精品社区| 亚洲国产高潮在线观看| 午夜精品久久久久久久久久久久| 亚洲视频免费看| 欧美国产第一页| 欧美99久久| 亚洲欧美日韩国产综合精品二区 | 欧美日韩系列| 亚洲丰满少妇videoshd| 精品av久久707| 亚洲人成高清| 最近看过的日韩成人| 欧美一区二区三区四区高清| 亚洲欧美日本视频在线观看| 欧美日韩国产一区| 欧美激情成人在线视频| 精品999成人| 久久综合久色欧美综合狠狠| 久久亚洲一区二区三区四区| 国产日产亚洲精品| 午夜精品久久久久久久久久久久久| 亚洲蜜桃精久久久久久久| 嫩草国产精品入口| 亚洲国产精品久久久久久女王| 亚洲高清久久久| 免费看亚洲片| 亚洲激情啪啪| 亚洲一区精品视频| 国产精品成人免费| 亚洲免费在线视频| 久久九九精品| 国产欧美日韩综合精品二区| 欧美一区免费| 免费在线观看日韩欧美| 亚洲国产精品尤物yw在线观看| 乱码第一页成人| 亚洲精品国产精品国自产观看| 99精品国产在热久久下载| 欧美日韩国产精品成人| 亚洲综合视频1区| 亚洲一二三区在线| 国产欧美精品va在线观看| 久久高清国产| 亚洲国产精品久久| 亚洲天堂黄色| 亚洲国产精品悠悠久久琪琪| 国产精品日韩电影| 欧美—级高清免费播放| 欧美一区二区免费观在线| 亚洲人成艺术| 久久蜜桃精品| 午夜视频在线观看一区二区| 亚洲激情视频网| 黄色精品网站| 国产日韩欧美麻豆| 欧美色精品天天在线观看视频| 久久婷婷蜜乳一本欲蜜臀| 国产精品99久久久久久宅男| 亚洲国产91精品在线观看| 久久在线观看视频| 欧美一区二区日韩| 亚洲欧美另类国产| 一区二区三区蜜桃网| 亚洲日本精品国产第一区| 国产一区二区三区无遮挡| 国产精品区一区| 国产精品99免视看9| 欧美精品一区在线| 欧美激情五月| 欧美肥婆在线| 欧美寡妇偷汉性猛交| 久久亚洲综合色一区二区三区| 羞羞视频在线观看欧美| 亚洲制服欧美中文字幕中文字幕| 99精品99久久久久久宅男| 亚洲国产成人精品女人久久久 | 免费在线成人| 乱人伦精品视频在线观看| 久久av免费一区| 久久精品久久综合| 欧美一区国产一区| 久久成人精品无人区| 欧美一区二区三区在线视频| 午夜精品免费| 久久久久国产成人精品亚洲午夜| 欧美一区二区三区成人| 久久成人这里只有精品| 久久久噜噜噜久久狠狠50岁| 久久精品91| 免费不卡中文字幕视频| 欧美gay视频| 亚洲精品国产系列| 9l国产精品久久久久麻豆| 9人人澡人人爽人人精品| 国产精品99久久99久久久二8| 亚洲午夜视频| 欧美在线观看视频| 美女精品自拍一二三四| 欧美另类久久久品| 国产精品国产三级国产普通话蜜臀| 国产精品美女xx| 国产一区三区三区| 亚洲国产91色在线| 亚洲午夜av| 久久亚洲国产精品日日av夜夜| 欧美韩国日本一区| 亚洲免费观看高清完整版在线观看| 亚洲一区999| 久久久夜夜夜| 欧美四级在线| 激情丁香综合| 在线亚洲一区观看| 久久久噜噜噜久久中文字免 | 亚洲已满18点击进入久久| 久久大逼视频| 亚洲国产三级在线| 亚洲免费影视| 欧美激情1区2区| 国产亚洲在线观看| 99精品热6080yy久久| 久久久噜噜噜久久中文字免| 亚洲精品乱码久久久久久蜜桃麻豆| 午夜精品久久久| 欧美精品在线免费播放| 国产亚洲欧美一区| 一区二区三区日韩精品视频| 毛片精品免费在线观看| 这里只有精品在线播放| 久久久精品一区二区三区| 国产精品久久久久久av福利软件| 亚洲电影在线观看| 久久久久久高潮国产精品视|