﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-逛奔的蜗牛-随笔分类-OpenGL</title><link>http://www.cppblog.com/biao/category/9975.html</link><description> 我不聪明，但我会很努力</description><language>zh-cn</language><lastBuildDate>Thu, 18 Apr 2013 17:23:05 GMT</lastBuildDate><pubDate>Thu, 18 Apr 2013 17:23:05 GMT</pubDate><ttl>60</ttl><item><title>OpenGL：展示OpenGL特性的软件Tutors</title><link>http://www.cppblog.com/biao/archive/2013/04/19/199557.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Thu, 18 Apr 2013 16:24:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2013/04/19/199557.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/199557.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2013/04/19/199557.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/199557.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/199557.html</trackback:ping><description><![CDATA[<table width="600" border="0" cellspacing="0" cellpadding="0" style="font-family: 'arial narrow', helvetica; background-color: #ffffff; ">
    <tbody>
        <tr>
            <td><img src="http://user.xmission.com/~nate/pics/naterobins.jpg" alt="nate robins" width="600" height="80" border="0" vspace="0" hspace="0" /></td>
        </tr>
    </tbody>
</table>
<table width="600" border="0" cellspacing="0" cellpadding="0" style="font-family: 'arial narrow', helvetica; background-color: #ffffff; ">
    <tbody>
        <tr>
            <td><img src="http://user.xmission.com/~nate/pics/menu-left.jpg" alt="" width="20" height="30" border="0" vspace="0" hspace="0" /></td>
            <td><a href="http://user.xmission.com/~nate/index.html"><img src="http://user.xmission.com/~nate/pics/main-dim.jpg" alt="main" width="80" height="30" border="0" vspace="0" hspace="0" /></a></td>
            <td><a href="http://user.xmission.com/~nate/opengl.html"><img src="http://user.xmission.com/~nate/pics/opengl-lit.jpg" alt="OPENGL" width="145" height="30" border="0" vspace="0" hspace="0" /></a></td>
            <td><a href="http://user.xmission.com/~nate/chronicles.html"><img src="http://user.xmission.com/~nate/pics/chronicles-dim.jpg" alt="chronicles" width="215" height="30" border="0" vspace="0" hspace="0" /></a></td>
            <td><a href="http://user.xmission.com/~nate/allies.html"><img src="http://user.xmission.com/~nate/pics/allies-dim.jpg" alt="allies" width="120" height="30" border="0" vspace="0" hspace="0" /></a></td>
            <td><img src="http://user.xmission.com/~nate/pics/menu-right.jpg" alt="" width="20" height="30" border="0" vspace="0" hspace="0" /></td>
        </tr>
    </tbody>
</table>
<table width="600" border="0" cellspacing="0" cellpadding="0" style="font-family: 'arial narrow', helvetica; background-color: #ffffff; ">
    <tbody>
        <tr>
            <td><img src="http://user.xmission.com/~nate/pics/up-left.jpg" alt="---" width="300" height="50" border="0" vspace="0" hspace="0" /></td>
            <td align="center" valign="bottom" width="200"><em>Tutors</em></td>
            <td><img src="http://user.xmission.com/~nate/pics/up-right.jpg" alt="---" width="100" height="50" border="0" vspace="0" hspace="0" /></td>
        </tr>
    </tbody>
