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

Shuffy

不斷的學(xué)習(xí),不斷的思考,才能不斷的進步.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 閱讀(212) 評論(0)  編輯 收藏 引用 所屬分類: MFC,OpenGL
     本文在8篇文章的基礎(chǔ)上,為其加入燈光效果。

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,設(shè)置燈光和材質(zhì)屬性

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時調(diào)用上述函數(shù)

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/    

本文版權(quán)歸作者和博客園共有,歡迎轉(zhuǎn)載,但未經(jīng)作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,否則保留追究法律責(zé)任的權(quán)利。
原文鏈接: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>
            亚洲欧美日韩成人高清在线一区| 亚洲国产一区二区视频| 久久久精品999| 亚洲日本va午夜在线电影| 亚洲开发第一视频在线播放| 欧美电影在线播放| 午夜精品成人在线视频| 久久久久久有精品国产| 一本久久a久久精品亚洲| 亚洲美女一区| 狠狠色香婷婷久久亚洲精品| 亚洲黄色在线观看| 欧美久久久久免费| 欧美影院视频| 欧美高清一区| 久久视频在线免费观看| 欧美性猛交xxxx乱大交退制版| 麻豆国产va免费精品高清在线| 欧美日本韩国在线| 久久夜色精品一区| 国产精品外国| 91久久精品国产91性色| 国内精品久久久久影院优| 一区二区精品| 欧美影视一区| 午夜精品久久久久久久99水蜜桃 | 欧美一区二区三区精品| 麻豆亚洲精品| 久久久精品2019中文字幕神马| 蜜桃av久久久亚洲精品| 久久日韩精品| 国产片一区二区| 夜夜嗨av一区二区三区四区| 亚洲国产精品久久人人爱蜜臀| 亚洲看片网站| 亚洲人成网站999久久久综合| 欧美在线你懂的| 亚洲欧美激情视频| 欧美日韩亚洲一区二区三区四区| 亚洲高清视频的网址| 国产午夜一区二区三区| 亚洲欧美精品在线观看| 性欧美video另类hd性玩具| 欧美日韩一级大片网址| 亚洲欧洲日产国产综合网| 亚洲国产日韩欧美综合久久| 久久国产精品99精品国产| 国产精品初高中精品久久| 亚洲第一天堂av| 亚洲国产精品一区二区www| 久久精品国产2020观看福利| 久久久久久久久岛国免费| 国产精品一区久久| 亚洲男人第一网站| 久久国产黑丝| 娇妻被交换粗又大又硬视频欧美| 久久久久国产精品一区三寸 | 久久亚洲高清| 影音先锋成人资源站| 欧美黄色影院| 午夜久久资源| 亚洲激情在线观看视频免费| 欧美日韩国产探花| 亚洲欧美日韩精品久久久久| 欧美顶级艳妇交换群宴| 亚洲一区亚洲| 在线国产欧美| 国产精品视频福利| 理论片一区二区在线| 国产精品99久久久久久宅男| 久久久天天操| 亚洲视频免费观看| 激情视频一区| 欧美性天天影院| 久久免费国产精品| 亚洲小说欧美另类社区| 欧美国产一区二区三区激情无套| 欧美午夜在线一二页| 久久久91精品国产一区二区精品| 亚洲精品久久在线| 久久久免费精品| 亚洲综合首页| 亚洲精品午夜| 国产亚洲欧美一区在线观看| 欧美伦理91| 久久人人97超碰国产公开结果| 亚洲网站视频| 亚洲精品视频一区二区三区| 久久欧美中文字幕| 欧美亚洲视频在线观看| 日韩一级成人av| 黑人一区二区三区四区五区| 国产精品久久二区| 欧美人与禽性xxxxx杂性| 毛片精品免费在线观看| 性欧美videos另类喷潮| 一区二区精品在线| 91久久嫩草影院一区二区| 国产精品一区二区在线| 欧美日韩中国免费专区在线看| 久久av资源网站| 欧美一级一区| 午夜在线精品| 亚洲欧美一级二级三级| aaa亚洲精品一二三区| 欧美不卡在线视频| 久久婷婷国产综合国色天香| 久久精品免费电影| 久久疯狂做爰流白浆xx| 香蕉久久a毛片| 性色一区二区| 国产欧美综合在线| 国产欧美日韩视频| 国产欧美日韩在线观看| 国产精品一级| 国产免费成人av| 国产女人18毛片水18精品| 国产精品久久久久久久久久久久久久| 欧美精品一区二区三区蜜臀| 欧美精品1区2区| 欧美区一区二区三区| 欧美日本免费| 欧美视频一区| 国产亚洲福利社区一区| 国产亚洲欧美一级| 在线日韩中文字幕| 亚洲国产精品一区二区第四页av| 亚洲国产你懂的| 亚洲精品午夜精品| 亚洲午夜精品久久久久久app| 欧美国产先锋| 欧美亚男人的天堂| 国产精品一区二区在线观看不卡 | 亚洲国产三级网| 亚洲三级免费观看| 一区二区动漫| 欧美专区日韩视频| 免费成人高清| 99精品国产热久久91蜜凸| 在线视频欧美一区| 亚洲欧美在线高清| 久久久久久久综合色一本| 欧美成人亚洲| 国产精品护士白丝一区av| 国产日韩欧美精品在线| 在线精品福利| 亚洲在线观看视频网站| 国产揄拍国内精品对白| 91久久精品美女| 亚洲淫性视频| 免费一级欧美片在线播放| 99亚洲伊人久久精品影院红桃| 亚洲一区二区三区中文字幕| 久久另类ts人妖一区二区| 欧美极品影院| 国产午夜精品理论片a级大结局| 亚洲国产成人不卡| 亚洲欧美国产高清| 欧美成人精品激情在线观看| 正在播放亚洲一区| 久久久成人网| 国产精品极品美女粉嫩高清在线| 极品裸体白嫩激情啪啪国产精品| 亚洲免费不卡| 久久久噜噜噜久久| 中文一区二区在线观看| 麻豆成人av| 国产精品视频一区二区三区| 亚洲韩日在线| 久久人人精品| 亚洲欧美亚洲| 欧美视频国产精品| 亚洲靠逼com| 久久一本综合频道| 亚洲视频在线免费观看| 欧美r片在线| 黄色一区二区三区| 欧美一级久久| 一本色道**综合亚洲精品蜜桃冫 | 这里只有精品视频| 免播放器亚洲一区| 国产一区二区三区的电影| 亚洲一级片在线看| 亚洲国产小视频在线观看| 欧美在线短视频| 国产精品乱子久久久久| 在线亚洲激情| 91久久国产综合久久91精品网站| 性伦欧美刺激片在线观看| 国产精品成人免费视频| 日韩一级黄色大片| 欧美激情1区2区| 久久综合亚洲社区| 精品91视频| 久久亚洲欧美| 久久精品一二三区| 韩日在线一区| 农村妇女精品| 久久av一区二区| 久久av在线|