opengl-intro: text.c

File text.c, 1.7 KB (added by msitar, 15 years ago)

Primer osenčene kocke z besedilom na vsaki stranici

Line 
1#include <GL/glut.h>                                                  
2                                                                                                               
3float kvadrat(char *s)
4{
5  char *c;
6  glPushMatrix();
7  glTranslatef(0.0, 0.0, 1.0);
8  glNormal3f(0.0, 0.0, 1.0);
9  glRectf(-1.0, -1.0, 1.0, 1.0);
10  glTranslatef(-0.8, 0.0, 0.01);
11  glDisable(GL_LIGHTING);
12  glScalef(0.003, 0.003, 0.003);
13  glColor3f(1.0, 0.0, 0.0);
14  for(c=s; *c; c++)
15  {
16    glutStrokeCharacter(GLUT_STROKE_ROMAN, *c);
17  }
18  glEnable(GL_LIGHTING);
19  glPopMatrix();
20}
21
22void display()
23{
24  float mat[4]={0.9, 0.6, 0.3, 1.0};
25  glClear(GL_COLOR_BUFFER_BIT);
26  glClear(GL_DEPTH_BUFFER_BIT);
27  glPushMatrix();
28  glRotatef(30.0, 1.0, 0.0, 0.0);
29  glRotatef(30.0, 0.0, 1.0, 0.0);
30  glScalef(0.5, 0.5, 0.5);
31  glMaterialfv(GL_FRONT, GL_DIFFUSE, mat);
32  kvadrat("Spredaj");
33  glRotatef(90.0, 0.0, 1.0, 0.0);
34  kvadrat("Desno");
35  glRotatef(90.0, 0.0, 1.0, 0.0);
36  kvadrat("Zadaj");
37  glRotatef(90.0, 0.0, 1.0, 0.0);
38  kvadrat("Levo");
39  glRotatef(90.0, 1.0, 0.0, 0.0);
40  kvadrat("Spodaj");
41  glRotatef(180.0, 1.0, 0.0, 0.0);
42  kvadrat("Zgoraj");
43  glPopMatrix();
44  glFlush();
45}
46
47void reshape (int w, int h)
48{
49  double l;
50  l = 1;
51  glViewport (0, 0, w, h);
52  glMatrixMode (GL_PROJECTION);
53  glLoadIdentity();
54  glOrtho(-l, l, -l, l, -l, l);
55  glMatrixMode(GL_MODELVIEW);
56  glLoadIdentity();
57}
58
59int main(int argc, char *argv[])
60{
61  glutInit(&argc, argv);
62  glutInitDisplayMode(GLUT_SINGLE|GLUT_DEPTH);
63  glutCreateWindow("C GLUT program");
64  glutDisplayFunc(display);
65  glutReshapeFunc(reshape);
66  glEnable(GL_DEPTH_TEST);
67  glEnable(GL_LIGHTING);
68  glEnable(GL_LIGHT0);
69  glClearColor(1.0, 1.0, 1.0, 1.0);
70  glutMainLoop();
71  return 0;
72}