3
* Mesa 3-D graphics library
5
* Copyright (C) 1999 Brian Paul All Rights Reserved.
7
* Permission is hereby granted, free of charge, to any person obtaining a
8
* copy of this software and associated documentation files (the "Software"),
9
* to deal in the Software without restriction, including without limitation
10
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
11
* and/or sell copies of the Software, and to permit persons to whom the
12
* Software is furnished to do so, subject to the following conditions:
14
* The above copyright notice and this permission notice shall be included
15
* in all copies or substantial portions of the Software.
17
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
* Example of using glXUseXFont().
40
static const char *ProgramName = "xfont";
42
static const char *FontName = "fixed";
44
static GLuint FontBase = 0;
48
static void redraw( Display *dpy, Window w )
50
static const char *text = "This is glXUseXFont()";
52
glClear( GL_COLOR_BUFFER_BIT );
55
glColor3f( 0.2, 0.2, 1.0 );
56
glBegin(GL_TRIANGLES);
58
glVertex2f( -0.8, -0.7 );
59
glVertex2f( 0.8, -0.7 );
64
glRasterPos2f(-0.8, 0);
66
glCallLists(strlen(text), GL_UNSIGNED_BYTE, (GLubyte *) text);
68
glXSwapBuffers( dpy, w );
73
static void resize( unsigned int width, unsigned int height )
75
glViewport( 0, 0, width, height );
76
glMatrixMode( GL_PROJECTION );
78
glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 );
83
static void setup_font( Display *dpy )
85
XFontStruct *fontInfo;
87
unsigned int first, last;
89
fontInfo = XLoadQueryFont(dpy, FontName);
91
printf("Error: font %s not found\n", FontName);
96
first = fontInfo->min_char_or_byte2;
97
last = fontInfo->max_char_or_byte2;
99
FontBase = glGenLists((GLuint) last + 1);
101
printf("Error: unable to allocate display lists\n");
104
glXUseXFont(id, first, last - first + 1, FontBase + first);
107
static Window make_rgb_db_window( Display *dpy, int xpos, int ypos,
108
unsigned int width, unsigned int height )
110
int attrib[] = { GLX_RGBA,
117
XSetWindowAttributes attr;
122
XVisualInfo *visinfo;
124
scrnum = DefaultScreen( dpy );
125
root = RootWindow( dpy, scrnum );
127
visinfo = glXChooseVisual( dpy, scrnum, attrib );
129
printf("Error: couldn't get an RGB, Double-buffered visual\n");
133
/* window attributes */
134
attr.background_pixel = 0;
135
attr.border_pixel = 0;
136
attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone);
137
attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
138
mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
140
win = XCreateWindow( dpy, root, 0, 0, width, height,
141
0, visinfo->depth, InputOutput,
142
visinfo->visual, mask, &attr );
145
XSizeHints sizehints;
148
sizehints.width = width;
149
sizehints.height = height;
150
sizehints.flags = USSize | USPosition;
151
XSetNormalHints(dpy, win, &sizehints);
152
XSetStandardProperties(dpy, win, ProgramName, ProgramName,
153
None, (char **)NULL, 0, &sizehints);
157
ctx = glXCreateContext( dpy, visinfo, NULL, True );
159
glXMakeCurrent( dpy, win, ctx );
165
static void event_loop( Display *dpy )
170
XNextEvent( dpy, &event );
172
switch (event.type) {
174
redraw( dpy, event.xany.window );
176
case ConfigureNotify:
177
resize( event.xconfigure.width, event.xconfigure.height );
189
int main( int argc, char *argv[] )
194
dpy = XOpenDisplay(NULL);
196
win = make_rgb_db_window( dpy, 0, 0, 300, 300 );
199
glShadeModel( GL_FLAT );
200
glClearColor( 0.5, 0.5, 1.0, 1.0 );
202
XMapWindow( dpy, win );