</table>
<br style="font-family: 'arial narrow', helvetica; font-size: medium; line-height: normal; text-align: " />
<table width="550" border="0" cellpadding="0" cellspacing="20" style="font-family: 'arial narrow', helvetica; background-color: #ffffff; ">
    <tbody>
        <tr>
            <td align="center"><a href="http://user.xmission.com/~nate/tutors/tutors-src.zip">Tutors source code package (tutors-src.zip 920KB)</a>&nbsp;<br />
            <br />
            <a href="http://user.xmission.com/~nate/tutors/tutors-win32.zip">Source package + Windows executables (tutors-win32.zip 1.24MB)</a>&nbsp;<br />
            <br />
            <a href="http://user.xmission.com/~nate/tutors/tutors-macosx.zip">Source package + Mac OS X universal binaries (tutors-macosx.zip 1.2MB)</a>&nbsp;<br />
            <br />
            <a href="http://user.xmission.com/~nate/tutors-contrib.html">Contributions</a>&nbsp;from various people (Unix makefiles, etc).&nbsp;<br />
            <br />
            </td>
        </tr>
        <tr>
            <td>
            <table align="right" border="0" cellspacing="0" cellpadding="0">
                <tbody>
                    <tr>
                        <td><a href="http://user.xmission.com/~nate/tutors/fog.png"><img src="http://user.xmission.com/~nate/tutors/fog-.png" alt="fog" width="225" height="225" border="1" vspace="0" hspace="5" align="right" /></a></td>
                    </tr>
                    <tr>
                        <td><center><font size="1">(click on image to enlarge it)</font></center></td>
                    </tr>
                </tbody>
            </table>
            The fog tutorial program (shown at right) demonstrates how to use depth cueing (or fog) in OpenGL. It includes command panels that allow dynamic update of the parameters for linear, exponential and exponential<sup>2</sup>&nbsp;fog functions. The fog color can also be dynamically changed.</td>
        </tr>
        <tr>
            <td>
            <table align="left" border="0" cellspacing="0" cellpadding="0">
                <tbody>
                    <tr>
                        <td><a href="http://user.xmission.com/~nate/tutors/lightposition.png"><img src="http://user.xmission.com/~nate/tutors/lightposition-.png" alt="lightposition" width="225" height="225" border="1" vspace="0" hspace="5" /></a></td>
                    </tr>
                    <tr>
                        <td><center><font size="1">(click on image to enlarge it)</font></center></td>
                    </tr>
                </tbody>
            </table>
            The lightposition tutorial program (shown at left) demonstrates how lighting position is effected by the viewing transformation. The order in which the light position and the viewing transform are established is configurable, as are the parameters for the position and transform.</td>
        </tr>
        <tr>
            <td>
            <table align="center" border="0" cellspacing="0" cellpadding="0">
                <tbody>
                    <tr>
                        <td><a href="http://user.xmission.com/~nate/tutors/lightmaterial.png"><img src="http://user.xmission.com/~nate/tutors/lightmaterial-.png" alt="lightmaterial" width="475" height="317" border="1" vspace="0" hspace="5" /></a></td>
                    </tr>
                    <tr>
                        <td><center><font size="1">(click on image to enlarge it)</font></center></td>
                    </tr>
                </tbody>
            </table>
            <br />
            The lightmaterial tutorial program (shown above) demonstrates how OpenGL lighting and material properties interact and effect each other. All material &amp; light properties are tweakable. A second command panel allows spotlight parameters &amp; attenuation factors to be changed.</td>
        </tr>
        <tr>
            <td>
            <table align="right" border="0" cellspacing="0" cellpadding="0">
                <tbody>
                    <tr>
                        <td><a href="http://user.xmission.com/~nate/tutors/projection.png"><img src="http://user.xmission.com/~nate/tutors/projection-.png" alt="projection" width="225" height="225" border="1" vspace="0" hspace="5" /></a></td>
                    </tr>
                    <tr>
                        <td><center><font size="1">(click on image to enlarge it)</font></center></td>
                    </tr>
                </tbody>
            </table>
            The projection tutorial program (shown at right) demonstrates how the many types of projection transformations work. A command panel is included for gluPerspective(), glOrtho() and glFrustum(). In addition, the viewing transform can be modified via the gluLookat() function.</td>
        </tr>
        <tr>
            <td>
            <table align="left" border="0" cellspacing="0" cellpadding="0">
                <tbody>
                    <tr>
                        <td><a href="http://user.xmission.com/~nate/tutors/transformation.png"><img src="http://user.xmission.com/~nate/tutors/transformation-.png" alt="transformation" width="225" height="225" border="1" vspace="0" hspace="5" align="left" /></a></td>
                    </tr>
                    <tr>
                        <td><center><font size="1">(click on image to enlarge it)</font></center></td>
                    </tr>
                </tbody>
            </table>
            The transformation tutorial program (shown at left) demonstrates how the basic transformations of rotate, translate and scale operate in OpenGL. The order of the transforms can be changed to see how that effects rendering.</td>
        </tr>
        <tr>
            <td>
            <table align="center" border="0" cellspacing="0" cellpadding="0">
                <tbody>
                    <tr>
                        <td><a href="http://user.xmission.com/~nate/tutors/texture.png"><img src="http://user.xmission.com/~nate/tutors/texture-.png" alt="texture" width="475" height="317" border="1" vspace="0" hspace="5" /></a></td>
                    </tr>
                    <tr>
                        <td><center><font size="1">(click on image to enlarge it)</font></center></td>
                    </tr>
                </tbody>
            </table>
            <br />
            The texture tutorial program (shown above) demonstrates how OpenGL texturing works. Specifically, the texture coordinates for a polygon are provided for manipulation as are the polygons coordinates themselves. The texture parameter &amp; environment attributes are tweakable. A separate command panel allows manipulation of the texture matrix.</td>
        </tr>
        <tr>
            <td>
            <table align="right" border="0" cellspacing="0" cellpadding="0">
                <tbody>
                    <tr>
                        <td><a href="http://user.xmission.com/~nate/tutors/shapes.png"><img src="http://user.xmission.com/~nate/tutors/shapes-.png" alt="shapes" width="263" height="225" border="1" vspace="0" hspace="5" align="right" /></a></td>
                    </tr>
                    <tr>
                        <td><center><font size="1">(click on image to enlarge it)</font></center></td>
                    </tr>
                </tbody>
            </table>
            The shapes tutorial program (shown at right) demonstrates how the many types of primitives work. A command panel for each primitive type is included. This tutorial was written by Mason Woo (<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#109;&#97;&#115;&#111;&#110;&#64;&#119;&#111;&#111;&#46;&#99;&#111;&#109;">mason@woo.com</a>).</td>
        </tr>
    </tbody>
</table>
<br style="font-family: 'arial narrow', helvetica; font-size: medium; line-height: normal; text-align: " />
<br style="font-family: 'arial narrow', helvetica; font-size: medium; line-height: normal; text-align: " />
<table width="600" border="0" cellspacing="0" cellpadding="0" style="font-family: 'arial narrow', helvetica; background-color: #ffffff; ">
    <tbody>
        <tr>
            <td align="center"><a href="http://www.digits.com/web_counter"><img src="http://counter.digits.com/wc/-d/8/-r/-z/-c/26/-f/aaaaaa/-b/ffffff/opengl_tutors" border="0"  alt="" /></a></td>
        </tr>
    </tbody>
</table>
<br style="font-family: 'arial narrow', helvetica; font-size: medium; line-height: normal; text-align: " />
<table width="600" border="0" cellspacing="0" cellpadding="0" style="font-family: 'arial narrow', helvetica; background-color: #ffffff; ">
    <tbody>
        <tr>
            <td><img src="http://user.xmission.com/~nate/pics/dn-left.jpg" alt="---" width="100" height="50" border="0" vspace="0" hspace="0" /></td>
            <td><img src="http://user.xmission.com/~nate/pics/dn-middle.jpg" alt="---" width="200" height="50" border="0" vspace="0" hspace="0" /></td>
            <td><img src="http://user.xmission.com/~nate/pics/dn-right.jpg" alt="---" width="300" height="50" border="0" vspace="0" hspace="0" /><br />
            <br />
            </td>
        </tr>
    </tbody>
</table>
@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);<img src ="http://www.cppblog.com/biao/aggbug/199557.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2013-04-19 00:24 <a href="http://www.cppblog.com/biao/archive/2013/04/19/199557.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java：强大的Eclipse</title><link>http://www.cppblog.com/biao/archive/2010/12/17/136784.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Fri, 17 Dec 2010 10:09:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2010/12/17/136784.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/136784.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2010/12/17/136784.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/136784.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/136784.html</trackback:ping><description><![CDATA[<span  style="line-height: 15px; color: rgb(0, 134, 198); font-family: 'BBAlpha Sans', 'Prelude Medium', 'S60 Sans', Tahoma, Verdana, Arial, sans-serif; font-size: 12px; "><div style="line-height: 15px; ">在Eclipse中写OpenGL, Qt, C, C++, Java, links方式安装插件，导入工程：</div><div style="line-height: 15px; "><font color="#00ff00" style="line-height: normal; ">Java:</font>&nbsp;Eclipse要运行在jre的环境之上，自带Java环境</div><div style="line-height: 15px; "><font color="#00ff00" style="line-height: normal; ">C, C++:&nbsp;&nbsp;</font>下载CDT，不同版本的CDT与不同版本的Eclipse匹配，因为他们的更新很快</div><div style="line-height: 15px; ">&nbsp;</div><div style="line-height: 15px; ">安装CDT和Eclipse时，并没有C/C++编译器，得自己下一个，对于windows有两个比较好:Cygwin和MinGW，都是使用Linux下的GCC windows移植版，对标准支持非常好，不像windows自己的，搞得乱七八糟，不过最好是安装MinGW，因为大多数都是支持MinGW，而且Qt的windows安装版本就只支持MinGW，如果要用Cygwin的话，那得自己编译Qt的源码。安装MinGW的一个更好的方式，使用免费开源的Dev-Cpp，其中就自带了MinGW，更好的一点是，可以用他的包管理器到网络上下载需要的程序库，非常方便，他还支持OpenGL，如想用glut库，他也可以在网上自动找到，Qt的安装版中已经支持了OpenGL，所以对于C/C++:</div><div style="line-height: 15px; ">Dev-Cpp + CDT + Eclipse = 搞定.</div><div style="line-height: 15px; ">&nbsp;</div><div style="line-height: 15px; "><font color="#00ff00" style="line-height: normal; ">OpenGL + glut:</font>&nbsp;用Dev-Cpp下载glut库，然后在Eclipse的工程的库中引入外部库：</div><div style="line-height: 15px; ">opengl32, glu32, glut32, gdi32, winmm = 搞定</div><div style="line-height: 15px; ">&nbsp;</div><div style="line-height: 15px; "><font color="#00ff00" style="line-height: normal; ">links方式安装插件：</font>在Eclipse的目录下建一个links文件夹，在里面任意建文件xxxx.link，在xxxx.link里写上插件所在目录：</div><div style="line-height: 15px; ">path=D:/Software/Eclipse-SDK-3.3M6-win32/CDT-4.0.0-M7-win32.x86，这里必须注意，其中的文件分隔符用的是linux的文件分隔符/，而不是windows的文件分隔符\，写错了插件就显示不出来...开始的时候用\，晕ing，插件没显示出来，还好不傻，试了一下/，嘿嘿，出来了。</div><div style="line-height: 15px; ">&nbsp;</div><div style="line-height: 15px; "><font color="#00ff00" style="line-height: normal; ">Qt:&nbsp;</font>先装CDT，然后下载Qt Eclipse Integration安装，直接搞定。对于新加入的.h, .cpp文件，.pro文件会自动更新。</div><div style="line-height: 15px; ">Download:&nbsp;<a href="http://trolltech.com/developer/downloads/qt/index?searchterm=eclipse+integration" style="line-height: 15px; font-weight: inherit; text-decoration: none; color: rgb(0, 102, 167); cursor: pointer; ">http://trolltech.com/developer/downloads/qt/index?searchterm=eclipse+integration</a></div><div style="line-height: 15px; ">&nbsp;</div><div style="line-height: 15px; "><font color="#00ff00" style="line-height: normal; ">完整安装顺序：</font></div><div style="line-height: 15px; "><font color="#00ff00" style="line-height: normal; ">JDK + Eclipse + Dev-Cpp(MinGW...package tool + glut / boost==) + CDT(links安装) + Qt4.3 + Qt Eclipse Integration</font></div></span>
<img src ="http://www.cppblog.com/biao/aggbug/136784.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2010-12-17 18:09 <a href="http://www.cppblog.com/biao/archive/2010/12/17/136784.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>OpenGL：图像取样量化插值距离算子</title><link>http://www.cppblog.com/biao/archive/2010/12/17/136779.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Fri, 17 Dec 2010 10:05:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2010/12/17/136779.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/136779.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2010/12/17/136779.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/136779.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/136779.html</trackback:ping><description><![CDATA[<span style="line-height: 15px; color: rgb(0, 134, 198); font-family: 'BBAlpha Sans', 'Prelude Medium', 'S60 Sans', Tahoma, Verdana, Arial, sans-serif; font-size: 12px; "><div style="line-height: 15px; ">计算机内是离散的处理数字</div><div style="line-height: 15px; ">&nbsp;</div><div style="line-height: 15px; ">把连续图像（如人眼看到的图像就是连续的）转化为数字图像：数字图像可用二维数组存放，也即把图像光栅化了。</div><div style="line-height: 15px; ">图像的<font color="#00ff00" style="line-height: normal; ">坐标(x, y)，</font>图像的<font color="#00ff00" style="line-height: normal; ">强度，幅度或灰度</font>&nbsp;<font color="#00ff00" style="line-height: normal; ">f(x, y)。</font></div><div style="line-height: 15px; ">图像的坐标和幅度可能是连续的，数字化坐标称为取样，数字化幅度称为量化(离散的灰度值,如RGB&nbsp;<font color="#00ff00" style="line-height: normal; ">255 &lt;&lt; 16 + 255 &lt;&lt; 8 + 255</font>种)。</div><div style="line-height: 15px; ">一行沿水平方向从左到右对图像等间隔对图像取样，得到幅度的值，可画出一维曲线函数图，幅度值的随机变化是由图像噪声引起的。</div><div style="line-height: 15px; ">一行一行的从上到下对图像取样，量化，最后得到存储在二维数组里的数字图像。取样和量化的结果是一个实际的矩阵。也即为什么图像</div><div style="line-height: 15px; ">都是方形的。</div><div style="line-height: 15px; ">&nbsp;</div><div style="line-height: 15px; ">数字图像的质量很大程度上取决于取样和量化中所使用的取样数和灰度级。</div><div style="line-height: 15px; ">1. 简单的图像抽样（灰度级保持不变），从原图像中<font color="#00ff00" style="line-height: normal; ">删去一样的行和列</font>1024*1024 -&gt; 512*512 -&gt; 256*256 -&gt; 64*64 -&gt; 32*32,从大到小，很难看出抽样带来的影响。但如果把抽样后的图像<font color="#00ff00" style="line-height: normal; ">复制行和列</font>恢复到1024*1024大小后，就看出影响来了，出现小方块，图像不自然。这也是nearst的filter。</div><div style="line-height: 15px; ">2. 取样数恒定，但灰度值以2的幂次数降低。</div><div style="line-height: 15px; ">&nbsp;</div><div style="line-height: 15px; ">取样和量化是针对连续图像。</div><div style="line-height: 15px; ">放大和缩小可用于数字图像。</div><div style="line-height: 15px; ">简单的放大和缩小：500&#215;500 -&gt; 750*750</div><div style="line-height: 15px; ">在原始图像上虚构一个750*750的栅格，显然栅格的间隔小于1个像素。为了对覆盖层上的任何点进行灰度赋值，在原始图像上<font color="#00ff00" style="line-height: normal; ">寻找最靠</font><font color="#00ff00" style="line-height: normal; ">近</font></div><div style="line-height: 15px; "><font color="#00ff00" style="line-height: normal; ">的像素</font>并把它的灰度值赋给栅格上的像素：<font color="#00ff00" style="line-height: normal; ">称为最邻近域内插法</font>。</div><div style="line-height: 15px; ">寻找最邻近域：</div><div style="line-height: 15px; ">array[y][x];</div><div style="line-height: 15px; ">if (((float)x / 1.5 - 0.5)&nbsp;&lt; 0.0)</div><div style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return floor((float)x / 1.5);</div><div style="line-height: 15px; ">else&nbsp;&nbsp; return ceil((float)x / 1.5);</div><div style="line-height: 15px; ">整数倍扩大与缩小时可以使用像素复制法与删除法。</div><div style="line-height: 15px; ">优点：速度快</div><div style="line-height: 15px; ">缺点：马塞克，特别是放大时</div><div style="line-height: 15px; ">&nbsp;</div><div style="line-height: 15px; ">稍微改进一点的方法：<font color="#00ff00" style="line-height: normal; ">采用4个最邻近点的双线性内插：还可以采用更多邻近点的插值（更平滑）</font></div><div style="line-height: 15px; ">v(x', y') = ax' + by' + cx'y' + d;</div><div style="line-height: 15px; ">4个系数由点(x', y')的4个最邻近点写出的4个未知方程决定。</div><div style="line-height: 15px; ">垂直和水平的4个邻近点：(x-1, y), (x+1, y), (x, y-1), (x, y+1)</div><div style="line-height: 15px; ">对于通常数字图像的放大和收缩，双线性内插法首选，效果不错，计算量不大。</div><div style="line-height: 15px; ">&nbsp;</div><div style="line-height: 15px; ">两个像素的连通性：它们是否相邻，这们的灰度值是否满足特定的相似性准则（比如相等，相差不大）。</div><div style="line-height: 15px; ">&nbsp;</div><div style="line-height: 15px; "><font color="#00ff00" style="line-height: normal; ">距离度量：p(x, y), q(s, t)</font></div><div style="line-height: 15px; "><font color="#00ff00" style="line-height: normal; ">1. 欧氏距离：</font>D(p, q) = squrt((x-s)*(x-s) + (y-t)*(y-t)); 以(x, y)为圆心r为半径的圆平面</div><div style="line-height: 15px; "><font color="#00ff00" style="line-height: normal; ">2. 城市街区距离：</font>D(p, q) = |x-s| + |y-t|; 以(x, y)为中心的菱形 D == 1（4邻域）</div><div style="line-height: 15px; "><font color="#00ff00" style="line-height: normal; ">3. 棋盘距离：</font>D(p, q) = max(|x-s|, |y-t|); 以(x, y)为中心的方形 D == 1（8邻域）</div><div style="line-height: 15px; ">&nbsp;</div><div style="line-height: 15px; "><font color="#00ff00" style="line-height: normal; ">线性与非线性操作：</font></div><div style="line-height: 15px; ">两幅图像f和g与级两个标题a和b关系如下 ，则H称为线性算子：</div><div style="line-height: 15px; ">H(a*f + b*g) = a*H(f) + b*H(g)</div><div style="line-height: 15px; ">线性算子在图像处理中非常重要，是充分了解理解和实践的主要基础。</div><div style="line-height: 15px; ">对K幅图像的求和是一个线性算子，计算两幅图像的差分绝对值的算不是线性算子。</div></span>
<img src="http://www.cppblog.com/images/cppblog_com/biao/interpolation-1.jpg" id="" vspace="0" hspace="0" border="" align="baseline" alt="" longdesc=""><img src="http://www.cppblog.com/images/cppblog_com/biao/interpolation-2.jpg" id="" vspace="0" hspace="0" border="" align="baseline" alt="" longdesc=""><img src="http://www.cppblog.com/images/cppblog_com/biao/interpolation-3.jpg" id="" vspace="0" hspace="0" border="" align="baseline" alt="" longdesc=""><img src ="http://www.cppblog.com/biao/aggbug/136779.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2010-12-17 18:05 <a href="http://www.cppblog.com/biao/archive/2010/12/17/136779.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>OpenGL：数字图像的直方图</title><link>http://www.cppblog.com/biao/archive/2010/12/17/136776.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Fri, 17 Dec 2010 09:55:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2010/12/17/136776.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/136776.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2010/12/17/136776.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/136776.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/136776.html</trackback:ping><description><![CDATA[<span style="line-height: 15px; color: rgb(0, 134, 198); font-family: 'BBAlpha Sans', 'Prelude Medium', 'S60 Sans', Tahoma, Verdana, Arial, sans-serif; font-size: 12px; "><div style="line-height: 15px; ">灰度级为[0, L-1]范围内的<font color="#00ff00" style="line-height: normal; ">数字图像的直方图</font>是一个离散函数h(rk) = nk，rk是第k级灰度，nk是灰度级为rk的像素个数(k = 0, 1, ..., L-1)。</div><div style="line-height: 15px; ">归一化的直方图：P(rk) = nk / n，n为图像中像素点的总数。</div><div style="line-height: 15px; ">简单的说，P(rk)给出了灰度级为rk的发生的概率估计值，提供图像统计资料。<font color="#00ff00" style="line-height: normal; ">归一化的直方图</font>的所有部分之和应为1。</div><div style="line-height: 15px; ">直方图是多种空间域处理技术的基础，直方图能有效的利用于图像增强，压缩与分割。</div><div style="line-height: 15px; ">&nbsp;</div><div style="line-height: 15px; ">若一幅图像像素占有全部可能的灰度级，并且分部均匀，这样的图像具有高对比级和多变的灰度色调。</div><div style="line-height: 15px; ">可以快速的开发出一种函数，该函数仅仅依靠输入图像的直方图信息，实现灰度级丰富且动态范围大的图像。</div><div style="line-height: 15px; ">&nbsp;</div><div style="line-height: 15px; ">以下图像是在直方图在图像增强中的介绍，四个基本灰度级特征（暗，亮，低对比度，高对比度）做出的花粉图像。</div><div style="line-height: 15px; ">暗色图像中，直方图的组成成分集中在灰度级低的一侧，亮的直方图倾向于灰度级高的一侧，低对比度的直方图集中于灰度级的中部，</div><div style="line-height: 15px; ">高对比度的直方图覆盖了灰度级很宽的范围，且像素的分部没有太不均匀，只有少量的曲线比其他的高许多。</div></span>
<img src="http://www.cppblog.com/images/cppblog_com/biao/histogram.jpg" id="" vspace="0" hspace="0" border="" align="baseline" alt="" longdesc=""><img src ="http://www.cppblog.com/biao/aggbug/136776.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2010-12-17 17:55 <a href="http://www.cppblog.com/biao/archive/2010/12/17/136776.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>OpenGL：MipMap</title><link>http://www.cppblog.com/biao/archive/2010/12/17/136765.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Fri, 17 Dec 2010 09:45:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2010/12/17/136765.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/136765.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2010/12/17/136765.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/136765.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/136765.html</trackback:ping><description><![CDATA[<span  style="line-height: 15px; color: rgb(0, 134, 198); font-family: 'BBAlpha Sans', 'Prelude Medium', 'S60 Sans', Tahoma, Verdana, Arial, sans-serif; font-size: 12px; "><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">imageData = readImage();</font></div><div style="line-height: 15px; ">&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">glEnable(GL_TEXTURE_2D);</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">glGenTextures(1, &amp;texture[0]);</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">glBindTexture(GL_TEXTURE_2D, texture[0]);</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);<br style="line-height: 15px; ">glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);<br style="line-height: 15px; ">glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, g_envMode);</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "><font color="#00ff00" style="line-height: normal; ">// GL_DECAL, GL_BLEND , GL_MODULATE</font></font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "><font color="#00ff00" style="line-height: normal; ">decal是直接画上去覆盖原来的颜色值</font></font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "><font color="#00ff00" style="line-height: normal; ">blend为 r = src.r * (1-alpha) + dis.r * alpha</font></font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "><font color="#00ff00" style="line-height: normal; ">modulate为 r = src.r * dis.r</font><br style="line-height: 15px; ">gluBuild2DMipmaps(GL_TEXTURE_2D, 3, 512, 512, GL_RGB, GL_FLOAT, imageData);</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "><br style="line-height: 15px; ">delete[](imageData);<br style="line-height: 15px; ">imageData = NULL;</font></div></span>
<img src ="http://www.cppblog.com/biao/aggbug/136765.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2010-12-17 17:45 <a href="http://www.cppblog.com/biao/archive/2010/12/17/136765.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>OpenGL：飘动的旗帜</title><link>http://www.cppblog.com/biao/archive/2010/12/17/136764.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Fri, 17 Dec 2010 09:45:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2010/12/17/136764.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/136764.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2010/12/17/136764.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/136764.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/136764.html</trackback:ping><description><![CDATA[
一、<div><span style="line-height: 15px; color: rgb(0, 134, 198); font-family: 'BBAlpha Sans', 'Prelude Medium', 'S60 Sans', Tahoma, Verdana, Arial, sans-serif; font-size: 12px; "><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">在写风吹旗帜效果的时候，注意的是上一个点与下一个点的如Ｚ坐标的关系，下一个点的Ｚ坐标是上一个点的此时的Ｚ坐标，其实就是按波的传递性来计算，Ｚ坐标可以按任何曲线的函数来计算，如sin, cos,这只是最基本的思想，要做得真实，就看算法的了，但动态实现就是用坐标传递。</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "><strong style="line-height: 15px; font-weight: bold; ">如把旗帜分成４4行，４4列，只计算Ｚ坐标的传递，不考试Ｘ与Ｙ，</strong></font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "><strong style="line-height: 15px; font-weight: bold; ">那么，一共有45 * 45个点，每个点三个坐标值</strong></font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const float PI = 3.1415;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const int row = 44;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#00ff00" style="line-height: normal; ">//要分成的行数</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const int column = 44;&nbsp;&nbsp;&nbsp;</font><font color="#00ff00" style="line-height: normal; ">// 要分成的列数</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const float length = 9;&nbsp;&nbsp;</font><font color="#00ff00" style="line-height: normal; ">//旗帜的长度</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const disx = length / (float)column;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const disy = length / (float)row;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; float coord[row][column][3];</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#00ff00" style="line-height: normal; ">// 按行逐行计算坐标值</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int i＝0; i &lt; row; i++) {</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; float y = i * disy - length / 2.0;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int j=0; j &lt; column; j++) {</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; coord[i][j][0] = j * disx - length / 2.0;&nbsp;</font><font color="#00ff00" style="line-height: normal; ">//是为了保证旗帜处于正中间</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; coord[i][j][1] = y;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; coord[i][j][2] = sin((float)j / (float)colum *&nbsp;2.0 * PI);</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 注意除法时要不要把两个数都是整数</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "><strong style="line-height: 15px; font-weight: bold; ">传递Ｚ坐标</strong></font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int i＝0; i &lt; row; i++) {</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; float hold = coord[i][0][2];&nbsp;</font><font color="#00ff00" style="line-height: normal; ">//保存第一个点的Ｚ坐标，最后一个点要使用</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int j=0; j &lt; column-1; j++) {</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dba04f" style="line-height: normal; ">coord[i][j][2] = coord[i][j+1][2];</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</font></div><div style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;coord[i][column-1] = hold;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></div><div style="line-height: 15px; ">&nbsp;</div></font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">这是最简单的计算，每一列的Ｚ坐标都相同，重复了最后一个点的Ｚ坐标与第一个点的Ｚ坐标，还可以把列点的Ｚ坐标按照一定的曲线方程来计算，然后把它传递给下一个点，还有Ｘ与Ｚ坐标也有可能会变化，这里都是最简单的形式。</font></div><div style="line-height: 15px; "><font color="#DBA04F"><span style="line-height: normal;"><br></span></font></div><div style="line-height: 15px; "><font color="#DBA04F"><span style="line-height: normal;">二、</span></font></div><div style="line-height: 15px; "><font color="#DBA04F"><span style="line-height: normal;"><span style="color: rgb(0, 134, 198); line-height: 15px; "><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">为了能使Ｚ轴即能在垂直方向运动，又能在水平方向运动，则需要两个数组来保存水平方向和垂直方向的Ｚ坐标值。然后Ｚ坐标为这两个坐标值的合成：</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const int row = 45;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const int column = 45;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const float width= 9.0f;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const float height = 9.0f;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; float coord[row][column][3];&nbsp;</font><font color="#00ff00" style="line-height: normal; ">&nbsp;// Flag的坐标</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; float hzcoord[row][column];&nbsp;&nbsp;&nbsp;</font><font color="#00ff00" style="line-height: normal; ">// Flag的Ｚ坐标水平分量</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; float vzcoord[column][row];&nbsp;&nbsp;&nbsp;</font><font color="#00ff00" style="line-height: normal; ">// Flag的Ｚ坐标垂直分量</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#00ff00" style="line-height: normal; ">//计算Ｚ坐标的水平分量</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; row; i++) {</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int j = 0; j &lt; column; j++) {</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hzcoord[i][j] = sin((float)j / (float)column * 360 * 3.1415 / 180);</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#00ff00" style="line-height: normal; ">//计算Ｚ坐标的垂直分量</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; column; i++) {</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int j = 0; j &lt; row; j++) {</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vzcoord[i][j] = sin((float)j / (float)column * 360 * 3.1415 / 180);</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;<font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; float disx = width / column;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; float disy = height /row;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#00ff00" style="line-height: normal; ">//计算每个点的坐标</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; row; i++) {</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int j = 0; j &lt; column; j++) {</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; coord[i][j][0] = j * disx - width / 2.0;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; coord[i][j][1] = i * disy - height / 2.0;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; coord[i][j][2] = hzcoord[i][j] + vzoord[j][i];</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">上面已经完成初始化每个点的坐标，下面就到了动态的每一帧时Ｚ坐标的传递了：</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#00ff00" style="line-height: normal; ">//水平坐标分量的传递</font></div><div style="line-height: 15px; "><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; row; i++) {</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; float hold = hzcoord[i][0];</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int j = 0; j &lt; column - 1; j++) {</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hzcoord[i][j] = hzcoord[i][j+1];</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hzcoord[i][column-1] = hold;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#00ff00" style="line-height: normal; ">//垂直坐标分量的传递</font></div><div style="line-height: 15px; "><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; column; i++) {</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; float hold = vzcoord[i][0];</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int j = 0; j &lt; row - 1; j++) {</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vzcoord[i][j] = vzcoord[i][j+1];</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vzcoord[i][row-1] = hold;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></div></div></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#00ff00" style="line-height: normal; ">&nbsp;//每一帧时要计算的每个点的坐标</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; row; i++) {</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int j = 0; j &lt; column; j++) {</font></div><div style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ff00" style="line-height: normal; ">//Ｘ与Ｙ坐标我们不用去变换，因为只考虑了Ｚ坐标的变化</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //coord[i][j][0] = j * disx - width / 2.0;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //coord[i][j][1] = i * disy - height / 2.0;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; coord[i][j][2] = hzcoord[i][j] + vzoord[j][i];</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></div></font></div></span></span></font></div></span></div><img src="http://www.cppblog.com/images/cppblog_com/biao/flag.png" id="" vspace="0" hspace="0" border="" align="baseline" alt="" longdesc=""><img src ="http://www.cppblog.com/biao/aggbug/136764.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2010-12-17 17:45 <a href="http://www.cppblog.com/biao/archive/2010/12/17/136764.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>OpenGL：球面映射贴图</title><link>http://www.cppblog.com/biao/archive/2010/12/17/136763.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Fri, 17 Dec 2010 09:41:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2010/12/17/136763.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/136763.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2010/12/17/136763.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/136763.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/136763.html</trackback:ping><description><![CDATA[<span style="line-height: 15px; color: rgb(0, 134, 198); font-family: 'BBAlpha Sans', 'Prelude Medium', 'S60 Sans', Tahoma, Verdana, Arial, sans-serif; font-size: 12px; "><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">球面映射贴图：Sphere Map</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">1. 使用OpenGL为我们自动生成Sphere Mpa的S, T方向的纹理</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">　　　glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SHPERE_MAP);</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">2. 启用映射贴图</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glEnable(GL_TEXTURE_GEN_S</font><font color="#dba04f" style="line-height: normal; ">)</font><font color="#dba04f" style="line-height: normal; ">;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glEnable(GL_TEXTURE_GEN_T);</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">{3}. 关闭球面映射贴图</font></div><div style="line-height: 15px; "><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glDisable(GL_TEXTURE_GEN_S</font><font color="#dba04f" style="line-height: normal; ">)</font><font color="#dba04f" style="line-height: normal; ">;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glDisable(GL_TEXTURE_GEN_T);</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">经过上面两步就实在了球面映射贴图，简单吧。</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "><br></font></div></span>
<img src="http://www.cppblog.com/images/cppblog_com/biao/shpere.png" id="" vspace="0" hspace="0" border="" align="baseline" alt="" longdesc=""><img src ="http://www.cppblog.com/biao/aggbug/136763.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2010-12-17 17:41 <a href="http://www.cppblog.com/biao/archive/2010/12/17/136763.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>OpenG：Reflection-Stencil Buffer</title><link>http://www.cppblog.com/biao/archive/2010/12/17/136762.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Fri, 17 Dec 2010 09:39:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2010/12/17/136762.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/136762.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2010/12/17/136762.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/136762.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/136762.html</trackback:ping><description><![CDATA[<span style="line-height: 15px; color: rgb(0, 134, 198); font-family: 'BBAlpha Sans', 'Prelude Medium', 'S60 Sans', Tahoma, Verdana, Arial, sans-serif; font-size: 12px; "><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">每个像素都有自己对应的 Buffer，其实就是一个 32bit 的数，如 Color Buffer, Depth Buffer, Stencil Buffer. Stencil Buffer 与 Depth Buffer 有点特别，因为他们共用同一个 Buffer, Depth Buffer 占用 Buffer 前面的 24Bit, Stencil Buffer 占用后面的 8Bit. Stencil Buffer 可以使用从 1Bit－8Bit.　如在绘制反射时，就像照镜子一样，因为只需要在反射平面上绘制物体的镜像，即要么在反射平面上绘制，要不就不绘制，所以只需要用到 1Bit 的 Stencil Buffer.</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">什么叫 Stencil Buffer ?</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">即是一个模板，也就是说，他可以是一个平面，也可以是一个立体几何图形，如一个四边形，一个Teapot. 在模板所占据的空间中，他的值为 1(values stored in the stencil buffer),　在启用 Stencil Buffer 时，我们所画的图形只有在这个空间中的部分才能显示出来，所以我们可以创建一个模板，他是一个字，然后以后画的图形最多只能把这个字给显示出来，这个图形有其他部分都没有被写进 Color Buffer.</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#00ff00" style="line-height: normal; ">Stencil Buffer 最简单的运用，用来生成镜面反射。</font></div><div style="line-height: 15px; "><font color="#00ff00" style="line-height: normal; ">1. 先要使编程环境支持 Stencil Buffer</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_STENCIL);</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#00ff00" style="line-height: normal; ">2. 设置清除 Stencil Buffer 使用的函数</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glClearStencil(0);</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#00ff00" style="line-height: normal; ">3. 在我们创建模板的时候，要先关掉 Depth Test und Color Mask,</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#00ff00" style="line-height: normal; ">&nbsp;因为我们并不想把模板画到屏幕上</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glDisable(GL_DEPTH_TEST);</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#00ff00" style="line-height: normal; ">// 为了把我们的模板图形不显示到屏幕上，但又要写入 Stencil Buffer 中。</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 我们什么时候创建模板的？就是在启用模板缓存后进行的第一次进绘制的图形就是模板。</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OpenGL会根据我们所设定的 glStencilFunc 的值和 glStencilOp 来比较，</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 然后在 plane 中(即视口所对应的那个二维数组)写入比较的结果值。</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#00ff00" style="line-height: normal; ">4. 开始创建模板</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glEnable(GL_STENCIL_TEST);</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glStencilFunc(GL_ALWAYS, 0x1, 0x1);</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#00ff00" style="line-height: normal; ">// 把模板图形所在的区域的 Buffer 值设置成 1, 其余的还是 0.</font></div><div style="line-height: 15px; "><font color="#00ff00" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 这时用的就是给 glStencilFunc 指定的 ref 的值，现在是 1</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#00ff00" style="line-height: normal; ">// 当然可以有其他的操作，如 GL_INCR, GL_INVERT(bitwise invert)</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#00ff00" style="line-height: normal; ">&nbsp;// 开始创建模板的图形</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; drawFloor();</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#00ff00" style="line-height: normal; ">// 模板创建好后，我们就要设置下一次进行绘制时的模板函数</font></div><div style="line-height: 15px; "><font color="#00ff00" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 只有通过条件的像素才能被显示到屏幕上，否则就被丢弃</font></div><div style="line-height: 15px; "><font color="#00ff00" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 但要注意，现在我们要进行绘制的就是镜像了，所以是要被显示到屏幕上的，</font></div><div style="line-height: 15px; "><font color="#00ff00" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 所以在绘制之前，要把颜色屏蔽关掉和启用深度测试</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glEnable(GL_DEPTH_TEST);</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ff00" style="line-height: normal; ">// Stencil buffer 值等于 1 的地方才绘制到屏幕上&nbsp;&nbsp;&nbsp;&nbsp;</font>&nbsp;&nbsp;&nbsp;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glStencilFunc(GL_EQUAL, 0x1, 0x1);</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#00ff00" style="line-height: normal; ">5. 绘制镜像图像</font></div><div style="line-height: 15px; "><font color="#00ff00" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 现在绘制我们的镜像图像</font></div><div style="line-height: 15px; "><font color="#00ff00" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 镜像是跟原来的物体对称的, 所以用 glScalef 来进行反转，实现对称</font></div><div style="line-height: 15px; "><font color="#00ff00" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 在绘制镜像物体的时候，灯光也要相应的反转</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glPushMatrix();</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glScalef(1, -1, 1);</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glutSolidTeapot(1.0f);</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glPopMatrix();</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#00ff00" style="line-height: normal; ">6. 在模板中显示的镜像图像已经创建好，不再需要模板了，所以我们关掉 stencil buffer</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glDisable(GL_STENCIL_TEST);</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#00ff00" style="line-height: normal; ">7. 绘制镜像所在的平面，就如镜子</font></div><div style="line-height: 15px; "><font color="#00ff00" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 使用 Blend 与镜像图像混合起来</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glEnable(GL_BLEND);</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; drawFloor();</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glDisable(GL_BLEND);</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#00ff00" style="line-height: normal; ">8. 绘制产生镜像的物体</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glutSolidTeapot(1.0f);</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">至此，真正的镜面反射已经创建完成。</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">非真正的反射可以如下实现：</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">先画对称物体，画出镜面(使用 Blend), 然后画出原物体，但这时如果旋转Camera，就会发现，那个对称的物体并不是平面的，还是原来的空间立体物体。但用 Stencil Buffer 实现的镜面反射是真正的镜面反射，镜像是只在镜面上显示，即是平面的。</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; ">下面的代码可以很好的工作</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;</font><font color="#00ff00" style="line-height: normal; ">//****************************************************************//</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;if (useStencil) {<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glClearStencil(0);<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);<br style="line-height: 15px; ">&nbsp;} else {<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);<br style="line-height: 15px; ">&nbsp;}<br style="line-height: 15px; "><font color="#00ff00" style="line-height: normal; "><br style="line-height: 15px; "></font>&nbsp;if (useStencil) {<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glDisable(GL_DEPTH_TEST);<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ff00" style="line-height: normal; ">&nbsp;/* Draw 1 into the stencil buffer. */<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glEnable(GL_STENCIL_TEST);<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glStencilFunc(GL_ALWAYS, 1, 0xffffffff);</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ff00" style="line-height: normal; ">&nbsp;/* Now render floor; floor pixels just get their stencil set to 1. */</font><br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; drawFloor();</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ff00" style="line-height: normal; ">/* Re-enable update of color and depth. */</font><br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glEnable(GL_DEPTH_TEST);</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ff00" style="line-height: normal; ">&nbsp;/* Now, only render where stencil is set to 1. */<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glStencilFunc(GL_EQUAL, 1, 0xffffffff); /* draw if ==1 */<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);<br style="line-height: 15px; ">&nbsp;}</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;glPushMatrix();<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glScalef(1, -1, 1);<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glTranslatef(0.0, 0.8, 0);<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glColor3f(0, 1, 0);<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glutSolidTeapot(1);<br style="line-height: 15px; ">&nbsp;glPopMatrix();</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;if (useStencil) {<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glDisable(GL_STENCIL_TEST);<br style="line-height: 15px; ">&nbsp;}</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;glEnable(GL_BLEND);<br style="line-height: 15px; ">&nbsp;glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);<br style="line-height: 15px; ">&nbsp;glColor4f(0.7, 0.0, 0.0, 0.3);<br style="line-height: 15px; ">&nbsp;drawFloor();<br style="line-height: 15px; ">&nbsp;glDisable(GL_BLEND);</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;glTranslatef(0, -0.0001, 0);<br style="line-height: 15px; ">&nbsp;glFrontFace(GL_CW);<br style="line-height: 15px; ">&nbsp;glColor3f(1, 1, 1);<br style="line-height: 15px; ">&nbsp;drawFloor();</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;glTranslatef(0.0, 0.8, 0);<br style="line-height: 15px; ">&nbsp;glColor3f(0, 1, 0);<br style="line-height: 15px; ">&nbsp;glutSolidTeapot(1);<br style="line-height: 15px; "></font><font color="#00ff00" style="line-height: normal; ">&nbsp;//****************************************************************//</font></div></span>&nbsp;<div><img src="http://www.cppblog.com/images/cppblog_com/biao/stencilbuffer-1.jpg" id="" vspace="0" hspace="0" border="" align="baseline" alt="" longdesc=""></div><div><img src="http://www.cppblog.com/images/cppblog_com/biao/stencilbuffer-2.jpg" id="" vspace="0" hspace="0" border="" align="baseline" alt="" longdesc=""></div><img src ="http://www.cppblog.com/biao/aggbug/136762.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2010-12-17 17:39 <a href="http://www.cppblog.com/biao/archive/2010/12/17/136762.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>OpenGL：Stencil Buffer</title><link>http://www.cppblog.com/biao/archive/2010/12/17/136761.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Fri, 17 Dec 2010 09:34:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2010/12/17/136761.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/136761.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2010/12/17/136761.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/136761.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/136761.html</trackback:ping><description><![CDATA[<span  style="color: rgb(219, 160, 79); font-family: 'BBAlpha Sans', 'Prelude Medium', 'S60 Sans', Tahoma, Verdana, Arial, sans-serif; font-size: 12px; ">模板所占用的 Buffer 空间，是指模板经过投影后到二维平面时，在视口中对应的二维数组所占的区域，即在模板中要显示出来的物体，并不是指在三维空间中，物体在模板中的部分，而指的是这个物体投影到二维平面后与模板的投影相交的部分(这里是用于１Bit的模板镜面反射)。我们所看到在屏幕上显示的图形是经过投影后的二维平面图形，只不过是因为视觉欺骗，所以感觉还是三维的，从三维转换到二维，是不可逆的，会丢失深度信息。但是X，Y的信息不会丢失。</span>
<img src ="http://www.cppblog.com/biao/aggbug/136761.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2010-12-17 17:34 <a href="http://www.cppblog.com/biao/archive/2010/12/17/136761.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>OpenGL：BMPLoad</title><link>http://www.cppblog.com/biao/archive/2010/12/17/136759.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Fri, 17 Dec 2010 09:33:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2010/12/17/136759.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/136759.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2010/12/17/136759.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/136759.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/136759.html</trackback:ping><description><![CDATA[<span  style="line-height: 15px; color: rgb(0, 134, 198); font-family: 'BBAlpha Sans', 'Prelude Medium', 'S60 Sans', Tahoma, Verdana, Arial, sans-serif; font-size: 12px; "><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">这个代码写得有些阿格里拉，但也不失为一种方法</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">#ifndef _BMPLOAD_H_<br style="line-height: 15px; ">#define _BMPLOAD_H_<br style="line-height: 15px; ">#include &lt;iostream&gt;<br style="line-height: 15px; ">#include &lt;stdio.h&gt;<br style="line-height: 15px; ">using namespace std;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#00ff00" style="line-height: normal; ">/*-------------&nbsp;<br style="line-height: 15px; ">&nbsp;类型定义<br style="line-height: 15px; ">&nbsp;--------------*/</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "><font color="#00ff00" style="line-height: normal; ">// 纹理图像结构</font><br style="line-height: 15px; ">typedef struct {<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int imgWidth;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 纹理宽度<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int imgHeight;<font color="#00ff00" style="line-height: normal; ">&nbsp;// 纹理高度<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned int rgbType;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 每个象素对应的字节数，3：24位图，4：带alpha通道的24位图</font><br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned char *data;<font color="#00ff00" style="line-height: normal; ">&nbsp;// 纹理数据<br style="line-height: 15px; "></font>} TEXTUREIMAGE;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "><font color="#00ff00" style="line-height: normal; ">// BMP文件头</font><br style="line-height: 15px; ">typedef struct {<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned short bfType;<font color="#00ff00" style="line-height: normal; ">&nbsp;// 文件类型<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned long bfSize;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 文件大小<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned short bfReserved1;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 保留位</font><br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned short bfReserved2;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 保留位<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned long bfOffBits;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 数据偏移位置</font><br style="line-height: 15px; ">} BMPFILEHEADER;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "><font color="#00ff00" style="line-height: normal; ">// BMP信息头</font><br style="line-height: 15px; ">typedef struct {<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned long biSize;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 此结构大小</font><br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; long biWidth;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 图像宽度<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; long biHeight;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 图像高度</font><br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned short biPlanes;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 调色板数量<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned short biBitCount;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 每个象素对应的位数，24：24位图，32：带alpha通道的24位图</font><br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned long biCompression;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 压缩<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned long biSizeImage;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 图像大小<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; long biXPelsPerMeter;<font color="#00ff00" style="line-height: normal; ">&nbsp;// 横向分辨率<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; long biYPelsPerMeter;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 纵向分辨率<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned long biClrUsed;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 颜色使用数<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned long biClrImportant;<font color="#00ff00" style="line-height: normal; ">&nbsp;// 重要颜色数</font><br style="line-height: 15px; ">} BMPINFOHEADER;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "><font color="#00ff00" style="line-height: normal; ">// 读取BMP文件创建纹理</font><br style="line-height: 15px; ">GLboolean LoadBmp(char *filename, TEXTUREIMAGE *textureImg) {<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int i, j;<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FILE *file;<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BMPFILEHEADER bmpFile;<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BMPINFOHEADER bmpInfo;<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int pixel_size;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 初始化纹理数据<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; textureImg-&gt;imgWidth = 0;<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; textureImg-&gt;imgHeight = 0;<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; textureImg-&gt;rgbType = 0;<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (textureImg-&gt;data != NULL) {<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; delete []textureImg-&gt;data;<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ff00" style="line-height: normal; ">&nbsp;// 打开文件</font><br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; file = fopen(filename, "rb");<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (file == NULL) {<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cout &lt;&lt; "Open File Error" &lt;&lt;endl;<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ff00" style="line-height: normal; ">&nbsp;// 获取文件头<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rewind(file);<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fread(&amp;bmpFile, sizeof(BMPFILEHEADER)-2, 1, file);<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ff00" style="line-height: normal; ">//因为Ｃ语言对结构按四位对齐，所以不能直接用sizeof(BMPFILEHEADER)<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fread(&amp;bmpInfo, sizeof(BMPINFOHEADER), 1, file);</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 验证文件类型<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (bmpFile.bfType != 0x4D42) {<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout &lt;&lt; "File Type Error" &lt;&lt;endl;<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fclose(file);<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ff00" style="line-height: normal; ">&nbsp;// 获取图像色彩数<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pixel_size = bmpInfo.biBitCount &gt;&gt; 3;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 读取文件数据<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; textureImg-&gt;data = new unsigned char[bmpInfo.biWidth * bmpInfo.biHeight * pixel_size];<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (textureImg-&gt;data == NULL) {<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fclose(file);<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "><br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rewind(file);<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fseek(file, 54L, 0);<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (i = 0; i &lt; bmpInfo.biHeight; i++) {<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (j = 0; j &lt; bmpInfo.biWidth; j++) {<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ff00" style="line-height: normal; ">&nbsp;// 红色分量<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fread(textureImg-&gt;data + (i * bmpInfo.biWidth + j) * pixel_size + 2,<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sizeof(unsigned char), 1, file);<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 绿色分量</font><br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fread(textureImg-&gt;data + (i * bmpInfo.biWidth + j) * pixel_size + 1,<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sizeof(unsigned char), 1, file);<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 蓝色分量<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fread(textureImg-&gt;data + (i * bmpInfo.biWidth + j) * pixel_size + 0,<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sizeof(unsigned char), 1, file);<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ff00" style="line-height: normal; ">&nbsp;// Alpha分量</font><br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (pixel_size == 4) {<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fread(textureImg-&gt;data + (i * bmpInfo.biWidth + j) * pixel_size + 3,<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sizeof(unsigned char), 1, file);<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 记录图像相关参数<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; textureImg-&gt;imgWidth = bmpInfo.biWidth;<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; textureImg-&gt;imgHeight = bmpInfo.biHeight;<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; textureImg-&gt;rgbType = pixel_size;<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fclose(file);<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;<br style="line-height: 15px; ">}</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">#endif</font></div></span>
<img src ="http://www.cppblog.com/biao/aggbug/136759.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2010-12-17 17:33 <a href="http://www.cppblog.com/biao/archive/2010/12/17/136759.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>OpenGL：BMPLoad</title><link>http://www.cppblog.com/biao/archive/2010/12/17/136760.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Fri, 17 Dec 2010 09:33:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2010/12/17/136760.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/136760.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2010/12/17/136760.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/136760.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/136760.html</trackback:ping><description><![CDATA[<span  style="line-height: 15px; color: rgb(0, 134, 198); font-family: 'BBAlpha Sans', 'Prelude Medium', 'S60 Sans', Tahoma, Verdana, Arial, sans-serif; font-size: 12px; "><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">这个代码写得有些阿格里拉，但也不失为一种方法</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">#ifndef _BMPLOAD_H_<br style="line-height: 15px; ">#define _BMPLOAD_H_<br style="line-height: 15px; ">#include &lt;iostream&gt;<br style="line-height: 15px; ">#include &lt;stdio.h&gt;<br style="line-height: 15px; ">using namespace std;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#00ff00" style="line-height: normal; ">/*-------------&nbsp;<br style="line-height: 15px; ">&nbsp;类型定义<br style="line-height: 15px; ">&nbsp;--------------*/</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "><font color="#00ff00" style="line-height: normal; ">// 纹理图像结构</font><br style="line-height: 15px; ">typedef struct {<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int imgWidth;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 纹理宽度<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int imgHeight;<font color="#00ff00" style="line-height: normal; ">&nbsp;// 纹理高度<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned int rgbType;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 每个象素对应的字节数，3：24位图，4：带alpha通道的24位图</font><br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned char *data;<font color="#00ff00" style="line-height: normal; ">&nbsp;// 纹理数据<br style="line-height: 15px; "></font>} TEXTUREIMAGE;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "><font color="#00ff00" style="line-height: normal; ">// BMP文件头</font><br style="line-height: 15px; ">typedef struct {<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned short bfType;<font color="#00ff00" style="line-height: normal; ">&nbsp;// 文件类型<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned long bfSize;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 文件大小<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned short bfReserved1;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 保留位</font><br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned short bfReserved2;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 保留位<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned long bfOffBits;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 数据偏移位置</font><br style="line-height: 15px; ">} BMPFILEHEADER;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "><font color="#00ff00" style="line-height: normal; ">// BMP信息头</font><br style="line-height: 15px; ">typedef struct {<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned long biSize;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 此结构大小</font><br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; long biWidth;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 图像宽度<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; long biHeight;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 图像高度</font><br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned short biPlanes;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 调色板数量<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned short biBitCount;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 每个象素对应的位数，24：24位图，32：带alpha通道的24位图</font><br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned long biCompression;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 压缩<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned long biSizeImage;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 图像大小<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; long biXPelsPerMeter;<font color="#00ff00" style="line-height: normal; ">&nbsp;// 横向分辨率<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; long biYPelsPerMeter;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 纵向分辨率<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned long biClrUsed;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 颜色使用数<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned long biClrImportant;<font color="#00ff00" style="line-height: normal; ">&nbsp;// 重要颜色数</font><br style="line-height: 15px; ">} BMPINFOHEADER;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "><font color="#00ff00" style="line-height: normal; ">// 读取BMP文件创建纹理</font><br style="line-height: 15px; ">GLboolean LoadBmp(char *filename, TEXTUREIMAGE *textureImg) {<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int i, j;<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FILE *file;<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BMPFILEHEADER bmpFile;<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BMPINFOHEADER bmpInfo;<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int pixel_size;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 初始化纹理数据<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; textureImg-&gt;imgWidth = 0;<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; textureImg-&gt;imgHeight = 0;<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; textureImg-&gt;rgbType = 0;<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (textureImg-&gt;data != NULL) {<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; delete []textureImg-&gt;data;<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ff00" style="line-height: normal; ">&nbsp;// 打开文件</font><br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; file = fopen(filename, "rb");<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (file == NULL) {<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cout &lt;&lt; "Open File Error" &lt;&lt;endl;<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ff00" style="line-height: normal; ">&nbsp;// 获取文件头<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rewind(file);<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fread(&amp;bmpFile, sizeof(BMPFILEHEADER)-2, 1, file);<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ff00" style="line-height: normal; ">//因为Ｃ语言对结构按四位对齐，所以不能直接用sizeof(BMPFILEHEADER)<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fread(&amp;bmpInfo, sizeof(BMPINFOHEADER), 1, file);</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 验证文件类型<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (bmpFile.bfType != 0x4D42) {<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout &lt;&lt; "File Type Error" &lt;&lt;endl;<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fclose(file);<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ff00" style="line-height: normal; ">&nbsp;// 获取图像色彩数<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pixel_size = bmpInfo.biBitCount &gt;&gt; 3;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 读取文件数据<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; textureImg-&gt;data = new unsigned char[bmpInfo.biWidth * bmpInfo.biHeight * pixel_size];<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (textureImg-&gt;data == NULL) {<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fclose(file);<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "><br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rewind(file);<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fseek(file, 54L, 0);<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (i = 0; i &lt; bmpInfo.biHeight; i++) {<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (j = 0; j &lt; bmpInfo.biWidth; j++) {<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ff00" style="line-height: normal; ">&nbsp;// 红色分量<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fread(textureImg-&gt;data + (i * bmpInfo.biWidth + j) * pixel_size + 2,<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sizeof(unsigned char), 1, file);<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 绿色分量</font><br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fread(textureImg-&gt;data + (i * bmpInfo.biWidth + j) * pixel_size + 1,<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sizeof(unsigned char), 1, file);<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 蓝色分量<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fread(textureImg-&gt;data + (i * bmpInfo.biWidth + j) * pixel_size + 0,<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sizeof(unsigned char), 1, file);<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ff00" style="line-height: normal; ">&nbsp;// Alpha分量</font><br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (pixel_size == 4) {<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fread(textureImg-&gt;data + (i * bmpInfo.biWidth + j) * pixel_size + 3,<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sizeof(unsigned char), 1, file);<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 记录图像相关参数<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; textureImg-&gt;imgWidth = bmpInfo.biWidth;<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; textureImg-&gt;imgHeight = bmpInfo.biHeight;<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; textureImg-&gt;rgbType = pixel_size;<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fclose(file);<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;<br style="line-height: 15px; ">}</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">#endif</font></div></span>
<img src ="http://www.cppblog.com/biao/aggbug/136760.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2010-12-17 17:33 <a href="http://www.cppblog.com/biao/archive/2010/12/17/136760.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>OpenGL：TGALoad</title><link>http://www.cppblog.com/biao/archive/2010/12/17/136758.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Fri, 17 Dec 2010 09:32:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2010/12/17/136758.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/136758.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2010/12/17/136758.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/136758.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/136758.html</trackback:ping><description><![CDATA[<span  style="line-height: 15px; color: rgb(0, 134, 198); font-family: 'BBAlpha Sans', 'Prelude Medium', 'S60 Sans', Tahoma, Verdana, Arial, sans-serif; font-size: 12px; "><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">用 Targa(TGA) 图像文件，因为它简单并且支持 alpha 通道，它可以使你更容易的创建酷的效果。</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">TGA 文件与 BMP 文件一样，图像数据都是按 BGR 存储，而 OpenGL 的图像是按 RGB 来使用的。</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">这里用了一个很好的方法，一次性读入所有的图像数据，然后再进行转换 R 与 B，而不是每次读一个 R，G，B，A，这种读法很省时间。</font><font color="#00ff00" style="line-height: normal; ">fread(buffer, size, number, file);按块读取文件内容</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">size 为每次读取几个 byte，如按字节读取，这里使用的一样，size == 1;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">number 为一共读取多少个 size 的内容，number = width * height * bytesPerPixel;(整个图像的数据内容)</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">这个方法只能读取无压缩的 TGA 文件</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">TGA 开始为 12 字节的内容为描述文件的一般信息，接下来的 6 字节为最重要的信息，文件宽，高，每个像素的位数， 从第 18 个字节开始，就是图像的数据内容。</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">更重要的一点，这个程序进行了各种出错处理。</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">#ifndef _TGALOAD_H_<br style="line-height: 15px; ">#define _TGALOAD_H_</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">#include &lt;stdio.h&gt;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">typedef struct {<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GLubyte* data;<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GLuint width;<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GLuint height;<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GLuint rgbType;<br style="line-height: 15px; ">} TextureImage;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">GLboolean loadTGA(char* fileName, TextureImage* textureImage) {<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GLubyte TGAheader[12]= { 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0 };&nbsp;<font color="#00ff00" style="line-height: normal; ">// 无压缩的TGA文件头</font><br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GLubyte TGAcompare[12];&nbsp;<font color="#00ff00" style="line-height: normal; ">// 保存读入的文件头信息<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GLubyte header[6];&nbsp;<font color="#00ff00" style="line-height: normal; ">// 保存最有用的图像信息，宽，高，位深<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GLuint bytesPerPixel;<font color="#00ff00" style="line-height: normal; ">&nbsp;// 记录每个颜色所占用的字节数<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GLuint imageSize;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 记录文件大小<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GLuint temp;&nbsp;</font><font color="#00ff00" style="line-height: normal; ">// 临时变量</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FILE *file = fopen(fileName, "rb");&nbsp;<font color="#00ff00" style="line-height: normal; ">// 打开一个TGA文件<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (file==NULL ||&nbsp;<font color="#00ff00" style="line-height: normal; ">// 文件存在么?<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fread(TGAcompare, 1, sizeof(TGAcompare), file)!= sizeof(TGAcompare) ||</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 是否包含12个字节的文件头?<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; memcmp(TGAheader, TGAcompare, sizeof(TGAheader))!= 0 ||</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ff00" style="line-height: normal; ">&nbsp;// 是否是我们需要的格式?<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fread(header, 1, sizeof(header), file)!= sizeof(header)) {</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 如果是读取下面六个图像信息<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (file == NULL)&nbsp;<font color="#00ff00" style="line-height: normal; ">// 文件不存在返回错误<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else {<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fclose(file);&nbsp;<font color="#00ff00" style="line-height: normal; ">// 关闭文件返回错误<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; textureImage-&gt;width = header[1] * 256 + header[0];&nbsp;<font color="#00ff00" style="line-height: normal; ">// 记录文件宽度<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; textureImage-&gt;height = header[3] * 256 + header[2];&nbsp;</font><font color="#00ff00" style="line-height: normal; ">// 记录文件高度</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (textureImage-&gt;width &lt;= 0 ||<font color="#00ff00" style="line-height: normal; ">&nbsp;// 宽度是否小于0</font><br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; textureImage-&gt;height &lt;= 0 ||&nbsp;<font color="#00ff00" style="line-height: normal; ">// 高度是否小于0<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (header[4] != 24 &amp;&amp; header[4] != 32)) {&nbsp;<font color="#00ff00" style="line-height: normal; ">// TGA文件是24/32位？</font><br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fclose(file);&nbsp;<font color="#00ff00" style="line-height: normal; ">// 如果失败关闭文件，返回错误<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bytesPerPixel = header[4] &gt;&gt; 3;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 记录每个象素所占的字节数<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; textureImage-&gt;rgbType = bytesPerPixel;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 记录每个象素所占的字节数<br style="line-height: 15px; "></font>&nbsp;<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; imageSize = textureImage-&gt;width *textureImage-&gt;height * bytesPerPixel;</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 计算TGA文件加载所需要的内存大小<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; textureImage-&gt;data = (GLubyte*)malloc(imageSize);&nbsp;<font color="#00ff00" style="line-height: normal; ">// 分配内存去保存TGA数据</font><br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (textureImage-&gt;data == NULL ||&nbsp;<font color="#00ff00" style="line-height: normal; ">// 系统是否分配了足够的内存？</font><br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fread(textureImage-&gt;data, 1, imageSize, file)!= imageSize) {</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 是否成功读入内存?<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (textureImage-&gt;data != NULL) {<font color="#00ff00" style="line-height: normal; ">&nbsp;// 是否有数据被加载<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; free(textureImage-&gt;data);<font color="#00ff00" style="line-height: normal; ">&nbsp;// 如果是，则释放载入的数据<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fclose(file);&nbsp;<font color="#00ff00" style="line-height: normal; ">// 关闭文件</font><br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 返回错误<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (GLuint i=0; i&lt;GLuint(imageSize); i+=bytesPerPixel) {</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ff00" style="line-height: normal; ">// 循环所有的像素<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 交换R和B的值<br style="line-height: 15px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; temp = textureImage-&gt;data[i];<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; textureImage-&gt;data[i] = textureImage-&gt;data[i + 2];<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; textureImage-&gt;data[i + 2] = temp;<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fclose(file);<font color="#00ff00" style="line-height: normal; ">&nbsp;// 关闭文件<br style="line-height: 15px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font>return true;<br style="line-height: 15px; ">}</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">#endif</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div></span>
<img src ="http://www.cppblog.com/biao/aggbug/136758.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2010-12-17 17:32 <a href="http://www.cppblog.com/biao/archive/2010/12/17/136758.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>OpenGL：数据转换</title><link>http://www.cppblog.com/biao/archive/2010/12/17/136755.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Fri, 17 Dec 2010 09:28:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2010/12/17/136755.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/136755.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2010/12/17/136755.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/136755.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/136755.html</trackback:ping><description><![CDATA[<span  style="line-height: 15px; color: rgb(0, 134, 198); font-family: 'BBAlpha Sans', 'Prelude Medium', 'S60 Sans', Tahoma, Verdana, Arial, sans-serif; font-size: 12px; "><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">在许多图像的数据存储中，都是按字节来存储的(也有按float型的，如PPM)，因为颜色的值为0 ~ 255，即一个无符号整型的数据GLubyte。但在图像颜色数据之前，还包括图像的很多信息，如图像的类型，图像的每个像素信息是否含有alpha域，图像的宽，高得，就像ＭＢＰ一样，前五十四个字节是图像的相关信息，从第五十四个字节后才是图像的颜色数据，ＴＧＡ的前十二字节包含了是否压缩等，第十三个到第十八个字节是图像的宽，高，alpha信息。但现在有个问题，图像的宽高什么的数据在图像的二进制文件中都是按字节来存放的，但他们又是　int　型或者　short(TGA)　型的，一个字节的数据并表示不完一个图像的宽高等，而一般用二个或四个，那怎么从每次读入的单个字节的信息来组装成一个int 或者 short信息呢？</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">这就要先知道这些信息在文件中是怎么存储的，一般如ＴＧＡ中，都是按从低位到高位进行存储，0x1234这是一个占有两个字节的数据，即shot型，在图像文件中的存储方式是 0x34， 0x12，当我们读出这两个字节后，如这两个字节在这里表示图像的宽，则转换成 short 为：int width = 0x12 * 16^2 + 0x34即 18 * 256 + 52，</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">这个可以来这么理解：</font></div><div style="line-height: 15px; "><font color="#00ff00" style="line-height: normal; ">0x12345678 = 0x12000000 + 0x340000 + 0x5600 + 0x78</font></div><div style="line-height: 15px; "><font color="#00ff00" style="line-height: normal; ">= 0x12 * 16^6 + 0x34 * 16^4 + 0x56 * 16^2 + 0x78</font></div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; "></font>&nbsp;</div><div style="line-height: 15px; "><font color="#dba04f" style="line-height: normal; ">这也是内存为什么是按字节来读取，但最后又可以转换成各种类型的基础。</font></div></span>
<img src ="http://www.cppblog.com/biao/aggbug/136755.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2010-12-17 17:28 <a href="http://www.cppblog.com/biao/archive/2010/12/17/136755.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>OpenGL：Shader</title><link>http://www.cppblog.com/biao/archive/2010/12/17/136753.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Fri, 17 Dec 2010 09:23:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2010/12/17/136753.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/136753.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2010/12/17/136753.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/136753.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/136753.html</trackback:ping><description><![CDATA[<span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">vec4 v, u;
mat4 m;
v </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">*</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> u          component</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">-</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">wise
v </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">*</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> m         v </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 255); ">is</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> row vector
m </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">*</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> v         v </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 255); ">is</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> column vector
m </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">*</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> m        linear</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">-</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">algebraic matrix multiplication
 
