Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4349 Serge 1
/*
2
 * Demo of off-screen Mesa rendering
3
 *
4
 * See Mesa/include/GL/osmesa.h for documentation of the OSMesa functions.
5
 *
6
 * If you want to render BIG images you'll probably have to increase
7
 * MAX_WIDTH and MAX_Height in src/config.h.
8
 *
9
 * This program is in the public domain.
10
 *
11
 * Brian Paul
12
 *
13
 * PPM output provided by Joerg Schmalzl.
14
 * ASCII PPM output added by Brian Paul.
15
 *
16
 * Usage: osdemo [filename]
17
 */
18
 
19
 
20
#include 
21
#include 
22
#include 
23
#include 
24
#include 
25
#define GL_GLEXT_PROTOTYPES
26
#include "GL/osmesa.h"
27
#include 
28
#include "GL/glu.h"
29
#include "shaderutil.h"
30
#include 
31
 
32
int _CRT_MT=0;
33
 
34
static int Width = 500;
35
static int Height = 400;
36
 
37
int check_events();
38
 
39
GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0;
40
GLfloat angle = 0.0;
41
 
42
GLboolean animate = GL_TRUE;	/* Animation */
43
GLfloat eyesep = 5.0;		/* Eye separation. */
44
GLfloat fix_point = 40.0;	/* Fixation point distance.  */
45
GLfloat left, right, asp;	/* Stereo frustum params.  */
46
 
47
void Init( void );
48
void Reshape( int width, int height );
49
void Draw( void );
50
void Idle();
51
void Key(unsigned char key, int x, int y);
52
 
53
 
54
inline void Blit(void *bitmap, int dst_x, int dst_y,
55
                        int src_x, int src_y, int w, int h,
56
                        int src_w, int src_h, int stride)
57
{
58
    volatile struct blit_call bc;
59
 
60
    bc.dstx = dst_x;
61
    bc.dsty = dst_y;
62
    bc.w    = w;
63
    bc.h    = h;
64
    bc.srcx = src_x;
65
    bc.srcy = src_y;
66
    bc.srcw = src_w;
67
    bc.srch = src_h;
68
    bc.stride = stride;
69
    bc.bitmap = bitmap;
70
 
71
    __asm__ __volatile__(
72
    "int $0x40"
73
    ::"a"(73),"b"(0),"c"(&bc.dstx));
74
 
75
};
76
 
77
 
78
static inline uint32_t wait_os_event(int time)
79
{
80
    uint32_t val;
81
    __asm__ __volatile__(
82
    "int $0x40"
83
    :"=a"(val)
84
    :"a"(23),"b"(time));
85
    return val;
86
};
87
 
88
 
89
int main(int argc, char *argv[])
90
{
91
    OSMesaContext ctx;
92
    void *buffer;
93
    char *filename = NULL;
94
    int ev;
95
    int repeat=1;
96
 
97
   /* Create an RGBA-mode context */
98
   /* specify Z, stencil, accum sizes */
99
 
100
    ctx = OSMesaCreateContextExt( OSMESA_RGBA, 16, 0, 0, NULL );
101
    if (!ctx) {
102
        printf("OSMesaCreateContext failed!\n");
103
        return 0;
104
    }
105
 
106
   /* Allocate the image buffer */
107
    buffer = malloc( Width * Height * 4 * sizeof(GLubyte) );
108
    if (!buffer) {
109
        printf("Alloc image buffer failed!\n");
110
        return 0;
111
    }
112
 
113
 //  __asm__ __volatile__("int3");
114
 
115
   /* Bind the buffer to the context and make it current */
116
   if (!OSMesaMakeCurrent( ctx, buffer, GL_UNSIGNED_BYTE, Width, Height )) {
117
      printf("OSMesaMakeCurrent failed!\n");
118
      return 0;
119
   }
120
 
121
   {
122
      int z, s, a;
123
      glGetIntegerv(GL_DEPTH_BITS, &z);
124
      glGetIntegerv(GL_STENCIL_BITS, &s);
125
      glGetIntegerv(GL_ACCUM_RED_BITS, &a);
126
      printf("Depth=%d Stencil=%d Accum=%d\n", z, s, a);
127
   }
128
 
129
    Reshape(Width, Height);
130
    Init();
131
    Draw();
132
 
133
    printf("all done\n");
134
 
135
    DrawWindow(10, 10, Width+9, Height+26, "OpenGL Engine Demo", 0x000000, 0x74);
136
    Blit(buffer, 5, 22, 0, 0, Width, Height, Width,Height,Width*4);
137
 
138
    while(repeat)
139
    {
140
        oskey_t   key;
141
 
142
        ev = wait_os_event(1);
143
        switch(ev)
144
        {
145
            case 1:
146
                DrawWindow(10, 10, Width+9, Width+26, NULL, 0x000000,0x74);
147
                Blit(buffer, 5, 22, 0, 0, Width, Height, Width,Height,Width*4);
148
                continue;
149
 
150
            case 2:
151
                key = get_key();
152
                Key(key.code, 0, 0);
153
                Draw();
154
                Blit(buffer, 5, 22, 0, 0, Width, Height, Width,Height,Width*4);
155
                continue;
156
 
157
            case 3:
158
                if(get_os_button()==1)
159
                    repeat=0;
160
                    continue;
161
        };
162
        Idle();
163
        Draw();
164
        Blit(buffer, 5, 22, 0, 0, Width, Height, Width,Height,Width*4);
165
    };
166
 
167
   /* free the image buffer */
168
   free( buffer );
169
 
170
   /* destroy the context */
171
   OSMesaDestroyContext( ctx );
172
 
173
   return 0;
174
}
175
 
176
int atexit(void (*func)(void))
177
{
178
    return 0;
179
};
180