opengl-intro: osvetlitev.c

File osvetlitev.c, 1.2 KB (added by msitar, 15 years ago)

Izris osenčene kocke

Line 
1#include <GL/glut.h>
2
3float kvadrat() 
4{
5  glPushMatrix();
6  glTranslatef(0.0, 0.0, 1.0);
7  glNormal3f(0.0, 0.0, 1.0);
8  glRectf(-1.0, -1.0, 1.0, 1.0);
9  glPopMatrix();
10}
11
12void display()
13{
14  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
15  glColor3f(0.7, 0.6, 0.2);
16  glPushMatrix();
17  glScalef(0.5, 0.5, 0.5);
18  kvadrat();
19  glRotatef(90.0, 0.0, 1.0, 0.0);
20  kvadrat();
21  glRotatef(90.0, 0.0, 1.0, 0.0);
22  kvadrat();
23  glRotatef(90.0, 0.0, 1.0, 0.0);
24  kvadrat();
25  glRotatef(90.0, 1.0, 0.0, 0.0);
26  kvadrat();
27  glRotatef(180.0, 1.0, 0.0, 0.0);
28  kvadrat();
29  glPopMatrix();
30  glFlush();
31}
32
33void reshape (int w, int h)
34{
35  double l;
36  l = 1.0;
37  glViewport (0, 0, w, h);
38  glMatrixMode (GL_PROJECTION);
39  glLoadIdentity();
40  glOrtho(-l, l, -l, l, -l, l);
41  glMatrixMode(GL_MODELVIEW);
42  glLoadIdentity();
43  glRotatef(30.0, 1.0, 0.0, 0.0);
44  glRotatef(30.0, 0.0, 1.0, 0.0);
45}
46
47
48int main(int argc, char *argv[])
49{
50  glutInit(&argc, argv);
51  glutInitDisplayMode(GLUT_SINGLE|GLUT_DEPTH);
52  glutCreateWindow("Osencena kocka");
53  glutDisplayFunc(display);
54  glutReshapeFunc(reshape);
55  glClearColor(1.0, 1.0, 1.0, 1.0);
56  glEnable(GL_LIGHTING);
57  glEnable(GL_LIGHT0);
58  glEnable(GL_DEPTH_TEST);
59  glEnable(GL_COLOR_MATERIAL);
60  glutMainLoop();
61  return 0;
62}