/docs/MyDocs

To get this branch, use:
bzr branch http://darksoft.org/webbzr/docs/MyDocs

« back to all changes in this revision

Viewing changes to Development/libraries/opengl/example/nurb.c

  • Committer: Suren A. Chilingaryan
  • Date: 2009-04-09 03:21:08 UTC
  • Revision ID: csa@dside.dyndns.org-20090409032108-w4edamdh4adrgdu3
import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <unistd.h>
 
3
#include <time.h>
 
4
 
 
5
 
 
6
#include <GL/glx.h>
 
7
#include <GL/gl.h>
 
8
#include <GL/glu.h>
 
9
#include <GL/glut.h>
 
10
 
 
11
#include "config.h"
 
12
 
 
13
#include "functions.h"
 
14
#include "xfunctions.h"
 
15
#include "objects.h"
 
16
 
 
17
 
 
18
#define PRECISION 8
 
19
 
 
20
GLfloat ctrlpoints[4][4][3] = {
 
21
    {{-1.5, -1.5, 4.0}, {-0.5, -1.5, 2.0}, 
 
22
        {0.5, -1.5, -1.0}, {1.5, -1.5, 2.0}}, 
 
23
    {{-1.5, -0.5, 1.0}, {-0.5, -0.5, 3.0}, 
 
24
        {0.5, -0.5, 0.0}, {1.5, -0.5, -1.0}}, 
 
25
    {{-1.5, 0.5, 4.0}, {-0.5, 0.5, 0.0}, 
 
26
        {0.5, 0.5, 3.0}, {1.5, 0.5, 4.0}}, 
 
27
    {{-1.5, 1.5, -2.0}, {-0.5, 1.5, -2.0}, 
 
28
        {0.5, 1.5, 0.0}, {1.5, 1.5, -1.0}}
 
29
};
 
30
 
 
31
void initlights(void)
 
32
{
 
33
    GLfloat ambient[] = { 0.2, 0.2, 0.2, 1.0 };
 
34
    GLfloat position[] = { 0.0, 0.0, 2.0, 1.0 };
 
35
    GLfloat mat_diffuse[] = { 0.6, 0.6, 0.6, 1.0 };
 
36
    GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
 
37
    GLfloat mat_shininess[] = { 50.0 };
 
38
 
 
39
    glEnable(GL_LIGHTING);
 
40
    glEnable(GL_LIGHT0);
 
41
 
 
42
    glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
 
43
    glLightfv(GL_LIGHT0, GL_POSITION, position);
 
44
    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse);
 
45
    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
 
46
    glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS, mat_shininess);
 
47
}
 
48
 
 
49
void myinit(void)
 
50
{
 
51
 
 
52
    glClearColor (0.0, 0.0, 0.0, 1.0);
 
53
    glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4,
 
54
       0, 1, 12, 4, &ctrlpoints[0][0][0]);
 
55
    glEnable(GL_MAP2_VERTEX_3);
 
56
    glEnable(GL_DEPTH_TEST);
 
57
    glEnable(GL_AUTO_NORMAL);
 
58
    glMapGrid2f(PRECISION, 0.0, 1.0, PRECISION, 0.0, 1.0);
 
59
    initlights();
 
60
}
 
61
 
 
62
void Draw(long pos)
 
63
{
 
64
   int i, j;
 
65
 
 
66
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
67
    glColor3f(1.0, 1.0, 1.0);
 
68
    glPushMatrix ();
 
69
    glRotatef(85.0+pos, 1.0, 1.0, 1.0);
 
70
 
 
71
    glEvalMesh2(GL_FILL, 0, PRECISION, 0, PRECISION);
 
72
/*
 
73
    for (j = 0; j <= 8; j++) {
 
74
        glBegin(GL_LINE_STRIP);
 
75
            for (i = 0; i <= 30; i++)
 
76
                glEvalCoord2f((GLfloat)i/30.0, (GLfloat)j/8.0);
 
77
        glEnd();
 
78
        glBegin(GL_LINE_STRIP);
 
79
            for (i = 0; i <= 30; i++)
 
80
                glEvalCoord2f((GLfloat)j/8.0, (GLfloat)i/30.0);
 
81
        glEnd();
 
82
    }
 
83
*/
 
84
    glPopMatrix ();
 
85
    glFlush();    
 
86
}
 
87
 
 
88
 
 
89
void myReshape(GLsizei w, GLsizei h)
 
90
{
 
91
    glViewport(0, 0, w, h);
 
92
    glMatrixMode(GL_PROJECTION);
 
93
    glLoadIdentity();
 
94
    if (w <= h)
 
95
        glOrtho(-5.0, 5.0, -5.0*(GLfloat)h/(GLfloat)w, 
 
96
            5.0*(GLfloat)h/(GLfloat)w, -5.0, 5.0);
 
97
    else
 
98
        glOrtho(-5.0*(GLfloat)w/(GLfloat)h, 
 
99
            5.0*(GLfloat)w/(GLfloat)h, -5.0, 5.0, -5.0, 5.0);
 
100
    glMatrixMode(GL_MODELVIEW);
 
101
    glLoadIdentity();
 
102
}
 
103
 
 
104
 
 
105
 
 
106
 
 
107
int main(int argc, char *argv[]) {
 
108
    Display *dpy;
 
109
    Window win;
 
110
    GLXContext cx;
 
111
    
 
112
    int i,j;
 
113
 
 
114
        // Initialization
 
115
    OpenGLWindow(&dpy, &cx, &win, 800, 600);
 
116
    
 
117
    myinit();
 
118
 
 
119
 
 
120
 
 
121
    myReshape(800,600);
 
122
    Draw(0);
 
123
    glXSwapBuffers(dpy,win);
 
124
 
 
125
    for (i=0;i<360;i++) {
 
126
        Draw(i);
 
127
        myReshape(800,600);
 
128
        glXSwapBuffers(dpy,win);
 
129
        delay(100);
 
130
    }
 
131
 
 
132
    sleep(30);
 
133
}