Small OpenGL based c++ rendering library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

glfontengine.h 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* libsegl - Sebas Extended GL Library
  2. * Collection of Opengl/3D-Math helpers
  3. *
  4. * Copyright (c) 2008 by Sebastian Lohff, seba@seba-geek.de
  5. * http://www.seba-geek.de
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Library General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Library General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Library General Public
  18. * License along with this library; if not, write to the
  19. * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
  20. * Boston, MA 02110-1301, USA.
  21. */
  22. #ifndef __GLFONTENGINE_H
  23. #define __GLFONTENGINE_H
  24. #include <iostream>
  25. #include <string>
  26. #include <vector>
  27. #include <map>
  28. #include <cmath>
  29. #include <SDL.h>
  30. #include <SDL_opengl.h>
  31. #include "gltexture.h"
  32. #include "color.h"
  33. namespace segl {
  34. class GLFont {
  35. public:
  36. GLFont(std::string fontfile, float cwdth) {
  37. charwidth = cwdth;
  38. font = new GLTexture(fontfile);
  39. }
  40. ~GLFont() {
  41. delete(font);
  42. }
  43. GLTexture* font;
  44. float charwidth;
  45. };
  46. class GLFontEngine {
  47. private:
  48. static std::map<std::string, GLFont*> fontpool;
  49. GLFont *font;
  50. bool fontloaded;
  51. Color col;
  52. // float r, g, b, a;
  53. int fsize;
  54. void init();
  55. public:
  56. static bool addFont(std::string fontfile, std::string fontname);
  57. static void quit();
  58. static void prepare2DbyPushingMatrix();
  59. static void regain3DbyPoppingMatrix();
  60. static void paintSDLRect(SDL_Rect);
  61. GLFontEngine();
  62. GLFontEngine(std::string);
  63. bool fontSelect(std::string);
  64. void setColor(float, float, float, float=1.0f);
  65. void setColor(Color);
  66. void renderText(std::string, SDL_Rect); // wrapper
  67. // void renderText(std::string, int x, int y, *SDL_Rect=0, bool center=false);
  68. // void renderLines(std::string, int x, int y,
  69. void renderLine(std::string, SDL_Rect);
  70. void renderLine(std::string, int x, int y, bool center=false, SDL_Rect *rendered_to=0);
  71. void renderLines(std::string, int x, int y, bool center=false, SDL_Rect *rendered_to=0, int wrap=0, int paintbackground=0);
  72. void setSize(int);
  73. int getSize();
  74. void getSDLRect(const std::string&, SDL_Rect*);
  75. int getTextWidth(const std::string&);
  76. int getTextWidthbyInt(int length);
  77. };
  78. } // namespace segl
  79. #endif