-static void freetexture (Circuit *ci, GLuint texture)
-{
- ci->s_refs[texture]--;
- if (ci->s_refs[texture] < 1) {
- glDeleteTextures(1, &texture);
- }
-}
-
-static TexNum * fonttexturealloc (ModeInfo *mi,
- const char *str, float *fg, float *bg)
-{
- Circuit *ci = &circuit[MI_SCREEN(mi)];
- int i;
- XImage *ximage;
- char *c;
- TexNum *t;
- GLuint mintex;
- if (ci->font_init == 0) {
- for (i = 0 ; i < 50 ; i++) {
- ci->font_strings[i] = NULL;
- ci->s_refs[i] = 0;
- ci->font_w[i] = 0; ci->font_h[i] = 0;
- }
- ci->font_init++;
- }
- for (i = 0 ; i < 50 ; i++) {
- if (!ci->s_refs[i] && ci->font_strings[i]) {
- free (ci->font_strings[i]);
- ci->font_strings[i] = NULL;
- }
- if (ci->font_strings[i] && !strcmp(str, ci->font_strings[i])) { /* if one matches */
- t = malloc(sizeof(TexNum));
- t->w = ci->font_w[i]; t->h = ci->font_h[i];
- t->num = i;
- ci->s_refs[i]++;
- return t;
- }
- }
-
- /* at this point we need to make the new texture */
- ximage = text_to_ximage (mi->xgwa.screen,
- mi->xgwa.visual,
- font, str,
- fg, bg);
- glGenTextures (1, &mintex);
- for (i = mintex ; ci->font_strings[i] != NULL ; i++) { /* set i to the next unused value */
- if (i > 49) {
- fprintf(stderr, "Texture cache full!\n");
- free(ximage->data);
- ximage->data = 0;
- XFree (ximage);
- return NULL;
- }
- }
-
- glBindTexture(GL_TEXTURE_2D, i);
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-
- clear_gl_error();
-#if 0
- i = gluBuild2DMipmaps(GL_TEXTURE_2D, 4,
- ximage->width, ximage->height,
- GL_RGBA, GL_UNSIGNED_BYTE, ximage->data);
- if (i)
- {
- const char *s = (char *) gluErrorString (i);
- fprintf (stderr, "%s: error mipmapping %dx%d texture: %s\n",
- progname, ximage->width, ximage->height,
- (s ? s : "(unknown)"));
- abort();
- }
- check_gl_error("mipmapping");
-#else
- glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, ximage->width, ximage->height, 0,
- GL_RGBA, GL_UNSIGNED_BYTE, ximage->data);
- check_gl_error("texture");
-#endif
-
- t = malloc(sizeof(TexNum));
- t->w = ximage->width;
- t->h = ximage->height;
- ci->font_w[i] = t->w; ci->font_h[i] = t->h;
- free(ximage->data);
- ximage->data = 0;
- XFree (ximage);
- c = malloc(strlen(str)+1);
- strncpy(c, str, strlen(str)+1);
- ci->font_strings[i] = c;
- ci->s_refs[i]++;
- t->num = i;
- return t;
-}
-