Inverse      求逆
Transpose  转置
gl_ModelViewMatrixInverse;
gl_ModelViewProjectionMatrixInverseTranspose
gl_NormalMatrix </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 255); ">is</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> the transpose of the inverse of the gl_ModelViewMatrix.
 
function prototype:
vec4 fract(vec4 x); </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">==</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> x </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">-</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> floor(x); </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">&lt;-</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> [</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">0</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">, </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">1</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">) </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 128, 0); ">//</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 128, 0); "> fract 片断</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 128, 0); ">
</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">vec4 clamp(</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 255); ">float</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> x, </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 255); ">float</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> minVal, </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 255); ">float</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> maxVal); returns min(max(x, minVal), maxVal);
vec4 mix(vec4 x, vec4 y, vec4 a); </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 255); ">return</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> x </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">*</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> (</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">1.0</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">-</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> a) </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">+</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> y </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">*</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> a;
 
vec4 step(vec4 edge, vec4 x); returns </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">0</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 255); ">if</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> x </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">&lt;</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> edge, otherwise returns </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">1</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">.
vec4 smoothstep(vec4 edge0, vec4 edge1, vec4 x);
   returns </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 255); ">if</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> x </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">&lt;=</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> edge0, returns </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">1</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 255); ">if</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> x </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">&gt;=</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> edge1, perform hermite interpolation
