| 1 |
#ifndef CVD_GL_HELPERS_H |
| 2 |
#define CVD_GL_HELPERS_H |
| 3 |
|
| 4 |
#include <iostream> |
| 5 |
#include <map> |
| 6 |
#include <utility> |
| 7 |
|
| 8 |
#include <cvd/byte.h> |
| 9 |
#include <cvd/config.h> |
| 10 |
#include <cvd/image.h> |
| 11 |
#include <cvd/image_ref.h> |
| 12 |
#include <cvd/rgb.h> |
| 13 |
#include <cvd/rgb8.h> |
| 14 |
#include <cvd/rgba.h> |
| 15 |
#ifdef WIN32 |
| 16 |
#define NOMINMAX |
| 17 |
#include <windows.h> |
| 18 |
#endif |
| 19 |
|
| 20 |
#ifdef __APPLE__ |
| 21 |
#include <OpenGL/gl.h> |
| 22 |
#include <OpenGL/glu.h> |
| 23 |
#else |
| 24 |
#include <GL/gl.h> |
| 25 |
#include <GL/glu.h> |
| 26 |
#endif |
| 27 |
|
| 28 |
#include <cvd/internal/gl_types.h> |
| 29 |
|
| 30 |
#ifdef CVD_HAVE_TOON |
| 31 |
#include <TooN/TooN.h> |
| 32 |
#include <TooN/se2.h> |
| 33 |
#include <TooN/se3.h> |
| 34 |
#include <TooN/so2.h> |
| 35 |
#include <TooN/so3.h> |
| 36 |
#endif |
| 37 |
|
| 38 |
namespace CVD |
| 39 |
{ |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
inline void glVertex(const ImageRef& i) |
| 45 |
{ |
| 46 |
glVertex2i(i.x, i.y); |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
inline void glTexCoord(const ImageRef& i) |
| 53 |
{ |
| 54 |
glTexCoord2i(i.x, i.y); |
| 55 |
} |
| 56 |
|
| 57 |
#ifdef GL_GLEXT_PROTOTYPES |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
inline void glMultiTexCoord(GLenum unit, const ImageRef& i) |
| 63 |
{ |
| 64 |
glMultiTexCoord2i(unit, i.x, i.y); |
| 65 |
} |
| 66 |
#endif |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
inline void glRasterPos(const ImageRef& i) |
| 71 |
{ |
| 72 |
glRasterPos2i(i.x, i.y); |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
inline void glRect(const ImageRef& p, const ImageRef& q) |
| 80 |
{ |
| 81 |
glRecti(p.x, p.y, q.x, q.y); |
| 82 |
} |
| 83 |
|
| 84 |
#ifdef CVD_HAVE_TOON |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
template <class B> |
| 89 |
inline void glVertex(const TooN::Vector<2, double, B>& v) |
| 90 |
{ |
| 91 |
glVertex2d(v[0], v[1]); |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
template <class B> |
| 98 |
inline void glVertex(const TooN::Vector<2, float, B>& v) |
| 99 |
{ |
| 100 |
glVertex2f(v[0], v[1]); |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
template <class B> |
| 107 |
inline void glVertex(const TooN::Vector<2, int, B>& v) |
| 108 |
{ |
| 109 |
glVertexi(v[0], v[1]); |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
template <class B> |
| 116 |
inline void glVertex(const TooN::Vector<3, double, B>& v) |
| 117 |
{ |
| 118 |
glVertex3d(v[0], v[1], v[2]); |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
template <class B> |
| 125 |
inline void glVertex(const TooN::Vector<3, float, B>& v) |
| 126 |
{ |
| 127 |
glVertex3f(v[0], v[1], v[2]); |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
template <class B> |
| 134 |
inline void glVertex(const TooN::Vector<3, int, B>& v) |
| 135 |
{ |
| 136 |
glVertex3i(v[0], v[1], v[2]); |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
template <class B> |
| 143 |
inline void glVertex(const TooN::Vector<4, double, B>& v) |
| 144 |
{ |
| 145 |
glVertex4d(v[0], v[1], v[2], v[3]); |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
template <class B> |
| 152 |
inline void glVertex(const TooN::Vector<4, float, B>& v) |
| 153 |
{ |
| 154 |
glVertex4f(v[0], v[1], v[2], v[3]); |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
template <class B> |
| 161 |
inline void glVertex(const TooN::Vector<4, int, B>& v) |
| 162 |
{ |
| 163 |
glVertex4i(v[0], v[1], v[2], v[3]); |
| 164 |
} |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
inline void glTexCoord(const TooN::Vector<2>& v) |
| 170 |
{ |
| 171 |
glTexCoord2d(v[0], v[1]); |
| 172 |
} |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
inline void glTexCoord(const TooN::Vector<3>& v) |
| 178 |
{ |
| 179 |
glTexCoord3d(v[0], v[1], v[2]); |
| 180 |
} |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
inline void glTexCoord(const TooN::Vector<4>& v) |
| 186 |
{ |
| 187 |
glTexCoord4d(v[0], v[1], v[2], v[3]); |
| 188 |
} |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
inline void glRect(const TooN::Vector<2>& p, const TooN::Vector<2>& q) |
| 195 |
{ |
| 196 |
glRectd(p[0], p[1], q[0], q[1]); |
| 197 |
} |
| 198 |
|
| 199 |
#ifdef GL_GLEXT_PROTOTYPES |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
inline void glMultiTexCoord(GLenum unit, const TooN::Vector<2>& v) |
| 205 |
{ |
| 206 |
glMultiTexCoord2d(unit, v[0], v[1]); |
| 207 |
} |
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
inline void glMultiTexCoord(GLenum unit, const TooN::Vector<3>& v) |
| 214 |
{ |
| 215 |
glMultiTexCoord3d(unit, v[0], v[1], v[2]); |
| 216 |
} |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
inline void glMultiTexCoord(GLenum unit, const TooN::Vector<4>& v) |
| 223 |
{ |
| 224 |
glMultiTexCoord4d(unit, v[0], v[1], v[2], v[3]); |
| 225 |
} |
| 226 |
#endif |
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
inline void glRasterPos(const TooN::Vector<2>& v) |
| 232 |
{ |
| 233 |
glRasterPos2d(v[0], v[1]); |
| 234 |
} |
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
inline void glRasterPos(const TooN::Vector<3>& v) |
| 240 |
{ |
| 241 |
glRasterPos3d(v[0], v[1], v[2]); |
| 242 |
} |
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
inline void glRasterPos(const TooN::Vector<4>& v) |
| 248 |
{ |
| 249 |
glRasterPos4d(v[0], v[1], v[2], v[3]); |
| 250 |
} |
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
inline void glNormal(const TooN::Vector<3>& n) |
| 256 |
{ |
| 257 |
glNormal3d(n[0], n[1], n[2]); |
| 258 |
} |
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
inline void glTranslate(const ImageRef& v) |
| 264 |
{ |
| 265 |
glTranslatef(static_cast<GLfloat>(v.x), static_cast<GLfloat>(v.y), 0); |
| 266 |
} |
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
template <int N> |
| 272 |
inline void glTranslate(const TooN::Vector<N>& v) |
| 273 |
{ |
| 274 |
glTranslated(v[0], v[1], v[2]); |
| 275 |
} |
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
template <> |
| 282 |
inline void glTranslate(const TooN::Vector<2>& v) |
| 283 |
{ |
| 284 |
glTranslated(v[0], v[1], 0); |
| 285 |
} |
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
template <> |
| 292 |
inline void glTranslate(const TooN::Vector<1>& v) |
| 293 |
{ |
| 294 |
glTranslated(v[0], 0, 0); |
| 295 |
} |
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
template <int N, class P, class A> |
| 303 |
inline void glMultMatrix(const TooN::Matrix<N, N, P, A>& m) |
| 304 |
{ |
| 305 |
GLdouble glm[16]; |
| 306 |
glm[0] = m[0][0]; |
| 307 |
glm[1] = m[1][0]; |
| 308 |
glm[2] = m[2][0]; |
| 309 |
glm[3] = m[3][0]; |
| 310 |
glm[4] = m[0][1]; |
| 311 |
glm[5] = m[1][1]; |
| 312 |
glm[6] = m[2][1]; |
| 313 |
glm[7] = m[3][1]; |
| 314 |
glm[8] = m[0][2]; |
| 315 |
glm[9] = m[1][2]; |
| 316 |
glm[10] = m[2][2]; |
| 317 |
glm[11] = m[3][2]; |
| 318 |
glm[12] = m[0][3]; |
| 319 |
glm[13] = m[1][3]; |
| 320 |
glm[14] = m[2][3]; |
| 321 |
glm[15] = m[3][3]; |
| 322 |
glMultMatrixd(glm); |
| 323 |
} |
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
template <class P, class A> |
| 331 |
inline void glMultMatrix(const TooN::Matrix<3, 3, P, A>& m) |
| 332 |
{ |
| 333 |
GLdouble glm[16]; |
| 334 |
glm[0] = m[0][0]; |
| 335 |
glm[1] = m[1][0]; |
| 336 |
glm[2] = m[2][0]; |
| 337 |
glm[3] = 0; |
| 338 |
glm[4] = m[0][1]; |
| 339 |
glm[5] = m[1][1]; |
| 340 |
glm[6] = m[2][1]; |
| 341 |
glm[7] = 0; |
| 342 |
glm[8] = m[0][2]; |
| 343 |
glm[9] = m[1][2]; |
| 344 |
glm[10] = m[2][2]; |
| 345 |
glm[11] = 0; |
| 346 |
glm[12] = 0; |
| 347 |
glm[13] = 0; |
| 348 |
glm[14] = 0; |
| 349 |
glm[15] = 1; |
| 350 |
glMultMatrixd(glm); |
| 351 |
} |
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
template <class P, class A> |
| 359 |
inline void glMultMatrix(const TooN::Matrix<2, 2, P, A>& m) |
| 360 |
{ |
| 361 |
GLdouble glm[16]; |
| 362 |
glm[0] = m[0][0]; |
| 363 |
glm[1] = m[1][0]; |
| 364 |
glm[2] = 0; |
| 365 |
glm[3] = 0; |
| 366 |
glm[4] = m[0][1]; |
| 367 |
glm[5] = m[1][1]; |
| 368 |
glm[6] = 0; |
| 369 |
glm[7] = 0; |
| 370 |
glm[8] = 0; |
| 371 |
glm[9] = 0; |
| 372 |
glm[10] = 1; |
| 373 |
glm[11] = 0; |
| 374 |
glm[12] = 0; |
| 375 |
glm[13] = 0; |
| 376 |
glm[14] = 0; |
| 377 |
glm[15] = 1; |
| 378 |
glMultMatrixd(glm); |
| 379 |
} |
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
template <typename P> |
| 385 |
inline void glMultMatrix(const TooN::SO3<P>& so3) |
| 386 |
{ |
| 387 |
glMultMatrix(so3.get_matrix()); |
| 388 |
} |
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
template <typename P> |
| 395 |
inline void glMultMatrix(const TooN::SE3<P>& se3) |
| 396 |
{ |
| 397 |
glTranslate(se3.get_translation()); |
| 398 |
glMultMatrix(se3.get_rotation()); |
| 399 |
} |
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
template <typename P> |
| 405 |
inline void glMultMatrix(const TooN::SO2<P>& so2) |
| 406 |
{ |
| 407 |
glMultMatrix(so2.get_matrix()); |
| 408 |
} |
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
template <typename P> |
| 415 |
inline void glMultMatrix(const TooN::SE2<P>& se2) |
| 416 |
{ |
| 417 |
glTranslate(se2.get_translation()); |
| 418 |
glMultMatrix(se2.get_rotation()); |
| 419 |
} |
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
inline void glOrtho(const CVD::ImageRef& size, const double nearPlane = -1.0, const double farPlane = 1.0) |
| 429 |
{ |
| 430 |
::glOrtho(-0.375, size.x - 0.375, size.y - 0.375, -0.375, nearPlane, farPlane); |
| 431 |
} |
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
inline void glOrtho(const TooN::Vector<6>& param) |
| 438 |
{ |
| 439 |
::glOrtho(param[0], param[1], param[2], param[3], param[4], param[5]); |
| 440 |
} |
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
template <typename P, typename A> |
| 455 |
inline void glFrustum(const TooN::Vector<4, P, A>& params, double width, double height, double nearPlane = 0.1, double farPlane = 100) |
| 456 |
{ |
| 457 |
GLdouble left, right, bottom, top; |
| 458 |
left = -nearPlane * params[2] / params[0]; |
| 459 |
top = nearPlane * params[3] / params[1]; |
| 460 |
right = nearPlane * (width - params[2]) / params[0]; |
| 461 |
bottom = -nearPlane * (height - params[3]) / params[1]; |
| 462 |
::glFrustum(left, right, bottom, top, nearPlane, farPlane); |
| 463 |
} |
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
template <class CAMERA> |
| 474 |
inline void glFrustum(const CAMERA& camera, double width, double height, double nearPlane = 0.1, double farPlane = 100) |
| 475 |
{ |
| 476 |
glFrustum(camera.get_parameters().template slice<0, 4>(), width, height, nearPlane, farPlane); |
| 477 |
} |
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
inline void glFrustum(const TooN::Vector<6>& param) |
| 484 |
{ |
| 485 |
::glFrustum(param[0], param[1], param[2], param[3], param[4], param[5]); |
| 486 |
} |
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
inline void glColor(const TooN::Vector<3>& v) |
| 493 |
{ |
| 494 |
glColor3d(v[0], v[1], v[2]); |
| 495 |
} |
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
inline void glColor(const TooN::Vector<4>& v) |
| 502 |
{ |
| 503 |
glColor4d(v[0], v[1], v[2], v[3]); |
| 504 |
} |
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
inline void glClearColor(const TooN::Vector<4>& v) |
| 511 |
{ |
| 512 |
::glClearColor((GLclampf)v[0], (GLclampf)v[1], (GLclampf)v[2], (GLclampf)v[3]); |
| 513 |
} |
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
inline void glClearColor(const TooN::Vector<3>& v) |
| 520 |
{ |
| 521 |
::glClearColor((GLclampf)v[0], (GLclampf)v[1], (GLclampf)v[2], 0); |
| 522 |
} |
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
inline void glColor(const TooN::Vector<-1>& v) |
| 528 |
{ |
| 529 |
switch(v.size()) |
| 530 |
{ |
| 531 |
case 3: |
| 532 |
glColor3d(v[0], v[1], v[2]); |
| 533 |
break; |
| 534 |
case 4: |
| 535 |
glColor4d(v[0], v[1], v[2], v[3]); |
| 536 |
break; |
| 537 |
} |
| 538 |
} |
| 539 |
#endif |
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
template <class P1, class P2> |
| 545 |
inline void glLine(const P1& x1, const P2& x2) |
| 546 |
{ |
| 547 |
glBegin(GL_LINES); |
| 548 |
glVertex(x1); |
| 549 |
glVertex(x2); |
| 550 |
glEnd(); |
| 551 |
} |
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
template <class C> |
| 558 |
inline void glVertex(const C& list) |
| 559 |
{ |
| 560 |
for(typename C::const_iterator v = list.begin(); v != list.end(); ++v) |
| 561 |
glVertex(*v); |
| 562 |
} |
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
inline void glColor(const CVD::Rgb<byte>& c) |
| 569 |
{ |
| 570 |
glColor3ub(c.red, c.green, c.blue); |
| 571 |
} |
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
inline void glColor(const CVD::Rgb<float>& c) |
| 578 |
{ |
| 579 |
glColor3f(c.red, c.green, c.blue); |
| 580 |
} |
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
inline void glColor3(const CVD::Rgb8& c) |
| 587 |
{ |
| 588 |
glColor3ub(c.red, c.green, c.blue); |
| 589 |
} |
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
inline void glColor4(const CVD::Rgb8& c) |
| 596 |
{ |
| 597 |
glColor4ub(c.red, c.green, c.blue, c.dummy); |
| 598 |
} |
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
inline void glColor(const CVD::Rgba<unsigned char>& c) |
| 605 |
{ |
| 606 |
glColor4ub(c.red, c.green, c.blue, c.alpha); |
| 607 |
} |
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
inline void glColor(const CVD::Rgba<float>& c) |
| 614 |
{ |
| 615 |
glColor4f(c.red, c.green, c.blue, c.alpha); |
| 616 |
} |
| 617 |
|
| 618 |
namespace Internal |
| 619 |
{ |
| 620 |
static inline int cvdalignof(const void* ptr) |
| 621 |
{ |
| 622 |
size_t p = (size_t)ptr; |
| 623 |
|
| 624 |
if(p & 3) |
| 625 |
if(p & 1) |
| 626 |
return 1; |
| 627 |
else |
| 628 |
return 2; |
| 629 |
else if(p & 4) |
| 630 |
return 4; |
| 631 |
else |
| 632 |
return 8; |
| 633 |
} |
| 634 |
} |
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
template <class C> |
| 641 |
inline void glDrawPixels(const BasicImage<C>& i) |
| 642 |
{ |
| 643 |
::glPixelStorei(GL_UNPACK_ALIGNMENT, std::min(Internal::cvdalignof(i[0]), Internal::cvdalignof(i[1]))); |
| 644 |
::glPixelStorei(GL_UNPACK_ROW_LENGTH, i.row_stride()); |
| 645 |
::glDrawPixels(i.size().x, i.size().y, gl::data<C>::format, gl::data<C>::type, i.data()); |
| 646 |
::glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); |
| 647 |
} |
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
template <class C> |
| 654 |
inline void glReadPixels(BasicImage<C>& i, ImageRef origin = ImageRef(0, 0)) |
| 655 |
{ |
| 656 |
::glPixelStorei(GL_PACK_ALIGNMENT, 1); |
| 657 |
::glPixelStorei(GL_PACK_ROW_LENGTH, i.row_stride()); |
| 658 |
::glReadPixels(origin.x, origin.y, i.size().x, i.size().y, gl::data<C>::format, gl::data<C>::type, i.data()); |
| 659 |
} |
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
template <class C> |
| 666 |
inline Image<C> glReadPixels(ImageRef size, ImageRef origin = ImageRef(0, 0)) |
| 667 |
{ |
| 668 |
Image<C> i(size); |
| 669 |
glReadPixels(i, origin); |
| 670 |
return i; |
| 671 |
} |
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
template <class C> |
| 678 |
inline void glTexSubImage2D(const BasicImage<C>& i, GLint xoffset = 0, GLint yoffset = 0, GLenum target = GL_TEXTURE_2D, GLint level = 0) |
| 679 |
{ |
| 680 |
::glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
| 681 |
::glPixelStorei(GL_UNPACK_ROW_LENGTH, i.row_stride()); |
| 682 |
::glTexSubImage2D(target, level, xoffset, yoffset, i.size().x, i.size().y, gl::data<C>::format, gl::data<C>::type, i.data()); |
| 683 |
::glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); |
| 684 |
} |
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
template <class C> |
| 691 |
inline void glTexImage2D(const BasicImage<C>& i, GLint border = 0, GLenum target = GL_TEXTURE_2D, GLint level = 0) |
| 692 |
{ |
| 693 |
::glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
| 694 |
::glPixelStorei(GL_UNPACK_ROW_LENGTH, i.row_stride()); |
| 695 |
::glTexImage2D(target, level, gl::data<C>::format, i.size().x, i.size().y, border, gl::data<C>::format, gl::data<C>::type, i.data()); |
| 696 |
::glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); |
| 697 |
} |
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
inline void glPrintErrors(void) |
| 702 |
{ |
| 703 |
GLenum code; |
| 704 |
while((code = glGetError()) != GL_NO_ERROR) |
| 705 |
{ |
| 706 |
std::cout << "GL:" << code << std::endl; |
| 707 |
} |
| 708 |
} |
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
void glSetFont(const std::string& fontname); |
| 717 |
|
| 718 |
|
| 719 |
const std::string& glGetFont(); |
| 720 |
|
| 721 |
|
| 722 |
enum TEXT_STYLE |
| 723 |
{ |
| 724 |
FILL = 0, |
| 725 |
OUTLINE = 1, |
| 726 |
NICE = 2 |
| 727 |
}; |
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
std::pair<double, double> glDrawText(const std::string& text, enum TEXT_STYLE style = NICE, double spacing = 1.5, double kerning = 0.1); |
| 739 |
|
| 740 |
|
| 741 |
std::pair<double, double> glGetExtends(const std::string& text, double spacing = 1.5, double kerning = 0.1); |
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
}; |
| 746 |
|
| 747 |
#endif |