File: test.c

package info (click to toggle)
mgltools-pyglf 1.5.7-3
  • links: PTS, VCS
  • area: non-free
  • in suites: buster
  • size: 1,868 kB
  • sloc: ansic: 1,804; python: 153; sh: 78; makefile: 14
file content (176 lines) | stat: -rw-r--r-- 3,519 bytes parent folder | download | duplicates (4)
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
/*
=========================================================================
| GLF Library Test
|
| Author: Roman Podobedov
| Email: romka@ut.ee
| WEB: http://romka.demonews.com
=========================================================================
*/

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <GL/glut.h>
#include "glf.h"

int WindW, WindH;
int i;

void Draw(void)
{

	glClear(GL_COLOR_BUFFER_BIT);

	glColor3f(1, 1, 1);
	
	glfStringCentering(GL_FALSE);
	glfSetRotateAngle(0.0f);

	// Info message
	glfStringDirection(GLF_LEFT);
	glPushMatrix();
	glTranslatef(-1.2, 0.9, 0);
	glScalef(0.05, 0.05, 1);
	glfDrawSolidString("GLF Library - Text rotation and direction example");
	glPopMatrix();

	// Write down
	glfStringDirection(GLF_DOWN);
	glPushMatrix();
	glTranslatef(-1.2, 0.5, 0);
	glScalef(0.05, 0.05, 1);
	glfDrawSolidString("Direction - DOWN");
	glPopMatrix();

	// Write up
	glfStringDirection(GLF_UP);
	glPushMatrix();
	glTranslatef(1.2, -0.5, 0);
	glScalef(0.05, 0.05, 1);
	glfDrawSolidString("Direction - UP");
	glPopMatrix();

	// Write left
	glfStringDirection(GLF_LEFT);
	glPushMatrix();
	glTranslatef(0, 0.5, 0);
	glScalef(0.05, 0.05, 1);
	glfDrawSolidString("Direction - LEFT");
	glPopMatrix();

	// Write right
	glfStringDirection(GLF_RIGHT);
	glPushMatrix();
	glTranslatef(0, -0.5, 0);
	glScalef(0.05, 0.05, 1);
	glfDrawSolidString("Direction - RIGHT");
	glPopMatrix();

	// Rotated text
	glfStringCentering(GL_TRUE);
	
	glfStringDirection(GLF_LEFT);
	glfSetRotateAngle(45);

	glPushMatrix();
	glTranslatef(-0.5, 0, 0);
	glScalef(0.05, 0.05, 1);
	glfDrawSolidString("Rotated text");
	glPopMatrix();

	glfSetRotateAngle(-45);
	glfStringDirection(GLF_DOWN);
	glPushMatrix();
	glTranslatef(0, 0, 0);
	glScalef(0.05, 0.05, 1);
	glfDrawSolidString("Rotated text");
	glPopMatrix();

	glfSetRotateAngle(-45);
	glfStringDirection(GLF_UP);
	glPushMatrix();
	glTranslatef(0, -0.5, 0);
	glScalef(0.05, 0.05, 1);
	glfDrawSolidString("Rotated text");
	glPopMatrix();

	for (i=0; i<12; i++)
	{
		glfSetRotateAngle(i*30);
		glfStringDirection(GLF_UP);
		glPushMatrix();
		glTranslatef(0.6, -0.5, 0);
		glScalef(0.03, 0.03, 1);
		glfDrawSolidString(" ABC");
		glPopMatrix();
	}

	for (i=0; i<12; i++)
	{
		glfSetRotateAngle(i*30);
		glfStringDirection(GLF_RIGHT);
		glPushMatrix();
		glTranslatef(-0.6, 0.5, 0);
		glScalef(0.03, 0.03, 1);
		glfDrawSolidString(" FLG");
		glPopMatrix();
	}


	glFlush();
	glutSwapBuffers();
}


void Reshape(int width, int height)
{
  glViewport(0, 0, width, height);

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();

  gluOrtho2D(-1.33, 1.33, -1, 1);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  
  WindW = width;
  WindH = height;
}

static void Key(unsigned char key, int x, int y)
{
  switch (key)
  {
    case 27: exit(0);
             break;
  }
}

void timf(int value)
{
  glutPostRedisplay();
  glutTimerFunc(1, timf, 0);
}


void main(int argc, char *argv[])
{
  WindW = 1024;
  WindH = 768;

  glfInit();
  glfLoadFont("fonts/times_new1.glf");
  glutInit(&argc, argv);
  glutInitWindowSize(WindW, WindH);
  glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
  (void)glutCreateWindow("GLF Demo - Solid Text");

  glutReshapeFunc(Reshape);
  glutDisplayFunc(Draw);
  glutKeyboardFunc(Key);
  glutTimerFunc(40, timf, 0);

  glClearColor(0, 0, 0, 0);
  glutMainLoop();
}