between </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">0</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> and </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">1</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> when edge0 </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">&lt;</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> x </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">&lt;</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> edge1
０到１之间的Hermite插值算法 equal to
t </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">=</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> clamp((x </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">-</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> edge0) </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">/</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> (edge1 </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">-</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> edge0), </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">0.0</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">, </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">1.0</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">);
</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 255); ">return</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> t </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">*</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> t </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">*</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> (</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">3</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">-</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">2</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">*</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> t);
 
vec3 cross(vec3 x, vec3 y); </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 128, 0); ">//</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 128, 0); ">　只有这种形式，即只有三个component的向量才行 dot(N, L);</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 128, 0); ">
</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">result[</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">0</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">] </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">=</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> x[</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">1</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">] </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">*</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> y[</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">2</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">] </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">-</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> x[</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">2</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">] </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">*</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> y[</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">1</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">];
result[</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">1</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">] </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">=</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> x[</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">2</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">] </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">*</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> y[</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">0</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">] </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">-</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> x[</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">0</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">] </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">*</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> y[</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">2</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">];
result[</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">2</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">] </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">=</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> x[</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">0</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">] </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">*</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> y[</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">1</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">] </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">-</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> x[</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">1</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">] </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">*</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> y[</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">0</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">];
 
</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 255); ">float</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> dot(vec4 x, vec4 y);
result </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">=</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> x[</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">0</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">] </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">*</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> y[</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">0</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">] </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">+</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> x[</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">1</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">] </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">*</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> y[</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">1</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">] </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">+</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> ...;
 
vec4 reflect(vec4 I, vec4 N); </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 128, 0); ">//</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 128, 0); "> 反射光线向量</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 128, 0); ">
</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">For the incident vector I and surface orientation N, returns the reflection direction
result </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">=</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> I </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">-</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">2.0</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">*</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> dot(N, I) </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">*</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> N;
    vec3 ecPosition </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">=</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> vec3 (gl_ModelViewMatrix </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">*</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> gl_Vertex);
    vec3 tnorm      </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">=</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> normalize(gl_NormalMatrix </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">*</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> gl_Normal);
    vec3 lightVec   </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">=</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> normalize(LightPosition </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">-</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> ecPosition);
    vec3 reflectVec </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">=</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> reflect(</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">-</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">lightVec, tnorm);
    vec3 viewVec    </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">=</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> normalize(</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">-</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">ecPosition);
vec4 refract(vec4 I, vec4 N, </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 255); ">float</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> eta); </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 128, 0); ">//</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 128, 0); "> 折射光线向量</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 128, 0); ">
</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">For the incident vector I and surface normal N and the ratio(比率) of refraction eta,
returns the refraction vector. The returned result </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 255); ">is</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> computed </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 255); ">as</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">
k </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">=</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">1.0</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">-</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> eta </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">*</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> eta </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">*</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> (</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">1.0</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">-</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> dot(N, I) </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">*</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> dot(N, I));
</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 255); ">if</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> (k </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">&lt;</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">0.0</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">) {
        result </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">=</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">0.0</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">;
        </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 128, 0); ">//</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 128, 0); "> the return type is float of vec2/3/4</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 128, 0); ">
</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">} </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 255); ">else</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> {
        result </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">=</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> eta </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">*</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> I </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">-</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> (eta </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">*</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> dot(N, I) </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">*</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">sqrt(k)) </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">*</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> N;
}
 
mat4 matrixComMult(mat4 x, mat4 y); component</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">-</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">wise
to </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 255); ">get</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> linear</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">-</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">algebraic multiplication, use the multiply </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 255); ">operator</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> (</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">*</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">)
mat4 x, y; x </span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); ">*</span></span><span  style="font-family: monospace; font-size: 13px; white-space: pre; "><span style="color: rgb(0, 0, 0); "> y;</span></span><img src ="http://www.cppblog.com/biao/aggbug/136753.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2010-12-17 17:23 <a href="http://www.cppblog.com/biao/archive/2010/12/17/136753.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>OpenGL: 图形表述基本函数使用</title><link>http://www.cppblog.com/biao/archive/2009/06/01/86420.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Mon, 01 Jun 2009 08:13:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2009/06/01/86420.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/86420.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2009/06/01/86420.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/86420.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/86420.html</trackback:ping><description><![CDATA[

<img src="http://www.cppblog.com/images/cppblog_com/biao/Transformation.png" id="" vspace="0" hspace="0" border="" align="baseline" alt="" longdesc=""><img src="http://www.cppblog.com/images/cppblog_com/biao/LightPosition.png" id="" vspace="0" hspace="0" border="" align="baseline" alt="" longdesc=""><img src="http://www.cppblog.com/images/cppblog_com/biao/Fog.png" id="" vspace="0" hspace="0" border="" align="baseline" alt="" longdesc=""><img src="http://www.cppblog.com/images/cppblog_com/biao/Shapes.png" id="" vspace="0" hspace="0" border="" align="baseline" alt="" longdesc=""><img src="http://www.cppblog.com/images/cppblog_com/biao/Texture.png" id="" vspace="0" hspace="0" border="" align="baseline" alt="" longdesc=""><img src="http://www.cppblog.com/images/cppblog_com/biao/LightAndMaterial.png" id="" vspace="0" hspace="0" border="" align="baseline" alt="" longdesc=""><img src ="http://www.cppblog.com/biao/aggbug/86420.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2009-06-01 16:13 <a href="http://www.cppblog.com/biao/archive/2009/06/01/86420.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>OpenGL: 函数列表</title><link>http://www.cppblog.com/biao/archive/2009/06/01/86413.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Mon, 01 Jun 2009 07:10:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2009/06/01/86413.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/86413.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2009/06/01/86413.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/86413.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/86413.html</trackback:ping><description><![CDATA[
<span style="font-family: Times; font-size: 23px; "><dt><dt>5.&nbsp;<a href="itss://chm/OpenglBlueBook/ch05.html">OpenGL Reference Pages</a></dt><dd><dl><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5449115">glAccum</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5450028">glAlphaFunc</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5450783">glBegin</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5452091">glBitmap</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5452795">glBlendFunc</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5455400">glCallList</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5455795">glCallLists</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5456674">glClear</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5457318">glClearAccum</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5457585">glClearColor</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5457799">glClearDepth</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5458017">glClearIndex</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5458286">glClearStencil</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5458517">glClipPlane</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5458953">glColor</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5460137">glColorMask</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5460487">glColorMaterial</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5461000">glCopyPixels</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5462537">glCullFace</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5462910">glDeleteLists</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5463190">glDepthFunc</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5463808">glDepthMask</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5464080">glDepthRange</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5464391">glDrawBuffer</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5465193">glDrawPixels</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5467722">glEdgeFlag</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5468083">glEnable</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5471215">glEvalCoord</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5472447">glEvalMesh</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5474059">glEvalPoint</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5474777">glFeedbackBuffer</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5476200">glFinish</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5476402">glFlush</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5476627">glFog</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5477735">glFrontFace</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5478066">glFrustum</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5478661">glGenLists</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5478953">glGet</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5487905">glGetClipPlane</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5488181">glGetError</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5488607">glGetLight</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5489496">glGetMap</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5490285">glGetMaterial</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5490876">glGetPixelMap</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5491668">glGetPolygonStipple</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5491932">glGetString</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5492310">glGetTexEnv</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5492765">glGetTexGen</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5493335">glGetTexImage</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5494214">glGetTexLevelParameter</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5494842">glGetTexParameter</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5495369">glHint</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5496026">glIndex</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5496385">glIndexMask</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5496680">glInitNames</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5496901">glIsEnabled</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5498750">glIsList</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5498984">glLight</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5500242">glLightModel</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5500945">glLineStipple</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5501432">glLineWidth</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5501839">glListBase</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5502064">glLoadIdentity</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5502311">glLoadMatrix</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5502647">glLoadName</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5502957">glLogicOp</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5503965">glMap1</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5505626">glMap2</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5507647">glMapGrid</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5508483">glMaterial</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5509492">glMatrixMode</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5509833">glMultMatrix</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5510201">glNewList</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5510854">glNormal</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5511492">glOrtho</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5512093">glPassThrough</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5512384">glPixelMap</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5514324">glPixelStore</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5516742">glPixelTransfer</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5519122">glPixelZoom</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5519499">glPointSize</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5520001">glPolygonMode</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5520655">glPolygonStipple</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5521070">glPushAttrib</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5523373">glPushMatrix</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5511908">glPushName</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5525431">glRasterPos</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5526802">glReadBuffer</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5527285">glReadPixels</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5529589">glRect</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5530227">glRenderMode</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5530972">glRotate</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5531421">glScale</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5531954">glScissor</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5532330">glSelectBuffer</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5532929">glShadeModel</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5533480">glStencilFunc</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5534423">glStencilMask</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5534740">glStencilOp</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5535535">glTexCoord</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5536596">glTexEnv</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5538281">glTexGen</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5539986">glTexImage1D</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5541644">glTexImage2D</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5543436">glTexParameter</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5544938">glTranslate</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5545557">glVertex</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch05.html#id5546518">glViewport</a></dt></dl></dd><p>&#160;</p><dt>6.&nbsp;<a href="itss://chm/OpenglBlueBook/ch06.html">GLU Reference Pages</a></dt><dd><dl><dt><a href="itss://chm/OpenglBlueBook/ch06.html#id5546906">gluBeginCurve</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch06.html#id5547245">gluBeginPolygon</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch06.html#id5547634">gluBeginSurface</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch06.html#id5548054">gluBeginTrim</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch06.html#id5549582">gluBuild1DMipmaps</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch06.html#id5550108">gluBuild2DMipmaps</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch06.html#id5550631">gluCylinder</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch06.html#id5551102">gluDeleteNurbsRenderer</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch06.html#id5551238">gluDeleteQuadric</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch06.html#id5551413">gluDeleteTess</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch06.html#id5551585">gluDisk</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch06.html#id5551982">gluErrorString</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch06.html#id5552230">gluGetNurbsProperty</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch06.html#id5552440">gluLoadSamplingMatrices</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch06.html#id5552781">gluLookAt</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch06.html#id5553064">gluNewNurbsRenderer</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch06.html#id5553234">gluNewQuadric</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch06.html#id5553431">gluNewTess</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch06.html#id5553592">gluNextContour</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch06.html#id5554132">gluNurbsCallback</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch06.html#id5554403">gluNurbsCurve</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch06.html#id5555100">gluNurbsProperty</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch06.html#id5555620">gluNurbsSurface</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch06.html#id5556407">gluOrtho2D</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch06.html#id5556583">gluPartialDisk</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch06.html#id5557116">gluPerspective</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch06.html#id5557442">gluPickMatrix</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch06.html#id5557853">gluProject</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch06.html#id5558170">gluPwlCurve</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch06.html#id5558540">gluQuadricCallback</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch06.html#id5558794">gluQuadricDrawStyle</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch06.html#id5559131">gluQuadricNormals</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch06.html#id5559435">gluQuadricOrientation</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch06.html#id5559737">gluQuadricTexture</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch06.html#id5559949">gluScaleImage</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch06.html#id5560597">gluSphere</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch06.html#id5561019">gluTessCallback</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch06.html#id5561652">gluTessVertex</a></dt><dt><a href="itss://chm/OpenglBlueBook/ch06.html#id5562033">gluUnProject</a></dt></dl></dd></dt><dd><dl></dl></dd></span><img src ="http://www.cppblog.com/biao/aggbug/86413.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2009-06-01 15:10 <a href="http://www.cppblog.com/biao/archive/2009/06/01/86413.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>OpenGL: 纹理贴图基础</title><link>http://www.cppblog.com/biao/archive/2009/06/01/86389.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Mon, 01 Jun 2009 05:52:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2009/06/01/86389.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/86389.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2009/06/01/86389.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/86389.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/86389.html</trackback:ping><description><![CDATA[

