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"
20 # include "gl_compat_4_4.h"
28 import "textureManager"
31 public class FontRenderer : FontManagerRenderer
35 int textureWidth, textureHeight;
41 ColorAlpha stateColor;
42 ColorAlpha stateCursorColor;
46 imageList = new DMImage[imageAlloc];
49 stateCursorColor = white;
50 stateLayer = DM_LAYER_ABOVE;
54 property DrawManager drawManager { set { dm = value; } }
62 bool createTexture( int width, int height )
66 format = { width = width, height = height, type = grayScale, bytesPerPixel = 1, bytesPerLine = width };
71 texture = { 0 << DM_TEXTURE_ORDER_SHIFT };
72 texture.build(image, 0, 0.0, 0 );
75 textureHeight = height;
79 int resizeTexture( int width, int height )
83 // Reuse create to resize too.
87 imageList = new DMImage[imageAlloc];
89 retval = createTexture( width, height );
93 void updateTexture( int *rect, const byte* data )
97 int w = rect[2] - rect[0];
98 int h = rect[3] - rect[1];
100 glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT );
101 glPushAttrib( GL_TEXTURE_BIT );
102 glBindTexture( GL_TEXTURE_2D, texture.glTex );
103 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
104 glPixelStorei( GL_UNPACK_ROW_LENGTH, textureWidth );
105 glPixelStorei( GL_UNPACK_SKIP_PIXELS, rect[0] );
106 glPixelStorei( GL_UNPACK_SKIP_ROWS, rect[1] );
107 glTexSubImage2D( GL_TEXTURE_2D, 0, rect[0], rect[1], w, h, GL_RED, GL_UNSIGNED_BYTE, data );
113 image.format.width = textureWidth;
114 image.format.height = textureHeight;
115 image.format.type = IMG_FORMAT_TYPE_GRAYSCALE;
116 image.format.bytesPerPixel = 1;
117 image.format.bytesPerLine = image.format.width * image.format.bytesPerPixel;
119 imgWritePngFile( "zzz2.png", &image, 1.0 );
129 int registerImage( int offsetx, int offsety, int width, int height )
131 int imageindex = imagecount;
134 if( imagecount >= imageAlloc )
137 imageList = renew imageList DMImage[imageAlloc];
141 image = &imageList[ imageindex ];
143 image->defineImage( texture, offsetx, offsety, width, height, 1, DM_PROGRAM_ALPHABLEND, stateLayer );
145 image->defineImage( texture, offsetx, offsety, width, height, 1, DM_PROGRAM_NORMAL, stateLayer );
151 void drawImage( int targetx, int targety, int imageindex )
153 DMImage *image = &imageList[ imageindex ];
154 dm.drawImage( image, targetx, targety, image->sizex, image->sizey, stateColor );
157 void drawImageCursor( int targetx, int targety, int imageindex )
159 DMImage *image = &imageList[ imageindex ];
160 dm.drawImage( image, targetx, targety, image->sizex, image->sizey, stateCursorColor );
163 void drawImageAlt( byte *texdata, int targetx, int targety, int offsetx, int offsety, int width, int height )
168 void drawImageFloat( float targetx, float targety, float angsin, float angcos, int imageindex )
170 DMImage *image = &imageList[ imageindex ];
172 /* 0.2588190451, 0.965925826289 */
174 dm.drawImageFloat( image, targetx, targety, (float)image->sizex, (float)image->sizey, angsin, angcos, stateColor );
182 void setColor( ColorAlpha color )
184 stateColor = { color.a, { color.color.b, color.color.g, color.color.r } };
187 void setCursorColor( ColorAlpha color )
189 stateCursorColor = { color.a, { color.color.b, color.color.g, color.color.r } };
192 void setLayer( uint32 layerIndex )
194 stateLayer = layerIndex;