1 /* QuesoGLC
2 * A free implementation of the OpenGL Character Renderer (GLC)
3 * Copyright (c) 2002, 2004-2008, Bertrand Coconnier
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 /* $Id: test10.c 712 2008-01-26 19:46:49Z bcoconni $ */
20
21 /** \file
22 * Regression test for bug #1820546 (reported by Alok Kulkarni) :
23 *
24 * The function glcRenderString works incorrectly when passed an empty string.
25 * It is observed to render any previously-rendered string without its first
26 * character.
27 *
28 * For example, the following sequence of calls:
29 *
30 * ... set some position
31 * glcRenderString ("ABCD");
32 *
33 * ... set some other position
34 * glcRenderString ("");
35 *
36 * will produce the following two results:
37 *
38 * ABCD
39 * BCD
40 *
41 * This is observed to be true regardless of render style.
42 */
43
44 #include "GL/glc.h"
45 #if defined __APPLE__ && defined __MACH__
46 #include <GLUT/glut.h>
47 #else
48 #include <GL/glut.h>
49 #endif
50 #include <stdlib.h>
51 #include <stdio.h>
52
53 GLuint id = 0;
54
55
reshape(int width,int height)56 void reshape(int width, int height)
57 {
58 glClearColor(0., 0., 0., 0.);
59 glViewport(0, 0, width, height);
60 glMatrixMode(GL_PROJECTION);
61 glLoadIdentity();
62 gluOrtho2D(0., width, 0., height);
63 glMatrixMode(GL_MODELVIEW);
64 glLoadIdentity();
65 glFlush();
66 }
67
keyboard(unsigned char key,int x,int y)68 void keyboard(unsigned char key, int x, int y)
69 {
70 switch(key) {
71 case 27: /* Escape Key */
72 exit(0);
73 default:
74 break;
75 }
76 }
77
display(void)78 void display(void)
79 {
80 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
81
82 /* Render "Hello world!" */
83 glColor3f(1.f, 0.f, 0.f);
84 glLoadIdentity();
85 glScalef(100.f, 100.f, 1.f);
86 glTranslatef(0.5f, 0.5f, 0.f);
87 glcRenderCountedString(4, "ABCDE");
88 glLoadIdentity();
89 glScalef(100.f, 100.f, 1.f);
90 glTranslatef(0.5f, 1.5f, 0.f);
91 glcRenderString(""); /* If the bug is not fixed, it displays "BCD" */
92
93 glFlush();
94 }
95
main(int argc,char ** argv)96 int main(int argc, char **argv)
97 {
98 GLint ctx = 0;
99 GLint myFont = 0;
100
101 glutInit(&argc, argv);
102 glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
103 glutInitWindowSize(640, 300);
104 glutCreateWindow("Tutorial");
105 glutDisplayFunc(display);
106 glutReshapeFunc(reshape);
107 glutKeyboardFunc(keyboard);
108
109 glEnable(GL_TEXTURE_2D);
110
111 /* Set up and initialize GLC */
112 ctx = glcGenContext();
113 glcContext(ctx);
114 glcAppendCatalog("/usr/lib/X11/fonts/Type1");
115
116 /* Create a font "Palatino Bold" */
117 myFont = glcGenFontID();
118 #ifdef __WIN32__
119 glcNewFontFromFamily(myFont, "Palatino Linotype");
120 #else
121 glcNewFontFromFamily(myFont, "Palatino");
122 #endif
123 glcFontFace(myFont, "Bold");
124 glcFont(myFont);
125 glcRenderStyle(GLC_TEXTURE);
126
127 glutMainLoop();
128 return 0;
129 }
130