File: testrender.c

package info (click to toggle)
quesoglc 0.7.2-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,192 kB
  • sloc: ansic: 14,620; sh: 9,718; makefile: 283; python: 50
file content (178 lines) | stat: -rw-r--r-- 4,784 bytes parent folder | download | duplicates (7)
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/* QuesoGLC
 * A free implementation of the OpenGL Character Renderer (GLC)
 * Copyright (c) 2002, 2004-2008, Bertrand Coconnier
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
/* $Id: testrender.c 713 2008-01-26 20:10:13Z bcoconni $ */

/* Example of how to render text using the rendering styles defined in the
 * GLC specs.
 */

#include "GL/glc.h"
#include <stdio.h>
#if defined __APPLE__ && defined __MACH__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include <stdlib.h>

#ifdef __WIN32__
/* Font face "Arial Regular" for Windows in order to make a regression test for
 * bug #1856336.
 */
#define FAMILY "Arial"
#define FACE "Regular"
#else
#define FAMILY "Courier"
#define FACE "Italic"
#endif

void display(void)
{
  GLfloat BitmapBoundingBox[8];

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glLoadIdentity();
  glcRenderStyle(GLC_LINE);
  glColor3f(0., 1., 0.);
  glTranslatef(100., 50., 0.);
  glRotatef(45., 0., 0., 1.);
  glScalef(90., 90., 0.);
  glcRenderChar('L');
  glcRenderString("ine");

  glLoadIdentity();
  glcRenderStyle(GLC_TEXTURE);
  glColor3f(0., 0., 1.);
  glTranslatef(30., 150., 0.);
  glScalef(90., 90., 0.);
  glcRenderChar('T');
  glcRenderString("exture");

  glLoadIdentity();
  glcRenderStyle(GLC_BITMAP);
  glColor3f(1., 0., 0.);
  glRasterPos2f(30., 200.);
  glcLoadIdentity();
  glcScale(90., 90.);
  glcRotate(-10.);
  glcRenderChar('B');
  glcRenderString("itmap");

  glcLoadIdentity();
  glcMeasureString(GL_FALSE, "Bitmap");
  glcGetStringMetric(GLC_BOUNDS, BitmapBoundingBox);
  glTranslatef(30., 200., 0.);
  glScalef(90., 90., 1.);
  glRotatef(-10., 0., 0., 1.);
  glBegin(GL_LINE_LOOP);
    glVertex2fv(&(BitmapBoundingBox[0]));
    glVertex2fv(&(BitmapBoundingBox[2]));
    glVertex2fv(&(BitmapBoundingBox[4]));
    glVertex2fv(&(BitmapBoundingBox[6]));
  glEnd();

  glLoadIdentity();
  glcRenderStyle(GLC_TRIANGLE);
  glColor3f(1., 1., 0.);
  glTranslatef(30., 50., 0.);
  glScalef(90., 90., 0.);
  glcRenderString("Tr");
  glcRenderStyle(GLC_LINE);
  glcRenderChar('i');
  glcRenderStyle(GLC_TRIANGLE);
  glcRenderString("angle");

  glFlush();
}

void reshape(int width, int height)
{
  glClearColor(0., 0., 0., 0.);
  glViewport(0, 0, width, height);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluOrtho2D(-0.325, width - 0.325, -0.325, height - 0.325);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  glFlush();
}

void keyboard(unsigned char key, int x, int y)
{
  GLint i = 0;

  switch(key) {
  case 27: /* Escape Key */
    printf("Textures : %d\n", glcGeti(GLC_TEXTURE_OBJECT_COUNT));
    for (i = 0; i < glcGeti(GLC_TEXTURE_OBJECT_COUNT); i++)
      printf("Texture #%d : %d\n", i, glcGetListi(GLC_TEXTURE_OBJECT_LIST, i));
    printf("Display Lists : %d\n", glcGeti(GLC_LIST_OBJECT_COUNT));
    for (i = 0; i < glcGeti(GLC_LIST_OBJECT_COUNT); i++)
      printf("Display List #%d : %d\n", i,
	     glcGetListi(GLC_LIST_OBJECT_LIST, i));
    printf("Buffer Objects : %d\n", glcGeti(GLC_BUFFER_OBJECT_COUNT_QSO));
    for (i = 0; i < glcGeti(GLC_BUFFER_OBJECT_COUNT_QSO); i++)
      printf("Buffer Object #%d : %d\n", i,
	     glcGetListi(GLC_BUFFER_OBJECT_LIST_QSO, i));
    glcDeleteGLObjects();
    glcDeleteContext(glcGetCurrentContext());
    glcContext(0);
    exit(0);
  default:
    break;
  }
}

int main(int argc, char **argv)
{
  int ctx = 0;
  int font = 0;
  GLCenum error = 0;

  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  glutInitWindowSize(640, 480);
  glutCreateWindow("QuesoGLC");
  glutDisplayFunc(display);
  glutReshapeFunc(reshape);
  glutKeyboardFunc(keyboard);

  glEnable(GL_TEXTURE_2D);

  ctx = glcGenContext();
  glcContext(ctx);
  font = glcNewFontFromFamily(glcGenFontID(), FAMILY);
  glcFont(font);
  error = glcGetError();
  glcFontFace(font, FACE);

#ifdef __WIN32__
  /* Regression test for bug #1856336 */
  error = glcGetError();
  if (error == GLC_RESOURCE_ERROR) {
    printf("Unable to select the font %s %s\n", FAMILY, FACE);
    return -1;
  }
#endif

  glutMainLoop();
  glcDeleteContext(ctx);
  return 0;
}