File: xfont.c

package info (click to toggle)
viewmol 2.3-5
  • links: PTS
  • area: main
  • in suites: woody
  • size: 9,424 kB
  • ctags: 2,239
  • sloc: ansic: 29,098; sh: 909; makefile: 513; python: 238
file content (95 lines) | stat: -rw-r--r-- 2,634 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*******************************************************************************
*                                                                              *
*                                   Viewmol                                    *
*                                                                              *
*                                X F O N T . C                                 *
*                                                                              *
*                 Copyright (c) Joerg-R. Hill, December 2000                   *
*                                                                              *
********************************************************************************
*
* $Id: xfont.c,v 1.5 2000/12/10 15:19:30 jrh Exp $
* $Log: xfont.c,v $
* Revision 1.5  2000/12/10 15:19:30  jrh
* Release 2.3
*
* Revision 1.4  1999/05/24 01:28:08  jrh
* Release 2.2.1
*
* Revision 1.3  1999/02/07 22:00:25  jrh
* Release 2.2
*
* Revision 1.2  1998/01/26 00:49:52  jrh
* Release 2.1
*
* Revision 1.1  1996/12/10  18:44:32  jrh
* Initial revision
*
*/
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<X11/Xlib.h>
#include<X11/Xutil.h>
#include<GL/gl.h>
#include<GL/glu.h>
#include<GL/glx.h>
#include "viewmol.h"

extern void *getmem(size_t, size_t);
extern void fremem(void **);

extern int drawingDevice;
extern char *textPointer;

XFontStruct *makeRasterFont(Display *display, char *font, GLuint *base)
{
  XFontStruct *fontInfo, *f;
  Font id;
  unsigned int first, last;

  /* leaks memory */
  if ((fontInfo=XLoadQueryFont(display, font)) == NULL)
    return(fontInfo);

  id=fontInfo->fid;
  first=fontInfo->min_char_or_byte2;
  last=fontInfo->max_char_or_byte2;

  if ((*base=glGenLists((GLuint)last+1)) == 0)
  {
    XFreeFont(display, fontInfo);
    return((XFontStruct *)NULL);
  }

  /* leaks memory */
  f=(XFontStruct *)getmem((size_t)1, sizeof(XFontStruct));
  memcpy((void *)f, (void *)fontInfo, sizeof(XFontStruct));
  glXUseXFont(id, first, last-first+1, *base+first);

   return(f);
}

void printString(char *s, double x, double y, double z, double offset, GLuint base)
{
  glRasterPos3d(x+offset, y, z);
  glListBase(base);
  glCallLists(strlen(s), GL_UNSIGNED_BYTE, (GLubyte *)s);
}

int StringWidth(XFontStruct *font, char *string)
{
  return(XTextWidth(font, string, strlen(string)));
}

int StringHeight(XFontStruct *font)
{
  return(font->ascent+font->descent);
/*return(font->ascent); */
}

void deleteFontList(GLuint base, XFontStruct *font)
{
  glDeleteLists(base, font->max_char_or_byte2-font->min_char_or_byte2+1);
  fremem((void **)&font);
}