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

Shuffy

不斷的學習,不斷的思考,才能不斷的進步.Let's do better together!
posts - 102, comments - 43, trackbacks - 0, articles - 19

《基于MFC的OpenGL編程》Part 9 Lighting

Posted on 2010-03-31 20:37 Shuffy 閱讀(210) 評論(0)  編輯 收藏 引用 所屬分類: MFC,OpenGL
     本文在8篇文章的基礎上,為其加入燈光效果。

Materials

OpenGL materials are description of what objects are made of. It basically specifies how much of light they reflect and this is what we would be seeing. OpenGL lighting goes a long way towards modeling real world lighting. In order achieve proper lighting effects in OpenGL we need to specify material properties. Material properties are of the following types - Diffuse and Ambient properties, Specular and Shininess Properties and Emissive Properties. These are the properties that specify how a surface dissipates light.

Diffuse and Ambient Properties

The diffuse and ambient reflective material properties are a type of reflective effect that is independent of the viewpoint. Diffuse lighting is light from a particular direction and ambient lighting is light that is coming from all directions. A particular light source can have both a diffuse and an ambient component. These material properties describe how the material reflects diffuse and ambient light falling on it.

Specular and Shininess Properties

The specular and the shininess properties of the surface describe the reflective effects that are affected by the position of the viewpoint. Specular light is reflected from a surface that produces the reflective highlights in a surface. The shininess is a value that describes how focussed the reflective properties are.

Emissive Property

This is the light that an object gives off by itself. A typical example of this is a light source itself.

Specifying a material property

In order to specify a material property we have to use the OpenGL function - glMaterial*(). We can individually specify the material properties using this function. Another way to go about this is by color tracking. This can be achieved by enabling color tracking and specifying what parameters of the material would be affected by the glColor command. This is an optimization feature that OpenGL provides and is useful in cases where we will be changing only particular properties of the material and not all of them. In this tutorial we will use glMaterial to specify the material properties as we will be individually setting each one of them.

Choosing the material properties determine how the object will look. We will follow the following steps in choosing the material properties -

  • Decide on the diffuse and ambient colors.
  • Decide on the shininess depending on the type of material object that is being modeled such as silver, wood etc.
  • Decide whether the object would be giving off any light on its own.

The above values can be obtained by mere trial and error. We will look at how we go about doing this when we write a program.

Lighting

OpenGL has two types of lighting: global lighting or ambient lighting and individual light sources which have position and direction. The way an object is lit depends on the material of the object, all the lights and their properties, their positions and direction etc. This means lighting calculations are quite expensive and are hence turned off by OpenGL by default. So we have to turn on lighting before using it. Global lighting parameters can be set using the glLightModel function which specify the lighting model we would be using - such as an infinite viewer or a local viewer (for specular highlights), single sided or two sided lighting and the RGBA value for the ambient light. In addition to this we would be specifying the individual light sources.  

1,設置燈光和材質屬性

void CCY457OpenGLView::SetupLighting ()
{
    
//Material Properties
    GLfloat matSpecular[] = { 1.0f0.0f0.0f1.0f};
    GLfloat matShininess[] 
= { 50.0f};
    GLfloat matAmbient[] 
= { 0.25f0.25f0.25f1.0f};
    GLfloat matDiffuse[] 
= { 0.5f0.5f0.5f1.0f};
    glMaterialfv(GL_FRONT, GL_SPECULAR, matSpecular);
    glMaterialfv(GL_FRONT, GL_SHININESS, matShininess);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, matDiffuse);
    glMaterialfv(GL_FRONT, GL_AMBIENT, matAmbient);
    
//Lighting Parameters
    
//Enable Lighting
    glEnable(GL_LIGHTING);
    
//Specify a single directional light
    GLfloat ambient1[] = { 0.5f,0.5f,0.5f};
    GLfloat diffuse1[] 
= { 0.5f,0.5f,0.5f};
    GLfloat specular1[] 
= { 1.0f,0.0f,0.0f};
    GLfloat position1[] 
= { 0.0f,0.0f,5.0f,0.0};
    glLightfv(GL_LIGHT0, GL_AMBIENT, ambient1);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse1);
    glLightfv(GL_LIGHT0, GL_SPECULAR, specular1);
    glLightfv(GL_LIGHT0, GL_POSITION, position1);    
    glEnable(GL_LIGHT0);
    
