1 /* $Id: xfont.c,v 1.3 1999/11/05 08:12:46 brianp Exp $ */
4 * Mesa 3-D graphics library
6 * Copyright (C) 1999 Brian Paul All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * Example of using glXUseXFont().
41 static const char *ProgramName
= "xfont";
43 static const char *FontName
= "fixed";
45 static GLuint FontBase
= 0;
49 static void redraw( Display
*dpy
, Window w
)
51 static const char *text
= "This is glXUseXFont()";
53 glClear( GL_COLOR_BUFFER_BIT
);
56 glColor3f( 0.2, 0.2, 1.0 );
57 glBegin(GL_TRIANGLES
);
59 glVertex2f( -0.8, -0.7 );
60 glVertex2f( 0.8, -0.7 );
65 glRasterPos2f(-0.8, 0);
67 glCallLists(strlen(text
), GL_UNSIGNED_BYTE
, (GLubyte
*) text
);
69 glXSwapBuffers( dpy
, w
);
74 static void resize( unsigned int width
, unsigned int height
)
76 glViewport( 0, 0, width
, height
);
77 glMatrixMode( GL_PROJECTION
);
79 glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 );
84 static void setup_font( Display
*dpy
)
86 XFontStruct
*fontInfo
;
88 unsigned int first
, last
;
90 fontInfo
= XLoadQueryFont(dpy
, FontName
);
92 printf("Error: font %s not found\n", FontName
);
97 first
= fontInfo
->min_char_or_byte2
;
98 last
= fontInfo
->max_char_or_byte2
;
100 FontBase
= glGenLists((GLuint
) last
+ 1);
102 printf("Error: unable to allocate display lists\n");
105 glXUseXFont(id
, first
, last
- first
+ 1, FontBase
+ first
);
108 static Window
make_rgb_db_window( Display
*dpy
, int xpos
, int ypos
,
109 unsigned int width
, unsigned int height
)
111 int attrib
[] = { GLX_RGBA
,
118 XSetWindowAttributes attr
;
123 XVisualInfo
*visinfo
;
125 scrnum
= DefaultScreen( dpy
);
126 root
= RootWindow( dpy
, scrnum
);
128 visinfo
= glXChooseVisual( dpy
, scrnum
, attrib
);
130 printf("Error: couldn't get an RGB, Double-buffered visual\n");
134 /* window attributes */
135 attr
.background_pixel
= 0;
136 attr
.border_pixel
= 0;
137 attr
.colormap
= XCreateColormap( dpy
, root
, visinfo
->visual
, AllocNone
);
138 attr
.event_mask
= StructureNotifyMask
| ExposureMask
| KeyPressMask
;
139 mask
= CWBackPixel
| CWBorderPixel
| CWColormap
| CWEventMask
;
141 win
= XCreateWindow( dpy
, root
, 0, 0, width
, height
,
142 0, visinfo
->depth
, InputOutput
,
143 visinfo
->visual
, mask
, &attr
);
146 XSizeHints sizehints
;
149 sizehints
.width
= width
;
150 sizehints
.height
= height
;
151 sizehints
.flags
= USSize
| USPosition
;
152 XSetNormalHints(dpy
, win
, &sizehints
);
153 XSetStandardProperties(dpy
, win
, ProgramName
, ProgramName
,
154 None
, (char **)NULL
, 0, &sizehints
);
158 ctx
= glXCreateContext( dpy
, visinfo
, NULL
, True
);
160 glXMakeCurrent( dpy
, win
, ctx
);
166 static void event_loop( Display
*dpy
)
171 XNextEvent( dpy
, &event
);
173 switch (event
.type
) {
175 redraw( dpy
, event
.xany
.window
);
177 case ConfigureNotify
:
178 resize( event
.xconfigure
.width
, event
.xconfigure
.height
);
190 int main( int argc
, char *argv
[] )
195 dpy
= XOpenDisplay(NULL
);
197 win
= make_rgb_db_window( dpy
, 0, 0, 300, 300 );
200 glShadeModel( GL_FLAT
);
201 glClearColor( 0.5, 0.5, 1.0, 1.0 );
203 XMapWindow( dpy
, win
);