1 /* *****************************************************************************
2 * Original Version Copyright (c) 2007-2014 Alexis Naveros.
4 * Ecere Corporation has unlimited/unrestricted rights.
5 * *****************************************************************************/
16 #if !defined(__ANDROID__) && !defined(__EMSCRIPTEN__) && !defined(__ODROID__)
18 //# include "gl_core_3_3.h"
19 # include "gl_compat_4_4.h" // FIXME: no glPushAttrib() in core profile
21 # include "gl_compat_4_4.h"
29 import "textureManager"
32 public class FontRenderer : FontManagerRenderer
36 int textureWidth, textureHeight;
43 ColorAlpha stateColor;
44 ColorAlpha stateCursorColor;
48 imageList = new DMImage[imageAlloc];
51 stateCursorColor = white;
52 stateLayer = DM_LAYER_ABOVE;
56 property DrawManager drawManager { set { dm = value; } }
58 bool init(int channelCount)
60 this.channelcount = channelCount;
70 bool createTexture( int width, int height )
74 format = { width = width, height = height, type = grayScale, bytesPerPixel = channelcount, bytesPerLine = width };
79 texture = { 0 << DM_TEXTURE_ORDER_SHIFT };
80 texture.build(image, 0, 0.0, 0 );
83 textureHeight = height;
87 int resizeTexture( int width, int height )
91 // Reuse create to resize too.
95 imageList = new DMImage[imageAlloc];
97 retval = createTexture( width, height );
101 void updateTexture( int *rect, const byte* data )
105 int glformat = GL_RED;
106 int w = rect[2] - rect[0];
107 int h = rect[3] - rect[1];
109 if( channelcount == 1 )
111 else if( channelcount == 2 )
113 else if( channelcount == 3 )
115 else if( channelcount == 4 )
118 // FIXME: no glPushAttrib() in core profile
120 glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT );
121 glPushAttrib( GL_TEXTURE_BIT );
123 glBindTexture( GL_TEXTURE_2D, texture.glTex );
124 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
125 glPixelStorei( GL_UNPACK_ROW_LENGTH, textureWidth );
126 glPixelStorei( GL_UNPACK_SKIP_PIXELS, rect[0] );
127 glPixelStorei( GL_UNPACK_SKIP_ROWS, rect[1] );
128 glTexSubImage2D( GL_TEXTURE_2D, 0, rect[0], rect[1], w, h, glformat, GL_UNSIGNED_BYTE, data );
136 image.format.width = textureWidth;
137 image.format.height = textureHeight;
138 image.format.type = channelcount == 4 ? IMG_FORMAT_TYPE_RGBA32 : IMG_FORMAT_TYPE_GRAYSCALE;
139 image.format.bytesPerPixel = channelcount;
140 image.format.bytesPerLine = image.format.width * image.format.bytesPerPixel;
142 imgWritePngFile( "zzz2.png", &image, 1.0 );
152 int registerImage( int offsetx, int offsety, int width, int height )
154 int imageindex = imagecount;
157 if( imagecount >= imageAlloc )
160 imageList = renew imageList DMImage[imageAlloc];
164 image = &imageList[ imageindex ];
166 image->defineImage( texture, offsetx, offsety, width, height, 1, DM_PROGRAM_ALPHABLEND_INTENSITY, stateLayer );
168 image->defineImage( texture, offsetx, offsety, width, height, 1, DM_PROGRAM_ALPHABLEND, stateLayer );
170 image->defineImage( texture, offsetx, offsety, width, height, 1, DM_PROGRAM_NORMAL, stateLayer );
176 void drawImage( int targetx, int targety, int imageindex )
178 DMImage *image = &imageList[ imageindex ];
179 dm.drawImage( image, targetx, targety, image->sizex, image->sizey, stateColor );
182 void drawImageCursor( int targetx, int targety, int imageindex )
184 DMImage *image = &imageList[ imageindex ];
185 dm.drawImage( image, targetx, targety, image->sizex, image->sizey, stateCursorColor );
188 void drawImageAlt( byte *texdata, int targetx, int targety, int offsetx, int offsety, int width, int height )
193 void drawImageFloat( float targetx, float targety, float angsin, float angcos, int imageindex )
195 DMImage *image = &imageList[ imageindex ];
197 /* 0.2588190451, 0.965925826289 */
199 dm.drawImageFloat( image, targetx, targety, (float)image->sizex, (float)image->sizey, angsin, angcos, stateColor );
207 void setColor( ColorAlpha color )
209 stateColor = { color.a, { color.color.b, color.color.g, color.color.r } };
212 void setCursorColor( ColorAlpha color )
214 stateCursorColor = { color.a, { color.color.b, color.color.g, color.color.r } };
217 void setLayer( uint32 layerIndex )
219 stateLayer = layerIndex;