2 * Mesa 3-D graphics library
4 * Copyright (C) 1999 Brian Paul All Rights Reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * Example of using glXUseRotatedXFontMESA().
37 #include "xuserotfont.h"
40 static const char *ProgramName
= "xfont";
42 static const char *FontName
= "fixed";
44 static GLuint FontBase
[4];
47 static void redraw( Display
*dpy
, Window w
)
49 static const char *text
= " Rotated bitmap text";
52 glClear( GL_COLOR_BUFFER_BIT
);
55 glColor3f( 0.2, 0.2, 1.0 );
56 glBegin(GL_TRIANGLES
);
57 glVertex2f( -0.8, 0.7 );
58 glVertex2f( -0.8, -0.7 );
59 glVertex2f( 0.8, 0.0 );
71 for (i
= 0; i
< 4; i
++) {
73 glListBase(FontBase
[i
]);
74 glCallLists(strlen(text
), GL_UNSIGNED_BYTE
, (GLubyte
*) text
);
77 glXSwapBuffers( dpy
, w
);
82 static void resize( unsigned int width
, unsigned int height
)
84 glViewport( 0, 0, width
, height
);
85 glMatrixMode( GL_PROJECTION
);
87 glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 );
92 static void setup_font( Display
*dpy
)
94 XFontStruct
*fontInfo
;
96 unsigned int first
, last
;
99 fontInfo
= XLoadQueryFont(dpy
, FontName
);
101 printf("Error: font %s not found\n", FontName
);
106 first
= fontInfo
->min_char_or_byte2
;
107 last
= fontInfo
->max_char_or_byte2
;
109 for (i
= 0; i
< 4; i
++) {
110 FontBase
[i
] = glGenLists((GLuint
) last
+ 1);
112 printf("Error: unable to allocate display lists\n");
115 glXUseRotatedXFontMESA(id
, first
, last
- first
+ 1, FontBase
[i
] + first
,
121 static Window
make_rgb_db_window( Display
*dpy
, int xpos
, int ypos
,
122 unsigned int width
, unsigned int height
)
124 int attrib
[] = { GLX_RGBA
,
131 XSetWindowAttributes attr
;
136 XVisualInfo
*visinfo
;
138 scrnum
= DefaultScreen( dpy
);
139 root
= RootWindow( dpy
, scrnum
);
141 visinfo
= glXChooseVisual( dpy
, scrnum
, attrib
);
143 printf("Error: couldn't get an RGB, Double-buffered visual\n");
147 /* window attributes */
148 attr
.background_pixel
= 0;
149 attr
.border_pixel
= 0;
150 attr
.colormap
= XCreateColormap( dpy
, root
, visinfo
->visual
, AllocNone
);
151 attr
.event_mask
= StructureNotifyMask
| ExposureMask
| KeyPressMask
;
152 mask
= CWBackPixel
| CWBorderPixel
| CWColormap
| CWEventMask
;
154 win
= XCreateWindow( dpy
, root
, 0, 0, width
, height
,
155 0, visinfo
->depth
, InputOutput
,
156 visinfo
->visual
, mask
, &attr
);
159 XSizeHints sizehints
;
162 sizehints
.width
= width
;
163 sizehints
.height
= height
;
164 sizehints
.flags
= USSize
| USPosition
;
165 XSetNormalHints(dpy
, win
, &sizehints
);
166 XSetStandardProperties(dpy
, win
, ProgramName
, ProgramName
,
167 None
, (char **)NULL
, 0, &sizehints
);
171 ctx
= glXCreateContext( dpy
, visinfo
, NULL
, True
);
173 glXMakeCurrent( dpy
, win
, ctx
);
179 static void event_loop( Display
*dpy
)
184 XNextEvent( dpy
, &event
);
186 switch (event
.type
) {
188 redraw( dpy
, event
.xany
.window
);
190 case ConfigureNotify
:
191 resize( event
.xconfigure
.width
, event
.xconfigure
.height
);
203 int main( int argc
, char *argv
[] )
208 dpy
= XOpenDisplay(NULL
);
210 win
= make_rgb_db_window( dpy
, 0, 0, 300, 300 );
213 glShadeModel( GL_FLAT
);
214 glClearColor( 0.5, 0.5, 1.0, 1.0 );
216 XMapWindow( dpy
, win
);