//Specify a single positional spotlight
    GLfloat ambient2[] = { 1.0f,1.0f,0.0f};
    GLfloat diffuse2[] 
= { 1.0f,0.0f,0.0f};
    GLfloat position2[] 
= { 1.0f,0.0f,5.0f,1.0};
    GLfloat direction2[] 
= {0.0f,0.0f,-5.0f};
    glLightfv(GL_LIGHT1, GL_AMBIENT, ambient2);
    glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse2);
    glLightfv(GL_LIGHT1, GL_POSITION, position2);    
    glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, direction2);
    glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, 
15.0f);
    glEnable(GL_LIGHT1);
}

2,在初始化OpenGL時調用上述函數

BOOL CCY457OpenGLView::InitializeOpenGL()
{
    
//Get a DC for the Client Area
    m_pDC = new CClientDC(this);
    
//Failure to Get DC
    if(m_pDC == NULL)
    {
        MessageBox(
"Error Obtaining DC");
        
return FALSE;
    }
    
//Failure to set the pixel format
    if(!SetupPixelFormat())
    {
        
return FALSE;
    }
    
//Create Rendering Context
    m_hRC = ::wglCreateContext (m_pDC->GetSafeHdc ());
    
//Failure to Create Rendering Context
    if(m_hRC == 0)
    {
        MessageBox(
"Error Creating RC");
        
return FALSE;
    }
    
//Make the RC Current
    if(::wglMakeCurrent (m_pDC->GetSafeHdc (), m_hRC)==FALSE)
    {
        MessageBox(
"Error making RC Current");
        
return FALSE;
    }
    
//Specify Black as the clear color
    ::glClearColor(0.0f,0.0f,0.0f,0.0f);
    
//Specify the back of the buffer as clear depth
    ::glClearDepth(1.0f);
    
//Enable Depth Testing
    ::glEnable(GL_DEPTH_TEST);
    glShadeModel(GL_FLAT);
    SetupLighting();
    
return TRUE;
}

 

作者:洞庭散人

出處:http://phinecos.cnblogs.com/    

