~ubuntu-branches/ubuntu/quantal/mesa-glw/quantal

« back to all changes in this revision

Viewing changes to progs/windml/uglflip.c

  • Committer: Bazaar Package Importer
  • Author(s): Morten Kjeldgaard
  • Date: 2008-05-06 16:19:15 UTC
  • Revision ID: james.westby@ubuntu.com-20080506161915-uynz7nftmfixu6bq
Tags: upstream-7.0.3
ImportĀ upstreamĀ versionĀ 7.0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/* uglflip.c - WindML/Mesa example program */
 
3
 
 
4
/* Copyright (C) 2001 by Wind River Systems, Inc */
 
5
 
 
6
/*
 
7
 * Mesa 3-D graphics library
 
8
 * Version:  3.5
 
9
 *
 
10
 * The MIT License
 
11
 * Permission is hereby granted, free of charge, to any person obtaining a
 
12
 * copy of this software and associated documentation files (the "Software"),
 
13
 * to deal in the Software without restriction, including without limitation
 
14
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 
15
 * and/or sell copies of the Software, and to permit persons to whom the
 
16
 * Software is furnished to do so, subject to the following conditions:
 
17
 *
 
18
 * The above copyright notice and this permission notice shall be included
 
19
 * in all copies or substantial portions of the Software.
 
20
 *
 
21
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 
22
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
23
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 
24
 * THE AUTHORS OR COPYRIGHT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
25
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 
26
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 
27
 * DEALINGS IN THE SOFTWARE.
 
28
 */
 
29
 
 
30
/*
 
31
 * Authors:
 
32
 * Stephane Raimbault <stephane.raimbault@windriver.com> 
 
33
 */
 
34
 
 
35
/*
 
36
DESCRIPTION
 
37
Draw a triangle and flip the screen
 
38
*/
 
39
 
 
40
#include <stdio.h>
 
41
#include <math.h>
 
42
 
 
43
#include <ugl/ugl.h>
 
44
#include <ugl/uglucode.h>
 
45
#include <ugl/uglevent.h>
 
46
#include <ugl/uglinput.h>
 
47
 
 
48
#include <GL/uglmesa.h>
 
49
#include <GL/glu.h>
 
50
 
 
51
#define BLACK     (0)
 
52
#define RED       (1)
 
53
#define GREEN     (2)
 
54
#define BLUE      (3)
 
55
#define CI_OFFSET  4
 
56
 
 
57
UGL_LOCAL GLuint rgb;
 
58
UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId;
 
59
UGL_LOCAL UGL_EVENT_Q_ID qId;
 
60
UGL_LOCAL volatile UGL_BOOL stopWex;
 
61
 
 
62
UGL_LOCAL UGL_MESA_CONTEXT umc;
 
63
 
 
64
UGL_LOCAL void initGL (void)
 
65
    {
 
66
    uglMesaSetColor(BLACK, 0.0, 0.0, 0.0);
 
67
    uglMesaSetColor(RED, 1.0, 0.3, 0.3);
 
68
    uglMesaSetColor(GREEN, 0.3, 1.0, 0.3);
 
69
    uglMesaSetColor(BLUE, 0.3, 0.3, 1.0);
 
70
    
 
71
    glClearColor(0.0, 0.0, 0.0, 0.0);
 
72
    glClearIndex(BLACK);
 
73
 
 
74
    glMatrixMode(GL_PROJECTION);
 
75
    glLoadIdentity();
 
76
    glMatrixMode(GL_MODELVIEW);
 
77
    }
 
78
 
 
79
UGL_LOCAL void drawGL (void)
 
80
    {
 
81
    glClear(GL_COLOR_BUFFER_BIT);
 
82
    
 
83
    glBegin(GL_TRIANGLES);
 
84
        (rgb) ? glColor3f(1.0, 0.3, 0.3) : glIndexi(RED);
 
85
        glVertex2f(0.75, -0.50);
 
86
        (rgb) ? glColor3f(0.3, 1.0, 0.3) : glIndexi(GREEN);
 
87
        glVertex2f(0.0, 0.75);
 
88
        (rgb) ? glColor3f(0.3, 0.3, 1.0) : glIndexi(BLUE);
 
89
        glVertex2f(-0.75, -0.50);
 
90
    glEnd();
 
91
    
 
92
    glBegin(GL_LINES);
 
93
        (rgb) ? glColor3f(1.0, 0.3, 0.3) : glIndexi(RED);
 
94
        glVertex2f(-1.0, 1.0);
 
95
        (rgb) ? glColor3f(0.3, 0.3, 1.0) : glIndexi(BLUE);
 
96
        glVertex2f(1.0, -1.0);
 
97
    glEnd();
 
98
 
 
99
    glFlush();
 
100
 
 
101
    uglMesaSwapBuffers();
 
102
    }    
 
103
 
 
104
UGL_LOCAL void echoUse(void)
 