<div style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal verdana; background-image: initial; background-repeat: initial; background-attachment: initial; -webkit-background-clip: initial; -webkit-background-origin: initial; background-color: rgb(255, 255, 255); background-position: initial initial; "><span style="font-family: Courier; font-size: 14px; line-height: 20px; "><div style="padding-right: 32px; padding-left: 32px; background-image: initial; background-repeat: initial; background-attachment: initial; -webkit-background-clip: initial; -webkit-background-origin: initial; background-color: rgb(255, 255, 255); padding-bottom: 32px; border-left-color: rgb(187, 187, 187); padding-top: 32px; "><strong><p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong>OpenGL: Texture Mapping: When we apply image to a geometric primitive, we call this texture or texture mapping.</strong></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier">Load texture image: <span class="Apple-tab-span" style="white-space:pre">		</span><strong>glTexImage /glTexSubImage</strong></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier">Map textures to geometry: <span class="Apple-tab-span" style="white-space:pre">	</span><strong>glTexCoord</strong></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier">Change the texture environment: <strong>glTexEnv</strong></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier">Set texture mapping parameters: <strong>glTexparameter</strong></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier">Generate mipmaps: <span class="Apple-tab-span" style="white-space:pre">		</span><strong>gluBuildMipmaps</strong></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier">Manage multiple textures: <span class="Apple-tab-span" style="white-space:pre">	</span><strong>glBindTexture</strong></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong>dramatic</strong> differnece: <span style="font: 14.0px STHeiti Light">戏剧性的</span>.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong>richness</strong>: <span style="font: 14.0px STHeiti Light">丰富</span>.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier">stark <strong>contrast</strong>: <span style="font: 14.0px STHeiti Light">对比</span>.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong>texel</strong>: the individual elements in a texture.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong>pixel</strong>: the individual elements in a pixmap.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier">A one-to-one correspondence seldom exists between texels and pixels on the screen.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong>shrink</strong>: <span style="font: 14.0px STHeiti Light">收缩</span>.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier">bias: <span style="font: 14.0px STHeiti Light">误差</span>, <span style="font: 14.0px STHeiti Light">偏差</span>.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong>Step on applying a texture map to geometry:</strong>&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong>First</strong>: Load the texture into memory:&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">	</span><strong>void glTexImage2D(GLenum target, GLint level,&nbsp;</strong></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong><span class="Apple-tab-span" style="white-space:pre">		</span>GLint internalformat,&nbsp;</strong></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong><span class="Apple-tab-span" style="white-space:pre">		</span>GLsizei width, GLsizei height,&nbsp;</strong></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong><span class="Apple-tab-span" style="white-space:pre">		</span>GLint border,&nbsp;GLenum format,&nbsp;</strong></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong><span class="Apple-tab-span" style="white-space:pre">		</span>GLenum type, void *data);&nbsp;</strong></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier; min-height: 17.0px"><strong><span class="Apple-tab-span" style="white-space:pre">	</span></strong></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong><span class="Apple-tab-span" style="white-space:pre">	</span>target: GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D</strong></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong><span class="Apple-tab-span" style="white-space:pre">	</span>level: specifies the mipmap level being loaded, for non-mipmaped texutres always to <span class="Apple-tab-span" style="white-space:pre">		</span>set this to 0.&nbsp;</strong></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong><span class="Apple-tab-span" style="white-space:pre">	</span>internalformat: how many color components you want to store per texel.</strong></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 9.0px Helvetica; min-height: 11.0px"><img src="http://www.cppblog.com/images/cppblog_com/biao/texture1.png" id="" vspace="0" hspace="0" border="" align="baseline" alt="" longdesc=""></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong><span class="Apple-tab-span" style="white-space:pre">	</span>format: e.g. GL_RGB, GL_RGBA</strong></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong><span class="Apple-tab-span" style="white-space:pre">	</span>type: e.g. GL_UNSIGNED_BYTE, GL_BYTE, GL_FLOAT,&nbsp;</strong></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong><span class="Apple-tab-span" style="white-space:pre">	</span>data: picture data.</strong></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier; min-height: 17.0px"><strong></strong><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier">You should also be aware that OpenGL <strong>copies</strong> the texture information&nbsp;from&nbsp;data&nbsp;when you call one of these functions(after loading, delete the data array, the wanted data is copied into the memory).&nbsp;Loaded textures are not applied to geometry unless the appropriate texture state is&nbsp;enabled.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong>Second</strong>: specify texture coordinates.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">	</span><strong>glTexCoord2f(s, t);</strong></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier; min-height: 17.0px"><img src="http://www.cppblog.com/images/cppblog_com/biao/texture2.png" id="" vspace="0" hspace="0" border="" align="baseline" alt="" longdesc=""><img src="http://www.cppblog.com/images/cppblog_com/biao/texture3.png" id="" vspace="0" hspace="0" border="" align="baseline" alt="" longdesc=""><img src="http://www.cppblog.com/images/cppblog_com/biao/texture4.png" id="" vspace="0" hspace="0" border="" align="baseline" alt="" longdesc=""></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier">Texture matrix: glMatrixMode(GL_TEXTURE)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">	</span>texture coordinates can also be transformated, rotated, and even scaled.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong>coordinate&nbsp;wrapping, texture filters, and the texture environment.</strong></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong>glTexImage2D</strong>(GL_TEXTURE_2D, 0, iComponents, iWidth, iHeight,&nbsp;0, eFormat, GL_UNSIGNED_BYTE, pBytes);&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong>free</strong>(pBytes);&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong>glTexParameteri</strong>(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong>glTexParameteri</strong>(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong>glTexParameteri</strong>(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong>glTexParameteri</strong>(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong>glTexEnvi</strong>(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong>glEnable</strong>(GL_TEXTURE_2D);&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong>Texture environment</strong>: How OpenGL combines the colors from texels and the color of the underlying geometry.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong><span class="Apple-tab-span" style="white-space:pre">	</span>glTexEnvi</strong>(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier; min-height: 17.0px"><strong></strong><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong>GL_MODULATE</strong>:&nbsp;The modulate environment mode multiplies the texel color by the geometry color (after&nbsp;lighting calculations).</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong>GL_REPLACE</strong>: Simply replace the color of the underlying geometry.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong>GL_BLEND</strong>: If the texture has an alpha channel, you can enable blending. Otherwise GL_BLEND behavors the same way as GL_REPLACE.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier">Textures can also be blended with a constant blending color using the GL_BLENDtexture&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier">environment. If you set this environment mode, you must also set the texture environ-&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier">ment color:&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">	</span>GLfloat fColor[4] = { 1.0f, 0.0f, 0.0f, 0.0f };&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">	</span><strong>glTexEnvi</strong>(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, <strong>GL_BLEND</strong>);&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">	</span><strong>glTexEnvfv</strong>(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, <strong>fColor</strong>);&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong>GL_ADD</strong>: Simply add the texel color values to the color of the underlying fragment.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong>Texture Parameters</strong>:</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">	</span>GL_TEXTURE_MAG_FILTER, GL_TEXTURE_MIN_FILTER</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">	</span>GL_NEAREST, GL_LINE</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong><span class="Apple-tab-span" style="white-space:pre">	</span>glTexParameteri</strong>(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong><span class="Apple-tab-span" style="white-space:pre">	</span>glTexParameteri</strong>(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong>Texture Wrap(s, t)</strong>:</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier">Normally, you specify texture coordinates between 0.0 and 1.0 to map out the texels in a&nbsp;texture map. If texture coordinates fall out side this range, OpenGL handles them according to the current texture wrapping mode. You can set the <strong>wrap mode</strong> for each coordinate&nbsp;individually by calling <strong>glTexParameteri</strong>&nbsp;with&nbsp;<strong>GL_TEXTURE_WRAP_S</strong>, <strong>GL_TEXTURE_WRAP_T</strong>, or&nbsp;<strong>GL_TEXTURE_WRAP_R&nbsp;</strong>as the parameter name. The wrap mode can then be set to one of the&nbsp;following values: <strong>GL_REPEAT</strong>, <strong>GL_CLAMP</strong>, <strong>GL_CLAMP_TO_EDGE</strong>, or <strong>GL_CLAMP_TO_BORDER</strong>.&nbsp;The&nbsp;GL_REPEAT&nbsp;wrap mode simply causes the texture to repeat in the direction in which&nbsp;the texture coordinate has exceeded 1.0. The texture repeats again for every integer texture&nbsp;coordinate. <strong>This mode is very useful for applying a small tiled texture to large geometric&nbsp;surfaces</strong>.&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong>Toon-shading</strong>, which is often refered to <strong>cell-shading</strong>, idea:</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier">The basic idea is to use a s<strong>urface normal</strong> from the geometry and a <strong>vector to the light</strong>&nbsp;<strong>source</strong> to find the intensity of the light striking the surface of the model. The <strong>dot</strong> <strong>product</strong>&nbsp;of these two vectors gives a value between 0.0 and 1.0 and is used as a one dimensional&nbsp;texture coordinate.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong>Mipmapping(many things in a small space)</strong>:</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier">Mipmappingis a powerful texturing technique that can improve both the rendering performance and the visual quality of a scene.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier">In essence, you load not a single image into the texture state, but a whole series of images from lagerest to smallest into a single "mipmapped" texture state. OpenGL use a new set of filter modes to choose the best-fitting texture or textures for given geometry.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier">Using a square set of mipmapps requires about one-third more memory than not using mipmapps.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier">Each one half the size of the previous image.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px STHeiti Light">自动生成的<span style="font: 14.0px Courier"><strong>, </strong></span>质量比较差的<span style="font: 14.0px Courier"><strong>Mipmaps:</strong></span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong>gluBuild2DMipmaps:</strong> it automatically creates the scaled images for you and loads them&nbsp;appropriately with glTexImage.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">	</span>int <strong>gluBuild2DMipmaps</strong>(GLenum target, GLint internalFormat,&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span>GLint width, GLint height,&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span>GLenum format, GLenum type, const void *data);&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier">You should also be aware that using these functions may not produce mip&nbsp;level images with the same quality you can obtain with other tools such as Photoshop.&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px STHeiti Light">自动生成的<span style="font: 14.0px Courier"><strong>, </strong></span>质量比较好的<span style="font: 14.0px Courier"><strong>Mipmaps:</strong></span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier">With newer versions of the GLU library, you can also obtain a finer-grained control over&nbsp;which mip levels are loaded with these functions:</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">	</span>int <strong>gluBuild2DMipmapLevels</strong>(GLenum target, GLint internalFormat,&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span>GLint width, GLint height,&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span>GLenum format, GLenum type, GLint level,&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span>GLint base, GLint max, const void *data);&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier">With these functions, <strong>level</strong>&nbsp;is the mip level specified by the data&nbsp;parameter. This texture&nbsp;data is used to build mip levels <strong>base</strong>&nbsp;through&nbsp;<strong>max</strong>.&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 12.0px Helvetica; min-height: 14.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><span style="font: 14.0px STHeiti Light">使用硬件加速生成</span><strong>Mipmaps(</strong><span style="font: 14.0px STHeiti Light">对于整个场境都使用</span><strong>mipmaps):</strong></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong>Hardware Generation of Mipmaps:</strong>&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier">If you know beforehand that you <strong>want all mip levels loaded</strong>, you can also use OpenGL&nbsp;hardware acceleration to quickly generate all the necessary mip levels. You do so by setting&nbsp;the texture parameter <strong>GL_GENERATE_MIPMAP&nbsp;to&nbsp;GL_TRUE</strong>:&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">	</span><strong>glTexParameteri</strong>(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier">When this parameter is set, all calls to glTexImage&nbsp;or&nbsp;glTexSubImage&nbsp;that update the base&nbsp;texture map (<strong>mip level 0</strong>) automatically update all the lower mip levels. By making use of&nbsp;the graphics hardware, this feature is substantially faster than using gluBuildMipmaps.&nbsp;However, you should be aware that this feature was originally an extension and was&nbsp;promoted to the OpenGL core API only as of version 1.4. This is definitely the fastest and&nbsp;easiest way to build mipmaps on-the-fly.&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><strong>Texture Objects:</strong></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier">Loading and maintaining the <strong>texture state</strong>&nbsp;occupies a considerable portion of many texture-heavy OpenGL applications (games in&nbsp;particular).&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier">Texture objects allow you to load up more than one texture state at a time.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><span style="font: 14.0px STHeiti Light">为</span><strong>texture</strong><span style="font: 14.0px STHeiti Light">对象分配内存</span><strong>:</strong></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier">You allocate a number of texture objects with the following function:&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">	</span><strong>void glGenTextures(GLsizei n, GLuint *textures);&nbsp;</strong></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier">With this function, you specify the <strong>number of texture objects</strong> and a pointer to an array of&nbsp;unsigned integers that will be populated with the <strong>texture object identifiers</strong>.&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px STHeiti Light">指定<span style="font: 14.0px Courier"><strong>texture</strong></span>对象<span style="font: 14.0px Courier"><strong>(</strong></span>用一个整数来标志一个纹理对象<span style="font: 14.0px Courier"><strong>):</strong></span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">	</span><strong>void glBindTexture(GLenum target, GLuint texture);&nbsp;</strong></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier">The&nbsp;target&nbsp;parameter needs to specify GL_TEXTURE_1D, <strong>GL_TEXTURE_2D</strong>, or GL_TEXTURE_3D,&nbsp;and&nbsp;textureis the specific texture object to bind to. Hereafter, <strong>all texture loads and&nbsp;texture parameter settings affect only the currently bound texture object.</strong>&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><span style="font: 14.0px STHeiti Light">每一个</span>texture<span style="font: 14.0px STHeiti Light">都要设置自己的</span>parameter, <span style="font: 14.0px STHeiti Light">因为每个</span>parameter<span style="font: 14.0px STHeiti Light">只对某个绑定的</span>texture<span style="font: 14.0px STHeiti Light">有效</span>.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px STHeiti Light">删除<span style="font: 14.0px Courier"><strong>texture</strong></span>对象的内存空间<span style="font: 14.0px Courier"><strong>, </strong></span>释放内存<span style="font: 14.0px Courier"><strong>:</strong></span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier">To delete texture&nbsp;objects, you call the following function:&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">	</span><strong>void glDeleteTextures(GLsizei n, GLuint *textures);&nbsp;</strong></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier">Calling glDeleteTextures&nbsp;multiple times may&nbsp;incur some delay, but only because you are deallocating possibly large amounts of texture&nbsp;memory.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px STHeiti Light">测试是否有效的<span style="font: 14.0px Courier"><strong>texture, </strong></span>如被删除后<span style="font: 14.0px Courier"><strong>:</strong></span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier">You can test texture object names (or handles) to see whether they are valid by using the&nbsp;following function:&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">	</span><strong>GLboolean glIsTexture(GLuint texture);&nbsp;</strong></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 14.0px Courier">This function returns GL_TRUE&nbsp;if the integer is a previously allocated texture object name&nbsp;or&nbsp;GL_FALSE&nbsp;if not.</p></strong></div></span></div><img src ="http://www.cppblog.com/biao/aggbug/86389.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2009-06-01 13:52 <a href="http://www.cppblog.com/biao/archive/2009/06/01/86389.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>OpenGL: 图片的浮雕效果(Embossed effect)</title><link>http://www.cppblog.com/biao/archive/2009/05/30/86171.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Sat, 30 May 2009 07:19:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2009/05/30/86171.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/86171.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2009/05/30/86171.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/86171.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/86171.html</trackback:ping><description><![CDATA[<div>源图片:</div><img src="http://www.cppblog.com/images/cppblog_com/biao/embossedEffect_source.png" id="" vspace="0" hspace="0" border="" align="baseline" alt="" longdesc="">