本文版權歸作者和博客園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,否則保留追究法律責任的權利。
原文鏈接:http://www.cnblogs.com/phinecos/archive/2008/11/05/1327595.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一区二区三区中文字幕| 国产午夜精品久久| 一区二区三区鲁丝不卡| 欧美 日韩 国产在线 | 米奇777超碰欧美日韩亚洲| 国产美女精品在线| 亚洲欧美激情诱惑| 亚洲视频1区2区| 欧美午夜激情视频| 亚洲一区二区三区午夜| 99精品视频免费| 国产精品igao视频网网址不卡日韩| 亚洲蜜桃精久久久久久久| 欧美华人在线视频| 欧美激情国产日韩精品一区18| 在线看片第一页欧美| 免费成人高清| 欧美国产日本在线| 99国产精品自拍| 99国产一区| 国产精品一区二区三区成人| 欧美在线免费视频| 久久夜色精品国产| 亚洲麻豆一区| 中日韩午夜理伦电影免费| 欧美性猛交99久久久久99按摩| 亚洲自拍偷拍一区| 久久成人免费电影| 亚洲精品欧美精品| 亚洲小说春色综合另类电影| 国产亚洲一区二区三区在线播放| 蜜臀va亚洲va欧美va天堂| 嫩模写真一区二区三区三州| 一区二区三区|亚洲午夜| 日韩亚洲欧美精品| 国产一区二区三区av电影 | 免播放器亚洲| 欧美激情中文字幕一区二区| 亚洲主播在线观看| 欧美一区二区三区日韩| 亚洲日韩中文字幕在线播放| 中文精品一区二区三区| 极品少妇一区二区三区| 亚洲人成高清| 国产精品美女www爽爽爽视频| 久久久国产精品一区| 欧美精品99| 久久久91精品| 欧美日韩亚洲91| 久久躁日日躁aaaaxxxx| 欧美精品xxxxbbbb| 久久久久久香蕉网| 欧美日韩精品伦理作品在线免费观看| 久久成人羞羞网站| 欧美久久久久久| 久久青草久久| 国产精品私人影院| 日韩视频一区二区三区| 极品尤物一区二区三区| 中国日韩欧美久久久久久久久| 在线日韩精品视频| 午夜免费久久久久| 国产精品99久久久久久有的能看| 久久精品五月| 欧美专区一区二区三区| 欧美日韩视频免费播放| 欧美成人性生活| 国内综合精品午夜久久资源| 中文亚洲免费| 亚洲一区二区三区欧美| 欧美二区乱c少妇| 免费成人高清视频| 国产在线观看精品一区二区三区| 中文精品视频| 亚洲色图在线视频| 欧美日本免费| 亚洲经典视频在线观看| 亚洲国产精品传媒在线观看| 久久精品免费观看| 久久久久久黄| 国产在线精品自拍| 欧美一区二区黄| 久久精品毛片| 国产一区二区三区精品欧美日韩一区二区三区 | 国产精品久久久久99| 亚洲精选久久| 一区二区三区鲁丝不卡| 欧美黄色网络| 亚洲国产三级在线| 亚洲精品你懂的| 欧美精品一区二区三区高清aⅴ| 亚洲国产欧美国产综合一区| 亚洲福利电影| 久久亚洲国产精品日日av夜夜| 你懂的网址国产 欧美| 亚洲第一综合天堂另类专| 蜜桃精品久久久久久久免费影院| 欧美成人亚洲| 亚洲最新视频在线播放| 欧美日韩一本到| 亚洲调教视频在线观看| 欧美一区二区视频免费观看| 国产欧美精品在线播放| 久久狠狠婷婷| 亚洲国产成人av好男人在线观看| 999亚洲国产精| 欧美视频一区二区三区…| 亚洲欧美日韩一区| 欧美大片一区| 亚洲无人区一区| 国产女人精品视频| 久久综合狠狠综合久久综青草| 亚洲成色最大综合在线| 一区二区av| 国产模特精品视频久久久久 | 欧美高清视频在线| 日韩一级精品| 久久久久久久一区| 最新国产成人在线观看| 欧美视频一区二区| 久久久久久国产精品一区| 亚洲欧洲精品天堂一级 | 欧美在线视频网站| 欧美激情在线| 亚洲欧美在线免费观看| 在线看欧美日韩| 国产精品magnet| 久久精品五月婷婷| 夜夜嗨av一区二区三区四区| 久久久无码精品亚洲日韩按摩| 日韩一级片网址| 国产日产欧美精品| 欧美精品在欧美一区二区少妇| 亚洲女同在线| 亚洲欧洲久久| 毛片精品免费在线观看| 中文在线资源观看网站视频免费不卡 | 亚洲桃色在线一区| 亚洲电影免费观看高清完整版| 亚洲欧美日韩中文在线制服| 尤妮丝一区二区裸体视频| 欧美色偷偷大香| 米奇777在线欧美播放| 午夜在线精品偷拍| 亚洲精品久久久久久久久| 久久精品国产久精国产爱| 亚洲深夜福利在线| 91久久精品网| 在线播放日韩专区| 国产一区亚洲| 国产日韩一区二区三区在线| 欧美日韩一级黄| 欧美高清视频www夜色资源网| 久久精品国产一区二区三| 亚洲综合欧美日韩| 亚洲无线一线二线三线区别av| 亚洲欧洲日产国码二区| 欧美高清在线视频观看不卡| 久久久久久久久久看片| 亚洲一区三区视频在线观看| 亚洲乱亚洲高清| 亚洲欧洲一区二区在线播放| 影音先锋另类| 狠狠色狠狠色综合人人| 国产亚洲精久久久久久| 国产精品日韩在线观看| 国产精品拍天天在线| 国产精品福利av| 国产精品成人一区二区三区夜夜夜 | 午夜免费在线观看精品视频| 99re热这里只有精品视频| 亚洲国产91色在线| 亚洲丁香婷深爱综合| 亚洲国产成人午夜在线一区| 欧美大片一区二区三区| 免费成人在线观看视频| 欧美国产亚洲另类动漫| 亚洲成色www久久网站| 亚洲高清久久| 亚洲国产高清一区| 亚洲精选久久| 亚洲一区二区三区精品在线| 亚洲一区二区三区四区五区黄| 中文网丁香综合网| 亚洲影院免费观看| 欧美一区二视频| 久久国内精品自在自线400部| 久久久久久久综合日本| 老司机免费视频久久| 美女主播一区| 欧美日韩免费在线| 国产精品久久福利| 国产日韩欧美在线观看| 一区二区三区亚洲| 亚洲精品视频二区| 亚洲综合电影| 久久野战av| 亚洲精品一区二区在线观看| 亚洲一区国产视频|