#include "glTexFontInclude.h"
+
/* just a global for our default colors */
float white[] = {1.0, 1.0, 1.0, 1.0};
float gray[] = {0.5, 0.5, 0.5, 1.0};
-/* the font structure we will use in the library, all values are defaults */
-texFont_t font =
-{
- {1.0, 1.0, 1.0, 1.0}, /* white text */
- {0.5, 0.5, 0.5, 1.0}, /* gray gradient */
- {0.5, 0.5, 0.5, 1.0}, /* gray shadow */
- 12, /* size 12 font */
- 0, /* no shadow */
- 0, /* no gradient */
- 0, /* italic amount */
- 0, /* no bold */
- 0,0,0,0,0, /* text region stuff */
- 0.0,0.0, /* texture inc stuff */
- FONT_BLOCK_ROW, /* characters per row */
- FONT_BLOCK_COL, /* characters por col */
- 0, /* texture id */
-};
/*
tPoints contains our map for the font image. After fontMakeMap this array
Load the passed image name and use it for the font.
=============
*/
-int fontLoad (char *name)
+int fontLoad (texFont_t* font,char *name)
{
- glGenTextures (1, &font.texId);
+ glGenTextures (1, &(font->texId));
- font.blockRow = FONT_BLOCK_ROW;
- font.blockCol = FONT_BLOCK_COL;
+ font->blockRow = FONT_BLOCK_ROW;
+ font->blockCol = FONT_BLOCK_COL;
- fontMakeMap ();
+ fontMakeMap (font);
// return fontLoadTGA (name, font.texId);
- return fontLoadPNG ("c:\\pango_test.png", font.texId);
+ return fontLoadPNG ("c:\\pango_test.png", font->texId);
}
/*
characters per row.
=============
*/
-int fontLoadEx (char *name, int row, int col)
+int fontLoadEx (texFont_t* font,char *name, int row, int col)
{
/* make sure we have valid dimensions */
/* if (row * col != 256)
return 0;*/
- glGenTextures (1, &font.texId);
+ glGenTextures (1, &(font->texId));
- font.blockRow = row;
- font.blockCol = col;
+ font->blockRow = row;
+ font->blockCol = col;
- fontMakeMap ();
+ fontMakeMap (font);
- return fontLoadTGA (name, font.texId);
+ return fontLoadTGA (name, font->texId);
}
/*
=============
Draws a character that is 'size' pixels in w and h.
=============
*/
-void fontDrawChar (char c, GLfloat x, GLfloat y, GLfloat size, int shadow)
+void fontDrawChar (texFont_t* font,char c, GLfloat x, GLfloat y, GLfloat size, int shadow)
{
- if (!font.gradient && !shadow)
- glColor4fv (font.fgColor);
- else if (!font.gradient && shadow)
- glColor4fv (font.bgColor);
- else if (font.gradient && !shadow)
- glColor4fv (font.gdColor);
+ if (!font->gradient && !shadow)
+ glColor4fv (font->fgColor);
+ else if (!font->gradient && shadow)
+ glColor4fv (font->bgColor);
+ else if (font->gradient && !shadow)
+ glColor4fv (font->gdColor);
glBegin (GL_QUADS);
glTexCoord2f (tPoints[(int)c][0], tPoints[(int)c][1]);
glVertex3f (x, y,0);
- glTexCoord2f (tPoints[(int)c][0] + font.tIncX, tPoints[(int)c][1]);
+ glTexCoord2f (tPoints[(int)c][0] + font->tIncX, tPoints[(int)c][1]);
glVertex3f (x + size, y,0);
if (!shadow)
- glColor4fv (font.fgColor);
- else glColor4fv (font.bgColor);
+ glColor4fv (font->fgColor);
+ else glColor4fv (font->bgColor);
- glTexCoord2f (tPoints[(int)c][0] + font.tIncX, tPoints[(int)c][1] + font.tIncY);
- glVertex3f (x + size + font.italic, y + size,0);
+ glTexCoord2f (tPoints[(int)c][0] + font->tIncX, tPoints[(int)c][1] + font->tIncY);
+ glVertex3f (x + size + font->italic, y + size,0);
- glTexCoord2f (tPoints[(int)c][0], tPoints[(int)c][1] + font.tIncY);
- glVertex3f (x + font.italic, y + size,0);
+ glTexCoord2f (tPoints[(int)c][0], tPoints[(int)c][1] + font->tIncY);
+ glVertex3f (x + font->italic, y + size,0);
glEnd ();
}
/*
Normal scissor region for text rendering.
=============
*/
-void fontScissorNormal (int xpos, int ypos, int tabs, int carrage, int size, int len)
+void fontScissorNormal (texFont_t* font,int xpos, int ypos, int tabs, int carrage, int size, int len)
{
int sy;
int ex;
sy = ypos;
ey = size;
}
- glScissor (xpos, sy, ex, ey);
+ glScissor (font,xpos, sy, ex, ey);
}
/*
=============
Scissor region used setup for a text region.
=============
*/
-void fontScissorTextRegion (void)
+void fontScissorTextRegion (texFont_t* font)
{
- glScissor (font.regionX, font.regionY, font.regionW, font.regionH);
+ glScissor (font,font->regionX, font->regionY, font->regionW, font->regionH);
}
/*
=============
Resets the font color.
=============
*/
-void fontForeColorReset (void)
+void fontForeColorReset (texFont_t* font)
{
- fontColorCopy (white, font.fgColor);
+ fontColorCopy (white, font->fgColor);
}
/*
=============
Resets the shadow color.
=============
*/
-void fontShadowColorReset (void)
+void fontShadowColorReset (texFont_t* font)
{
- fontColorCopy (gray, font.bgColor);
+ fontColorCopy (gray, font->bgColor);
}
/*
=============
Resets the gradient color.
=============
*/
-void fontGradientColorReset (void)
+void fontGradientColorReset (texFont_t* font)
{
- fontColorCopy (gray, font.gdColor);
+ fontColorCopy (gray, font->gdColor);
}
/*
=============
Resets the font. Only resets variables that could possible change.
=============
*/
-void fontReset (void)
+void fontReset (texFont_t* font)
{
- font.size = 12;
- font.shadow = 0;
- font.region = 0;
- font.gradient = 0;
- font.italic = 0;
- font.bold = 0;
- font.regionX = 0;
- font.regionY = 0;
- font.regionW = 0;
- font.regionH = 0;
- fontForeColorReset ();
- fontShadowColorReset ();
- fontGradientColorReset ();
+ font->size = 12;
+ font->shadow = 0;
+ font->region = 0;
+ font->gradient = 0;
+ font->italic = 0;
+ font->bold = 0;
+ font->regionX = 0;
+ font->regionY = 0;
+ font->regionW = 0;
+ font->regionH = 0;
+ fontForeColorReset (font);
+ fontShadowColorReset (font);
+ fontGradientColorReset (font);
}
/*
=============
Sets up a font region. Only good for one fontDrawString.
=============
*/
-void fontRegion (int x, int y, int w, int h)
+void fontRegion (texFont_t* font,int x, int y, int w, int h)
{
- font.region = 1;
- font.regionX = x;
- font.regionY = y - h;
- font.regionW = w;
- font.regionH = h;
+ font->region = 1;
+ font->regionX = x;
+ font->regionY = y - h;
+ font->regionW = w;
+ font->regionH = h;
}
/*
=============
Sets the font size.
=============
*/
-void fontSize (GLfloat size)
+void fontSize (texFont_t* font,GLfloat size)
{
- font.size = size;
+ font->size = size;
}
-void fontzdepth(GLfloat zdepth)
+void fontzdepth(texFont_t* font,GLfloat zdepth)
{
- font.zdepth=zdepth;
+ font->zdepth=zdepth;
}
/*
=============
Draws a shadow if called.
=============
*/
-void fontShadow (void)
+void fontShadow (texFont_t* font)
{
- font.shadow = 1;
+ font->shadow = 1;
}
/*
=============
Draws gradient text if called.
=============
*/
-void fontGradient (void)
+void fontGradient (texFont_t* font)
{
- font.gradient = 1;
+ font->gradient = 1;
}
/*
=============
Bold is just a hack, nothing special
=============
*/
-void fontRenderChar (char c, GLfloat x, GLfloat y, GLfloat size)
+void fontRenderChar (texFont_t* font,char c, GLfloat x, GLfloat y, GLfloat size)
{
- if (font.shadow)
+ if (font->shadow)
{
- if (!font.bold)
- fontDrawChar (c, x + 1.0, y + 1.0, size, 1);
- else fontDrawChar (c, x + 2.0, y + 1.0, size, 1);
+ if (!font->bold)
+ fontDrawChar (font,c, x + 1.0, y + 1.0, size, 1);
+ else fontDrawChar (font,c, x + 2.0, y + 1.0, size, 1);
}
- fontDrawChar (c, x, y, size, 0);
+ fontDrawChar (font,c, x, y, size, 0);
- if (font.bold)
- fontDrawChar (c, x + 1.0, y, size, 0);
+ if (font->bold)
+ fontDrawChar (font,c, x + 1.0, y, size, 0);
}
/*
=============
After this funtion *buffptr ++ will be the next character to draw or parse.
=============
*/
-int fontSlashParser (char *buffPtr, GLfloat *x, GLfloat *y)
+int fontSlashParser (texFont_t* font,char *buffPtr, GLfloat *x, GLfloat *y)
{
int ret = 0;
{
case 'a':
case 'c':
- *x -= font.size;
- return fontSetColorFromToken (buffPtr);
+ *x -= font->size;
+ return fontSetColorFromToken (font,buffPtr);
break;
case 'i':
- *x -= font.size;
- return fontItalicsMode (buffPtr);
+ *x -= font->size;
+ return fontItalicsMode (font,buffPtr);
break;
case 'b':
- *x -= font.size;
- return fontBoldMode (buffPtr);
+ *x -= font->size;
+ return fontBoldMode (font,buffPtr);
break;
default:
*buffPtr --;
- fontRenderChar (*buffPtr, *x, *y, font.size);
+ fontRenderChar (font,*buffPtr, *x, *y, font->size);
return ret;
break;
}
Does the actual rendering of our string.
=============
*/
-void fontWalkString (char *buffPtr, GLfloat xpos, GLfloat ypos, int *vPort,float width)
+void fontWalkString (texFont_t* font,char *buffPtr, GLfloat xpos, GLfloat ypos, int *vPort,float width)
{
- GLfloat size = font.size;
+ GLfloat size = font->size;
GLfloat x = xpos;
GLfloat y = ypos;
GLfloat carrage = 0;
continue;
break;
case '\\':
- buffPtr += fontSlashParser (buffPtr, &x, &y);
+ buffPtr += fontSlashParser (font,buffPtr, &x, &y);
if (*buffPtr == '\n' || *buffPtr == '\t')
{
buffPtr -= 1;
}
break;
default :
- fontRenderChar (*buffPtr, x, y, size);
+ fontRenderChar (font,*buffPtr, x, y, size);
break;
}
}
Renders a string at xpos, ypos.
=============
*/
-void fontDrawString (GLfloat xpos, GLfloat ypos, char *s,GLfloat width,...)
+void fontDrawString (texFont_t* font,GLfloat xpos, GLfloat ypos, char *s,GLfloat width,...)
{
va_list msg;
char buffer[FONT_MAX_LEN] = {'\0'};
glMatrixMode (GL_MODELVIEW);
glPushMatrix ();
glLoadIdentity ();*/
- glBindTexture (GL_TEXTURE_2D, font.texId);
+ glBindTexture (GL_TEXTURE_2D, font->texId);
/* draw the string */
- fontWalkString (buffer, xpos, ypos, vPort,(float)width);
+ fontWalkString (font,buffer, xpos, ypos, vPort,(float)width);
/* glMatrixMode (GL_PROJECTION);
glPopMatrix ();
glPopMatrix ();*/
fontSetModes (FONT_RESTORE_MODES);
- fontReset ();
+ fontReset (font);
}
/*
=============
Grabs a color token from a buffer and sets color.
=============
*/
-int fontSetColorFromToken (char *s)
+int fontSetColorFromToken (texFont_t* font,char *s)
{
int clr[4];
int ret = 1;
s += 1;
if (sscanf (s, "(%d %d %d)", &clr[0], &clr[1], &clr[2]) != 3)
return -1;
- fontColor (clr[0] * FONT_ITOF, clr[1] * FONT_ITOF, clr[2] * FONT_ITOF);
+ fontColor (font,clr[0] * FONT_ITOF, clr[1] * FONT_ITOF, clr[2] * FONT_ITOF);
} else if (*s == 'a')
{
s += 1;
if (sscanf (s, "(%d %d %d %d)", &clr[0], &clr[1], &clr[2], &clr[3]) != 4)
return -1;
- fontColorA (clr[0] * FONT_ITOF, clr[1] * FONT_ITOF, clr[2] * FONT_ITOF, clr[3] * FONT_ITOF);
+ fontColorA (font,clr[0] * FONT_ITOF, clr[1] * FONT_ITOF, clr[2] * FONT_ITOF, clr[3] * FONT_ITOF);
}
while (*s != ')' && ret ++)
Either turns on or off italics.
=============
*/
-int fontItalicsMode (char *s)
+int fontItalicsMode (texFont_t* font,char *s)
{
s += 1;
if (*s == '+')
- font.italic = FONT_ITALIC;
+ font->italic = FONT_ITALIC;
else if (*s == '-')
- font.italic = 0;
+ font->italic = 0;
else return -1;
return 2;
Either turns on or off bold.
=============
*/
-int fontBoldMode (char *s)
+int fontBoldMode (texFont_t* font,char *s)
{
s += 1;
if (*s == '+')
- font.bold = 1;
+ font->bold = 1;
else if (*s == '-')
- font.bold = 0;
+ font->bold = 0;
else return -1;
return 2;
Makes the font map which allows the correct characters to be drawn.
=============
*/
-void fontMakeMap (void)
+void fontMakeMap (texFont_t* font)
{
#define VCOPY(d,x,y) {d[0] = x; d[1] = y;}
int i = 0;
float x, y;
- font.tIncX = (float)pow (font.blockCol, -1);
- font.tIncY = (float)pow (font.blockRow, -1);
+ font->tIncX = (float)pow (font->blockCol, -1);
+ font->tIncY = (float)pow (font->blockRow, -1);
- for (y = 1 - font.tIncY; y >= 0; y -= font.tIncY)
- for (x = 0; x <= 1 - font.tIncX; x += font.tIncX, i ++)
+ for (y = 1 - font->tIncY; y >= 0; y -= font->tIncY)
+ for (x = 0; x <= 1 - font->tIncX; x += font->tIncX, i ++)
VCOPY (tPoints[i], x, y);
#undef VCOPY
}
glMatrixMode (matrixMode);
}
}
+
+
+int fontId(fontset_t* fontset,char* fontdesc)
+{
+ int ind=0;
+ for (ind=0;ind < fontset->count;ind ++)
+ {
+ if (strcmp(fontset->fonts[ind]->fontdesc,fontdesc) == 0)
+ return ind;
+ }
+ return -1;
+}
+/*
+ load font via font description
+ returns the id,
+ if font already exists no malloc just returns the id
+*/
+
+void font_init(texFont_t* font)
+{
+ font->fgColor[0]=1.0;font->fgColor[1]=1.0;font->fgColor[2]=1.0;font->fgColor[3]=1.0;
+ font->gdColor[0]=0.5;font->gdColor[1]=0.5;font->gdColor[2]=0.5;font->gdColor[3]=1.0;
+ font->bgColor[0]=0.5;font->bgColor[1]=0.5;font->bgColor[2]=0.5;font->bgColor[3]=1.0;
+ font->size=12;
+ font->shadow=0;
+ font->gradient=0;
+ font->italic=0;
+ font->bold=0;
+ font->region=0;
+ font->regionX=0;
+ font->regionY=0;
+ font->regionW=0;
+ font->regionH=0;
+ font->tIncX=0.0;
+ font->tIncY=0.0;
+ font->blockRow=FONT_BLOCK_ROW;
+ font->blockCol=FONT_BLOCK_COL;
+ font->texId=0;
+ font->fontdesc=(char*)0;
+
+ glGenTextures (1, &(font->texId));
+ fontMakeMap (font);
+
+}
+
+
+int add_font(fontset_t* fontset,char* fontdesc)
+{
+ int id=0;
+ char buf[512];
+ id=fontId(fontset,fontdesc);
+ if (id==-1)
+ {
+ sprintf(buf,"%s//%s.png","c://fontfiles//",fontdesc);
+ if(create_font_file(fontdesc,buf,(float)256,(float)256)==0)
+ {
+ fontset->fonts=realloc(fontset->fonts,sizeof(texFont_t*)*(fontset->count+1));
+ fontset->fonts[fontset->count]=(texFont_t*)malloc(sizeof(texFont_t));
+ font_init(fontset->fonts[fontset->count]);
+ if(!fontLoadPNG (buf, fontset->fonts[fontset->count]->texId))
+ return -1;
+
+ fontset->count++;
+ return fontset->count;
+ }
+ else
+ return -1;
+ }
+ else
+ return id;
+}
+void free_font_set(fontset_t* fontset)
+{
+ int ind;
+ for (ind=0;ind < fontset->count;ind ++)
+ {
+ free(fontset->fonts[ind]->fontdesc);
+ free(fontset->fonts[ind]);
+ }
+ free(fontset->fonts);
+ free(fontset->font_directory)
+ free(fontset);
+}
+
#ifndef __GLTEXFONTH__
#define __GLTEXFONTH__
+#include <stdlib.h>
+
+#include "glpangofont.h"
+
typedef float GLfloat;
/* Error Codes */
int blockCol; /* characters per col */
unsigned int texId; /* texture id */
float zdepth; //third dimension , depth of fonts
+ char* fontdesc; //font description
} texFont_t;
-#endif
+
+typedef struct
+{
+ texFont_t** fonts;
+ int count;
+ int activefont;
+ char* font_directory; //location where the glfont files are stored
+}fontset_t;
+
#ifdef __cplusplus
extern "C" {
#endif
+/*
+ check if font is already loaded
+ if loaded returns the id
+ else returns -1
+*/
+int fontId(fontset_t* fontset,char* fontdesc);
+
+
+/*
+ load font via font description
+ returns the id,
+ if font already exists no malloc just returns the id
+*/
+int add_font(fontset_t* fontset,char* fontdesc);
+
/*
=============
fontLoad
Loads up out font from the passed image file name.
=============
*/
-int fontLoad (char *name);
+int fontLoad (texFont_t* font,char *name);
/*
=============
fontLoadEx
chars per column.
=============
*/
-int fontLoadEx (char *name, int row, int col);
+int fontLoadEx (texFont_t* font,char *name, int row, int col);
/*
=============
fontDrawString
Draws a string at (xpos, ypos) in the applications window.
=============
*/
-void fontDrawString (GLfloat xpos, GLfloat ypos, char *s,GLfloat width,...);
+void fontDrawString (texFont_t* font,GLfloat xpos, GLfloat ypos, char *s,GLfloat width,...);
/*
=============
fontRegion
The region is w units wide and h units tall.
=============
*/
-void fontRegion (int xpos, int ypos, int w, int h);
+void fontRegion (texFont_t* font,int xpos, int ypos, int w, int h);
/*
=============
fontSize
Sets the font size.
=============
*/
-void fontSize (GLfloat size);
+void fontSize (texFont_t* font,GLfloat size);
-void fontzdepth(float zdepth);
+void fontzdepth(texFont_t* font,float zdepth);
/*
=============
Draws shadowed text.
=============
*/
-void fontShadow (void);
+void fontShadow (texFont_t* font);
/*
=============
fontGradient
Draws gradient text.
=============
*/
-void fontGradient (void);
+void fontGradient (texFont_t* font);
/*
=============
fontColor*, fontShadowColor*, fonrGradientColor*
Sets color for various operations.
=============
*/
-void fontColor (float r, float g, float b);
-void fontColorA (float r, float g, float b, float a);
-void fontColorp (float *clr);
-void fontColorAp (float *clr);
-void fontShadowColor (float r, float g, float b);
-void fontShadowColorA (float r, float g, float b, float a);
-void fontShadowColorp (float *clr);
-void fontShadowColorAp (float *clr);
-void fontGradientColor (float r, float g, float b);
-void fontGradientColorA (float r, float g, float b, float a);
-void fontGradientColorp (float *clr);
-void fontGradientColorAp (float *clr);
+void fontColor (texFont_t* font,float r, float g, float b);
+void fontColorA (texFont_t* font,float r, float g, float b, float a);
+void fontColorp (texFont_t* font,float *clr);
+void fontColorAp (texFont_t* font,float *clr);
+void fontShadowColor (texFont_t* font,float r, float g, float b);
+void fontShadowColorA (texFont_t* font,float r, float g, float b, float a);
+void fontShadowColorp (texFont_t* font,float *clr);
+void fontShadowColorAp (texFont_t* font,float *clr);
+void fontGradientColor (texFont_t* font,float r, float g, float b);
+void fontGradientColorA (texFont_t* font,float r, float g, float b, float a);
+void fontGradientColorp (texFont_t* font,float *clr);
+void fontGradientColorAp (texFont_t* font,float *clr);
#ifdef __cplusplus
}
#endif
+
+#endif
+
+
Contact -- vandals1@home.com
Web -- http://members.home.com/vandals1
*/
-#include "glTexFont.h"
+#include "glTexfont.h"
-/* color functions must be defined in texFont.h */
-
-extern texFont_t font;
+/* color functions must be defined in texfont->h */
/*
=============
Sets the currect color for the text.
=============
*/
-void fontColor (float r, float g, float b)
+void fontColor (texFont_t* font,float r, float g, float b)
{
- font.fgColor[0] = r;
- font.fgColor[1] = g;
- font.fgColor[2] = b;
- font.fgColor[3] = 1.0;
+ font->fgColor[0] = r;
+ font->fgColor[1] = g;
+ font->fgColor[2] = b;
+ font->fgColor[3] = 1.0;
}
-void fontColorA (float r, float g, float b, float a)
+void fontColorA (texFont_t* font,float r, float g, float b, float a)
{
- font.fgColor[0] = r;
- font.fgColor[1] = g;
- font.fgColor[2] = b;
- font.fgColor[3] = a;
+ font->fgColor[0] = r;
+ font->fgColor[1] = g;
+ font->fgColor[2] = b;
+ font->fgColor[3] = a;
}
-void fontColorp (float *clr)
+void fontColorp (texFont_t* font,float *clr)
{
- font.fgColor[0] = clr[0];
- font.fgColor[1] = clr[1];
- font.fgColor[2] = clr[2];
- font.fgColor[3] = 1.0;
+ font->fgColor[0] = clr[0];
+ font->fgColor[1] = clr[1];
+ font->fgColor[2] = clr[2];
+ font->fgColor[3] = 1.0;
}
-void fontColorAp (float *clr)
+void fontColorAp (texFont_t* font,float *clr)
{
- font.fgColor[0] = clr[0];
- font.fgColor[1] = clr[1];
- font.fgColor[2] = clr[2];
- font.fgColor[3] = clr[3];
+ font->fgColor[0] = clr[0];
+ font->fgColor[1] = clr[1];
+ font->fgColor[2] = clr[2];
+ font->fgColor[3] = clr[3];
}
/*
=============
Sets the currect shadow color for the text.
=============
*/
-void fontShadowColor (float r, float g, float b)
+void fontShadowColor (texFont_t* font,float r, float g, float b)
{
- font.bgColor[0] = r;
- font.bgColor[1] = g;
- font.bgColor[2] = b;
- font.bgColor[3] = 1.0;
+ font->bgColor[0] = r;
+ font->bgColor[1] = g;
+ font->bgColor[2] = b;
+ font->bgColor[3] = 1.0;
}
-void fontShadowColorA (float r, float g, float b, float a)
+void fontShadowColorA (texFont_t* font,float r, float g, float b, float a)
{
- font.bgColor[0] = r;
- font.bgColor[1] = g;
- font.bgColor[2] = b;
- font.bgColor[3] = a;
+ font->bgColor[0] = r;
+ font->bgColor[1] = g;
+ font->bgColor[2] = b;
+ font->bgColor[3] = a;
}
-void fontShadowColorp (float *clr)
+void fontShadowColorp (texFont_t* font,float *clr)
{
- font.bgColor[0] = clr[0];
- font.bgColor[1] = clr[1];
- font.bgColor[2] = clr[2];
- font.bgColor[3] = 1.0;
+ font->bgColor[0] = clr[0];
+ font->bgColor[1] = clr[1];
+ font->bgColor[2] = clr[2];
+ font->bgColor[3] = 1.0;
}
-void fontShadowColorAp (float *clr)
+void fontShadowColorAp (texFont_t* font,float *clr)
{
- font.bgColor[0] = clr[0];
- font.bgColor[1] = clr[1];
- font.bgColor[2] = clr[2];
- font.bgColor[3] = clr[3];
+ font->bgColor[0] = clr[0];
+ font->bgColor[1] = clr[1];
+ font->bgColor[2] = clr[2];
+ font->bgColor[3] = clr[3];
}
/*
=============
Sets the currect gradient color for the text.
=============
*/
-void fontGradientColor (float r, float g, float b)
+void fontGradientColor (texFont_t* font,float r, float g, float b)
{
- font.gdColor[0] = r;
- font.gdColor[1] = g;
- font.gdColor[2] = b;
- font.gdColor[3] = 1.0;
+ font->gdColor[0] = r;
+ font->gdColor[1] = g;
+ font->gdColor[2] = b;
+ font->gdColor[3] = 1.0;
}
-void fontGradientColorA (float r, float g, float b, float a)
+void fontGradientColorA (texFont_t* font,float r, float g, float b, float a)
{
- font.gdColor[0] = r;
- font.gdColor[1] = g;
- font.gdColor[2] = b;
- font.gdColor[3] = a;
+ font->gdColor[0] = r;
+ font->gdColor[1] = g;
+ font->gdColor[2] = b;
+ font->gdColor[3] = a;
}
-void fontGradientColorp (float *clr)
+void fontGradientColorp (texFont_t* font,float *clr)
{
- font.gdColor[0] = clr[0];
- font.gdColor[1] = clr[1];
- font.gdColor[2] = clr[2];
- font.gdColor[3] = 1.0;
+ font->gdColor[0] = clr[0];
+ font->gdColor[1] = clr[1];
+ font->gdColor[2] = clr[2];
+ font->gdColor[3] = 1.0;
}
-void fontGradientColorAp (float *clr)
+void fontGradientColorAp (texFont_t* font,float *clr)
{
- font.gdColor[0] = clr[0];
- font.gdColor[1] = clr[1];
- font.gdColor[2] = clr[2];
- font.gdColor[3] = clr[3];
+ font->gdColor[0] = clr[0];
+ font->gdColor[1] = clr[1];
+ font->gdColor[2] = clr[2];
+ font->gdColor[3] = clr[3];
}
{
unsigned char *imageData = NULL;
unsigned char header[8];
- int rowbytes,i,ii,c;
+ int rowbytes,i,ii,c,pixeloffset;
png_structp png_ptr;
png_infop info_ptr;
FILE *fp = fopen(file_name, "rb");
if (!fp)
{
- return 0;
+ return (unsigned char*)0;
}
fread(header, 1, 8, fp);
is_png = !png_sig_cmp(header, 0, 8);
if (!is_png)
{
- return 1;
+ printf ("glcomp error:file is not a valid PNG file\n");
+ return (unsigned char*)0;
}
- else
- printf("file is a valid ping file \n");
png_ptr = png_create_read_struct
(PNG_LIBPNG_VER_STRING, NULL,NULL,NULL);
if (!png_ptr)
- return -1;
+ {
+ printf ("glcomp error:file can not be read\n");
+ return (unsigned char*)0;
+ }
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr)
{
png_destroy_read_struct(&png_ptr,
(png_infopp)NULL, (png_infopp)NULL);
- return -1;
+ printf ("glcomp error:PNG file header is corrupted\n");
+ return (unsigned char*)0;
}
end_info = png_create_info_struct(png_ptr);
if (!end_info)
{
- png_destroy_read_struct(&png_ptr, &info_ptr,
+ printf ("glcomp error:PNG file header is corrupted\n");
+ png_destroy_read_struct(&png_ptr, &info_ptr,
(png_infopp)NULL);
- return -1;
+ return (unsigned char*)0;
}
png_init_io(png_ptr, fp);
-//If you had previously opened the file and read any of the signature from the beginning in order to see if this was a PNG file, you need to let libpng know that there are some bytes missing from the start of the file.
-
- png_set_sig_bytes(png_ptr, 8);
- png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
+ png_set_sig_bytes(png_ptr, 8); //pass signature bytes
+ png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL); //read real image data
row_pointers = png_malloc(png_ptr,
info_ptr->height*sizeof(png_bytepp));
- row_pointers = png_get_rows(png_ptr, info_ptr);
+ row_pointers = png_get_rows(png_ptr, info_ptr);
*imageWidth=info_ptr->width;
*imageHeight=info_ptr->height;
- texFormat = GL_ALPHA;
- rowbytes = png_get_rowbytes(png_ptr, info_ptr);
-/* for (i=0; i < info_ptr->height; i++)
- row_pointers[i]=png_malloc(png_ptr,
- info_ptr->width*info_ptr->width/2);*/
- // png_set_rows(png_ptr, info_ptr, &row_pointers);
+ texFormat = GL_ALPHA; //it is always GL_ALPHA, we dont need textures have their own colors
imageData=malloc(info_ptr->height*info_ptr->width);
c=0;
+ //decide what pixel offset to use, ro
+ pixeloffset = png_get_rowbytes(png_ptr, info_ptr)/info_ptr->width;
+
for (i=0; i < info_ptr->height; i++)
{
- printf ("ROW:%i\n",i);
- for (ii=0;ii < 1024; ii=ii+4)
+ for (ii=0;ii < 1024; ii=ii+pixeloffset)
{
-/* if ((row_pointers[i][ii+1] == 0) || (row_pointers[i][ii+1] == 255))
- imageData[c]=0;
- else*/
imageData[c]=row_pointers[255-i][ii];
c++;
-// printf ("(%i %i)",row_pointers[i][ii],row_pointers[i][ii+1]);
}
- printf ("\n---------------\n");
}
-
-
+ //cleaning libpng mess
+ png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
+ png_free(png_ptr, row_pointers);
return imageData;
-
-
-
-
}
return 1;
}
-void naber()
-{
-
-}