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

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>
            亚洲夫妻自拍| 亚洲一区二区三区高清 | 欧美在线啊v| 欧美日韩mp4| 欧美激情小视频| 在线成人性视频| 久久激情五月激情| 欧美一区二区三区免费视频| 欧美日韩久久| 亚洲国产精品一区二区第一页| 国产欧美午夜| 亚洲综合精品一区二区| 亚洲网友自拍| 欧美国产日本韩| 欧美激情中文不卡| 亚洲电影欧美电影有声小说| 午夜一区二区三视频在线观看| 亚洲一区免费看| 国产精品成人在线观看| 日韩午夜在线视频| av成人老司机| 欧美日韩免费一区二区三区| 亚洲激情在线观看| 日韩一级成人av| 免费在线观看精品| 亚洲电影欧美电影有声小说| 亚洲黄色av| 欧美精品自拍| 日韩亚洲欧美一区| 亚洲一区二区三区四区五区午夜| 欧美日韩成人一区| 一区二区三区久久网| 亚洲综合色丁香婷婷六月图片| 欧美日韩免费在线观看| 亚洲一区二区三区涩| 欧美中文字幕在线视频| 很黄很黄激情成人| 久久青草久久| 亚洲国产精品一区| 亚洲网址在线| 国产日韩欧美一区二区三区在线观看 | 亚洲最新色图| 午夜在线视频观看日韩17c| 国产精品网站视频| 久久久久**毛片大全| 欧美电影免费观看| 亚洲网站在线| 国产一区二区三区久久| 久久亚洲私人国产精品va媚药| 欧美成人影音| 亚洲欧美另类中文字幕| 韩日精品视频| 欧美—级a级欧美特级ar全黄| 一本综合精品| 久久综合福利| 亚洲永久网站| 在线观看亚洲专区| 欧美三区免费完整视频在线观看| 午夜亚洲福利| 亚洲精品日韩综合观看成人91| 香蕉久久夜色精品| 亚洲黄色天堂| 国产日韩精品一区二区三区| 欧美成人精品在线观看| 亚洲午夜久久久久久尤物 | 一区二区三区不卡视频在线观看| 欧美一区视频在线| 亚洲理论电影网| 国产视频自拍一区| 欧美日韩国语| 美腿丝袜亚洲色图| 午夜精品视频在线| 日韩小视频在线观看| 久久综合中文字幕| 亚洲欧美日韩精品久久奇米色影视| 国产亚洲欧美一级| 国产精品久久久久久久电影| 免费一区二区三区| 久久国产精品高清| 亚洲综合视频1区| 日韩视频免费观看高清完整版| 久久人人爽爽爽人久久久| 亚洲一区二区在线免费观看| 亚洲欧洲精品一区二区精品久久久 | 午夜视频一区| 亚洲色诱最新| 亚洲精品欧洲精品| 狠狠色狠狠色综合日日tαg| 国产精品久久久久久久久免费 | 日韩亚洲国产精品| 亚洲国产高清视频| 国产一区二区三区日韩| 国产精品va在线| 欧美久久久久久久久| 免费一级欧美片在线观看| 久久国产精品免费一区| 欧美亚洲午夜视频在线观看| 亚洲视频中文| 一本色道久久加勒比精品| 亚洲精品久久久蜜桃| 欧美激情亚洲另类| 亚洲高清视频中文字幕| 欧美激情亚洲自拍| 欧美电影免费观看| 欧美激情精品久久久久久| 欧美国产视频日韩| 欧美国产一区视频在线观看 | 亚洲日本成人在线观看| 亚洲国产精品嫩草影院| 亚洲国产视频一区二区| 亚洲片国产一区一级在线观看| 欧美激情第五页| 亚洲国产欧美在线| 亚洲另类春色国产| 9国产精品视频| 一区二区三区久久网| 亚洲香蕉在线观看| 亚洲欧美一区二区三区极速播放| 亚洲一区不卡| 欧美怡红院视频一区二区三区| 欧美中文在线视频| 免费h精品视频在线播放| 女同性一区二区三区人了人一 | 一区二区欧美在线| 亚洲一区国产| 久久爱91午夜羞羞| 美女国产精品| 亚洲欧洲日本在线| 亚洲一区中文| 久久久久91| 欧美精品免费在线| 国产美女精品在线| 亚洲国产清纯| 亚洲在线播放电影| 久久精品123| 亚洲国产成人不卡| 亚洲综合好骚| 欧美sm视频| 国产精品亚洲人在线观看| 精品不卡一区二区三区| av成人动漫| 久久久久久久久久久成人| 亚洲第一在线综合在线| 亚洲天堂免费在线观看视频| 久久久久久午夜| 国产精品久久久久久久app | 黑人巨大精品欧美一区二区小视频| 亚洲国产精品va在看黑人| 亚洲午夜羞羞片| 亚洲日本中文| 国产一区二区无遮挡| 在线观看亚洲视频啊啊啊啊| 中文久久精品| 欧美暴力喷水在线| 宅男噜噜噜66一区二区| 久久综合中文字幕| 国产精品初高中精品久久| 亚洲国产欧美国产综合一区 | 激情丁香综合| 亚洲私人黄色宅男| 欧美顶级少妇做爰| 午夜国产精品视频| 欧美日韩午夜剧场| 一本一本久久| 久久三级视频| 亚洲香蕉伊综合在人在线视看| 麻豆成人小视频| 国产午夜亚洲精品不卡| 亚洲在线一区二区三区| 亚洲第一伊人| 久久久蜜桃精品| 国产日韩欧美不卡| 亚洲欧美日韩天堂一区二区| 亚洲国产另类精品专区| 久久久噜噜噜久噜久久| 国产日韩精品一区二区| 亚洲欧美在线看| 99这里只有久久精品视频| 欧美国产极速在线| 亚洲国产va精品久久久不卡综合| 久久精品一区二区三区中文字幕| 亚洲性xxxx| 国产精品swag| 亚洲欧美影院| 亚洲午夜在线观看视频在线| 欧美日韩一区二区精品| 日韩一区二区精品| 91久久在线观看| 欧美激情一区二区三区在线视频| 亚洲激情成人| 亚洲电影免费观看高清完整版在线观看| 久久久久国色av免费观看性色| 国产无遮挡一区二区三区毛片日本| 亚洲一区久久久| 久久久www成人免费毛片麻豆| 一本久久综合亚洲鲁鲁| 欧美精品少妇一区二区三区| 日韩网站在线| 99热在这里有精品免费| 欧美日韩一区二区免费视频|