
-- I am too lazy to write my own documentation right now, this is what doxygen was designed for right?
360 lines
28 KiB
HTML
360 lines
28 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
|
<title>Unuk: src/libUnuk/Sprite.cpp Source File</title>
|
|
<link href="tabs.css" rel="stylesheet" type="text/css"/>
|
|
<link href="search/search.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="search/search.js"></script>
|
|
<link href="navtree.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="jquery.js"></script>
|
|
<script type="text/javascript" src="navtree.js"></script>
|
|
<script type="text/javascript" src="resize.js"></script>
|
|
<script type="text/javascript">
|
|
$(document).ready(initResizable);
|
|
</script>
|
|
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
|
|
</head>
|
|
<body onload='searchBox.OnSelectItem(0);'>
|
|
<!-- Generated by Doxygen 1.7.4 -->
|
|
<script type="text/javascript"><!--
|
|
var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
|
--></script>
|
|
<div id="top">
|
|
<div id="titlearea">
|
|
<table cellspacing="0" cellpadding="0">
|
|
<tbody>
|
|
<tr style="height: 56px;">
|
|
<td id="projectlogo"><img alt="Logo" src="logo.png"/></td>
|
|
<td style="padding-left: 0.5em;">
|
|
<div id="projectname">Unuk <span id="projectnumber">1.0</span></div>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<div id="navrow1" class="tabs">
|
|
<ul class="tablist">
|
|
<li><a href="index.html"><span>Main Page</span></a></li>
|
|
<li><a href="annotated.html"><span>Classes</span></a></li>
|
|
<li class="current"><a href="files.html"><span>Files</span></a></li>
|
|
<li id="searchli">
|
|
<div id="MSearchBox" class="MSearchBoxInactive">
|
|
<span class="left">
|
|
<img id="MSearchSelect" src="search/mag_sel.png"
|
|
onmouseover="return searchBox.OnSearchSelectShow()"
|
|
onmouseout="return searchBox.OnSearchSelectHide()"
|
|
alt=""/>
|
|
<input type="text" id="MSearchField" value="Search" accesskey="S"
|
|
onfocus="searchBox.OnSearchFieldFocus(true)"
|
|
onblur="searchBox.OnSearchFieldFocus(false)"
|
|
onkeyup="searchBox.OnSearchFieldChange(event)"/>
|
|
</span><span class="right">
|
|
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
|
|
</span>
|
|
</div>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
<div id="navrow2" class="tabs2">
|
|
<ul class="tablist">
|
|
<li><a href="files.html"><span>File List</span></a></li>
|
|
<li><a href="globals.html"><span>File Members</span></a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
<div id="side-nav" class="ui-resizable side-nav-resizable">
|
|
<div id="nav-tree">
|
|
<div id="nav-tree-contents">
|
|
</div>
|
|
</div>
|
|
<div id="splitbar" style="-moz-user-select:none;"
|
|
class="ui-resizable-handle">
|
|
</div>
|
|
</div>
|
|
<script type="text/javascript">
|
|
initNavTree('_sprite_8cpp.html','');
|
|
</script>
|
|
<div id="doc-content">
|
|
<div class="header">
|
|
<div class="headertitle">
|
|
<div class="title">src/libUnuk/Sprite.cpp</div> </div>
|
|
</div>
|
|
<div class="contents">
|
|
<a href="_sprite_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#include <GL/glut.h></span>
|
|
<a name="l00002"></a>00002 <span class="preprocessor">#include <iostream></span>
|
|
<a name="l00003"></a>00003 <span class="preprocessor">#include <cstring></span>
|
|
<a name="l00004"></a>00004 <span class="preprocessor">#include "<a class="code" href="_sprite_8h.html">Sprite.h</a>"</span>
|
|
<a name="l00005"></a>00005 <span class="preprocessor">#include "<a class="code" href="_image_loader_8h.html">ImageLoader.h</a>"</span>
|
|
<a name="l00006"></a>00006 <span class="preprocessor">#include "<a class="code" href="_debug_8h.html">Debug.h</a>"</span>
|
|
<a name="l00007"></a>00007
|
|
<a name="l00008"></a><a class="code" href="class_sprite.html#ac9efd3711ed9c2cf94a0f8bdd0fcf332">00008</a> <a class="code" href="class_sprite.html#ac9efd3711ed9c2cf94a0f8bdd0fcf332">Sprite::Sprite</a>(<span class="keywordtype">string</span> filename) {
|
|
<a name="l00009"></a>00009 image = <span class="keyword">new</span> <a class="code" href="class_image_loader.html">ImageLoader</a>(filename.c_str());
|
|
<a name="l00010"></a>00010 angle = 0;
|
|
<a name="l00011"></a>00011 <a class="code" href="wglext_8h.html#ad77deca22f617d3f0e0eb786445689fc">x</a> = 0.0f;
|
|
<a name="l00012"></a>00012 <a class="code" href="wglext_8h.html#a9298c7ad619074f5285b32c6b72bfdea">y</a> = 0.0f;
|
|
<a name="l00013"></a>00013 <a class="code" href="class_sprite.html#a70d31712d0f598d26a68c268bd4390eb">SetPivot</a>(0.0f, 0.0f);
|
|
<a name="l00014"></a>00014 <a class="code" href="class_sprite.html#ae0db821f5ffe067ab771a419bcbdb971">SetScale</a>(1.0f, 1.0f);
|
|
<a name="l00015"></a>00015 }
|
|
<a name="l00016"></a>00016
|
|
<a name="l00017"></a><a class="code" href="class_sprite.html#ae2cc659dea1ee5802b336d5c9b4f8f41">00017</a> <a class="code" href="class_sprite.html#ae2cc659dea1ee5802b336d5c9b4f8f41">Sprite::~Sprite</a>(<span class="keywordtype">void</span>) {
|
|
<a name="l00018"></a>00018 <span class="keyword">delete</span> image;
|
|
<a name="l00019"></a>00019 }
|
|
<a name="l00020"></a>00020
|
|
<a name="l00021"></a>00021 <span class="comment">// Enable 2D drawing mode to draw our sprites. This function MUST be</span>
|
|
<a name="l00022"></a>00022 <span class="comment">// called before any sprite is drawn on screen using the Draw method.</span>
|
|
<a name="l00023"></a><a class="code" href="class_sprite.html#a56b5bbc83ef6c8f8d6fc97b281a08cf4">00023</a> <span class="keywordtype">void</span> <a class="code" href="class_sprite.html#a56b5bbc83ef6c8f8d6fc97b281a08cf4">Sprite::Enable2D</a>(<span class="keywordtype">void</span>) {
|
|
<a name="l00024"></a>00024 GLint iViewport[4];
|
|
<a name="l00025"></a>00025
|
|
<a name="l00026"></a>00026 <span class="comment">// Get a copy of the viewport.</span>
|
|
<a name="l00027"></a>00027 glGetIntegerv(GL_VIEWPORT, iViewport);
|
|
<a name="l00028"></a>00028 glPushMatrix();
|
|
<a name="l00029"></a>00029 glLoadIdentity();
|
|
<a name="l00030"></a>00030
|
|
<a name="l00031"></a>00031 <span class="comment">// Save a copy of the projection atrix so that we can restore</span>
|
|
<a name="l00032"></a>00032 <span class="comment">// it when it's time to do 3D rendering again.</span>
|
|
<a name="l00033"></a>00033 glMatrixMode(GL_PROJECTION);
|
|
<a name="l00034"></a>00034 glPushMatrix();
|
|
<a name="l00035"></a>00035 glLoadIdentity();
|
|
<a name="l00036"></a>00036
|
|
<a name="l00037"></a>00037 <span class="comment">// Set upt the orthographic projection.</span>
|
|
<a name="l00038"></a>00038 glOrtho( iViewport[0], iViewport[0] + iViewport[2],
|
|
<a name="l00039"></a>00039 iViewport[1] + iViewport[3], iViewport[1], -1, 1);
|
|
<a name="l00040"></a>00040 glMatrixMode(GL_MODELVIEW);
|
|
<a name="l00041"></a>00041 glPushMatrix();
|
|
<a name="l00042"></a>00042 glLoadIdentity();
|
|
<a name="l00043"></a>00043
|
|
<a name="l00044"></a>00044 <span class="comment">// Make sure depth testing and lighting are disabled for 2D rendering </span>
|
|
<a name="l00045"></a>00045 <span class="comment">//until we are finished rendering in 2D.</span>
|
|
<a name="l00046"></a>00046 glPushAttrib(GL_DEPTH_BUFFER_BIT | GL_LIGHTING_BIT);
|
|
<a name="l00047"></a>00047 glDisable(GL_DEPTH_TEST);
|
|
<a name="l00048"></a>00048 glDisable(GL_LIGHTING);
|
|
<a name="l00049"></a>00049 }
|
|
<a name="l00050"></a>00050
|
|
<a name="l00051"></a>00051 <span class="comment">// Disables the 2D drawing. This can be called before you are done </span>
|
|
<a name="l00052"></a>00052 <span class="comment">// drawing all 2D sprites on screen using the Draw method.</span>
|
|
<a name="l00053"></a><a class="code" href="class_sprite.html#ab1074ed774ebbdac0095e711dffc7ff5">00053</a> <span class="keywordtype">void</span> <a class="code" href="class_sprite.html#ab1074ed774ebbdac0095e711dffc7ff5">Sprite::Disable2D</a>(<span class="keywordtype">void</span>) {
|
|
<a name="l00054"></a>00054 glPopAttrib();
|
|
<a name="l00055"></a>00055 glMatrixMode(GL_PROJECTION);
|
|
<a name="l00056"></a>00056 glPopMatrix();
|
|
<a name="l00057"></a>00057 glMatrixMode(GL_MODELVIEW);
|
|
<a name="l00058"></a>00058 glPopMatrix();
|
|
<a name="l00059"></a>00059 }
|
|
<a name="l00060"></a>00060
|
|
<a name="l00061"></a>00061 <span class="comment">// Initializes extensions, textures, render states, etc. before rendering.</span>
|
|
<a name="l00062"></a>00062 <span class="keywordtype">void</span> Sprite::InitScene(<span class="keywordtype">void</span>) {
|
|
<a name="l00063"></a>00063 <span class="comment">// Disable lighting.</span>
|
|
<a name="l00064"></a>00064 glDisable(GL_LIGHTING);
|
|
<a name="l00065"></a>00065 <span class="comment">// Disable dithering.</span>
|
|
<a name="l00066"></a>00066 glDisable(GL_DITHER);
|
|
<a name="l00067"></a>00067 <span class="comment">// Disable blending (for now).</span>
|
|
<a name="l00068"></a>00068 glDisable(GL_BLEND);
|
|
<a name="l00069"></a>00069 <span class="comment">// Disable depth testing.</span>
|
|
<a name="l00070"></a>00070 glDisable(GL_DEPTH_TEST);
|
|
<a name="l00071"></a>00071
|
|
<a name="l00072"></a>00072 <span class="comment">// Is the extension supported on this driver/card?</span>
|
|
<a name="l00073"></a>00073 <span class="keywordflow">if</span>(!IsExtensionSupported(<span class="stringliteral">"GL_ARB_texture_rectangle"</span>)) {
|
|
<a name="l00074"></a>00074 <a class="code" href="class_debug.html#ace75e2aa3105e64f9fc82c537b45135d">Debug::logger</a>-><a class="code" href="class_debug.html#a7f171818a11f4d6b8dee3b44c4d6f0a7">message</a>(<span class="stringliteral">"\nERROR: Texture rectangles not supported on this video card!"</span>);
|
|
<a name="l00075"></a>00075 exit(-1);
|
|
<a name="l00076"></a>00076 }
|
|
<a name="l00077"></a>00077
|
|
<a name="l00078"></a>00078 <span class="comment">// TODO:</span>
|
|
<a name="l00079"></a>00079 <span class="comment">// If your machine does not support GL_NV_texture_rectangle, you can try</span>
|
|
<a name="l00080"></a>00080 <span class="comment">// using GL_EXT_texture_rectangle. Maybe I will run a test so I can support both.</span>
|
|
<a name="l00081"></a>00081
|
|
<a name="l00082"></a>00082 <span class="comment">// Enable the texture rectangle extension.</span>
|
|
<a name="l00083"></a>00083 glEnable(GL_TEXTURE_RECTANGLE_ARB);
|
|
<a name="l00084"></a>00084
|
|
<a name="l00085"></a>00085 <span class="comment">// Generate one texture ID.</span>
|
|
<a name="l00086"></a>00086 glGenTextures(1, &textureID);
|
|
<a name="l00087"></a>00087 <span class="comment">// Bind the texture using GL_TEXTURE_RECTANGLE_NV</span>
|
|
<a name="l00088"></a>00088 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, textureID);
|
|
<a name="l00089"></a>00089 <span class="comment">// Enable bilinear filtering on this texture.</span>
|
|
<a name="l00090"></a>00090 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
<a name="l00091"></a>00091 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
<a name="l00092"></a>00092
|
|
<a name="l00093"></a>00093 <span class="comment">// Write the 32-bit RGBA texture buffer to video memory.</span>
|
|
<a name="l00094"></a>00094 glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, image-><a class="code" href="class_image_loader.html#ab673a17dd93d0a4393934afc14b86885">GetWidth</a>(), image-><a class="code" href="class_image_loader.html#a82df5f39b2a699ab215ae2f1c714b76e">GetHeight</a>(),
|
|
<a name="l00095"></a>00095 0, GL_RGBA, GL_UNSIGNED_BYTE, image-><a class="code" href="class_image_loader.html#a3a4ed52e7b28bb4f48f967de8bf702a9">GetPixelData</a>());
|
|
<a name="l00096"></a>00096 }
|
|
<a name="l00097"></a>00097
|
|
<a name="l00098"></a>00098 <span class="comment">// =================================================================</span>
|
|
<a name="l00099"></a>00099 <span class="comment">// Set the pivot point in relation to the sprite itself, that is</span>
|
|
<a name="l00100"></a>00100 <span class="comment">// using the object coordinates system. In this coordinate system</span>
|
|
<a name="l00101"></a>00101 <span class="comment">// the bottom left point of the object is at (0,0) and the top</span>
|
|
<a name="l00102"></a>00102 <span class="comment">// right is at (1,1).</span>
|
|
<a name="l00103"></a>00103 <span class="comment">//</span>
|
|
<a name="l00104"></a>00104 <span class="comment">// Example: To set the pivot to be in the middle of the sprite use</span>
|
|
<a name="l00105"></a>00105 <span class="comment">// (0.5, 0.5) default values are (1,1).</span>
|
|
<a name="l00106"></a>00106 <span class="comment">// pivotX can be any value, but when x is in the range [0,1] the</span>
|
|
<a name="l00107"></a>00107 <span class="comment">// pivot is inside the sprite where 0 is the left edge of the sprite</span>
|
|
<a name="l00108"></a>00108 <span class="comment">// and 1 is the right edge of the sprite.</span>
|
|
<a name="l00109"></a>00109 <span class="comment">// pivotY is the same as pivotX but when y is in the range of [0,1]</span>
|
|
<a name="l00110"></a>00110 <span class="comment">// the pivot is inside the sprite where 0 is the bottom edge of the</span>
|
|
<a name="l00111"></a>00111 <span class="comment">// sprite and 1 is the top edge of the sprite.</span>
|
|
<a name="l00112"></a>00112 <span class="comment">// =================================================================</span>
|
|
<a name="l00113"></a><a class="code" href="class_sprite.html#a70d31712d0f598d26a68c268bd4390eb">00113</a> <span class="keywordtype">void</span> <a class="code" href="class_sprite.html#a70d31712d0f598d26a68c268bd4390eb">Sprite::SetPivot</a>(GLfloat pivotX, GLfloat pivotY) {
|
|
<a name="l00114"></a>00114 GLfloat deltaPivotX = pivotX - <a class="code" href="class_sprite.html#a5b3a7ec629671f2a0e55ec35906d4677">GetPivotX</a>();
|
|
<a name="l00115"></a>00115 GLfloat deltaPivotY = pivotY - <a class="code" href="class_sprite.html#ae9c1b0ea9f702290518565a279849454">GetPivotY</a>();
|
|
<a name="l00116"></a>00116
|
|
<a name="l00117"></a>00117 this->pivotX = pivotX;
|
|
<a name="l00118"></a>00118 this->pivotY = pivotY;
|
|
<a name="l00119"></a>00119
|
|
<a name="l00120"></a>00120 <a class="code" href="wglext_8h.html#ad77deca22f617d3f0e0eb786445689fc">x</a> += deltaPivotX * image-><a class="code" href="class_image_loader.html#ab673a17dd93d0a4393934afc14b86885">GetWidth</a>();
|
|
<a name="l00121"></a>00121 <a class="code" href="wglext_8h.html#a9298c7ad619074f5285b32c6b72bfdea">y</a> += deltaPivotY * image-><a class="code" href="class_image_loader.html#a82df5f39b2a699ab215ae2f1c714b76e">GetHeight</a>();
|
|
<a name="l00122"></a>00122 }
|
|
<a name="l00123"></a>00123
|
|
<a name="l00124"></a>00124 <span class="comment">// =================================================================</span>
|
|
<a name="l00125"></a>00125 <span class="comment">// Sets the pivot to be at the point where object's pivot is set.</span>
|
|
<a name="l00126"></a>00126 <span class="comment">// obj is the reference object to whose pivot we will set this pivot</span>
|
|
<a name="l00127"></a>00127 <span class="comment">// to be.</span>
|
|
<a name="l00128"></a>00128 <span class="comment">// Note: If the obj pivot changes or the obj moves after the SetPivot</span>
|
|
<a name="l00129"></a>00129 <span class="comment">// call has been issued, the pivot of this object will not reflect these</span>
|
|
<a name="l00130"></a>00130 <span class="comment">// changes. You must call SetPivot again with that object to update the</span>
|
|
<a name="l00131"></a>00131 <span class="comment">// pivot information.</span>
|
|
<a name="l00132"></a>00132 <span class="comment">// =================================================================</span>
|
|
<a name="l00133"></a><a class="code" href="class_sprite.html#aee58f3653a2874def9dfc11086ad109a">00133</a> <span class="keywordtype">void</span> <a class="code" href="class_sprite.html#a70d31712d0f598d26a68c268bd4390eb">Sprite::SetPivot</a>(<span class="keyword">const</span> <a class="code" href="class_sprite.html">Sprite</a> &obj) {
|
|
<a name="l00134"></a>00134 <span class="comment">// This x location if the pivot was at SetPivot(0, 0);</span>
|
|
<a name="l00135"></a>00135 GLint worldX;
|
|
<a name="l00136"></a>00136 <span class="comment">// This y location it the pivot was at SetPivot(0, 0);</span>
|
|
<a name="l00137"></a>00137 GLint worldY;
|
|
<a name="l00138"></a>00138 GLfloat newPivotX;
|
|
<a name="l00139"></a>00139 GLfloat newPivotY;
|
|
<a name="l00140"></a>00140
|
|
<a name="l00141"></a>00141 worldX = <a class="code" href="wglext_8h.html#ad77deca22f617d3f0e0eb786445689fc">x</a> - <a class="code" href="class_sprite.html#a5b3a7ec629671f2a0e55ec35906d4677">GetPivotX</a>() * image-><a class="code" href="class_image_loader.html#ab673a17dd93d0a4393934afc14b86885">GetWidth</a>();
|
|
<a name="l00142"></a>00142 worldY = <a class="code" href="wglext_8h.html#a9298c7ad619074f5285b32c6b72bfdea">y</a> - <a class="code" href="class_sprite.html#ae9c1b0ea9f702290518565a279849454">GetPivotY</a>() * image-><a class="code" href="class_image_loader.html#a82df5f39b2a699ab215ae2f1c714b76e">GetHeight</a>();
|
|
<a name="l00143"></a>00143
|
|
<a name="l00144"></a>00144 newPivotX = (float)(obj.x - worldX) / image-><a class="code" href="class_image_loader.html#ab673a17dd93d0a4393934afc14b86885">GetWidth</a>();
|
|
<a name="l00145"></a>00145 newPivotY = (float)(obj.y - worldY) / image-><a class="code" href="class_image_loader.html#a82df5f39b2a699ab215ae2f1c714b76e">GetHeight</a>();
|
|
<a name="l00146"></a>00146
|
|
<a name="l00147"></a>00147 <a class="code" href="class_sprite.html#a70d31712d0f598d26a68c268bd4390eb">SetPivot</a>(newPivotX, newPivotY);
|
|
<a name="l00148"></a>00148 }
|
|
<a name="l00149"></a>00149
|
|
<a name="l00150"></a>00150 <span class="comment">// Help determine if an OpenGL extension is supported on the target machine</span>
|
|
<a name="l00151"></a>00151 <span class="comment">// at runtime.</span>
|
|
<a name="l00152"></a>00152 <span class="keywordtype">bool</span> Sprite::IsExtensionSupported(<span class="keyword">const</span> <span class="keywordtype">char</span> *extension)<span class="keyword"> const </span>{
|
|
<a name="l00153"></a>00153 <span class="keyword">const</span> GLubyte *extensions = <a class="code" href="_node_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>;
|
|
<a name="l00154"></a>00154 <span class="keyword">const</span> GLubyte *start;
|
|
<a name="l00155"></a>00155 GLubyte *where, *terminator;
|
|
<a name="l00156"></a>00156
|
|
<a name="l00157"></a>00157 <span class="comment">// Extension names should not have spaces.</span>
|
|
<a name="l00158"></a>00158 where = (GLubyte *) strchr(extension, <span class="charliteral">' '</span>);
|
|
<a name="l00159"></a>00159
|
|
<a name="l00160"></a>00160 <span class="keywordflow">if</span> (where || *extension == <span class="charliteral">'\0'</span>) {
|
|
<a name="l00161"></a>00161 <span class="keywordflow">return</span> <span class="keyword">false</span>;
|
|
<a name="l00162"></a>00162 }
|
|
<a name="l00163"></a>00163
|
|
<a name="l00164"></a>00164 extensions = glGetString(GL_EXTENSIONS);
|
|
<a name="l00165"></a>00165
|
|
<a name="l00166"></a>00166 <span class="comment">// It takes a bit of care to be fool-proof about parsing the</span>
|
|
<a name="l00167"></a>00167 <span class="comment">// OpenGL extensions string. Don't be fooled by sub-strings, etc.</span>
|
|
<a name="l00168"></a>00168 start = extensions;
|
|
<a name="l00169"></a>00169
|
|
<a name="l00170"></a>00170 <span class="keywordflow">for</span> (;;) {
|
|
<a name="l00171"></a>00171 where = (GLubyte *) strstr((<span class="keyword">const</span> <span class="keywordtype">char</span> *) start, extension);
|
|
<a name="l00172"></a>00172
|
|
<a name="l00173"></a>00173 <span class="keywordflow">if</span> (!where) {
|
|
<a name="l00174"></a>00174 <span class="keywordflow">break</span>;
|
|
<a name="l00175"></a>00175 }
|
|
<a name="l00176"></a>00176
|
|
<a name="l00177"></a>00177 terminator = where + strlen(extension);
|
|
<a name="l00178"></a>00178 <span class="keywordflow">if</span> (where == start || *(where - 1) == <span class="charliteral">' '</span>) {
|
|
<a name="l00179"></a>00179 <span class="keywordflow">if</span> (*terminator == <span class="charliteral">' '</span> || *terminator == <span class="charliteral">'\0'</span>) {
|
|
<a name="l00180"></a>00180 <span class="keywordflow">return</span> <span class="keyword">true</span>;
|
|
<a name="l00181"></a>00181 }
|
|
<a name="l00182"></a>00182 }
|
|
<a name="l00183"></a>00183
|
|
<a name="l00184"></a>00184 start = terminator;
|
|
<a name="l00185"></a>00185 }
|
|
<a name="l00186"></a>00186
|
|
<a name="l00187"></a>00187 <span class="keywordflow">return</span> <span class="keyword">false</span>;
|
|
<a name="l00188"></a>00188 }
|
|
<a name="l00189"></a>00189
|
|
<a name="l00190"></a><a class="code" href="class_sprite.html#a0f9680e3bd7bf6bcd4c59620ba936347">00190</a> <span class="keywordtype">void</span> <a class="code" href="class_sprite.html#a0f9680e3bd7bf6bcd4c59620ba936347">Sprite::Render</a>(<span class="keywordtype">void</span>) {
|
|
<a name="l00191"></a>00191 InitScene();
|
|
<a name="l00192"></a>00192
|
|
<a name="l00193"></a>00193 glEnable(GL_BLEND);
|
|
<a name="l00194"></a>00194 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
|
|
<a name="l00195"></a>00195 glEnable(GL_TEXTURE_2D);
|
|
<a name="l00196"></a>00196
|
|
<a name="l00197"></a>00197 <span class="comment">// Set the primitive color to white</span>
|
|
<a name="l00198"></a>00198 glColor3f(1.0f, 1.0f, 1.0f);
|
|
<a name="l00199"></a>00199 <span class="comment">// Bind the texture to the polygons</span>
|
|
<a name="l00200"></a>00200 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, textureID);
|
|
<a name="l00201"></a>00201
|
|
<a name="l00202"></a>00202 glPushMatrix();
|
|
<a name="l00203"></a>00203
|
|
<a name="l00204"></a>00204 GLfloat transX = 1;
|
|
<a name="l00205"></a>00205 GLfloat transY = 1;
|
|
<a name="l00206"></a>00206
|
|
<a name="l00207"></a>00207 <span class="keywordflow">if</span>(<a class="code" href="wglext_8h.html#ad77deca22f617d3f0e0eb786445689fc">x</a> != 0.0) {
|
|
<a name="l00208"></a>00208 transX = <a class="code" href="wglext_8h.html#ad77deca22f617d3f0e0eb786445689fc">x</a>;
|
|
<a name="l00209"></a>00209 }
|
|
<a name="l00210"></a>00210
|
|
<a name="l00211"></a>00211 <span class="keywordflow">if</span>(<a class="code" href="wglext_8h.html#a9298c7ad619074f5285b32c6b72bfdea">y</a> != 0.0) {
|
|
<a name="l00212"></a>00212 transY = <a class="code" href="wglext_8h.html#a9298c7ad619074f5285b32c6b72bfdea">y</a>;
|
|
<a name="l00213"></a>00213 }
|
|
<a name="l00214"></a>00214
|
|
<a name="l00215"></a>00215 glLoadIdentity();
|
|
<a name="l00216"></a>00216 glTranslatef(transX, transY, 0);
|
|
<a name="l00217"></a>00217 glScalef(scaleX, scaleY, 1.0);
|
|
<a name="l00218"></a>00218 glRotatef(angle, 0.0, 0.0, 1.0);
|
|
<a name="l00219"></a>00219
|
|
<a name="l00220"></a>00220 <span class="comment">// =================================================================</span>
|
|
<a name="l00221"></a>00221 <span class="comment">// Render a quad</span>
|
|
<a name="l00222"></a>00222 <span class="comment">// Instead of the using (s,t) coordinates, with the GL_NV_texture_rectangle</span>
|
|
<a name="l00223"></a>00223 <span class="comment">// extension, you need to use the actual dimensions of the texture.</span>
|
|
<a name="l00224"></a>00224 <span class="comment">// This makes using 2D sprites for games and emulators much easier now</span>
|
|
<a name="l00225"></a>00225 <span class="comment">// that you won't have to convert :)</span>
|
|
<a name="l00226"></a>00226 <span class="comment">//</span>
|
|
<a name="l00227"></a>00227 <span class="comment">// convert the coordinates so that the bottom left corner changes to</span>
|
|
<a name="l00228"></a>00228 <span class="comment">// (0, 0) -> (1, 1) and the top right corner changes from (1, 1) -> (0, 0)</span>
|
|
<a name="l00229"></a>00229 <span class="comment">// we will use this new coordinate system to calculate the location of the sprite</span>
|
|
<a name="l00230"></a>00230 <span class="comment">// in the world coordinates to do the rotation and scaling. This mapping is done in</span>
|
|
<a name="l00231"></a>00231 <span class="comment">// order to make implementation simpler in this class and let the caller keep using</span>
|
|
<a name="l00232"></a>00232 <span class="comment">// the standard OpenGL coordinates system (bottom left corner at (0, 0))</span>
|
|
<a name="l00233"></a>00233 <span class="comment">// =================================================================</span>
|
|
<a name="l00234"></a>00234 glBegin(GL_QUADS);
|
|
<a name="l00235"></a>00235 glTexCoord2i(0, 0);
|
|
<a name="l00236"></a>00236 glVertex2i(-pivotX * image-><a class="code" href="class_image_loader.html#ab673a17dd93d0a4393934afc14b86885">GetWidth</a>(), -pivotY * image-><a class="code" href="class_image_loader.html#a82df5f39b2a699ab215ae2f1c714b76e">GetHeight</a>());
|
|
<a name="l00237"></a>00237
|
|
<a name="l00238"></a>00238 glTexCoord2i(0, image-><a class="code" href="class_image_loader.html#a82df5f39b2a699ab215ae2f1c714b76e">GetHeight</a>());
|
|
<a name="l00239"></a>00239 glVertex2i(-pivotX * image-><a class="code" href="class_image_loader.html#ab673a17dd93d0a4393934afc14b86885">GetWidth</a>(), (1 - pivotY) * image-><a class="code" href="class_image_loader.html#a82df5f39b2a699ab215ae2f1c714b76e">GetHeight</a>());
|
|
<a name="l00240"></a>00240
|
|
<a name="l00241"></a>00241 glTexCoord2i(image-><a class="code" href="class_image_loader.html#ab673a17dd93d0a4393934afc14b86885">GetWidth</a>(), image-><a class="code" href="class_image_loader.html#a82df5f39b2a699ab215ae2f1c714b76e">GetHeight</a>());
|
|
<a name="l00242"></a>00242 glVertex2i( (1 - pivotX) * image-><a class="code" href="class_image_loader.html#ab673a17dd93d0a4393934afc14b86885">GetWidth</a>(), (1 - pivotY) * image-><a class="code" href="class_image_loader.html#a82df5f39b2a699ab215ae2f1c714b76e">GetHeight</a>());
|
|
<a name="l00243"></a>00243
|
|
<a name="l00244"></a>00244 glTexCoord2i(image-><a class="code" href="class_image_loader.html#ab673a17dd93d0a4393934afc14b86885">GetWidth</a>(), 0);
|
|
<a name="l00245"></a>00245 glVertex2i( (1 - pivotX) * image-><a class="code" href="class_image_loader.html#ab673a17dd93d0a4393934afc14b86885">GetWidth</a>(), -pivotY * image-><a class="code" href="class_image_loader.html#a82df5f39b2a699ab215ae2f1c714b76e">GetHeight</a>());
|
|
<a name="l00246"></a>00246 glEnd();
|
|
<a name="l00247"></a>00247
|
|
<a name="l00248"></a>00248 glPopMatrix();
|
|
<a name="l00249"></a>00249 }
|
|
</pre></div></div>
|
|
</div>
|
|
<div id="nav-path" class="navpath">
|
|
<ul>
|
|
<li class="navelem"><a class="el" href="_sprite_8cpp.html">Sprite.cpp</a> </li>
|
|
<li class="footer">Generated on Wed Nov 2 2011 22:46:22 for Unuk by 
|
|
<a href="http://www.doxygen.org/index.html">
|
|
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </li>
|
|
</ul>
|
|
</div>
|
|
<!-- window showing the filter options -->
|
|
<div id="MSearchSelectWindow"
|
|
onmouseover="return searchBox.OnSearchSelectShow()"
|
|
onmouseout="return searchBox.OnSearchSelectHide()"
|
|
onkeydown="return searchBox.OnSearchSelectKey(event)">
|
|
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark"> </span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark"> </span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark"> </span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark"> </span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark"> </span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark"> </span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark"> </span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark"> </span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark"> </span>Defines</a></div>
|
|
|
|
<!-- iframe showing the search results (closed by default) -->
|
|
<div id="MSearchResultsWindow">
|
|
<iframe src="javascript:void(0)" frameborder="0"
|
|
name="MSearchResults" id="MSearchResults">
|
|
</iframe>
|
|
</div>
|
|
|
|
|
|
</body>
|
|
</html>
|