Morph-SynRJ

view rdr_font.cxx @ 0:22de913c2d84

morph-synrj intro
author "Cedric Pinson <cedric.pinson@alcove.fr> <mornifle@plopbyte.net>"
date Tue Nov 27 15:23:52 2007 +0100 (2007-11-27)
parents
children
line source
1 /** @file rdr_font.cxx
2 *
3 * @brief use font 2d in screen
4 *
5 *****************************************************************************
6 *
7 * @author psc80
8 *
9 * @date Created 2001/11
10 *
11 * @version $Id: rdr_font.cxx,v 1.7 2004/01/21 06:01:04 psc80 Exp $
12 *
13 ****************************************************************************/
15 #include "rdr_font.h"
16 #include "cmn_texture.h"
17 #include "cmn_intro.h"
18 #include <cstdarg>
19 #include <cstdio>
20 #include <cctype>
21 #include "sys_assert.h"
24 /** take trace of cursor on screen*/
25 static int RdrFontScreenPositionX=0;
26 static int RdrFontScreenPositionY=0;
29 rdrFont_t::rdrFont_t()
30 {
31 texture=0 ;
32 scalex=1.0;
33 scaley=1.0;
34 z=0;
35 }
38 rdrFont_t::~rdrFont_t()
39 {
40 Kill() ;
41 }
44 void rdrFont_t::Kill()
45 {
46 // if (texture)
47 // glDelete(texture);
48 texture=0 ;
49 }
52 void rdrFont_t::Init()
53 {
54 Kill() ;
55 sizeCharX=sizeCharY=0 ;
56 firstChar=lastChar=0 ;
57 }
60 int rdrFont_t::Init(GLuint _t,int _firstCharInFont ,int _sizeOfCharX,int _widthOfTexture,int _heightOfTexture)
61 {
62 SYS_ASSERT(_t);
64 Init() ;
65 texture=_t ;
67 firstChar=_firstCharInFont;
68 sizeCharX=_sizeOfCharX;
69 textureWidth=_widthOfTexture;
70 textureHeight=_heightOfTexture;
71 sizeCharY=_heightOfTexture;
72 lastChar=firstChar+textureWidth*1.0/sizeCharX ;
73 return 0 ;
74 }
78 void rdrFont_t::GetUVsOfChar(char _letter,float& _u,float& _v)
79 {
80 _letter=toupper(_letter) ;
81 _letter-=firstChar;
82 _u=_letter*sizeCharX*1.0/textureWidth;
83 _v=0;
84 }
88 /// TODO use echap command from ascii character
89 void rdrFont_t::_Print(int &x,int &y,char *s)
90 {
91 SYS_ASSERT(texture);
93 int sizex=textureWidth;
95 // cmnPushMatrix();
97 //glDisable(GL_BLEND);
99 // cmnSetPlanarView();
101 // glColor4f(1,1,1,1);
102 // glDisable(GL_DEPTH_TEST);
105 txtBindTexture2d(texture,0);
107 int c,tx ;
109 double div=sizeCharX*1.0/sizex;
111 glBegin(GL_QUADS);
112 while ( (c = *s++) ) {
113 c=toupper(c) ;
115 if (c=='\n') {
116 y-=sizeCharY*scaley;
117 x=0;
119 } else if ( c >= firstChar && c <= lastChar) {
121 c-=firstChar ;
122 tx=c ;
124 float x1,y1,z1;
125 x1=x;
126 y1=y;
127 z1=0;
129 glTexCoord2f(tx*div,0);
130 glVertex3f(x1,y1,z);
132 glTexCoord2f((tx+1)*div,0);
133 glVertex3f(x1+sizeCharX*scalex,y1,z);
135 glTexCoord2f((tx+1)*div,1);
136 glVertex3f(x1+sizeCharX*scalex,y1+sizeCharY*scaley,z);
138 glTexCoord2f(tx*div,1);
139 glVertex3f(x1,y1+sizeCharY*scaley,z);
141 x+=sizeCharX*scalex ;
142 }
143 }
145 glEnd();
147 txtUnBindTexture2d(0);
149 // cmnPopMatrix();
150 }
153 void rdrFont_t::Clear()
154 {
155 RdrFontScreenPositionY=RY-sizeCharY ;
156 // RdrFontScreenPositionY=0;
157 RdrFontScreenPositionX=0 ;
158 }
161 void rdrFont_t::Print(const char *fmt,...)
162 {
163 va_list list;
164 va_start(list, fmt);
166 char str[32768] ;
167 va_start(list, fmt);
168 vsprintf(str, fmt, list);
169 va_end(list);
171 _Print(RdrFontScreenPositionX,RdrFontScreenPositionY,str) ;
172 }
174 void rdrFont_t::Print(int x,int y,const char *fmt,...)
175 {
176 va_list list;
177 va_start(list, fmt);
179 char str[32768] ;
180 va_start(list, fmt);
181 vsprintf(str, fmt, list);
182 va_end(list);
184 int x2=x ;
185 int y2=y ;
186 _Print(x2,y2,str) ;
187 }