<div>效果图:</div><div><img src="http://www.cppblog.com/images/cppblog_com/biao/embossedEffect_result.png" id="" vspace="0" hspace="0" border="" align="baseline" alt="" longdesc=""></div><div><br></div><div>算法:</div><img src="http://www.cppblog.com/images/cppblog_com/biao/embossedEffect_algorithmu.png" id="" vspace="0" hspace="0" border="" align="baseline" alt="" longdesc="">&nbsp;<div><br></div><img src ="http://www.cppblog.com/biao/aggbug/86171.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2009-05-30 15:19 <a href="http://www.cppblog.com/biao/archive/2009/05/30/86171.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>OpenGL: Fog</title><link>http://www.cppblog.com/biao/archive/2009/05/24/85564.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Sat, 23 May 2009 20:28:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2009/05/24/85564.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/85564.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2009/05/24/85564.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/85564.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/85564.html</trackback:ping><description><![CDATA[
<span style="font-family: Courier; font-size: 14px; line-height: 20px; "><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span style="font-family: Courier; font-size: 14px; "><span style="font-weight: bold; ">Fog:</span></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span style="font-family: Courier; font-size: 14px; "><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">The amount of the fog color mixed with the geometry varies with the distance</span><span style="font: normal normal normal 12px/normal Helvetica; "><span style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">&nbsp;of the geometry from the&nbsp;<span style="font-weight: bold; ">camera origin</span>.&nbsp;</span></span></div></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span style="font-family: Courier; font-size: 14px; "><span class="Apple-tab-span" style="white-space: pre; ">	</span>glEnable(GL_FOG);<br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span style="font-family: Courier; font-size: 14px; "><span class="Apple-tab-span" style="white-space: pre; ">	</span>glFogfv(GL_FOG_COLOR, fogColor);<br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span style="font-family: Courier; font-size: 14px; "><span class="Apple-tab-span" style="white-space: pre; ">	</span>// GL_FOG_START and GL_FOG_END only for GL_LINEAR.</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span style="font-family: Courier; font-size: 14px; "><span class="Apple-tab-span" style="white-space: pre; ">	</span>glFogf(GL_FOG_START, 5.0f);<br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span style="font-family: Courier; font-size: 14px; "><span class="Apple-tab-span" style="white-space: pre; ">	</span>glFogf(GL_FOG_END, 30.0f);<br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span style="font-family: Courier; font-size: 14px; "><span class="Apple-tab-span" style="white-space: pre; ">	</span>glFogi(GL_FOG_MODE, GL_LINEAR); // Which fog equation to use.</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span style="font-family: Courier; font-size: 14px; "><br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span style="font-family: Courier; font-size: 14px; "><span class="Apple-tab-span" style="white-space: pre; ">	</span>glHint(GL_FOG_HINT, GL_NICEST); // 计算方式.<br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span style="font-family: Courier; font-size: 14px; "><br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span style="font-family: Courier; font-size: 14px; "><span class="Apple-tab-span" style="white-space: pre; ">	</span>// GL_EXP, GL_EXP2: 需要fog density</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span style="font-family: Courier; font-size: 14px; "><span class="Apple-tab-span" style="white-space: pre; ">	</span>glFogF(GL_FOG_DENSITY, 0.5f);<br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span style="font-family: Courier; font-size: 14px; "><span class="Apple-tab-span" style="white-space: pre; ">	</span><img src="http://www.cppblog.com/images/cppblog_com/biao/FogMode.png" id="" vspace="0" hspace="0" border="" align="baseline" alt="" longdesc=""></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span style="font-family: Courier; font-size: 14px; line-height: 20px; "><span class="Apple-tab-span" style="white-space: pre; ">	</span>d: fog density.<br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span style="font-family: Courier; font-size: 14px; line-height: 20px; "><span class="Apple-tab-span" style="white-space: pre; ">	</span>c: (z) the distance in eye coordinates from origin to fragment being fogged.</span><span style="line-height: 20px; "><span style="line-height: normal; "><span style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; "></span></span></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span style="line-height: 20px; "><span style="line-height: normal; "><span style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; "><span class="Apple-tab-span" style="white-space: pre; "><span style="line-height: 20px; ">	</span></span>c: is the distance of the fragment from the eye plane.</span></span></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span style="font-family: Courier; font-size: 14px; "><br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span style="font-family: Courier; font-size: 14px; "><span class="Apple-tab-span" style="white-space: pre; ">	</span>Density: 0.5f<br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span style="font-family: Courier; font-size: 14px; "><span class="Apple-tab-span" style="white-space: pre; ">	</span><img src="http://www.cppblog.com/images/cppblog_com/biao/FogDensityEquation.png" id="" vspace="0" hspace="0" border="" align="baseline" alt="" longdesc=""></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span style="font-family: Courier; font-size: 14px; "><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">The parameter&nbsp;</span><span style="font: normal normal normal 8px/normal Helvetica; "><span style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">GL_FOG_START&nbsp;</span></span><span style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">specifies how far away&nbsp;<span style="font-weight: bold; ">from the eye</span>&nbsp;fogging begins to take&nbsp;</span><span style="font: normal normal normal 12px/normal Helvetica; "><span style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; "><span style="background-color: transparent; color: black; ">effect, and&nbsp;</span><span style="font: normal normal normal 8px/normal Helvetica; "><span style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">GL_FOG_END&nbsp;</span></span><span style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">is the distance from the eye where the fog color completely over-&nbsp;</span><span style="font: normal normal normal 12px/normal Helvetica; "><span style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">powers the color of the object(如果再远, 物体完全被fog color给遮盖).</span></span></span></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; "><br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">Regardless of the fog mode,&nbsp;f&nbsp;is clamped to the range [0,1] after it is computed. Then, if the GL is in RGBA color mode, the fragment's color&nbsp;Cr&nbsp;is replaced by</span></div></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span style="font-family: Courier; font-size: 14px; "><span class="Apple-tab-span" style="white-space: pre; ">	</span><img src="http://www.cppblog.com/images/cppblog_com/biao/FogColor.png" id="" vspace="0" hspace="0" border="" align="baseline" alt="" longdesc=""></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span style="font-family: Courier; font-size: 14px; line-height: 20px; "><br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span style="font-family: Courier; font-size: 14px; "><span style="font-weight: bold; ">Fog Coordinates:</span>&nbsp;For example, you want to elevation to play a role, lending to volumetric fog effects.</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span style="font-family: Courier; font-size: 14px; "><span class="Apple-tab-span" style="white-space: pre; ">	</span>void glFogCoordf(GLfloat fFogDistance);<br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span style="font-family: Courier; font-size: 14px; "><span class="Apple-tab-span" style="white-space: pre; ">	</span>glFogi(GL_FOG_COORD_SRC, GL_FOG_COORD);<br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span style="font-family: Courier; font-size: 14px; "><br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span style="font-family: Courier; font-size: 14px; "><span class="Apple-tab-span" style="white-space: pre; ">	</span>return to OpenGL-drived fog effects:<br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span style="font-family: Courier; font-size: 14px; "><span class="Apple-tab-span" style="white-space: pre; ">	</span>glFogi(GL_FOG_COORD_SRC, GL_FRAGMENT_DEPTH);</span></div></span><img src ="http://www.cppblog.com/biao/aggbug/85564.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2009-05-24 04:28 <a href="http://www.cppblog.com/biao/archive/2009/05/24/85564.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>OpenGL: 累积缓存: Accumulation Buffer</title><link>http://www.cppblog.com/biao/archive/2009/05/24/85562.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Sat, 23 May 2009 19:35:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2009/05/24/85562.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/85562.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2009/05/24/85562.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/85562.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/85562.html</trackback:ping><description><![CDATA[<div><span  style="font-family: Courier; font-size: 14px; line-height: 20px; "><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; "><span  style="font-weight: bold; ">Accumulation Buffer(非时实绘制情况下, 做全局反锯齿的效果最好, 运动模糊):</span></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; ">Color Buffer, Depth Buffer, Stencil Buffer, Accumulation Buffer, (Double Buffer, ^_^)</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; "><br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; "><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; ">glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_ACCUM);&nbsp;</div></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; "><br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; "><span  style="font-weight: bold; ">The accumulation buffer is an extended-range color buffer. Images are not rendered into it. Rather, images rendered into one of the color buffers are added to the contents of the accumulation buffer after rendering. Effects such as antialiasing (of points, lines, and polygons), motion blur, and depth of field can be created by accumulating images generated with different transformation matrices.</span></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="font-family: Times; font-size: 23px; "><br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; "><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">This buffer allows you to render to the color buffer, and then instead</span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">&nbsp;<span  style="background-color: transparent; color: black; ">of displaying the results in the window, copy the contents of the color buffer to the accu</span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; "><span  style="background-color: transparent; color: black; ">mulation buffer. Several supported copy operations allow you to repeatedly blend, in</span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">&nbsp;<span  style="background-color: transparent; color: black; ">different ways, the color buffer contents with the accumulated contents in the accumula</span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">tion buffer (thus its name). When you have finished accumulating an image, you can&nbsp;<span  style="background-color: transparent; color: black; ">then copy the accumulation buffer back to the color buffer and display the results with a</span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">&nbsp;<span  style="background-color: transparent; color: black; ">buffer swap.</span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">&nbsp;</span></span></span></span></span></span></span></span></span></span></span></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; ">也是很简单的几步, 但是要把同一个物体多画几次, 累积出motion blur效果, 会占用很多内存与资源.</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; "><br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; "><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">Because of the l<span  style="font-weight: bold; ">arge amount of memory</span>&nbsp;that must be copied and processed for accumula</span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; "><span  style="background-color: transparent; color: black; ">tion buffer operations, few real-time applications make use of this capability. For<span  style="font-weight: bold; ">&nbsp;non-</span></span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; "><span  style="background-color: transparent; color: black; "><span  style="font-weight: bold; ">real-time rendering</span>, OpenGL can produce some&nbsp;<span  style="font-weight: bold; ">astonishing effects</span>&nbsp;that you might not</span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">&nbsp;<span  style="background-color: transparent; color: black; ">expect from a real-time API. For example, you can render a scene multiple times and move</span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">&nbsp;the point of view around by a fraction of a pixel each time.&nbsp;<span  style="background-color: transparent; color: black; ">Accumulating these multiple</span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">&nbsp;<span  style="background-color: transparent; color: black; ">rendering passes&nbsp;<span  style="font-weight: bold; ">blurs the sharp edges</span>&nbsp;and can produce an&nbsp;<span  style="font-weight: bold; ">entire scene fully antialiased</span></span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">&nbsp;<span  style="background-color: transparent; color: black; ">with a quality that surpasses anything that can be done with multisampling. You can also</span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">&nbsp;<span  style="background-color: transparent; color: black; ">use this blurring effect to blur the background or foreground of an image and then render</span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">&nbsp;the object of focus clearly afterward, simulating some depth-of-field camera effects.</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></div></span></div></span></div></div><div><br></div><div>操作:&nbsp;</div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">In our sample program MOTIONBLUR, we will demonstrate yet another use of the accu</span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; "><span  style="background-color: transparent; color: black; ">mulation buffer to create what appears to be a&nbsp;<span  style="font-weight: bold; ">motion blur effect</span>. A moving sphere is</span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">&nbsp;<span  style="background-color: transparent; color: black; "><span  style="font-weight: bold; ">drawn repeatedly in different positions</span>. Each time it is drawn, it is accumulated to the&nbsp;</span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; "><span  style="background-color: transparent; color: black; ">accumulation buffer, with a smaller weight on subsequent passes. The result is a brighter&nbsp;</span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">red sphere with a ghostlike image of itself following along behind.</span></span></span></span></span></span></span></span></div></div></span></div><img src="http://www.cppblog.com/images/cppblog_com/biao/AccumulationBuffer.png" id="" vspace="0" hspace="0" border="" align="baseline" alt="" longdesc="">