105
    {
 
106
    printf("tFlip keys:\n");
 
107
    printf("             d  Toggle dithering\n");
 
108
    printf("            up  Reduce the window\n");
 
109
    printf("          down  Enlarge the window\n");
 
110
    printf("       page up  Y==0 is the bottom line and increases upward\n");
 
111
    printf("     page down  Y==0 is the bottom line and increases downward\n");
 
112
    printf("           ESC  Exit\n");
 
113
    }
 
114
 
 
115
UGL_LOCAL void readKey (UGL_WCHAR key)
 
116
    {
 
117
    
 
118
    switch(key)
 
119
        {
 
120
        case UGL_UNI_UP_ARROW:
 
121
            uglMesaResizeWindow(8, 8);
 
122
            break;
 
123
        case UGL_UNI_DOWN_ARROW:
 
124
            glDrawBuffer(GL_FRONT_LEFT);
 
125
            glClear(GL_COLOR_BUFFER_BIT);
 
126
            glDrawBuffer(GL_BACK_LEFT);
 
127
            uglMesaResizeWindow(-8, -8);
 
128
            break;
 
129
        case UGL_UNI_PAGE_UP:
 
130
            uglMesaPixelStore(UGL_MESA_Y_UP, GL_TRUE);
 
131
            break;
 
132
        case UGL_UNI_PAGE_DOWN:
 
133
            uglMesaPixelStore(UGL_MESA_Y_UP, GL_FALSE);
 
134
            break;
 
135
        case UGL_UNI_ESCAPE:
 
136
            stopWex = UGL_TRUE;
 
137
            break;
 
138
        case 'd':
 
139
            if (glIsEnabled(GL_DITHER))
 
140
                glDisable(GL_DITHER);
 
141
            else
 
142
                glEnable(GL_DITHER);
 
143
            break;
 
144
        }
 
145
    }
 
146
 
 
147
UGL_LOCAL void loopEvent(void)
 
148
    {
 
149
    UGL_EVENT event;
 
150
    UGL_INPUT_EVENT * pInputEvent;
 
151
 
 
152
    drawGL();
 
153
 
 
154
    UGL_FOREVER
 
155
        {
 
156
        if (uglEventGet (qId, &event, sizeof (event), UGL_WAIT_FOREVER)
 
157
            != UGL_STATUS_Q_EMPTY)
 
158
            {
 
159
            pInputEvent = (UGL_INPUT_EVENT *)&event;
 
160
            
 
161
            if (pInputEvent->header.type == UGL_EVENT_TYPE_KEYBOARD &&
 
162
                pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN)
 
163
                {
 
164
                readKey(pInputEvent->type.keyboard.key);
 
165
                drawGL();
 
166
                }
 
167
            }
 
168
 
 
169
        if (stopWex)
 
170
            break;
 
171
        }
 
172
    }
 
173
 
 
174
void windMLFlip (UGL_BOOL windMLMode);
 
175
 
 
176
void uglflip (void)
 
177
    {
 
178
    taskSpawn ("tFlip", 210, VX_FP_TASK, 100000, (FUNCPTR)windMLFlip,
 
179
               UGL_FALSE,1,2,3,4,5,6,7,8,9);
 
180
    }
 
181
 
 
182
void windMLFlip (UGL_BOOL windMLMode)
 
183
    {
 
184
 
 
185
    UGL_INPUT_DEVICE_ID keyboardDevId;
 
186
 
 
187
    uglInitialize();
 
188
 
 
189
    uglDriverFind (UGL_KEYBOARD_TYPE, 0, (UGL_UINT32 *)&keyboardDevId);
 
190
 
 
191
    uglDriverFind (UGL_EVENT_SERVICE_TYPE, 0, (UGL_UINT32 *)&eventServiceId);
 
192
 
 
193
    qId = uglEventQCreate (eventServiceId, 100);
 
194
 
 
195
    if (windMLMode)
 
196
       umc = uglMesaCreateNewContext(UGL_MESA_SINGLE
 
197
                                     | UGL_MESA_WINDML_EXCLUSIVE, NULL);
 
198
    else
 
199
       umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE_SOFTWARE, NULL);
 
200
 
 
201
    if (umc == NULL)
 
202
        {
 
203
        uglDeinitialize();
 
204
        return;
 
205
        }
 
206
 
 
207
    uglMesaMakeCurrentContext(umc, 0, 0, UGL_MESA_FULLSCREEN_WIDTH,
 
208
                              UGL_MESA_FULLSCREEN_HEIGHT);
 
209
    
 
210
    uglMesaGetIntegerv(UGL_MESA_RGB, &rgb);
 
211
    
 
212
    initGL();
 
213
 
 
214
    echoUse();
 
215
    stopWex = UGL_FALSE;            
 
216
    loopEvent();
 
217
    
 
218
    uglEventQDestroy (eventServiceId, qId);
 
219
 
 
220
    uglMesaDestroyContext();
 
221
    uglDeinitialize();
 
222
 
 
223
    return;
 
224
    }