/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/bz.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
GLfloat ctrlpoints[4][3] = {
 
19
    { -4.0, -4.0, 0.0}, { -2.0, 4.0, 0.0}, 
 
20
    {2.0, -4.0, 0.0}, {4.0, 4.0, 0.0}};
 
21
 
 
22
void myinit(void)
 
23
{
 
24
    glClearColor(0.0, 0.0, 0.0, 1.0);
 
25
    glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4,&ctrlpoints[0][0]);
 
26
    glEnable(GL_MAP1_VERTEX_3);
 
27
    glShadeModel(GL_FLAT);
 
28
}
 
29
 
 
30
void Draw(long pos)
 
31
{
 
32
    int i;
 
33
 
 
34
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
35
    glColor3f(1.0, 1.0, 1.0);
 
36
    glBegin(GL_LINE_STRIP);
 
37
        for (i = 0; i <= 30; i++) 
 
38
            glEvalCoord1f((GLfloat) i/30.0);
 
39
    glEnd();
 
40
   /* The following code displays the control points as dots. */
 
41
    glPointSize(5.0);
 
42
    glColor3f(1.0, 1.0, 0.0);
 
43
    glBegin(GL_POINTS);
 
44
        for (i = 0; i < 4; i++) 
 
45
            glVertex3fv(&ctrlpoints[i][0]);
 
46
    glEnd();
 
47
    glFlush();
 
48
}
 
49
 
 
50
 
 
51
void myReshape(GLsizei w, GLsizei h)
 
52
{
 
53
    glViewport(0, 0, w, h);
 
54
    glMatrixMode(GL_PROJECTION);
 
55
    glLoadIdentity();
 
56
    if (w <= h)
 
57
        glOrtho(-5.0, 5.0, -5.0*(GLfloat)h/(GLfloat)w, 
 
58
            5.0*(GLfloat)h/(GLfloat)w, -5.0, 5.0);
 
59
    else
 
60
        glOrtho(-5.0*(GLfloat)w/(GLfloat)h, 
 
61
            5.0*(GLfloat)w/(GLfloat)h, -5.0, 5.0, -5.0, 5.0);
 
62
    glMatrixMode(GL_MODELVIEW);
 
63
    glLoadIdentity();
 
64
}
 
65
 
 
66
 
 
67
 
 
68
 
 
69
int main(int argc, char *argv[]) {
 
70
    Display *dpy;
 
71
    Window win;
 
72
    GLXContext cx;
 
73
    
 
74
    int i,j;
 
75
 
 
76
        // Initialization
 
77
    OpenGLWindow(&dpy, &cx, &win, 800, 600);
 
78
    
 
79
    myinit();
 
80
 
 
81
 
 
82
 
 
83
    myReshape(800,600);
 
84
    Draw(0);
 
85
    glXSwapBuffers(dpy,win);
 
86
 
 
87
    for (i=0;i<360;i++) {
 
88
        Draw(i);
 
89
        myReshape(800,600);
 
90
        glXSwapBuffers(dpy,win);
 
91
        delay(100);
 
92
    }
 
93
 
 
94
    sleep(30);
 
95
}