<div><span  style="font-family: Courier; font-size: 14px; line-height: 20px; "><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">Shows the&nbsp;</span><span style="font: normal normal normal 8px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">DrawGeometry&nbsp;</span></span><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">function, which draws all the geometry of the scene.</span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">&nbsp;</span></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">The&nbsp;</span><span style="font: normal normal normal 8px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">RenderScene&nbsp;</span></span><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">function then repeatedly calls this function and accumulates the results&nbsp;</span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; "><span  style="background-color: transparent; color: black; ">into the accumulation buffer. When that process is finished, the lines</span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">&nbsp;<span  style="background-color: transparent; color: black; "></span></span></span></span></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; "><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; "><span  style="background-color: transparent; color: black; "><span class="Apple-tab-span" style="white-space: pre; ">	</span>glAccum(GL_RETURN, 1.0f);</span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">&nbsp;</span></span></span></span></span></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 8px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; "><span class="Apple-tab-span" style="white-space: pre; ">	</span>glutSwapBuffers();</span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">&nbsp;</span></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">copy the accumulation buffer back to the color buffer and perform the buffer swap.</span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">&nbsp;</span></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; "><span  style="font-weight: bold; ">Using the Accumulation Buffer for Motion Blur:</span></span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; "><span  style="font-weight: bold; ">&nbsp;</span></span></span></div><div><span  style="font-family: Helvetica; font-size: 12px; line-height: normal; "><br></span></div></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; color: rgb(63, 127, 95); ">/////////////////////////////////////////////////////////////&nbsp;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; color: rgb(63, 127, 95); ">// Draw the ground and the revolving sphere&nbsp;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; "><span style="color: rgb(127, 0, 85); "><strong>void</strong></span>&nbsp;<strong>DrawGeometry</strong>(<span style="color: rgb(127, 0, 85); "><strong>void</strong></span>) {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; color: rgb(63, 127, 95); "><span style="color: rgb(0, 0, 0); ">&nbsp; &nbsp;&nbsp;</span>// Clear the window with current clearing color&nbsp;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; ">&nbsp; &nbsp;&nbsp;glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; ">&nbsp; &nbsp;&nbsp;glPushMatrix();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; ">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;DrawGround();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; color: rgb(63, 127, 95); "><span style="color: rgb(0, 0, 0); ">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span>// Place the moving sphere&nbsp;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; ">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;glColor3f(1.0f, 0.0f, 0.0f);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; ">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;glTranslatef(0.0f, 0.5f, -3.5f);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; ">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;glRotatef(-(yRot * 2.0f), 0.0f, 1.0f, 0.0f);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; ">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;glTranslatef(1.0f, 0.0f, 0.0f);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; ">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;glutSolidSphere(0.1f, 17, 9);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; ">&nbsp; &nbsp;&nbsp;glPopMatrix();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; ">}</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; min-height: 17px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; color: rgb(63, 127, 95); ">///////////////////////////////////////////////////////////////////////&nbsp;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; color: rgb(63, 127, 95); ">// Called to draw scene. The world is drawn multiple times with each&nbsp;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; color: rgb(63, 127, 95); ">// frame blended with the last. The current rotation is advanced each&nbsp;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; color: rgb(63, 127, 95); ">// time to create the illusion of motion blur.&nbsp;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; "><span style="color: rgb(127, 0, 85); "><strong>void</strong></span>&nbsp;<strong>RenderScene</strong>(<span style="color: rgb(127, 0, 85); "><strong>void</strong></span>) {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; ">&nbsp; &nbsp;&nbsp;GLfloat fPass;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; ">&nbsp; &nbsp;&nbsp;GLfloat fPasses = 10.0f;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; color: rgb(63, 127, 95); "><span style="color: rgb(0, 0, 0); ">&nbsp; &nbsp;&nbsp;</span>// Set the current rotation back a few degrees&nbsp;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; ">&nbsp; &nbsp;&nbsp;yRot = 35.0f;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; ">&nbsp; &nbsp;&nbsp;<span style="color: rgb(127, 0, 85); "><strong>for</strong></span>&nbsp;(fPass = 0.0f; fPass &lt; fPasses; fPass += 1.0f) {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; color: rgb(63, 127, 95); "><span style="color: rgb(0, 0, 0); ">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;yRot += .75f;&nbsp;</span>//1.0f / (fPass+1.0f);&nbsp;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; color: rgb(63, 127, 95); "><span style="color: rgb(0, 0, 0); ">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span>// Draw sphere&nbsp;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; ">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;DrawGeometry();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; color: rgb(63, 127, 95); "><span style="color: rgb(0, 0, 0); ">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span>// Accumulate to back buffer&nbsp;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; ">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span style="color: rgb(127, 0, 85); "><strong>if</strong></span>&nbsp;(fPass == 0.0f)</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; ">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;glAccum(GL_LOAD, 0.5f);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; ">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span style="color: rgb(127, 0, 85); "><strong>else</strong></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; ">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;glAccum(GL_ACCUM, 0.5f * (1.0f / fPasses));</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; ">&nbsp; &nbsp;&nbsp;}</div><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; min-height: 17px; ">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; color: rgb(63, 127, 95); "><span style="color: rgb(0, 0, 0); ">&nbsp; &nbsp;&nbsp;</span>// copy accumulation buffer to color buffer and&nbsp;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; color: rgb(63, 127, 95); "><span style="color: rgb(0, 0, 0); ">&nbsp; &nbsp;&nbsp;</span>// do the buffer Swap&nbsp;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; ">&nbsp; &nbsp;&nbsp;glAccum(GL_RETURN, 1.0f);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; ">&nbsp; &nbsp;&nbsp;glutSwapBuffers();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; ">}&nbsp;</div></div><div><br></div><div><br></div><div><br></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; "><span style="color: rgb(127, 0, 85); "><strong>void</strong></span>&nbsp;<strong>glAccum</strong>(GLenumm op, GLfloat value);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 14px/normal Courier; "><br></div></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 8px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; "><span class="Apple-tab-span" style="white-space: pre; ">				</span><span  style="font-weight: bold; ">Operation Description</span></span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; "><span  style="font-weight: bold; ">&nbsp;</span></span></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 8px/normal Helvetica; "><span style="font: normal normal normal 7px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; "><span  style="font-weight: bold; ">GL_ACCUM</span></span></span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">&nbsp;<span class="Apple-tab-span" style="white-space: pre; ">	</span></span></span><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">Scales the color buffer values by value and adds them to the current&nbsp;<span class="Apple-tab-span" style="white-space: pre; ">			</span>contents</span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">&nbsp;<span  style="background-color: transparent; color: black; ">of the accumulation buffer.</span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">&nbsp;</span></span></span></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 8px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; font-weight: bold; "><br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 8px/normal Helvetica; "><span style="font: normal normal normal 7px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; "><span  style="font-weight: bold; ">GL_LOAD</span></span></span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">&nbsp;<span class="Apple-tab-span" style="white-space: pre; ">	</span></span></span><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">Scales the color buffer values by value and&nbsp;<span  style="font-weight: bold; ">replaces</span>&nbsp;the current contents&nbsp;<span class="Apple-tab-span" style="white-space: pre; ">		</span>of</span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">&nbsp;<span  style="background-color: transparent; color: black; ">the accumulation buffer.</span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">&nbsp;</span></span></span></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 8px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; font-weight: bold; "><br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 8px/normal Helvetica; "><span style="font: normal normal normal 7px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; "><span  style="font-weight: bold; ">GL_RETURN</span></span></span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">&nbsp;<span class="Apple-tab-span" style="white-space: pre; ">	</span></span></span><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">Scales the color values from the accumulation buffer by value and then</span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">&nbsp;</span></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 8px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; "><span class="Apple-tab-span" style="white-space: pre; ">		</span>copies the values to the color buffer.</span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">&nbsp;</span></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 8px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; font-weight: bold; "><br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 8px/normal Helvetica; "><span style="font: normal normal normal 7px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; "><span  style="font-weight: bold; ">GL_MULT</span></span></span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">&nbsp;<span class="Apple-tab-span" style="white-space: pre; ">	</span></span></span><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">Scales the color values in the accumulation buffer by value and stores the</span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">&nbsp;</span></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 8px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; "><span class="Apple-tab-span" style="white-space: pre; ">		</span>result in the accumulation buffer.</span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">&nbsp;</span></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 8px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; font-weight: bold; "><br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 8px/normal Helvetica; "><span style="font: normal normal normal 7px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; "><span  style="font-weight: bold; ">GL_ADD</span></span></span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">&nbsp;<span class="Apple-tab-span" style="white-space: pre; ">		</span></span></span><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">Scales the color values in the accumulation buffer by value and adds the</span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">&nbsp;</span></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 8px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; "><span class="Apple-tab-span" style="white-space: pre; ">		</span>result to the current accumulation buffer contents.</span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">&nbsp;</span></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 8px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; "><br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 8px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; ">How to scale: ***</span></div><div><span  style="line-height: normal;"><br></span></div></div></span></div><img src ="http://www.cppblog.com/biao/aggbug/85562.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2009-05-24 03:35 <a href="http://www.cppblog.com/biao/archive/2009/05/24/85562.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>OenGL: 求法线(使物体表面平滑的顶点的法线)</title><link>http://www.cppblog.com/biao/archive/2009/05/23/85512.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Sat, 23 May 2009 07:27:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2009/05/23/85512.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/85512.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2009/05/23/85512.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/85512.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/85512.html</trackback:ping><description><![CDATA[
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:258;"><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #2a00ff"><span style="color: #7f0055"><strong>#include</strong></span><span style="color: #000000"> </span>"Vector3f.h"</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #7f0055"><strong>#include</strong><span style="color: #000000"> </span><span style="color: #2a00ff">&lt;cmath&gt;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><strong>Vector3f::Vector3f</strong>(<span style="color: #7f0055"><strong>float</strong></span> x, <span style="color: #7f0055"><strong>float</strong></span> y, <span style="color: #7f0055"><strong>float</strong></span> z) {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #7f0055"><strong>this</strong></span>-&gt;x = x;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #7f0055"><strong>this</strong></span>-&gt;y = y;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #7f0055"><strong>this</strong></span>-&gt;z = z;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">Vector3f <strong>Vector3f::crossProduct</strong>(<span style="color: #7f0055"><strong>const</strong></span> Vector3f &amp;v) {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #7f0055"><strong>float</strong></span> nx = y * v.z - z * v.y; <span style="color: #3f7f5f">// y-&gt;z</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #7f0055"><strong>float</strong></span> ny = z * v.x - x * v.z; <span style="color: #3f7f5f">// z-&gt;x</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #7f0055"><strong>float</strong></span> nz = x * v.y - y * v.x; <span style="color: #3f7f5f">// x-&gt;y</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #7f0055"><strong>return</strong></span> Vector3f(nx, ny, nz);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f">/**</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f">&nbsp; * Given three points in the order counter-clockwise.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f">&nbsp; */</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">Vector3f <strong>calculateNormal</strong>(<span style="color: #7f0055"><strong>const</strong></span> Point3f &amp;p1, <span style="color: #7f0055"><strong>const</strong></span> Point3f &amp;p2, <span style="color: #7f0055"><strong>const</strong></span> Point3f &amp;p3) {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; Vector3f vector1(p2.x - p1.x, p2.y - p1.y, p2.z - p1.z);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; Vector3f vector2(p3.x - p1.x, p3.y - p1.y, p3.z - p1.z);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #7f0055"><strong>return</strong></span> vector1.crossProduct(vector2);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">Vector3f <strong>normalize</strong>(<span style="color: #7f0055"><strong>const</strong></span> Vector3f &amp;v) {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #7f0055"><strong>float</strong></span> length = sqrt(v.x * v.x + v.y * v.y + v.z * v.z);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #7f0055"><strong>if</strong></span> (length &gt;= -0.001f &amp;&amp; length &lt;= 0.001f) {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7f0055"><strong>return</strong></span> Vector3f(0.0f, 0.0f, 0.0f);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; }</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #7f0055"><strong>return</strong></span> Vector3f(v.x / length, v.y / length, v.z / length);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">}</p></p><p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">如果是给组成物体的每个小平面都指定一条法线的话, 最后使用光照后得到的物体表面是faceted&nbsp;jewel(像有小面的珠宝似的), 使得物体表面不是平滑的. 解决这个问题的办法是给每个顶点指点一条法线, 而不是给每个小平面指定法线: 先计算每个小平面的法线. 然后再用这些面的法线来计算顶点的法线:<!--EndFragment--></p><p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><span class="Apple-tab-span" style="white-space:pre">	</span>共享有这个顶点的所有小平面的法线的平均值就是这个顶点的法线(近似).</p>
<img src ="http://www.cppblog.com/biao/aggbug/85512.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2009-05-23 15:27 <a href="http://www.cppblog.com/biao/archive/2009/05/23/85512.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>OpenGL: 反锯齿</title><link>http://www.cppblog.com/biao/archive/2009/05/23/85510.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Sat, 23 May 2009 07:14:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2009/05/23/85510.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/85510.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2009/05/23/85510.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/85510.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/85510.html</trackback:ping><description><![CDATA[<div><span  style="font-family: Courier; font-size: 14px; line-height: 20px; "><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; "><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; "><span  style="font-weight: bold; ">Antialiasing</span></span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">&nbsp;</span></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">Another use for OpenGL&#8217;s blending capabilities is antialiasing.&nbsp;</span></div></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; ">Turning on antialiasing is simple.&nbsp;</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; "><span class="Apple-tab-span" style="white-space: pre; ">	</span><span  style="font-weight: bold; ">First</span>: you must enable blending and set the blending function.<br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; "><span class="Apple-tab-span" style="white-space: pre; ">		</span>glEnable(GL_BLEND);<br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; "><span class="Apple-tab-span" style="white-space: pre; ">		</span>glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);<br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; "><br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; "><span class="Apple-tab-span" style="white-space: pre; ">	</span><span  style="font-weight: bold; ">Second</span>: choose to antialias points, lines, and/or polygons(any solid primitive) by&nbsp;<span class="Apple-tab-span" style="white-space: pre; ">	</span>calling glEnable:<br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; "><span class="Apple-tab-span" style="white-space: pre; ">		</span>glEnable(GL_POINT_SMOOTH);&nbsp;<span class="Apple-tab-span" style="white-space: pre; ">	</span>// Smooth out points.(smooth out: 使平滑)<br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; "><span class="Apple-tab-span" style="white-space: pre; ">		</span>glEnable(GL_LINE_SMOOTH);<span class="Apple-tab-span" style="white-space: pre; ">	</span>// Smooth out lines.<br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; "><span class="Apple-tab-span" style="white-space: pre; ">		</span>glEnable(GL_POLYGON_SMOOTH);<span class="Apple-tab-span" style="white-space: pre; ">	</span>// Smooth out polygon edges.<br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; "><span class="Apple-tab-span" style="white-space: pre; ">	</span><br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; "><span class="Apple-tab-span" style="white-space: pre; ">	</span><span  style="font-weight: bold; ">Third</span>: give hint to do the best job possible:<br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; "><span class="Apple-tab-span" style="white-space: pre; ">		</span>glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);<br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; "><br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; "><br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; ">Solid objects antialiasing called "<span  style="font-weight: bold; ">multisampling</span>", more tedious rules.</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; "><br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; "><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">Point and line</span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">&nbsp;<span  style="background-color: transparent; color: black; ">smoothing is widely supported, but&nbsp;<span  style="font-weight: bold; ">unfortunately polygon smoothing is not available on</span></span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; "><span  style="font-weight: bold; ">&nbsp;</span><span  style="background-color: transparent; color: black; "><span  style="font-weight: bold; ">all platforms.</span>&nbsp;Even when&nbsp;</span><span style="font: normal normal normal 8px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; "><span  style="font-weight: bold; ">GL_POLYGON_SMOOTH</span>&nbsp;</span></span><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">is available, it is not as convenient a means</span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">&nbsp;<span  style="background-color: transparent; color: black; ">of having your whole scene antialiased as you might think. Because it is&nbsp;<span  style="font-weight: bold; ">based on the</span></span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; "><span  style="font-weight: bold; ">&nbsp;blending operation</span>, you would need to sort all your primitives from front to back! Yuck.</span></span></span></span></span></span></span></span></div></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; "><br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; "><br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; "><span  style="font-weight: bold; ">Multisample(抽样)</span>:</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; "><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">A more recent addition to OpenGL to address this shortcoming is&nbsp;<span  style="font-weight: bold; ">multisampling</span>.</span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">&nbsp;</span></span><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">When</span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">&nbsp;<span  style="background-color: transparent; color: black; ">this feature is supported (it is an OpenGL 1.3 feature),&nbsp;<span  style="font-weight: bold; ">an additional buffer</span>&nbsp;is added to the&nbsp;</span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; "><span  style="background-color: transparent; color: black; "><span  style="font-weight: bold; ">framebuffer</span>&nbsp;that&nbsp;<span  style="font-weight: bold; ">includes the</span>&nbsp;<span  style="font-weight: bold; ">color, depth, and stencil values</span>. All primitives are sampled&nbsp;</span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">multiple times per pixel, and the results are stored in this buffer.</span></span></span></span></span></span></div></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; "><br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; "><span  style="font-weight: bold; ">First</span>: you must obtain a rendering context that has support for a multisampled framebuffer.</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span class="Apple-tab-span" style="white-space: pre; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">	</span></span><span  style="line-height: 20px; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; "><span  style="font-weight: bold; ">setFormat(QGLFormat(QGL::DoubleBuffer&nbsp;| QGL::DepthBuffer&nbsp;| QGL::SampleBuffers));</span></span></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; "><span  style="font-weight: bold; ">Second</span>: turn multisampling on or off:</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; "><span class="Apple-tab-span" style="white-space: pre; ">	</span><span  style="font-weight: bold; ">glEnable(GL_MULTISAMPLE);&nbsp;</span>// glDisable(GL_MULTISAMPLE);<br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; "><br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; "><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">Another important note about multisampling is that when it is enabled, the point, line,</span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">&nbsp;and polygon smoothing features are ignored if enabled.<span  style="background-color: transparent; color: black; ">&nbsp;On a given OpenGL implementa</span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; "><span  style="background-color: transparent; color: black; ">tion, points and lines may look better with smoothing turned on instead of multisam</span><span style="font: normal normal normal 12px/normal Helvetica; "><span  style="background-color: transparent; font-family: Courier; font-size: 14px; color: black; ">pling.</span></span></span></span></span></span></div></span></div></span></div><div><span  style="font-family: Courier; font-size: 14px; line-height: 20px; "><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; "><span  style="font-family: Courier; font-size: 14px; ">实体图形效果非常的好啊, 比使用前面的antialiasing好非常多. 而且就上面两步搞定. 但对于点和线来说, 使用smoothing的效果却比multisampling的效果好, 所以要看情况来定.</span></div></span></div><img src="http://www.cppblog.com/images/cppblog_com/biao/multisampling.png" id="" width="680" height="702" vspace="0" hspace="0" border="" align="baseline" alt="" longdesc="">
<img src ="http://www.cppblog.com/biao/aggbug/85510.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2009-05-23 15:14 <a href="http://www.cppblog.com/biao/archive/2009/05/23/85510.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Qt: OpenGL模板</title><link>http://www.cppblog.com/biao/archive/2009/05/19/83379.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Tue, 19 May 2009 07:15:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2009/05/19/83379.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/83379.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2009/05/19/83379.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/83379.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/83379.html</trackback:ping><description><![CDATA[
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><font color="#7F0055"><strong>==================================[GLWidget.h]==================================</strong></font></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span style="color: #7f0055"><strong>#ifndef</strong></span> GLWIDGET_H</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span style="color: #7f0055"><strong>#define</strong></span> GLWIDGET_H</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #2a00ff"><span style="color: #7f0055"><strong>#include</strong></span><span style="color: #000000"> </span>&lt;QtOpenGL/QGLWidget&gt;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span style="color: #7f0055"><strong>class</strong></span> <span style="color: #005032">GLWidget</span> : <span style="color: #7f0055"><strong>public</strong></span> QGLWidget {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; Q_OBJECT</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #7f0055"><strong>public</strong><span style="color: #000000">:</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; GLWidget(QWidget *parent = 0);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <strong>~GLWidget</strong>();</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #7f0055"><strong>protected</strong><span style="color: #000000">:</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #7f0055"><strong>virtual</strong></span> <span style="color: #7f0055"><strong>void</strong></span> <strong>initializeGL</strong>();</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #7f0055"><strong>virtual</strong></span> <span style="color: #7f0055"><strong>void</strong></span> <strong>resizeGL</strong>(<span style="color: #7f0055"><strong>int</strong></span> w, <span style="color: #7f0055"><strong>int</strong></span> h);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #7f0055"><strong>virtual</strong></span> <span style="color: #7f0055"><strong>void</strong></span> <strong>paintGL</strong>();</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #7f0055"><strong>virtual</strong></span> <span style="color: #7f0055"><strong>void</strong></span> <strong>hideEvent</strong>(<span style="color: #005032">QHideEvent</span> *event);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #7f0055"><strong>virtual</strong></span> <span style="color: #7f0055"><strong>void</strong></span> <strong>showEvent</strong>(<span style="color: #005032">QShowEvent</span> *event);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #7f0055"><strong>virtual</strong></span> <span style="color: #7f0055"><strong>void</strong></span> <strong>timerEvent</strong>(<span style="color: #005032">QTimerEvent</span> *event);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #7f0055"><strong>virtual</strong></span> <span style="color: #7f0055"><strong>void</strong></span> <strong>mousePressEvent</strong>(<span style="color: #005032">QMouseEvent</span> *event);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #7f0055"><strong>virtual</strong></span> <span style="color: #7f0055"><strong>void</strong></span> <strong>mouseMoveEvent</strong>(<span style="color: #005032">QMouseEvent</span> *event);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #7f0055"><strong>virtual</strong></span> <span style="color: #7f0055"><strong>void</strong></span> <strong>mouseReleaseEvent</strong>(<span style="color: #005032">QMouseEvent</span> *event);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #7f0055"><strong>virtual</strong></span> <span style="color: #7f0055"><strong>void</strong></span> <strong>wheelEvent</strong>(<span style="color: #005032">QWheelEvent</span> *event);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #7f0055"><strong>private</strong><span style="color: #000000">:</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #7f0055"><strong>int</strong></span> &nbsp; &nbsp; <span style="color: #0000c0">timerId</span>;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #005032">QPoint</span>&nbsp; <span style="color: #0000c0">lastPos</span>;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>GLfloat<span style="color: #000000"> </span><span style="color: #0000c0">rotateX</span><span style="color: #000000">;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>GLfloat<span style="color: #000000"> </span><span style="color: #0000c0">rotateY</span><span style="color: #000000">;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>GLfloat<span style="color: #000000"> </span><span style="color: #0000c0">rotateZ</span><span style="color: #000000">;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>GLfloat<span style="color: #000000"> </span><span style="color: #0000c0">zoom</span><span style="color: #000000">;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #7f0055"><strong>void</strong></span> <strong>drawCube</strong>(<span style="color: #005032">GLfloat</span> factorX = 1, <span style="color: #005032">GLfloat</span> factorY = 1,</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #005032">GLfloat</span> factorZ = 1, <span style="color: #005032">GLfloat</span> w = 1);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #7f0055"><strong>void</strong></span> <strong>drawCone</strong>(<span style="color: #005032">GLfloat</span> radius = 1.0f, <span style="color: #005032">GLfloat</span> height = 1,</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #005032">GLuint</span> steps = 18);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">};</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #7f0055"><strong>#endif</strong></span><span style="color: #000000"> </span>// GLWIDGET_H</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><span style="color: rgb(127, 0, 85); font-weight: bold; ">==================================[GLWidget.cpp]==================================</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #2a00ff"><span style="color: #7f0055"><strong>#include</strong></span><span style="color: #000000"> </span>"GLWidget.h"</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #7f0055"><strong>#include</strong><span style="color: #000000"> </span><span style="color: #2a00ff">&lt;qDebug&gt;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #2a00ff"><span style="color: #7f0055"><strong>#include</strong></span><span style="color: #000000"> </span>&lt;QTimerEvent&gt;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #2a00ff"><span style="color: #7f0055"><strong>#include</strong></span><span style="color: #000000"> </span>&lt;QMouseEvent&gt;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #7f0055"><strong>#include</strong><span style="color: #000000"> </span><span style="color: #2a00ff">&lt;cmath&gt;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><strong>GLWidget::GLWidget</strong>(<span style="color: #005032">QWidget</span> *parent)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; : QGLWidget(parent) {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #005032">setFormat</span>(<span style="color: #005032">QGLFormat</span>(<span style="color: #005032">QGL</span>::DoubleBuffer | <span style="color: #005032">QGL</span>::DepthBuffer));</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #0000c0">rotateX</span> = 0.0f;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #0000c0">rotateY</span> = 0.0f;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #0000c0">rotateZ</span> = 0.0f;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #0000c0">zoom</span> = 1.0f;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><strong>GLWidget::~GLWidget</strong>() {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span style="color: #7f0055"><strong>void</strong></span> <strong>GLWidget::hideEvent</strong>(<span style="color: #005032">QHideEvent</span> *event) {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #7f0055"><strong>this</strong></span>-&gt;<span style="color: #005032">killTimer</span>(<span style="color: #7f0055"><strong>this</strong></span>-&gt;<span style="color: #0000c0">timerId</span>);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span style="color: #7f0055"><strong>void</strong></span> <strong>GLWidget::showEvent</strong>(<span style="color: #005032">QShowEvent</span> *event) {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #7f0055"><strong>this</strong></span>-&gt;<span style="color: #0000c0">timerId</span> = <span style="color: #7f0055"><strong>this</strong></span>-&gt;<span style="color: #005032">startTimer</span>(500);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span style="color: #7f0055"><strong>void</strong></span> <strong>GLWidget::timerEvent</strong>(<span style="color: #005032">QTimerEvent</span> *event) {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #7f0055"><strong>if</strong></span> (event-&gt;timerId() == <span style="color: #7f0055"><strong>this</strong></span>-&gt;<span style="color: #0000c0">timerId</span>) {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; } <span style="color: #7f0055"><strong>else</strong></span> {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #005032">QGLWidget</span>::timerEvent(event);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; }</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span style="color: #7f0055"><strong>void</strong></span> <strong>GLWidget::mousePressEvent</strong>(<span style="color: #005032">QMouseEvent</span> *event) {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #7f0055"><strong>if</strong></span> (<span style="color: #005032">Qt</span>::LeftButton == event-&gt;button()) {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000c0">lastPos</span> = event-&gt;pos();</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; } <span style="color: #7f0055"><strong>else</strong></span> <span style="color: #7f0055"><strong>if</strong></span> (<span style="color: #005032">Qt</span>::RightButton == event-&gt;button()) {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000c0">lastPos</span> = event-&gt;pos();</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; }</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span style="color: #7f0055"><strong>void</strong></span> <strong>GLWidget::mouseMoveEvent</strong>(<span style="color: #005032">QMouseEvent</span> *event) {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #7f0055"><strong>if</strong></span> (<span style="color: #005032">Qt</span>::LeftButton &amp; event-&gt;buttons()) {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #005032">GLfloat</span> dx = event-&gt;pos().x() - <span style="color: #0000c0">lastPos</span>.x();</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #005032">GLfloat</span> dy = event-&gt;pos().y() - <span style="color: #0000c0">lastPos</span>.y();</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000c0">rotateX</span> += dy;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000c0">rotateY</span> += dx;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #005032">updateGL</span>();</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000">&nbsp; &nbsp; &nbsp; &nbsp; </span>//qDebug() &lt;&lt; QString("RotateX:%1, RotateY:%2").arg(rotateX).arg(rotateY);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; } <span style="color: #7f0055"><strong>else</strong></span> <span style="color: #7f0055"><strong>if</strong></span> (<span style="color: #005032">Qt</span>::RightButton &amp; event-&gt;buttons()) {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #005032">GLfloat</span> dz = event-&gt;pos().y() - <span style="color: #0000c0">lastPos</span>.y();</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; &nbsp; &nbsp; dz *= 0.01f;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000c0">zoom</span> += dz;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #005032">updateGL</span>();</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; }</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #0000c0">lastPos</span> = event-&gt;pos();</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span style="color: #7f0055"><strong>void</strong></span> <strong>GLWidget::mouseReleaseEvent</strong>(<span style="color: #005032">QMouseEvent</span> *event) {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span style="color: #7f0055"><strong>void</strong></span> <strong>GLWidget::wheelEvent</strong>(<span style="color: #005032">QWheelEvent</span> *event) {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #005032">GLfloat</span> degrees = event-&gt;delta();</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #0000c0">zoom</span> -= degrees * 0.0002f;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000">&nbsp; &nbsp; </span>// 注意, 如果zoom为负值, eye就会被放置到z轴的负方向, 而从物体的背面看了.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #7f0055"><strong>if</strong></span> (<span style="color: #0000c0">zoom</span> &lt; 1.0f) {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000c0">zoom</span> = 1.0f;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; }</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>updateGL<span style="color: #000000">();</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f">///////////////////////////////////////////////////////////////////////////////</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f">// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Opengl Code</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f">///////////////////////////////////////////////////////////////////////////////</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span style="color: #7f0055"><strong>void</strong></span> <strong>GLWidget::initializeGL</strong>() {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #005032">glClearColor</span>(0.0f, 0.0f, 0.0f, 1.0f);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>glEnable<span style="color: #000000">(</span>GL_DEPTH_TEST<span style="color: #000000">);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>glFrontFace<span style="color: #000000">(</span>GL_CCW<span style="color: #000000">);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000">&nbsp; &nbsp; </span>//glEnable(GL_CULL_FACE);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>glCullFace<span style="color: #000000">(</span>GL_BACK<span style="color: #000000">);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>glShadeModel<span style="color: #000000">(</span>GL_SMOOTH<span style="color: #000000">);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000">&nbsp; &nbsp; </span>// Point size</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000">&nbsp; &nbsp; </span>// glPointSize(GLfloat size);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #005032">GLfloat</span> sizes[2];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #005032">GLfloat</span> step;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>glGetFloatv<span style="color: #000000">(</span>GL_LINE_WIDTH_RANGE<span style="color: #000000">, sizes);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>glGetFloatv<span style="color: #000000">(</span>GL_LINE_WIDTH_GRANULARITY<span style="color: #000000">, &amp;step);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span style="color: #7f0055"><strong>void</strong></span> <strong>GLWidget::resizeGL</strong>(<span style="color: #7f0055"><strong>int</strong></span> w, <span style="color: #7f0055"><strong>int</strong></span> h) {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #005032">glViewport</span>(0, 0, w, h);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>glMatrixMode<span style="color: #000000">(</span>GL_PROJECTION<span style="color: #000000">);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>glLoadIdentity<span style="color: #000000">();</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #005032">gluPerspective</span>(75, (<span style="color: #005032">GLdouble</span>)w / h, 0.1, 100);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>glMatrixMode<span style="color: #000000">(</span>GL_MODELVIEW<span style="color: #000000">);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>glLoadIdentity<span style="color: #000000">();</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span style="color: #7f0055"><strong>void</strong></span> <strong>GLWidget::paintGL</strong>() {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>glClear<span style="color: #000000">(</span>GL_COLOR_BUFFER_BIT<span style="color: #000000"> | </span>GL_DEPTH_BUFFER_BIT<span style="color: #000000">);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>glLoadIdentity<span style="color: #000000">();</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000">&nbsp; &nbsp; </span>//glTranslatef(0.0f, 0.0f, zoom);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #005032">gluLookAt</span>(0.0f, 0.0f, <span style="color: #0000c0">zoom</span>, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #005032">glRotatef</span>(<span style="color: #0000c0">rotateX</span>, 1, 0, 0);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #005032">glRotatef</span>(<span style="color: #0000c0">rotateY</span>, 0, 1, 0);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #005032">glRotatef</span>(<span style="color: #0000c0">rotateZ</span>, 0, 0, 1);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000">&nbsp; &nbsp; </span>// Real draw code.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000">&nbsp; &nbsp; </span>//glColor3f(1.0f, 0.0f, 0.0f);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000">&nbsp; &nbsp; </span>//drawCube(1, 1, 1, 1);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>glPolygonMode<span style="color: #000000">(</span>GL_BACK<span style="color: #000000">, </span>GL_LINE<span style="color: #000000">);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; drawCone(1.0f, 1.50, 48);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span style="color: #7f0055"><strong>void</strong></span> <strong>GLWidget::drawCube</strong>(<span style="color: #005032">GLfloat</span> factorX, <span style="color: #005032">GLfloat</span> factorY,</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #005032">GLfloat</span> factorZ, <span style="color: #005032">GLfloat</span> w) {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #005032">GLfloat</span> x = factorX * 0.5f;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #005032">GLfloat</span> y = factorY * 0.5f;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #005032">GLfloat</span> z = factorZ * 0.5f;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000">&nbsp; &nbsp; </span>// x / w, y / w, z / w</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000">&nbsp; &nbsp; </span>// 前左下, 前右下, 前右上, 前左上: p0, p1, p2, p3</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000">&nbsp; &nbsp; </span>// 后左下, 后右下, 后右上, 后左上: p4, p5, p6, p7</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #005032">GLfloat</span> p0[4] = {-x, -y, z, w};</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #005032">GLfloat</span> p1[4] = {x, -y, z, w};</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #005032">GLfloat</span> p2[4] = {x, y, z, w};</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #005032">GLfloat</span> p3[4] = {-x, y, z, w};</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #005032">GLfloat</span> p4[4] = {-x, -y, -z, w};</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #005032">GLfloat</span> p5[4] = {x, -y, -z, w};</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #005032">GLfloat</span> p6[4] = {x, y, -z, w};</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #005032">GLfloat</span> p7[4] = {-x, y, -z, w};</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000">&nbsp; &nbsp; </span>// 开始绘制Cube的六个面: 逆时针</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>glBegin<span style="color: #000000">(</span>GL_QUADS<span style="color: #000000">);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000">&nbsp; &nbsp; </span>// 前面: p0, p1, p2, p3</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>glVertex4fv<span style="color: #000000">(p0);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>glVertex4fv<span style="color: #000000">(p1);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>glVertex4fv<span style="color: #000000">(p2);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>glVertex4fv<span style="color: #000000">(p3);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000">&nbsp; &nbsp; </span>// 右面: p1, p5, p6, p2</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>glVertex4fv<span style="color: #000000">(p1);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>glVertex4fv<span style="color: #000000">(p5);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>glVertex4fv<span style="color: #000000">(p6);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>glVertex4fv<span style="color: #000000">(p2);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000">&nbsp; &nbsp; </span>// 后面: p5, p4, p7, p6</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>glVertex4fv<span style="color: #000000">(p5);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>glVertex4fv<span style="color: #000000">(p4);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>glVertex4fv<span style="color: #000000">(p7);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>glVertex4fv<span style="color: #000000">(p6);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000">&nbsp; &nbsp; </span>// 左右: p4, p0, p3, p7</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>glVertex4fv<span style="color: #000000">(p4);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>glVertex4fv<span style="color: #000000">(p0);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>glVertex4fv<span style="color: #000000">(p3);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>glVertex4fv<span style="color: #000000">(p7);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000">&nbsp; &nbsp; </span>// 上面: p2, p6, p7, p3</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>glVertex4fv<span style="color: #000000">(p2);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>glVertex4fv<span style="color: #000000">(p6);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>glVertex4fv<span style="color: #000000">(p7);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>glVertex4fv<span style="color: #000000">(p3);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000">&nbsp; &nbsp; </span>// 下面: p0, p4, p5, p1</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>glVertex4fv<span style="color: #000000">(p0);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>glVertex4fv<span style="color: #000000">(p4);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>glVertex4fv<span style="color: #000000">(p5);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>glVertex4fv<span style="color: #000000">(p1);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #005032">glEnd</span>();</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span style="color: #7f0055"><strong>void</strong></span> <strong>GLWidget::drawCone</strong>(<span style="color: #005032">GLfloat</span> radius, <span style="color: #005032">GLfloat</span> height,</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #005032">GLuint</span> steps) {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #7f0055"><strong>const</strong></span> <span style="color: #005032">GLfloat</span> GL_PI = 3.1415f;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #005032">GLfloat</span> angles = 2 * GL_PI / steps;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #005032">GLfloat</span> vertices[steps][3];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #7f0055"><strong>for</strong></span> (<span style="color: #7f0055"><strong>int</strong></span> i = 0; i &lt; steps; ++i) {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; &nbsp; &nbsp; vertices[i][0] = radius * <span style="color: #005032">cos</span>(i * angles);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; &nbsp; &nbsp; vertices[i][1] = radius * <span style="color: #005032">sin</span>(i * angles);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; &nbsp; &nbsp; vertices[i][2] = 0;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; }</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000">&nbsp; &nbsp; </span>// top surface</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>glBegin<span style="color: #000000">(</span>GL_TRIANGLE_FAN<span style="color: #000000">);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #005032">glColor3f</span>(0.0f, 0.0f, 1.0f);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #005032">glVertex3f</span>(0.0f, 0.0f, height);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7f0055"><strong>for</strong></span> (<span style="color: #7f0055"><strong>int</strong></span> i = 0; i &lt; steps; ++i) {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #005032">glVertex3fv</span>(vertices[i]);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7f0055"><strong>if</strong></span> ((i &amp; 1) == 0) {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #005032">glColor3f</span>(1.0f, 0.0f, 0.0f);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } <span style="color: #7f0055"><strong>else</strong></span> {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #005032">glColor3f</span>(0.0f, 0.0f, 1.0f);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; &nbsp; &nbsp; }</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #005032">glVertex3fv</span>(vertices[0]);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #005032">glEnd</span>();</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000">&nbsp; &nbsp; </span>// bottom surface</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #005032"><span style="color: #000000">&nbsp; &nbsp; </span>glBegin<span style="color: #000000">(</span>GL_TRIANGLE_FAN<span style="color: #000000">);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #005032">glVertex3f</span>(0.0f, 0.0f, 0);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7f0055"><strong>for</strong></span> (<span style="color: #7f0055"><strong>int</strong></span> i = steps - 1; i &gt;= 0; --i) {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #005032">glVertex3fv</span>(vertices[i]);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7f0055"><strong>if</strong></span> ((i &amp; 1) == 0) {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #005032">glColor3f</span>(0.0f, 1.0f, 0.0f);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } <span style="color: #7f0055"><strong>else</strong></span> {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #005032">glColor3f</span>(1.0f, 0.0f, 1.0f);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; &nbsp; &nbsp; }</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #005032">glVertex3fv</span>(vertices[steps - 1]);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">&nbsp; &nbsp; <span style="color: #005032">glEnd</span>();</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">}</p><div><font face="Courier" size="4"><span style="font-size: 14px;"></span><br></font></div><img src ="http://www.cppblog.com/biao/aggbug/83379.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2009-05-19 15:15 <a href="http://www.cppblog.com/biao/archive/2009/05/19/83379.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>OpenGL: Transformation</title><link>http://www.cppblog.com/biao/archive/2009/05/15/83006.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Thu, 14 May 2009 19:38:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2009/05/15/83006.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/83006.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2009/05/15/83006.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/83006.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/83006.html</trackback:ping><description><![CDATA[


