1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>SFML - Simple and Fast Multimedia Library</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="tabs.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="logo">
<img src="./logo.jpg" width="770" height="200" title="SFML home" alt="SFML logo" />
</div>
<!-- Generated by Doxygen 1.5.8 -->
<div class="navigation" id="top">
<div class="tabs">
<ul>
<li><a href="index.htm"><span>Main Page</span></a></li>
<li><a href="namespaces.htm"><span>Namespaces</span></a></li>
<li><a href="annotated.htm"><span>Classes</span></a></li>
<li class="current"><a href="files.htm"><span>Files</span></a></li>
</ul>
</div>
<div class="tabs">
<ul>
<li><a href="files.htm"><span>File List</span></a></li>
</ul>
</div>
<h1>Image.cpp</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001
<a name="l00002"></a>00002 <span class="comment">//</span>
<a name="l00003"></a>00003 <span class="comment">// SFML - Simple and Fast Multimedia Library</span>
<a name="l00004"></a>00004 <span class="comment">// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)</span>
<a name="l00005"></a>00005 <span class="comment">//</span>
<a name="l00006"></a>00006 <span class="comment">// This software is provided 'as-is', without any express or implied warranty.</span>
<a name="l00007"></a>00007 <span class="comment">// In no event will the authors be held liable for any damages arising from the use of this software.</span>
<a name="l00008"></a>00008 <span class="comment">//</span>
<a name="l00009"></a>00009 <span class="comment">// Permission is granted to anyone to use this software for any purpose,</span>
<a name="l00010"></a>00010 <span class="comment">// including commercial applications, and to alter it and redistribute it freely,</span>
<a name="l00011"></a>00011 <span class="comment">// subject to the following restrictions:</span>
<a name="l00012"></a>00012 <span class="comment">//</span>
<a name="l00013"></a>00013 <span class="comment">// 1. The origin of this software must not be misrepresented;</span>
<a name="l00014"></a>00014 <span class="comment">// you must not claim that you wrote the original software.</span>
<a name="l00015"></a>00015 <span class="comment">// If you use this software in a product, an acknowledgment</span>
<a name="l00016"></a>00016 <span class="comment">// in the product documentation would be appreciated but is not required.</span>
<a name="l00017"></a>00017 <span class="comment">//</span>
<a name="l00018"></a>00018 <span class="comment">// 2. Altered source versions must be plainly marked as such,</span>
<a name="l00019"></a>00019 <span class="comment">// and must not be misrepresented as being the original software.</span>
<a name="l00020"></a>00020 <span class="comment">//</span>
<a name="l00021"></a>00021 <span class="comment">// 3. This notice may not be removed or altered from any source distribution.</span>
<a name="l00022"></a>00022 <span class="comment">//</span>
<a name="l00024"></a>00024 <span class="comment"></span>
<a name="l00026"></a>00026 <span class="comment">// Headers</span>
<a name="l00028"></a>00028 <span class="comment"></span><span class="preprocessor">#include <SFML/Graphics/Image.hpp></span>
<a name="l00029"></a>00029 <span class="preprocessor">#include <SFML/Graphics/ImageLoader.hpp></span>
<a name="l00030"></a>00030 <span class="preprocessor">#include <SFML/Graphics/RenderWindow.hpp></span>
<a name="l00031"></a>00031 <span class="preprocessor">#include <SFML/Graphics/GraphicsContext.hpp></span>
<a name="l00032"></a>00032 <span class="preprocessor">#include <algorithm></span>
<a name="l00033"></a>00033 <span class="preprocessor">#include <iostream></span>
<a name="l00034"></a>00034 <span class="preprocessor">#include <vector></span>
<a name="l00035"></a>00035 <span class="preprocessor">#include <string.h></span>
<a name="l00036"></a>00036
<a name="l00037"></a>00037
<a name="l00038"></a>00038 <span class="keyword">namespace </span>sf
<a name="l00039"></a>00039 {
<a name="l00043"></a><a class="code" href="classsf_1_1Image.htm#bb4caf3cb167b613345ebe36fc883f12">00043</a> <a class="code" href="classsf_1_1Image.htm#bb4caf3cb167b613345ebe36fc883f12" title="Default constructor.">Image::Image</a>() :
<a name="l00044"></a>00044 myWidth (0),
<a name="l00045"></a>00045 myHeight (0),
<a name="l00046"></a>00046 myTextureWidth (0),
<a name="l00047"></a>00047 myTextureHeight (0),
<a name="l00048"></a>00048 myTexture (0),
<a name="l00049"></a>00049 myIsSmooth (true),
<a name="l00050"></a>00050 myNeedTextureUpdate(false),
<a name="l00051"></a>00051 myNeedArrayUpdate (false)
<a name="l00052"></a>00052 {
<a name="l00053"></a>00053
<a name="l00054"></a>00054 }
<a name="l00055"></a>00055
<a name="l00056"></a>00056
<a name="l00060"></a><a class="code" href="classsf_1_1Image.htm#a38cae7c1c704aa0175b9e73645cb210">00060</a> <a class="code" href="classsf_1_1Image.htm#bb4caf3cb167b613345ebe36fc883f12" title="Default constructor.">Image::Image</a>(<span class="keyword">const</span> <a class="code" href="classsf_1_1Image.htm" title="Image is the low-level class for loading and manipulating images.">Image</a>& Copy) :
<a name="l00061"></a>00061 <a class="code" href="classsf_1_1Resource.htm" title="Base class for every resource that needs to notify dependent classes about its destruction...">Resource</a><<a class="code" href="classsf_1_1Image.htm" title="Image is the low-level class for loading and manipulating images.">Image</a>> (Copy),
<a name="l00062"></a>00062 myWidth (Copy.myWidth),
<a name="l00063"></a>00063 myHeight (Copy.myHeight),
<a name="l00064"></a>00064 myTextureWidth (Copy.myTextureWidth),
<a name="l00065"></a>00065 myTextureHeight (Copy.myTextureHeight),
<a name="l00066"></a>00066 myTexture (0),
<a name="l00067"></a>00067 myIsSmooth (Copy.myIsSmooth),
<a name="l00068"></a>00068 myPixels (Copy.myPixels),
<a name="l00069"></a>00069 myNeedTextureUpdate(false),
<a name="l00070"></a>00070 myNeedArrayUpdate (false)
<a name="l00071"></a>00071 {
<a name="l00072"></a>00072 CreateTexture();
<a name="l00073"></a>00073 }
<a name="l00074"></a>00074
<a name="l00075"></a>00075
<a name="l00079"></a><a class="code" href="classsf_1_1Image.htm#2a4c0ec448863784f83e9931d25dada2">00079</a> <a class="code" href="classsf_1_1Image.htm#bb4caf3cb167b613345ebe36fc883f12" title="Default constructor.">Image::Image</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> Width, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> Height, <span class="keyword">const</span> <a class="code" href="classsf_1_1Color.htm" title="Color is an utility class for manipulating 32-bits RGBA colors.">Color</a>& Col) :
<a name="l00080"></a>00080 myWidth (0),
<a name="l00081"></a>00081 myHeight (0),
<a name="l00082"></a>00082 myTextureWidth (0),
<a name="l00083"></a>00083 myTextureHeight (0),
<a name="l00084"></a>00084 myTexture (0),
<a name="l00085"></a>00085 myIsSmooth (true),
<a name="l00086"></a>00086 myNeedTextureUpdate(false),
<a name="l00087"></a>00087 myNeedArrayUpdate (false)
<a name="l00088"></a>00088 {
<a name="l00089"></a>00089 <a class="code" href="classsf_1_1Image.htm#4e2ce8821e8de36462604bbf99f39cde" title="Create an empty image.">Create</a>(Width, Height, Col);
<a name="l00090"></a>00090 }
<a name="l00091"></a>00091
<a name="l00092"></a>00092
<a name="l00096"></a><a class="code" href="classsf_1_1Image.htm#7092ba80cc19c053bf356e98a4743acb">00096</a> <a class="code" href="classsf_1_1Image.htm#bb4caf3cb167b613345ebe36fc883f12" title="Default constructor.">Image::Image</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> Width, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> Height, <span class="keyword">const</span> Uint8* Data) :
<a name="l00097"></a>00097 myWidth (0),
<a name="l00098"></a>00098 myHeight (0),
<a name="l00099"></a>00099 myTextureWidth (0),
<a name="l00100"></a>00100 myTextureHeight (0),
<a name="l00101"></a>00101 myTexture (0),
<a name="l00102"></a>00102 myIsSmooth (true),
<a name="l00103"></a>00103 myNeedTextureUpdate(false),
<a name="l00104"></a>00104 myNeedArrayUpdate (false)
<a name="l00105"></a>00105 {
<a name="l00106"></a>00106 <a class="code" href="classsf_1_1Image.htm#67d65c552c9bcba989a061e9c5b5d10c" title="Load the image directly from an array of pixels.">LoadFromPixels</a>(Width, Height, Data);
<a name="l00107"></a>00107 }
<a name="l00108"></a>00108
<a name="l00109"></a>00109
<a name="l00113"></a><a class="code" href="classsf_1_1Image.htm#0ba22a38e6c96e3b37dd88198046de83">00113</a> <a class="code" href="classsf_1_1Image.htm#0ba22a38e6c96e3b37dd88198046de83" title="Destructor.">Image::~Image</a>()
<a name="l00114"></a>00114 {
<a name="l00115"></a>00115 <span class="comment">// Destroy the OpenGL texture</span>
<a name="l00116"></a>00116 DestroyTexture();
<a name="l00117"></a>00117 }
<a name="l00118"></a>00118
<a name="l00119"></a>00119
<a name="l00123"></a><a class="code" href="classsf_1_1Image.htm#7cf6316aa5d022e0bdd95f1e79c9f50b">00123</a> <span class="keywordtype">bool</span> <a class="code" href="classsf_1_1Image.htm#7cf6316aa5d022e0bdd95f1e79c9f50b" title="Load the image from a file.">Image::LoadFromFile</a>(<span class="keyword">const</span> std::string& Filename)
<a name="l00124"></a>00124 {
<a name="l00125"></a>00125 <span class="comment">// Let the image loader load the image into our pixel array</span>
<a name="l00126"></a>00126 <span class="keywordtype">bool</span> Success = priv::ImageLoader::GetInstance().LoadImageFromFile(Filename, myPixels, myWidth, myHeight);
<a name="l00127"></a>00127
<a name="l00128"></a>00128 <span class="keywordflow">if</span> (Success)
<a name="l00129"></a>00129 {
<a name="l00130"></a>00130 <span class="comment">// Loading succeeded : we can create the texture</span>
<a name="l00131"></a>00131 <span class="keywordflow">if</span> (CreateTexture())
<a name="l00132"></a>00132 <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00133"></a>00133 }
<a name="l00134"></a>00134
<a name="l00135"></a>00135 <span class="comment">// Oops... something failed</span>
<a name="l00136"></a>00136 Reset();
<a name="l00137"></a>00137
<a name="l00138"></a>00138 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00139"></a>00139 }
<a name="l00140"></a>00140
<a name="l00141"></a>00141
<a name="l00145"></a><a class="code" href="classsf_1_1Image.htm#72565ffabe12dfb2602e209c2e6f0486">00145</a> <span class="keywordtype">bool</span> <a class="code" href="classsf_1_1Image.htm#72565ffabe12dfb2602e209c2e6f0486" title="Load the image from a file in memory.">Image::LoadFromMemory</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* Data, std::size_t SizeInBytes)
<a name="l00146"></a>00146 {
<a name="l00147"></a>00147 <span class="comment">// Check parameters</span>
<a name="l00148"></a>00148 <span class="keywordflow">if</span> (!Data || (SizeInBytes == 0))
<a name="l00149"></a>00149 {
<a name="l00150"></a>00150 std::cerr << <span class="stringliteral">"Failed to image font from memory, no data provided"</span> << std::endl;
<a name="l00151"></a>00151 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00152"></a>00152 }
<a name="l00153"></a>00153
<a name="l00154"></a>00154 <span class="comment">// Let the image loader load the image into our pixel array</span>
<a name="l00155"></a>00155 <span class="keywordtype">bool</span> Success = priv::ImageLoader::GetInstance().LoadImageFromMemory(Data, SizeInBytes, myPixels, myWidth, myHeight);
<a name="l00156"></a>00156
<a name="l00157"></a>00157 <span class="keywordflow">if</span> (Success)
<a name="l00158"></a>00158 {
<a name="l00159"></a>00159 <span class="comment">// Loading succeeded : we can create the texture</span>
<a name="l00160"></a>00160 <span class="keywordflow">if</span> (CreateTexture())
<a name="l00161"></a>00161 <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00162"></a>00162 }
<a name="l00163"></a>00163
<a name="l00164"></a>00164 <span class="comment">// Oops... something failed</span>
<a name="l00165"></a>00165 Reset();
<a name="l00166"></a>00166
<a name="l00167"></a>00167 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00168"></a>00168 }
<a name="l00169"></a>00169
<a name="l00170"></a>00170
<a name="l00174"></a><a class="code" href="classsf_1_1Image.htm#67d65c552c9bcba989a061e9c5b5d10c">00174</a> <span class="keywordtype">bool</span> <a class="code" href="classsf_1_1Image.htm#67d65c552c9bcba989a061e9c5b5d10c" title="Load the image directly from an array of pixels.">Image::LoadFromPixels</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> Width, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> Height, <span class="keyword">const</span> Uint8* Data)
<a name="l00175"></a>00175 {
<a name="l00176"></a>00176 <span class="keywordflow">if</span> (Data)
<a name="l00177"></a>00177 {
<a name="l00178"></a>00178 <span class="comment">// Store the texture dimensions</span>
<a name="l00179"></a>00179 myWidth = Width;
<a name="l00180"></a>00180 myHeight = Height;
<a name="l00181"></a>00181
<a name="l00182"></a>00182 <span class="comment">// Fill the pixel buffer with the specified raw data</span>
<a name="l00183"></a>00183 <span class="keyword">const</span> <a class="code" href="classsf_1_1Color.htm" title="Color is an utility class for manipulating 32-bits RGBA colors.">Color</a>* Ptr = <span class="keyword">reinterpret_cast<</span><span class="keyword">const </span><a class="code" href="classsf_1_1Color.htm" title="Color is an utility class for manipulating 32-bits RGBA colors.">Color</a>*<span class="keyword">></span>(Data);
<a name="l00184"></a>00184 myPixels.assign(Ptr, Ptr + Width * Height);
<a name="l00185"></a>00185
<a name="l00186"></a>00186 <span class="comment">// We can create the texture</span>
<a name="l00187"></a>00187 <span class="keywordflow">if</span> (CreateTexture())
<a name="l00188"></a>00188 {
<a name="l00189"></a>00189 <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00190"></a>00190 }
<a name="l00191"></a>00191 <span class="keywordflow">else</span>
<a name="l00192"></a>00192 {
<a name="l00193"></a>00193 <span class="comment">// Oops... something failed</span>
<a name="l00194"></a>00194 Reset();
<a name="l00195"></a>00195 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00196"></a>00196 }
<a name="l00197"></a>00197 }
<a name="l00198"></a>00198 <span class="keywordflow">else</span>
<a name="l00199"></a>00199 {
<a name="l00200"></a>00200 <span class="comment">// No data provided : create a white image</span>
<a name="l00201"></a>00201 <span class="keywordflow">return</span> <a class="code" href="classsf_1_1Image.htm#4e2ce8821e8de36462604bbf99f39cde" title="Create an empty image.">Create</a>(Width, Height, <a class="code" href="classsf_1_1Color.htm" title="Color is an utility class for manipulating 32-bits RGBA colors.">Color</a>(255, 255, 255, 255));
<a name="l00202"></a>00202 }
<a name="l00203"></a>00203 }
<a name="l00204"></a>00204
<a name="l00205"></a>00205
<a name="l00209"></a><a class="code" href="classsf_1_1Image.htm#50eed54ef8e9f3aeef5bb7f19144aa08">00209</a> <span class="keywordtype">bool</span> <a class="code" href="classsf_1_1Image.htm#50eed54ef8e9f3aeef5bb7f19144aa08" title="Save the content of the image to a file.">Image::SaveToFile</a>(<span class="keyword">const</span> std::string& Filename)<span class="keyword"> const</span>
<a name="l00210"></a>00210 <span class="keyword"></span>{
<a name="l00211"></a>00211 <span class="comment">// Check if the array of pixels needs to be updated</span>
<a name="l00212"></a>00212 EnsureArrayUpdate();
<a name="l00213"></a>00213
<a name="l00214"></a>00214 <span class="comment">// Let the image loader save our pixel array into the image</span>
<a name="l00215"></a>00215 <span class="keywordflow">return</span> priv::ImageLoader::GetInstance().SaveImageToFile(Filename, myPixels, myWidth, myHeight);
<a name="l00216"></a>00216 }
<a name="l00217"></a>00217
<a name="l00218"></a>00218
<a name="l00222"></a><a class="code" href="classsf_1_1Image.htm#4e2ce8821e8de36462604bbf99f39cde">00222</a> <span class="keywordtype">bool</span> <a class="code" href="classsf_1_1Image.htm#4e2ce8821e8de36462604bbf99f39cde" title="Create an empty image.">Image::Create</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> Width, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> Height, <a class="code" href="classsf_1_1Color.htm" title="Color is an utility class for manipulating 32-bits RGBA colors.">Color</a> Col)
<a name="l00223"></a>00223 {
<a name="l00224"></a>00224 <span class="comment">// Store the texture dimensions</span>
<a name="l00225"></a>00225 myWidth = Width;
<a name="l00226"></a>00226 myHeight = Height;
<a name="l00227"></a>00227
<a name="l00228"></a>00228 <span class="comment">// Recreate the pixel buffer and fill it with the specified color</span>
<a name="l00229"></a>00229 myPixels.clear();
<a name="l00230"></a>00230 myPixels.resize(Width * Height, Col);
<a name="l00231"></a>00231
<a name="l00232"></a>00232 <span class="comment">// We can create the texture</span>
<a name="l00233"></a>00233 <span class="keywordflow">if</span> (CreateTexture())
<a name="l00234"></a>00234 {
<a name="l00235"></a>00235 <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00236"></a>00236 }
<a name="l00237"></a>00237 <span class="keywordflow">else</span>
<a name="l00238"></a>00238 {
<a name="l00239"></a>00239 <span class="comment">// Oops... something failed</span>
<a name="l00240"></a>00240 Reset();
<a name="l00241"></a>00241 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00242"></a>00242 }
<a name="l00243"></a>00243 }
<a name="l00244"></a>00244
<a name="l00245"></a>00245
<a name="l00249"></a><a class="code" href="classsf_1_1Image.htm#e9a15fe9a4750295845b5ae081c2ec50">00249</a> <span class="keywordtype">void</span> <a class="code" href="classsf_1_1Image.htm#e9a15fe9a4750295845b5ae081c2ec50" title="Create transparency mask from a specified colorkey.">Image::CreateMaskFromColor</a>(<a class="code" href="classsf_1_1Color.htm" title="Color is an utility class for manipulating 32-bits RGBA colors.">Color</a> ColorKey, Uint8 Alpha)
<a name="l00250"></a>00250 {
<a name="l00251"></a>00251 <span class="comment">// Check if the array of pixels needs to be updated</span>
<a name="l00252"></a>00252 EnsureArrayUpdate();
<a name="l00253"></a>00253
<a name="l00254"></a>00254 <span class="comment">// Calculate the new color (old color with no alpha)</span>
<a name="l00255"></a>00255 <a class="code" href="classsf_1_1Color.htm" title="Color is an utility class for manipulating 32-bits RGBA colors.">Color</a> NewColor(ColorKey.<a class="code" href="classsf_1_1Color.htm#6a5256ca24a4f9f0e0808f6fc23e01e1" title="Red component.">r</a>, ColorKey.<a class="code" href="classsf_1_1Color.htm#591daf9c3c55dea830c76c962d6ba1a5" title="Green component.">g</a>, ColorKey.<a class="code" href="classsf_1_1Color.htm#6707aedd0609c8920e12df5d7abc53cb" title="Blue component.">b</a>, Alpha);
<a name="l00256"></a>00256
<a name="l00257"></a>00257 <span class="comment">// Replace the old color by the new one</span>
<a name="l00258"></a>00258 std::replace(myPixels.begin(), myPixels.end(), ColorKey, NewColor);
<a name="l00259"></a>00259
<a name="l00260"></a>00260 <span class="comment">// The texture will need to be updated</span>
<a name="l00261"></a>00261 myNeedTextureUpdate = <span class="keyword">true</span>;
<a name="l00262"></a>00262 }
<a name="l00263"></a>00263
<a name="l00264"></a>00264
<a name="l00270"></a><a class="code" href="classsf_1_1Image.htm#408c40c8675363adfa96a8b9a9576bc2">00270</a> <span class="keywordtype">void</span> <a class="code" href="classsf_1_1Image.htm#408c40c8675363adfa96a8b9a9576bc2" title="Copy pixels from another image onto this one.">Image::Copy</a>(<span class="keyword">const</span> <a class="code" href="classsf_1_1Image.htm" title="Image is the low-level class for loading and manipulating images.">Image</a>& Source, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> DestX, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> DestY, <span class="keyword">const</span> <a class="code" href="classsf_1_1Rect.htm">IntRect</a>& SourceRect, <span class="keywordtype">bool</span> ApplyAlpha)
<a name="l00271"></a>00271 {
<a name="l00272"></a>00272 <span class="comment">// Make sure both images are valid</span>
<a name="l00273"></a>00273 <span class="keywordflow">if</span> ((Source.<a class="code" href="classsf_1_1Image.htm#924ed57a1565f1248a4411e2be7e23e2" title="Image width.">myWidth</a> == 0) || (Source.<a class="code" href="classsf_1_1Image.htm#ceef290985323875724673f5fdc2f6d0" title="Image Height.">myHeight</a> == 0) || (myWidth == 0) || (myHeight == 0))
<a name="l00274"></a>00274 <span class="keywordflow">return</span>;
<a name="l00275"></a>00275
<a name="l00276"></a>00276 <span class="comment">// Make sure both images have up-to-date arrays</span>
<a name="l00277"></a>00277 EnsureArrayUpdate();
<a name="l00278"></a>00278 Source.<a class="code" href="classsf_1_1Image.htm#9e4a9bfca94b75367192b960b0d87a9d" title="Make sure the array of pixels is updated with the texture in video memory.">EnsureArrayUpdate</a>();
<a name="l00279"></a>00279
<a name="l00280"></a>00280 <span class="comment">// Adjust the source rectangle</span>
<a name="l00281"></a>00281 <a class="code" href="classsf_1_1Rect.htm">IntRect</a> SrcRect = SourceRect;
<a name="l00282"></a>00282 <span class="keywordflow">if</span> (SrcRect.<a class="code" href="classsf_1_1Rect.htm#6a8c09ef44123228aa44aff8f0b09087" title="Get the width of the rectangle.">GetWidth</a>() == 0 || (SrcRect.<a class="code" href="classsf_1_1Rect.htm#a3c1ca9c959dae33d2eec290b2e48d75" title="Get the height of the rectangle.">GetHeight</a>() == 0))
<a name="l00283"></a>00283 {
<a name="l00284"></a>00284 SrcRect.<a class="code" href="classsf_1_1Rect.htm#9619c6b9741163c86eea6a0b84b2f9b3" title="Left coordinate of the rectangle.">Left</a> = 0;
<a name="l00285"></a>00285 SrcRect.<a class="code" href="classsf_1_1Rect.htm#4addcc0bf656fb5f2f80d406cf90c047" title="Top coordinate of the rectangle.">Top</a> = 0;
<a name="l00286"></a>00286 SrcRect.<a class="code" href="classsf_1_1Rect.htm#6ce87895496327187a20a46dc2479383" title="Right coordinate of the rectangle.">Right</a> = Source.<a class="code" href="classsf_1_1Image.htm#924ed57a1565f1248a4411e2be7e23e2" title="Image width.">myWidth</a>;
<a name="l00287"></a>00287 SrcRect.<a class="code" href="classsf_1_1Rect.htm#b234b311011892cfd8a3e831dec341a8" title="Bottom coordinate of the rectangle.">Bottom</a> = Source.<a class="code" href="classsf_1_1Image.htm#ceef290985323875724673f5fdc2f6d0" title="Image Height.">myHeight</a>;
<a name="l00288"></a>00288 }
<a name="l00289"></a>00289 <span class="keywordflow">else</span>
<a name="l00290"></a>00290 {
<a name="l00291"></a>00291 <span class="keywordflow">if</span> (SrcRect.<a class="code" href="classsf_1_1Rect.htm#9619c6b9741163c86eea6a0b84b2f9b3" title="Left coordinate of the rectangle.">Left</a> < 0) SrcRect.<a class="code" href="classsf_1_1Rect.htm#9619c6b9741163c86eea6a0b84b2f9b3" title="Left coordinate of the rectangle.">Left</a> = 0;
<a name="l00292"></a>00292 <span class="keywordflow">if</span> (SrcRect.<a class="code" href="classsf_1_1Rect.htm#4addcc0bf656fb5f2f80d406cf90c047" title="Top coordinate of the rectangle.">Top</a> < 0) SrcRect.<a class="code" href="classsf_1_1Rect.htm#4addcc0bf656fb5f2f80d406cf90c047" title="Top coordinate of the rectangle.">Top</a> = 0;
<a name="l00293"></a>00293 <span class="keywordflow">if</span> (SrcRect.<a class="code" href="classsf_1_1Rect.htm#6ce87895496327187a20a46dc2479383" title="Right coordinate of the rectangle.">Right</a> > static_cast<int>(Source.<a class="code" href="classsf_1_1Image.htm#924ed57a1565f1248a4411e2be7e23e2" title="Image width.">myWidth</a>)) SrcRect.<a class="code" href="classsf_1_1Rect.htm#6ce87895496327187a20a46dc2479383" title="Right coordinate of the rectangle.">Right</a> = Source.<a class="code" href="classsf_1_1Image.htm#924ed57a1565f1248a4411e2be7e23e2" title="Image width.">myWidth</a>;
<a name="l00294"></a>00294 if (SrcRect.<a class="code" href="classsf_1_1Rect.htm#b234b311011892cfd8a3e831dec341a8" title="Bottom coordinate of the rectangle.">Bottom</a> > static_cast<int>(Source.<a class="code" href="classsf_1_1Image.htm#ceef290985323875724673f5fdc2f6d0" title="Image Height.">myHeight</a>)) SrcRect.<a class="code" href="classsf_1_1Rect.htm#b234b311011892cfd8a3e831dec341a8" title="Bottom coordinate of the rectangle.">Bottom</a> = Source.<a class="code" href="classsf_1_1Image.htm#ceef290985323875724673f5fdc2f6d0" title="Image Height.">myHeight</a>;
<a name="l00295"></a>00295 }
<a name="l00296"></a>00296
<a name="l00297"></a>00297 <span class="comment">// Then find the valid bounds of the destination rectangle</span>
<a name="l00298"></a>00298 <span class="keywordtype">int</span> Width = SrcRect.<a class="code" href="classsf_1_1Rect.htm#6a8c09ef44123228aa44aff8f0b09087" title="Get the width of the rectangle.">GetWidth</a>();
<a name="l00299"></a>00299 <span class="keywordtype">int</span> Height = SrcRect.<a class="code" href="classsf_1_1Rect.htm#a3c1ca9c959dae33d2eec290b2e48d75" title="Get the height of the rectangle.">GetHeight</a>();
<a name="l00300"></a>00300 <span class="keywordflow">if</span> (DestX + Width > myWidth) Width = myWidth - DestX;
<a name="l00301"></a>00301 <span class="keywordflow">if</span> (DestY + Height > myHeight) Height = myHeight - DestY;
<a name="l00302"></a>00302
<a name="l00303"></a>00303 <span class="comment">// Make sure the destination area is valid</span>
<a name="l00304"></a>00304 <span class="keywordflow">if</span> ((Width <= 0) || (Height <= 0))
<a name="l00305"></a>00305 <span class="keywordflow">return</span>;
<a name="l00306"></a>00306
<a name="l00307"></a>00307 <span class="comment">// Precompute as much as possible</span>
<a name="l00308"></a>00308 <span class="keywordtype">int</span> Pitch = Width * 4;
<a name="l00309"></a>00309 <span class="keywordtype">int</span> Rows = Height;
<a name="l00310"></a>00310 <span class="keywordtype">int</span> SrcStride = Source.<a class="code" href="classsf_1_1Image.htm#924ed57a1565f1248a4411e2be7e23e2" title="Image width.">myWidth</a> * 4;
<a name="l00311"></a>00311 <span class="keywordtype">int</span> DstStride = myWidth * 4;
<a name="l00312"></a>00312 <span class="keyword">const</span> Uint8* SrcPixels = Source.<a class="code" href="classsf_1_1Image.htm#85355b09f946aa4b985f9d2a1d620022" title="Get a read-only pointer to the array of pixels (RGBA 8 bits integers components)...">GetPixelsPtr</a>() + (SrcRect.<a class="code" href="classsf_1_1Rect.htm#9619c6b9741163c86eea6a0b84b2f9b3" title="Left coordinate of the rectangle.">Left</a> + SrcRect.<a class="code" href="classsf_1_1Rect.htm#4addcc0bf656fb5f2f80d406cf90c047" title="Top coordinate of the rectangle.">Top</a> * Source.<a class="code" href="classsf_1_1Image.htm#924ed57a1565f1248a4411e2be7e23e2" title="Image width.">myWidth</a>) * 4;
<a name="l00313"></a>00313 Uint8* DstPixels = <span class="keyword">reinterpret_cast<</span>Uint8*<span class="keyword">></span>(&myPixels[0]) + (DestX + DestY * myWidth) * 4;
<a name="l00314"></a>00314
<a name="l00315"></a>00315 <span class="comment">// Copy the pixels</span>
<a name="l00316"></a>00316 <span class="keywordflow">if</span> (ApplyAlpha)
<a name="l00317"></a>00317 {
<a name="l00318"></a>00318 <span class="comment">// Interpolation using alpha values, pixel by pixel (slower)</span>
<a name="l00319"></a>00319 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < Rows; ++i)
<a name="l00320"></a>00320 {
<a name="l00321"></a>00321 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j = 0; j < Width; ++j)
<a name="l00322"></a>00322 {
<a name="l00323"></a>00323 <span class="comment">// Get a direct pointer to the components of the current pixel</span>
<a name="l00324"></a>00324 <span class="keyword">const</span> Uint8* Src = SrcPixels + j * 4;
<a name="l00325"></a>00325 Uint8* Dst = DstPixels + j * 4;
<a name="l00326"></a>00326
<a name="l00327"></a>00327 <span class="comment">// Interpolate RGB components using the alpha value of the source pixel</span>
<a name="l00328"></a>00328 Uint8 Alpha = Src[3];
<a name="l00329"></a>00329 Dst[0] = (Src[0] * Alpha + Dst[0] * (255 - Alpha)) / 255;
<a name="l00330"></a>00330 Dst[1] = (Src[1] * Alpha + Dst[1] * (255 - Alpha)) / 255;
<a name="l00331"></a>00331 Dst[2] = (Src[2] * Alpha + Dst[2] * (255 - Alpha)) / 255;
<a name="l00332"></a>00332 }
<a name="l00333"></a>00333
<a name="l00334"></a>00334 SrcPixels += SrcStride;
<a name="l00335"></a>00335 DstPixels += DstStride;
<a name="l00336"></a>00336 }
<a name="l00337"></a>00337 }
<a name="l00338"></a>00338 <span class="keywordflow">else</span>
<a name="l00339"></a>00339 {
<a name="l00340"></a>00340 <span class="comment">// Optimized copy ignoring alpha values, row by row (faster)</span>
<a name="l00341"></a>00341 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < Rows; ++i)
<a name="l00342"></a>00342 {
<a name="l00343"></a>00343 memcpy(DstPixels, SrcPixels, Pitch);
<a name="l00344"></a>00344 SrcPixels += SrcStride;
<a name="l00345"></a>00345 DstPixels += DstStride;
<a name="l00346"></a>00346 }
<a name="l00347"></a>00347 }
<a name="l00348"></a>00348
<a name="l00349"></a>00349 <span class="comment">// The texture will need an update</span>
<a name="l00350"></a>00350 myNeedTextureUpdate = <span class="keyword">true</span>;
<a name="l00351"></a>00351 }
<a name="l00352"></a>00352
<a name="l00353"></a>00353
<a name="l00358"></a><a class="code" href="classsf_1_1Image.htm#96597746f70ce1925ec82d2df8ae6974">00358</a> <span class="keywordtype">bool</span> <a class="code" href="classsf_1_1Image.htm#96597746f70ce1925ec82d2df8ae6974" title="Create the image from the current contents of the given window.">Image::CopyScreen</a>(<a class="code" href="classsf_1_1RenderWindow.htm" title="Simple wrapper for sf::Window that allows easy 2D rendering.">RenderWindow</a>& <a class="code" href="classsf_1_1Window.htm" title="Window is a rendering window ; it can create a new window or connect to an existing...">Window</a>, <span class="keyword">const</span> <a class="code" href="classsf_1_1Rect.htm">IntRect</a>& SourceRect)
<a name="l00359"></a>00359 {
<a name="l00360"></a>00360 <span class="comment">// Adjust the source rectangle</span>
<a name="l00361"></a>00361 <a class="code" href="classsf_1_1Rect.htm">IntRect</a> SrcRect = SourceRect;
<a name="l00362"></a>00362 <span class="keywordflow">if</span> (SrcRect.<a class="code" href="classsf_1_1Rect.htm#6a8c09ef44123228aa44aff8f0b09087" title="Get the width of the rectangle.">GetWidth</a>() == 0 || (SrcRect.<a class="code" href="classsf_1_1Rect.htm#a3c1ca9c959dae33d2eec290b2e48d75" title="Get the height of the rectangle.">GetHeight</a>() == 0))
<a name="l00363"></a>00363 {
<a name="l00364"></a>00364 SrcRect.<a class="code" href="classsf_1_1Rect.htm#9619c6b9741163c86eea6a0b84b2f9b3" title="Left coordinate of the rectangle.">Left</a> = 0;
<a name="l00365"></a>00365 SrcRect.<a class="code" href="classsf_1_1Rect.htm#4addcc0bf656fb5f2f80d406cf90c047" title="Top coordinate of the rectangle.">Top</a> = 0;
<a name="l00366"></a>00366 SrcRect.<a class="code" href="classsf_1_1Rect.htm#6ce87895496327187a20a46dc2479383" title="Right coordinate of the rectangle.">Right</a> = Window.<a class="code" href="classsf_1_1RenderWindow.htm#e2b04f655a655b7c4bfac22958266e0c" title="Get the width of the rendering region of the window.">GetWidth</a>();
<a name="l00367"></a>00367 SrcRect.<a class="code" href="classsf_1_1Rect.htm#b234b311011892cfd8a3e831dec341a8" title="Bottom coordinate of the rectangle.">Bottom</a> = Window.<a class="code" href="classsf_1_1RenderWindow.htm#efa842a47f9c2415d1f8e93543ed2447" title="Get the height of the rendering region of the window.">GetHeight</a>();
<a name="l00368"></a>00368 }
<a name="l00369"></a>00369 <span class="keywordflow">else</span>
<a name="l00370"></a>00370 {
<a name="l00371"></a>00371 <span class="keywordflow">if</span> (SrcRect.<a class="code" href="classsf_1_1Rect.htm#9619c6b9741163c86eea6a0b84b2f9b3" title="Left coordinate of the rectangle.">Left</a> < 0) SrcRect.<a class="code" href="classsf_1_1Rect.htm#9619c6b9741163c86eea6a0b84b2f9b3" title="Left coordinate of the rectangle.">Left</a> = 0;
<a name="l00372"></a>00372 <span class="keywordflow">if</span> (SrcRect.<a class="code" href="classsf_1_1Rect.htm#4addcc0bf656fb5f2f80d406cf90c047" title="Top coordinate of the rectangle.">Top</a> < 0) SrcRect.<a class="code" href="classsf_1_1Rect.htm#4addcc0bf656fb5f2f80d406cf90c047" title="Top coordinate of the rectangle.">Top</a> = 0;
<a name="l00373"></a>00373 <span class="keywordflow">if</span> (SrcRect.<a class="code" href="classsf_1_1Rect.htm#6ce87895496327187a20a46dc2479383" title="Right coordinate of the rectangle.">Right</a> > static_cast<int>(Window.<a class="code" href="classsf_1_1RenderWindow.htm#e2b04f655a655b7c4bfac22958266e0c" title="Get the width of the rendering region of the window.">GetWidth</a>())) SrcRect.<a class="code" href="classsf_1_1Rect.htm#6ce87895496327187a20a46dc2479383" title="Right coordinate of the rectangle.">Right</a> = Window.<a class="code" href="classsf_1_1RenderWindow.htm#e2b04f655a655b7c4bfac22958266e0c" title="Get the width of the rendering region of the window.">GetWidth</a>();
<a name="l00374"></a>00374 <span class="keywordflow">if</span> (SrcRect.<a class="code" href="classsf_1_1Rect.htm#b234b311011892cfd8a3e831dec341a8" title="Bottom coordinate of the rectangle.">Bottom</a> > static_cast<int>(Window.<a class="code" href="classsf_1_1RenderWindow.htm#efa842a47f9c2415d1f8e93543ed2447" title="Get the height of the rendering region of the window.">GetHeight</a>())) SrcRect.<a class="code" href="classsf_1_1Rect.htm#b234b311011892cfd8a3e831dec341a8" title="Bottom coordinate of the rectangle.">Bottom</a> = Window.<a class="code" href="classsf_1_1RenderWindow.htm#efa842a47f9c2415d1f8e93543ed2447" title="Get the height of the rendering region of the window.">GetHeight</a>();
<a name="l00375"></a>00375 }
<a name="l00376"></a>00376
<a name="l00377"></a>00377 <span class="comment">// Store the texture dimensions</span>
<a name="l00378"></a>00378 myWidth = SrcRect.<a class="code" href="classsf_1_1Rect.htm#6a8c09ef44123228aa44aff8f0b09087" title="Get the width of the rectangle.">GetWidth</a>();
<a name="l00379"></a>00379 myHeight = SrcRect.<a class="code" href="classsf_1_1Rect.htm#a3c1ca9c959dae33d2eec290b2e48d75" title="Get the height of the rectangle.">GetHeight</a>();
<a name="l00380"></a>00380
<a name="l00381"></a>00381 <span class="comment">// We can then create the texture</span>
<a name="l00382"></a>00382 <span class="keywordflow">if</span> (Window.<a class="code" href="classsf_1_1Window.htm#9fc1e745594d5cf6a30225ec9ea36675" title="Activate of deactivate the window as the current target for rendering.">SetActive</a>() && CreateTexture())
<a name="l00383"></a>00383 {
<a name="l00384"></a>00384 GLint PreviousTexture;
<a name="l00385"></a>00385 GLCheck(glGetIntegerv(GL_TEXTURE_BINDING_2D, &PreviousTexture));
<a name="l00386"></a>00386
<a name="l00387"></a>00387 GLCheck(glBindTexture(GL_TEXTURE_2D, myTexture));
<a name="l00388"></a>00388 GLCheck(glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, SrcRect.<a class="code" href="classsf_1_1Rect.htm#9619c6b9741163c86eea6a0b84b2f9b3" title="Left coordinate of the rectangle.">Left</a>, SrcRect.<a class="code" href="classsf_1_1Rect.htm#4addcc0bf656fb5f2f80d406cf90c047" title="Top coordinate of the rectangle.">Top</a>, myWidth, myHeight));
<a name="l00389"></a>00389
<a name="l00390"></a>00390 GLCheck(glBindTexture(GL_TEXTURE_2D, PreviousTexture));
<a name="l00391"></a>00391
<a name="l00392"></a>00392 myNeedTextureUpdate = <span class="keyword">false</span>;
<a name="l00393"></a>00393 myNeedArrayUpdate = <span class="keyword">true</span>;
<a name="l00394"></a>00394
<a name="l00395"></a>00395 <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00396"></a>00396 }
<a name="l00397"></a>00397 <span class="keywordflow">else</span>
<a name="l00398"></a>00398 {
<a name="l00399"></a>00399 Reset();
<a name="l00400"></a>00400 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00401"></a>00401 }
<a name="l00402"></a>00402 }
<a name="l00403"></a>00403
<a name="l00404"></a>00404
<a name="l00408"></a><a class="code" href="classsf_1_1Image.htm#623f2379b30307b4ee4eb08d517d9584">00408</a> <span class="keywordtype">void</span> <a class="code" href="classsf_1_1Image.htm#623f2379b30307b4ee4eb08d517d9584" title="Change the color of a pixel.">Image::SetPixel</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> X, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> Y, <span class="keyword">const</span> <a class="code" href="classsf_1_1Color.htm" title="Color is an utility class for manipulating 32-bits RGBA colors.">Color</a>& Col)
<a name="l00409"></a>00409 {
<a name="l00410"></a>00410 <span class="comment">// First check if the array of pixels needs to be updated</span>
<a name="l00411"></a>00411 EnsureArrayUpdate();
<a name="l00412"></a>00412
<a name="l00413"></a>00413 <span class="comment">// Check if pixel is whithin the image bounds</span>
<a name="l00414"></a>00414 <span class="keywordflow">if</span> ((X >= myWidth) || (Y >= myHeight))
<a name="l00415"></a>00415 {
<a name="l00416"></a>00416 std::cerr << <span class="stringliteral">"Cannot set pixel ("</span> << X << <span class="stringliteral">","</span> << Y << <span class="stringliteral">") for image "</span>
<a name="l00417"></a>00417 << <span class="stringliteral">"(width = "</span> << myWidth << <span class="stringliteral">", height = "</span> << myHeight << <span class="stringliteral">")"</span> << std::endl;
<a name="l00418"></a>00418 <span class="keywordflow">return</span>;
<a name="l00419"></a>00419 }
<a name="l00420"></a>00420
<a name="l00421"></a>00421 myPixels[X + Y * myWidth] = Col;
<a name="l00422"></a>00422
<a name="l00423"></a>00423 <span class="comment">// The texture will need to be updated</span>
<a name="l00424"></a>00424 myNeedTextureUpdate = <span class="keyword">true</span>;
<a name="l00425"></a>00425 }
<a name="l00426"></a>00426
<a name="l00427"></a>00427
<a name="l00431"></a><a class="code" href="classsf_1_1Image.htm#b7590e372a153ace848cf8a6081c8bc4">00431</a> <span class="keyword">const</span> <a class="code" href="classsf_1_1Color.htm" title="Color is an utility class for manipulating 32-bits RGBA colors.">Color</a>& <a class="code" href="classsf_1_1Image.htm#b7590e372a153ace848cf8a6081c8bc4" title="Get a pixel from the image.">Image::GetPixel</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> X, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> Y)<span class="keyword"> const</span>
<a name="l00432"></a>00432 <span class="keyword"></span>{
<a name="l00433"></a>00433 <span class="comment">// First check if the array of pixels needs to be updated</span>
<a name="l00434"></a>00434 EnsureArrayUpdate();
<a name="l00435"></a>00435
<a name="l00436"></a>00436 <span class="comment">// Check if pixel is whithin the image bounds</span>
<a name="l00437"></a>00437 <span class="keywordflow">if</span> ((X >= myWidth) || (Y >= myHeight))
<a name="l00438"></a>00438 {
<a name="l00439"></a>00439 std::cerr << <span class="stringliteral">"Cannot get pixel ("</span> << X << <span class="stringliteral">","</span> << Y << <span class="stringliteral">") for image "</span>
<a name="l00440"></a>00440 << <span class="stringliteral">"(width = "</span> << myWidth << <span class="stringliteral">", height = "</span> << myHeight << <span class="stringliteral">")"</span> << std::endl;
<a name="l00441"></a>00441 <span class="keywordflow">return</span> <a class="code" href="classsf_1_1Color.htm#77c688197b981338f0b19dc58bd2facd" title="Black predefined color.">Color::Black</a>;
<a name="l00442"></a>00442 }
<a name="l00443"></a>00443
<a name="l00444"></a>00444 <span class="keywordflow">return</span> myPixels[X + Y * myWidth];
<a name="l00445"></a>00445 }
<a name="l00446"></a>00446
<a name="l00447"></a>00447
<a name="l00453"></a><a class="code" href="classsf_1_1Image.htm#85355b09f946aa4b985f9d2a1d620022">00453</a> <span class="keyword">const</span> Uint8* <a class="code" href="classsf_1_1Image.htm#85355b09f946aa4b985f9d2a1d620022" title="Get a read-only pointer to the array of pixels (RGBA 8 bits integers components)...">Image::GetPixelsPtr</a>()<span class="keyword"> const</span>
<a name="l00454"></a>00454 <span class="keyword"></span>{
<a name="l00455"></a>00455 <span class="comment">// First check if the array of pixels needs to be updated</span>
<a name="l00456"></a>00456 EnsureArrayUpdate();
<a name="l00457"></a>00457
<a name="l00458"></a>00458 <span class="keywordflow">if</span> (!myPixels.empty())
<a name="l00459"></a>00459 {
<a name="l00460"></a>00460 <span class="keywordflow">return</span> <span class="keyword">reinterpret_cast<</span><span class="keyword">const </span>Uint8*<span class="keyword">></span>(&myPixels[0]);
<a name="l00461"></a>00461 }
<a name="l00462"></a>00462 <span class="keywordflow">else</span>
<a name="l00463"></a>00463 {
<a name="l00464"></a>00464 std::cerr << <span class="stringliteral">"Trying to access the pixels of an empty image"</span> << std::endl;
<a name="l00465"></a>00465 <span class="keywordflow">return</span> NULL;
<a name="l00466"></a>00466 }
<a name="l00467"></a>00467 }
<a name="l00468"></a>00468
<a name="l00469"></a>00469
<a name="l00473"></a><a class="code" href="classsf_1_1Image.htm#74bda6dc927849ff25f8fce5143918e7">00473</a> <span class="keywordtype">void</span> <a class="code" href="classsf_1_1Image.htm#74bda6dc927849ff25f8fce5143918e7" title="Bind the image for rendering.">Image::Bind</a>()<span class="keyword"> const</span>
<a name="l00474"></a>00474 <span class="keyword"></span>{
<a name="l00475"></a>00475 <span class="comment">// First check if the texture needs to be updated</span>
<a name="l00476"></a>00476 EnsureTextureUpdate();
<a name="l00477"></a>00477
<a name="l00478"></a>00478 <span class="comment">// Bind it</span>
<a name="l00479"></a>00479 <span class="keywordflow">if</span> (myTexture)
<a name="l00480"></a>00480 {
<a name="l00481"></a>00481 GLCheck(glEnable(GL_TEXTURE_2D));
<a name="l00482"></a>00482 GLCheck(glBindTexture(GL_TEXTURE_2D, myTexture));
<a name="l00483"></a>00483 }
<a name="l00484"></a>00484 }
<a name="l00485"></a>00485
<a name="l00486"></a>00486
<a name="l00490"></a><a class="code" href="classsf_1_1Image.htm#d167422fd331cd069674391fb16e8452">00490</a> <span class="keywordtype">void</span> <a class="code" href="classsf_1_1Image.htm#d167422fd331cd069674391fb16e8452" title="Enable or disable image smooth filter.">Image::SetSmooth</a>(<span class="keywordtype">bool</span> Smooth)
<a name="l00491"></a>00491 {
<a name="l00492"></a>00492 <span class="keywordflow">if</span> (Smooth != myIsSmooth)
<a name="l00493"></a>00493 {
<a name="l00494"></a>00494 myIsSmooth = Smooth;
<a name="l00495"></a>00495
<a name="l00496"></a>00496 <span class="keywordflow">if</span> (myTexture)
<a name="l00497"></a>00497 {
<a name="l00498"></a>00498 <span class="comment">// Make sure we have a valid context</span>
<a name="l00499"></a>00499 priv::GraphicsContext Ctx;
<a name="l00500"></a>00500
<a name="l00501"></a>00501 GLint PreviousTexture;
<a name="l00502"></a>00502 GLCheck(glGetIntegerv(GL_TEXTURE_BINDING_2D, &PreviousTexture));
<a name="l00503"></a>00503
<a name="l00504"></a>00504 GLCheck(glBindTexture(GL_TEXTURE_2D, myTexture));
<a name="l00505"></a>00505 GLCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, myIsSmooth ? GL_LINEAR : GL_NEAREST));
<a name="l00506"></a>00506 GLCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, myIsSmooth ? GL_LINEAR : GL_NEAREST));
<a name="l00507"></a>00507
<a name="l00508"></a>00508 GLCheck(glBindTexture(GL_TEXTURE_2D, PreviousTexture));
<a name="l00509"></a>00509 }
<a name="l00510"></a>00510 }
<a name="l00511"></a>00511 }
<a name="l00512"></a>00512
<a name="l00513"></a>00513
<a name="l00517"></a><a class="code" href="classsf_1_1Image.htm#896f09a4eb769b5b866b6dde9c1a25e7">00517</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="classsf_1_1Image.htm#896f09a4eb769b5b866b6dde9c1a25e7" title="Return the width of the image.">Image::GetWidth</a>()<span class="keyword"> const</span>
<a name="l00518"></a>00518 <span class="keyword"></span>{
<a name="l00519"></a>00519 <span class="keywordflow">return</span> myWidth;
<a name="l00520"></a>00520 }
<a name="l00521"></a>00521
<a name="l00522"></a>00522
<a name="l00526"></a><a class="code" href="classsf_1_1Image.htm#f2131512b6290fd96fd10c539723fe89">00526</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="classsf_1_1Image.htm#f2131512b6290fd96fd10c539723fe89" title="Return the height of the image.">Image::GetHeight</a>()<span class="keyword"> const</span>
<a name="l00527"></a>00527 <span class="keyword"></span>{
<a name="l00528"></a>00528 <span class="keywordflow">return</span> myHeight;
<a name="l00529"></a>00529 }
<a name="l00530"></a>00530
<a name="l00531"></a>00531
<a name="l00535"></a><a class="code" href="classsf_1_1Image.htm#d175b4c9110549c5df324ba61c580ce3">00535</a> <span class="keywordtype">bool</span> <a class="code" href="classsf_1_1Image.htm#d175b4c9110549c5df324ba61c580ce3" title="Tells whether the smooth filtering is enabled or not.">Image::IsSmooth</a>()<span class="keyword"> const</span>
<a name="l00536"></a>00536 <span class="keyword"></span>{
<a name="l00537"></a>00537 <span class="keywordflow">return</span> myIsSmooth;
<a name="l00538"></a>00538 }
<a name="l00539"></a>00539
<a name="l00540"></a>00540
<a name="l00545"></a><a class="code" href="classsf_1_1Image.htm#066704507bcaabe27db17170bf02bd56">00545</a> <a class="code" href="classsf_1_1Rect.htm">FloatRect</a> <a class="code" href="classsf_1_1Image.htm#066704507bcaabe27db17170bf02bd56" title="Convert a subrect expressed in pixels, into float texture coordinates.">Image::GetTexCoords</a>(<span class="keyword">const</span> <a class="code" href="classsf_1_1Rect.htm">IntRect</a>& <a class="code" href="classsf_1_1Rect.htm" title="Rect is an utility class for manipulating rectangles.">Rect</a>)<span class="keyword"> const</span>
<a name="l00546"></a>00546 <span class="keyword"></span>{
<a name="l00547"></a>00547 <span class="keywordtype">float</span> Width = <span class="keyword">static_cast<</span><span class="keywordtype">float</span><span class="keyword">></span>(myTextureWidth);
<a name="l00548"></a>00548 <span class="keywordtype">float</span> Height = <span class="keyword">static_cast<</span><span class="keywordtype">float</span><span class="keyword">></span>(myTextureHeight);
<a name="l00549"></a>00549
<a name="l00550"></a>00550 <span class="keywordflow">return</span> <a class="code" href="classsf_1_1Rect.htm">FloatRect</a>(Rect.<a class="code" href="classsf_1_1Rect.htm#9619c6b9741163c86eea6a0b84b2f9b3" title="Left coordinate of the rectangle.">Left</a> / Width,
<a name="l00551"></a>00551 Rect.<a class="code" href="classsf_1_1Rect.htm#4addcc0bf656fb5f2f80d406cf90c047" title="Top coordinate of the rectangle.">Top</a> / Height,
<a name="l00552"></a>00552 Rect.<a class="code" href="classsf_1_1Rect.htm#6ce87895496327187a20a46dc2479383" title="Right coordinate of the rectangle.">Right</a> / Width,
<a name="l00553"></a>00553 Rect.<a class="code" href="classsf_1_1Rect.htm#b234b311011892cfd8a3e831dec341a8" title="Bottom coordinate of the rectangle.">Bottom</a> / Height);
<a name="l00554"></a>00554 }
<a name="l00555"></a>00555
<a name="l00556"></a>00556
<a name="l00560"></a><a class="code" href="classsf_1_1Image.htm#b41056600a1a4848833cc8b5239a9488">00560</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="classsf_1_1Image.htm#b41056600a1a4848833cc8b5239a9488" title="Get a valid texture size according to hardware support.">Image::GetValidTextureSize</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> Size)
<a name="l00561"></a>00561 {
<a name="l00562"></a>00562 <span class="comment">// Make sure we have a valid context</span>
<a name="l00563"></a>00563 priv::GraphicsContext Ctx;
<a name="l00564"></a>00564
<a name="l00565"></a>00565 <span class="keywordflow">if</span> (glewIsSupported(<span class="stringliteral">"GL_ARB_texture_non_power_of_two"</span>) != 0)
<a name="l00566"></a>00566 {
<a name="l00567"></a>00567 <span class="comment">// If hardware supports NPOT textures, then just return the unmodified size</span>
<a name="l00568"></a>00568 <span class="keywordflow">return</span> Size;
<a name="l00569"></a>00569 }
<a name="l00570"></a>00570 <span class="keywordflow">else</span>
<a name="l00571"></a>00571 {
<a name="l00572"></a>00572 <span class="comment">// If hardware doesn't support NPOT textures, we calculate the nearest power of two</span>
<a name="l00573"></a>00573 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> PowerOfTwo = 1;
<a name="l00574"></a>00574 <span class="keywordflow">while</span> (PowerOfTwo < Size)
<a name="l00575"></a>00575 PowerOfTwo *= 2;
<a name="l00576"></a>00576
<a name="l00577"></a>00577 <span class="keywordflow">return</span> PowerOfTwo;
<a name="l00578"></a>00578 }
<a name="l00579"></a>00579 }
<a name="l00580"></a>00580
<a name="l00581"></a>00581
<a name="l00585"></a><a class="code" href="classsf_1_1Image.htm#5f9927e407bbe34172553ecfff2f54f3">00585</a> <a class="code" href="classsf_1_1Image.htm" title="Image is the low-level class for loading and manipulating images.">Image</a>& <a class="code" href="classsf_1_1Image.htm#5f9927e407bbe34172553ecfff2f54f3" title="Assignment operator.">Image::operator =</a>(<span class="keyword">const</span> <a class="code" href="classsf_1_1Image.htm" title="Image is the low-level class for loading and manipulating images.">Image</a>& Other)
<a name="l00586"></a>00586 {
<a name="l00587"></a>00587 <a class="code" href="classsf_1_1Image.htm" title="Image is the low-level class for loading and manipulating images.">Image</a> Temp(Other);
<a name="l00588"></a>00588
<a name="l00589"></a>00589 std::swap(myWidth, Temp.<a class="code" href="classsf_1_1Image.htm#924ed57a1565f1248a4411e2be7e23e2" title="Image width.">myWidth</a>);
<a name="l00590"></a>00590 std::swap(myHeight, Temp.<a class="code" href="classsf_1_1Image.htm#ceef290985323875724673f5fdc2f6d0" title="Image Height.">myHeight</a>);
<a name="l00591"></a>00591 std::swap(myTextureWidth, Temp.<a class="code" href="classsf_1_1Image.htm#57135fd6e5145ba79934aa4864f6bcf1" title="Actual texture width (can be greater than image width because of padding).">myTextureWidth</a>);
<a name="l00592"></a>00592 std::swap(myTextureHeight, Temp.<a class="code" href="classsf_1_1Image.htm#5dbacc7c4665b2af3c52d8edf806ae59" title="Actual texture height (can be greater than image height because of padding).">myTextureHeight</a>);
<a name="l00593"></a>00593 std::swap(myTexture, Temp.<a class="code" href="classsf_1_1Image.htm#dc2b7c22a8d938976c71a071fb93f0ba" title="Internal texture identifier.">myTexture</a>);
<a name="l00594"></a>00594 std::swap(myIsSmooth, Temp.<a class="code" href="classsf_1_1Image.htm#fb002131ec00234570991c91da29c36c" title="Status of the smooth filter.">myIsSmooth</a>);
<a name="l00595"></a>00595 std::swap(myNeedArrayUpdate, Temp.<a class="code" href="classsf_1_1Image.htm#27bac2a5b153422015f55c68a884d902" title="Status of synchronization between pixels in central memory and the internal texture...">myNeedArrayUpdate</a>);
<a name="l00596"></a>00596 std::swap(myNeedTextureUpdate, Temp.<a class="code" href="classsf_1_1Image.htm#76172467f76c81f3e5a79c9babe82189" title="Status of synchronization between pixels in central memory and the internal texture...">myNeedTextureUpdate</a>);
<a name="l00597"></a>00597 myPixels.swap(Temp.<a class="code" href="classsf_1_1Image.htm#635da47010c1cf996389974e3618452f" title="Pixels of the image.">myPixels</a>);
<a name="l00598"></a>00598
<a name="l00599"></a>00599 <span class="keywordflow">return</span> *<span class="keyword">this</span>;
<a name="l00600"></a>00600 }
<a name="l00601"></a>00601
<a name="l00602"></a>00602
<a name="l00606"></a>00606 <span class="keywordtype">bool</span> Image::CreateTexture()
<a name="l00607"></a>00607 {
<a name="l00608"></a>00608 <span class="comment">// Check if texture parameters are valid before creating it</span>
<a name="l00609"></a>00609 <span class="keywordflow">if</span> (!myWidth || !myHeight)
<a name="l00610"></a>00610 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00611"></a>00611
<a name="l00612"></a>00612 <span class="comment">// Make sure we have a valid context</span>
<a name="l00613"></a>00613 priv::GraphicsContext Ctx;
<a name="l00614"></a>00614
<a name="l00615"></a>00615 <span class="comment">// Adjust internal texture dimensions depending on NPOT textures support</span>
<a name="l00616"></a>00616 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> TextureWidth = <a class="code" href="classsf_1_1Image.htm#b41056600a1a4848833cc8b5239a9488" title="Get a valid texture size according to hardware support.">GetValidTextureSize</a>(myWidth);
<a name="l00617"></a>00617 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> TextureHeight = <a class="code" href="classsf_1_1Image.htm#b41056600a1a4848833cc8b5239a9488" title="Get a valid texture size according to hardware support.">GetValidTextureSize</a>(myHeight);
<a name="l00618"></a>00618
<a name="l00619"></a>00619 <span class="comment">// Check the maximum texture size</span>
<a name="l00620"></a>00620 GLint MaxSize;
<a name="l00621"></a>00621 GLCheck(glGetIntegerv(GL_MAX_TEXTURE_SIZE, &MaxSize));
<a name="l00622"></a>00622 <span class="keywordflow">if</span> ((TextureWidth > static_cast<unsigned int>(MaxSize)) || (TextureHeight > static_cast<unsigned int>(MaxSize)))
<a name="l00623"></a>00623 {
<a name="l00624"></a>00624 std::cerr << <span class="stringliteral">"Failed to create image, its internal size is too high ("</span> << TextureWidth << <span class="stringliteral">"x"</span> << TextureHeight << <span class="stringliteral">")"</span> << std::endl;
<a name="l00625"></a>00625 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00626"></a>00626 }
<a name="l00627"></a>00627
<a name="l00628"></a>00628 <span class="comment">// Destroy the previous OpenGL texture if it already exists with another size</span>
<a name="l00629"></a>00629 <span class="keywordflow">if</span> ((TextureWidth != myTextureWidth) || (TextureHeight != myTextureHeight))
<a name="l00630"></a>00630 {
<a name="l00631"></a>00631 DestroyTexture();
<a name="l00632"></a>00632 myTextureWidth = TextureWidth;
<a name="l00633"></a>00633 myTextureHeight = TextureHeight;
<a name="l00634"></a>00634 }
<a name="l00635"></a>00635
<a name="l00636"></a>00636 <span class="comment">// Create the OpenGL texture</span>
<a name="l00637"></a>00637 <span class="keywordflow">if</span> (!myTexture)
<a name="l00638"></a>00638 {
<a name="l00639"></a>00639 GLint PreviousTexture;
<a name="l00640"></a>00640 GLCheck(glGetIntegerv(GL_TEXTURE_BINDING_2D, &PreviousTexture));
<a name="l00641"></a>00641
<a name="l00642"></a>00642 GLuint Texture = 0;
<a name="l00643"></a>00643 GLCheck(glGenTextures(1, &Texture));
<a name="l00644"></a>00644 GLCheck(glBindTexture(GL_TEXTURE_2D, Texture));
<a name="l00645"></a>00645 GLCheck(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, myTextureWidth, myTextureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL));
<a name="l00646"></a>00646 GLCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP));
<a name="l00647"></a>00647 GLCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP));
<a name="l00648"></a>00648 GLCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, myIsSmooth ? GL_LINEAR : GL_NEAREST));
<a name="l00649"></a>00649 GLCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, myIsSmooth ? GL_LINEAR : GL_NEAREST));
<a name="l00650"></a>00650 myTexture = <span class="keyword">static_cast<</span><span class="keywordtype">unsigned</span> <span class="keywordtype">int</span><span class="keyword">></span>(Texture);
<a name="l00651"></a>00651
<a name="l00652"></a>00652 GLCheck(glBindTexture(GL_TEXTURE_2D, PreviousTexture));
<a name="l00653"></a>00653 }
<a name="l00654"></a>00654
<a name="l00655"></a>00655 myNeedTextureUpdate = <span class="keyword">true</span>;
<a name="l00656"></a>00656
<a name="l00657"></a>00657 <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00658"></a>00658 }
<a name="l00659"></a>00659
<a name="l00660"></a>00660
<a name="l00665"></a>00665 <span class="keywordtype">void</span> Image::EnsureTextureUpdate()<span class="keyword"> const</span>
<a name="l00666"></a>00666 <span class="keyword"></span>{
<a name="l00667"></a>00667 <span class="keywordflow">if</span> (myNeedTextureUpdate)
<a name="l00668"></a>00668 {
<a name="l00669"></a>00669 <span class="comment">// Copy the pixels</span>
<a name="l00670"></a>00670 <span class="keywordflow">if</span> (myTexture && !myPixels.empty())
<a name="l00671"></a>00671 {
<a name="l00672"></a>00672 GLint PreviousTexture;
<a name="l00673"></a>00673 GLCheck(glGetIntegerv(GL_TEXTURE_BINDING_2D, &PreviousTexture));
<a name="l00674"></a>00674
<a name="l00675"></a>00675 <span class="comment">// Update the texture with the pixels array in RAM</span>
<a name="l00676"></a>00676 GLCheck(glBindTexture(GL_TEXTURE_2D, myTexture));
<a name="l00677"></a>00677 GLCheck(glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, myWidth, myHeight, GL_RGBA, GL_UNSIGNED_BYTE, &myPixels[0]));
<a name="l00678"></a>00678
<a name="l00679"></a>00679 GLCheck(glBindTexture(GL_TEXTURE_2D, PreviousTexture));
<a name="l00680"></a>00680 }
<a name="l00681"></a>00681
<a name="l00682"></a>00682 myNeedTextureUpdate = <span class="keyword">false</span>;
<a name="l00683"></a>00683 }
<a name="l00684"></a>00684 }
<a name="l00685"></a>00685
<a name="l00686"></a>00686
<a name="l00691"></a>00691 <span class="keywordtype">void</span> Image::EnsureArrayUpdate()<span class="keyword"> const</span>
<a name="l00692"></a>00692 <span class="keyword"></span>{
<a name="l00693"></a>00693 <span class="keywordflow">if</span> (myNeedArrayUpdate)
<a name="l00694"></a>00694 {
<a name="l00695"></a>00695 <span class="comment">// Save the previous texture</span>
<a name="l00696"></a>00696 GLint PreviousTexture;
<a name="l00697"></a>00697 GLCheck(glGetIntegerv(GL_TEXTURE_BINDING_2D, &PreviousTexture));
<a name="l00698"></a>00698
<a name="l00699"></a>00699 <span class="comment">// Resize the destination array of pixels</span>
<a name="l00700"></a>00700 myPixels.resize(myWidth * myHeight);
<a name="l00701"></a>00701
<a name="l00702"></a>00702 <span class="keywordflow">if</span> ((myWidth == myTextureWidth) && (myHeight == myTextureHeight))
<a name="l00703"></a>00703 {
<a name="l00704"></a>00704 <span class="comment">// Texture and array have the same size, we can use a direct copy</span>
<a name="l00705"></a>00705
<a name="l00706"></a>00706 <span class="comment">// Copy pixels from texture to array</span>
<a name="l00707"></a>00707 GLCheck(glBindTexture(GL_TEXTURE_2D, myTexture));
<a name="l00708"></a>00708 GLCheck(glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, &myPixels[0]));
<a name="l00709"></a>00709 }
<a name="l00710"></a>00710 <span class="keywordflow">else</span>
<a name="l00711"></a>00711 {
<a name="l00712"></a>00712 <span class="comment">// Texture and array don't have the same size, we have to use a slower algorithm</span>
<a name="l00713"></a>00713
<a name="l00714"></a>00714 <span class="comment">// All the pixels will first be copied to a temporary array</span>
<a name="l00715"></a>00715 std::vector<Color> AllPixels(myTextureWidth * myTextureHeight);
<a name="l00716"></a>00716 GLCheck(glBindTexture(GL_TEXTURE_2D, myTexture));
<a name="l00717"></a>00717 GLCheck(glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, &AllPixels[0]));
<a name="l00718"></a>00718
<a name="l00719"></a>00719 <span class="comment">// The we copy the useful pixels from the temporary array to the final one</span>
<a name="l00720"></a>00720 <span class="keyword">const</span> Color* Src = &AllPixels[0];
<a name="l00721"></a>00721 Color* Dst = &myPixels[0];
<a name="l00722"></a>00722 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = 0; i < myHeight; ++i)
<a name="l00723"></a>00723 {
<a name="l00724"></a>00724 std::copy(Src, Src + myWidth, Dst);
<a name="l00725"></a>00725 Src += myTextureWidth;
<a name="l00726"></a>00726 Dst += myWidth;
<a name="l00727"></a>00727 }
<a name="l00728"></a>00728 }
<a name="l00729"></a>00729
<a name="l00730"></a>00730 <span class="comment">// Restore the previous texture</span>
<a name="l00731"></a>00731 GLCheck(glBindTexture(GL_TEXTURE_2D, PreviousTexture));
<a name="l00732"></a>00732
<a name="l00733"></a>00733 myNeedArrayUpdate = <span class="keyword">false</span>;
<a name="l00734"></a>00734 }
<a name="l00735"></a>00735 }
<a name="l00736"></a>00736
<a name="l00737"></a>00737
<a name="l00741"></a>00741 <span class="keywordtype">void</span> Image::Reset()
<a name="l00742"></a>00742 {
<a name="l00743"></a>00743 DestroyTexture();
<a name="l00744"></a>00744
<a name="l00745"></a>00745 myWidth = 0;
<a name="l00746"></a>00746 myHeight = 0;
<a name="l00747"></a>00747 myTextureWidth = 0;
<a name="l00748"></a>00748 myTextureHeight = 0;
<a name="l00749"></a>00749 myTexture = 0;
<a name="l00750"></a>00750 myIsSmooth = <span class="keyword">true</span>;
<a name="l00751"></a>00751 myNeedTextureUpdate = <span class="keyword">false</span>;
<a name="l00752"></a>00752 myNeedArrayUpdate = <span class="keyword">false</span>;
<a name="l00753"></a>00753 myPixels.clear();
<a name="l00754"></a>00754 }
<a name="l00755"></a>00755
<a name="l00756"></a>00756
<a name="l00760"></a>00760 <span class="keywordtype">void</span> Image::DestroyTexture()
<a name="l00761"></a>00761 {
<a name="l00762"></a>00762 <span class="comment">// Destroy the internal texture</span>
<a name="l00763"></a>00763 <span class="keywordflow">if</span> (myTexture)
<a name="l00764"></a>00764 {
<a name="l00765"></a>00765 <span class="comment">// Make sure we have a valid context</span>
<a name="l00766"></a>00766 priv::GraphicsContext Ctx;
<a name="l00767"></a>00767
<a name="l00768"></a>00768 GLuint Texture = <span class="keyword">static_cast<</span>GLuint<span class="keyword">></span>(myTexture);
<a name="l00769"></a>00769 GLCheck(glDeleteTextures(1, &Texture));
<a name="l00770"></a>00770 myTexture = 0;
<a name="l00771"></a>00771 myNeedTextureUpdate = <span class="keyword">false</span>;
<a name="l00772"></a>00772 myNeedArrayUpdate = <span class="keyword">false</span>;
<a name="l00773"></a>00773 }
<a name="l00774"></a>00774 }
<a name="l00775"></a>00775
<a name="l00776"></a>00776 } <span class="comment">// namespace sf</span>
</pre></div></div>
<p id="footer">
:: Copyright © 2007-2008 Laurent Gomila, all rights reserved ::
Documentation generated by <a href="http://www.doxygen.org/" title="doxygen website">doxygen 1.5.2</a> ::
</p>
</body>
</html>
|