Viewing: Specify the location of the viewer or camera.<div>Modeling: Move objects around in a scene.</div><div>Viewing transformation is essentially nothing but a modeling transformation. They are used to made purely as a convenience to the programmer.&nbsp;</div><div>The term modelview indicats that viewing transformation and modeling transformation are combined in the transformation pipeline into a single matrix-modelview matrix.</div><div>Viewing transformation全局的移动所有的物体.&nbsp;</div><div>Modeling transformation一般是局部的移动物体, 当然也可以全局的移动.</div><div><br></div><div>glTranslatef();</div><div>glRotatef();</div><div>注意, 变换可以看成是对坐标系进行变换, 也可以看成是对物体的坐标进行变换, 而坐标系不受影响.</div><div>1. 对物体坐标进行变换: 因为矩阵的管理使用的是栈的形式, 所以实际上是glRotatef()先执行, 然后glTranslatef()后执行, 即先旋转, 后移动, 与代码的顺序正好相反. 实际内部是这样进行的, 但是这样一来, 矩阵的变换语句就得逆着来. 这也是为什么顶点坐标向量在OpenGL中要放在右边, 而变换矩阵要放在左边进行相乘.</div><div>2. 对坐标系进行变换: 这样就好理解一些, 因为变换结果与变换语句的顺序是一致的.</div><img src ="http://www.cppblog.com/biao/aggbug/83006.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2009-05-15 03:38 <a href="http://www.cppblog.com/biao/archive/2009/05/15/83006.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>OpenGL: Blend</title><link>http://www.cppblog.com/biao/archive/2008/09/25/62729.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Wed, 24 Sep 2008 21:15:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2008/09/25/62729.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/62729.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2008/09/25/62729.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/62729.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/62729.html</trackback:ping><description><![CDATA[

<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Times">The solution is to enable depth-buffering but make the depth buffer read-only while drawing the<span style="font: 12.0px Helvetica">&nbsp;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Times">translucent objects. First you draw all the opaque objects, with the depth buffer in normal operation.<span style="font: 12.0px Helvetica">&nbsp;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Times">Then, you preserve these depth values by making the depth buffer read-only. When the translucent<span style="font: 12.0px Helvetica">&nbsp;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Times">objects are drawn, their depth values are still compared to the values established by the opaque objects,<span style="font: 12.0px Helvetica">&nbsp;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Times">so they aren't drawn if they're behind the opaque ones. If they're closer to the viewpoint, however, they<span style="font: 12.0px Helvetica">&nbsp;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Times">don't eliminate the opaque objects, since the depth-buffer values can't change. Instead, they're blended<span style="font: 12.0px Helvetica">&nbsp;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Times">with the opaque objects. To control whether the depth buffer is writable, use <strong>glDepthMask()</strong>; if you<span style="font: 12.0px Helvetica">&nbsp;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Times">pass GL_FALSE as the argument, the buffer becomes read-only, whereas GL_TRUE restores the<span style="font: 12.0px Helvetica">&nbsp;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Times">normal, writable operation.<span style="font: 12.0px Helvetica">&nbsp;</span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Times"><span style="font-family: Helvetica; font-size: 12px;"></span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span style="color: #7f0055"><strong>void</strong></span> <strong>GLWidget::paintGL</strong>() {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #642880"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span><strong>glLoadIdentity</strong><span style="color: #000000">();</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">	</span><span style="color: #642880"><strong>glClear</strong></span>(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">	</span><span style="color: #642880"><strong>gluLookAt</strong></span>(0, 0, 8, 0, 0, 0, 0, 1, 0);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #642880"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span><strong>glPushMatrix</strong><span style="color: #000000">();</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">	</span>{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #642880"><strong>glColor3f</strong></span>(1.0, 0.0f, 0.0f);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #642880"><strong>glTranslatef</strong></span>(0.0f, 0.0f, -1.0f);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #7f0055"><strong>this</strong></span>-&gt;drawCube(1.0f, 1.0f, 1.0f, 0.1f);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">	</span>}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #642880"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span><strong>glPopMatrix</strong><span style="color: #000000">();</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #642880"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span><strong>glPushMatrix</strong><span style="color: #000000">();</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">	</span>{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #642880"><strong>glColor3f</strong></span>(0.0, 0.0f, 1.0f);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #642880"><strong>glTranslatef</strong></span>(0.60f, 0.0f, -0.5f);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #7f0055"><strong>this</strong></span>-&gt;drawCube(1.0f, 1.0f, 1.0f, 0.1f);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">	</span>}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #642880"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span><strong>glPopMatrix</strong><span style="color: #000000">();</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #642880"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span><strong>glPushMatrix</strong><span style="color: #000000">();</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">	</span>{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #642880"><strong>glEnable</strong></span>(GL_BLEND);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #642880"><strong>glBlendFunc</strong></span>(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #642880"><strong>glDepthMask</strong></span>(GL_FALSE);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #642880"><strong>glColor4f</strong></span>(0.0, 1.0f, 0.0f, 0.5f);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #642880"><strong>glTranslatef</strong></span>(0.20f, 0.0f, 0.0f);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #7f0055"><strong>this</strong></span>-&gt;drawCube(0.60f, 1.0f, 1.0f, 0.1f);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #642880"><strong>glDepthMask</strong></span>(GL_TRUE);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #642880"><strong>glDisable</strong></span>(GL_BLEND);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">	</span>}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #642880"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span><strong>glPopMatrix</strong><span style="color: #000000">();</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">}</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span style="color: #7f0055"><strong>void</strong></span> <strong>GLWidget::drawCube</strong>(<span style="color: #005032">GLfloat</span> len, <span style="color: #005032">GLfloat</span> xFactor, <span style="color: #005032">GLfloat</span> yFactor,</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #005032">GLfloat</span> zFactor) {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">	</span><span style="color: #005032">GLfloat</span> x = len * xFactor / 2;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">	</span><span style="color: #005032">GLfloat</span> y = len * yFactor / 2;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">	</span><span style="color: #005032">GLfloat</span> z = len * zFactor / 2;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">	</span>GLfloat p0[3] = { -x, -y, -z };</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">	</span>GLfloat p1[3] = { x, -y, -z };</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">	</span>GLfloat p2[3] = { x, y, -z };</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">	</span>GLfloat p3[3] = { -x, y, -z };</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">	</span>GLfloat p4[3] = { -x, -y, z };</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">	</span>GLfloat p5[3] = { x, -y, z };</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">	</span>GLfloat p6[3] = { x, y, z };</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">	</span>GLfloat p7[3] = { -x, y, z };</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">	</span><span style="color: #642880"><strong>glBegin</strong></span>(GL_QUADS);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">	</span>{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">		</span></span>// Draw left surface.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #642880"><strong>glNormal3f</strong></span>(-1.0f, 0.0f, 0.0f);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #642880"><strong>glVertex3f</strong></span>(-x, y, -z);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #642880"><strong>glVertex3f</strong></span>(-x, -y, -z);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #642880"><strong>glVertex3f</strong></span>(-x, -y, z);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #642880"><strong>glVertex3f</strong></span>(-x, y, z);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">		</span></span>// Draw front surface.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #642880"><strong>glNormal3f</strong></span>(0.0f, 0.0f, 1.0f);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #642880"><strong>glVertex3f</strong></span>(-x, -y, z);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #642880"><strong>glVertex3f</strong></span>(x, -y, z);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #642880"><strong>glVertex3f</strong></span>(x, y, z);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #642880"><strong>glVertex3f</strong></span>(-x, y, z);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">		</span></span>// Draw right surface.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #642880"><strong>glNormal3f</strong></span>(1.0f, 0.0f, 0.0f);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #642880"><strong>glVertex3f</strong></span>(x, -y, z);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #642880"><strong>glVertex3f</strong></span>(x, -y, -z);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #642880"><strong>glVertex3f</strong></span>(x, y, -z);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #642880"><strong>glVertex3f</strong></span>(x, y, z);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">		</span></span>// Draw back surface.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #642880"><strong>glNormal3f</strong></span>(0.0f, 0.0f, -1.0f);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #642880"><strong>glVertex3f</strong></span>(x, y, -z);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #642880"><strong>glVertex3f</strong></span>(x, -y, -z);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #642880"><strong>glVertex3f</strong></span>(-x, -y, -z);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #642880"><strong>glVertex3f</strong></span>(-x, y, -z);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">		</span></span>// Draw top surface.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #642880"><strong>glNormal3f</strong></span>(0.0f, 1.0f, 0.0f);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #642880"><strong>glVertex3f</strong></span>(x, y, z);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #642880"><strong>glVertex3f</strong></span>(x, y, -z);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #642880"><strong>glVertex3f</strong></span>(-x, y, -z);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #642880"><strong>glVertex3f</strong></span>(-x, y, z);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">		</span></span>// Draw bottom surface.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #642880"><strong>glNormal3f</strong></span>(0.0f, -1.0f, 0.0f);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #642880"><strong>glVertex3f</strong></span>(-x, -y, -z);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #642880"><strong>glVertex3f</strong></span>(x, -y, -z);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #642880"><strong>glVertex3f</strong></span>(x, -y, z);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">		</span><span style="color: #642880"><strong>glVertex3f</strong></span>(-x, -y, z);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier"><span class="Apple-tab-span" style="white-space:pre">	</span>}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #642880"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span><strong>glEnd</strong><span style="color: #000000">();</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; min-height: 17.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">	</span>glBegin(GL_QUADS);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">	</span>{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">		</span>// Draw left surface.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">		</span>glNormal3f(-1.0f, 0.0f, 0.0f);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">		</span>glVertex3fv(p3);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">		</span>glVertex3fv(p0);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">		</span>glVertex3fv(p4);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">		</span>glVertex3fv(p7);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">		</span>// Draw front surface.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">		</span>glNormal3f(0.0f, 0.0f, 1.0f);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">		</span>glVertex3fv(p4);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">		</span>glVertex3fv(p5);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">		</span>glVertex3fv(p6);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">		</span>glVertex3fv(p7);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">		</span>// Draw right surface.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">		</span>glNormal3f(1.0f, 0.0f, 0.0f);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">		</span>glVertex3fv(p5);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">		</span>glVertex3fv(p1);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">		</span>glVertex3fv(p2);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">		</span>glVertex3fv(p6);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">		</span>// Draw back surface.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">		</span>glNormal3f(0.0f, 0.0f, -1.0f);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">		</span>glVertex3fv(p2);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">		</span>glVertex3fv(p1);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">		</span>glVertex3fv(p0);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">		</span>glVertex3fv(p3);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">		</span>// Draw top surface.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">		</span>glNormal3f(0.0f, 1.0f, 0.0f);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">		</span>glVertex3fv(p6);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">		</span>glVertex3fv(p2);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">		</span>glVertex3fv(p3);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">		</span>glVertex3fv(p7);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">		</span>// Draw bottom surface.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">		</span>glNormal3f(0.0f, -1.0f, 0.0f);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">		</span>glVertex3fv(p0);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">		</span>glVertex3fv(p1);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">		</span>glVertex3fv(p5);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">		</span>glVertex3fv(p4);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">	</span>}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3f7f5f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//<span class="Apple-tab-span" style="white-space:pre">	</span>glEnd();</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier">}</p><p>&nbsp;</p><p>&nbsp;</p><img src ="http://www.cppblog.com/biao/aggbug/62729.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2008-09-25 05:15 <a href="http://www.cppblog.com/biao/archive/2008/09/25/62729.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>