2 (c) Copyright 2001 convergence integrated media GmbH.
5 Written by Denis Oliver Kropp <dok@convergence.de> and
6 Andreas Hundt <andi@convergence.de>.
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version.
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the
20 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA.
33 #include <directfbgl.h>
37 IDirectFBWindow
*window
;
38 IDirectFBSurface
*surface
;
44 unsigned long last_time
;
49 static const GLfloat blue
[4] = {0.2, 0.2, 1.0, 1.0};
51 static IDirectFB
*dfb
;
52 static IDirectFBDisplayLayer
*layer
;
53 static IDirectFBFont
*font
;
54 static IDirectFBEventBuffer
*events
= NULL
;
56 /* macro for a safe call to DirectFB functions */
57 #define DFBCHECK(x...) \
60 if (ret != DFB_OK) { \
61 fprintf( stderr, "%s <%d>:\n\t", __FILE__, __LINE__ ); \
62 DirectFBErrorFatal( #x, ret ); \
67 static inline unsigned long get_millis()
71 gettimeofday (&tv
, NULL
);
72 return (tv
.tv_sec
* 1000 + tv
.tv_usec
/ 1000);
77 setup( Context
*context
)
79 GLfloat pos
[4] = {5.0, 5.0, 10.0, 0.0};
81 context
->surface
->GetSize( context
->surface
,
82 &context
->width
, &context
->height
);
84 context
->gl
->Lock( context
->gl
);
86 glLightfv(GL_LIGHT0
, GL_POSITION
, pos
);
87 glEnable(GL_CULL_FACE
);
88 glEnable(GL_LIGHTING
);
90 glEnable(GL_DEPTH_TEST
);
92 glViewport(0, 0, context
->width
, context
->height
);
94 glMatrixMode(GL_PROJECTION
);
96 gluPerspective(70.0, context
->width
/ (float) context
->height
, 1.0, 80.0);
98 glMatrixMode(GL_MODELVIEW
);
100 glTranslatef(0.0, 0.0, -40.0);
102 context
->gl
->Unlock( context
->gl
);
106 update( Context
*context
)
109 IDirectFBSurface
*surface
= context
->surface
;
110 static __u8 r
= 0, g
= 0, b
= 0;
113 context
->gl
->Lock( context
->gl
);
115 glClearColor( r
++/255.0, g
++/255.0, b
++/255.0, 1.0 );
116 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
118 context
->gl
->Unlock( context
->gl
);
123 snprintf(buf
, sizeof(buf
), "%.1f FPS\n", context
->fps
);
125 surface
->SetColor( surface
, 0xff, 0x00, 0x00, 0xff );
126 surface
->DrawString( surface
, buf
, -1,
127 context
->width
- 5, 5, DSTF_TOPRIGHT
);
130 surface
->Flip( surface
, NULL
, 0 );
135 if (t
- context
->last_time
>= 2000) {
136 float seconds
= (t
- context
->last_time
) / 1000.0f
;
138 context
->fps
= context
->frames
/ seconds
;
140 context
->last_time
= t
;
146 main( int argc
, char *argv
[] )
152 Context contexts
[num
];
154 DFBCHECK(DirectFBInit( &argc
, &argv
));
156 /* create the super interface */
157 DFBCHECK(DirectFBCreate( &dfb
));
159 DFBCHECK(dfb
->GetDisplayLayer( dfb
, DLID_PRIMARY
, &layer
));
161 /* create the default font */
162 DFBCHECK(dfb
->CreateFont( dfb
, NULL
, NULL
, &font
));
164 for (i
=0; i
<num
; i
++) {
165 IDirectFBWindow
*window
;
166 IDirectFBSurface
*surface
;
168 DFBWindowDescription desc
;
170 desc
.flags
= DWDESC_POSX
| DWDESC_POSY
|
171 DWDESC_WIDTH
| DWDESC_HEIGHT
;
172 desc
.posx
= (i
%3) * 200 + 10;
173 desc
.posy
= (i
/3) * 200 + 10;
177 DFBCHECK(layer
->CreateWindow( layer
, &desc
, &window
));
178 DFBCHECK(window
->GetSurface( window
, &surface
));
179 DFBCHECK(surface
->GetGL( surface
, &gl
));
181 contexts
[i
].window
= window
;
182 contexts
[i
].surface
= surface
;
185 contexts
[i
].last_time
= get_millis();
186 contexts
[i
].frames
= 0;
189 setup( &contexts
[i
] );
192 DFBCHECK(window
->AttachEventBuffer( window
, events
));
194 DFBCHECK(window
->CreateEventBuffer( window
, &events
));
196 DFBCHECK(surface
->SetFont( surface
, font
));
198 window
->SetOpacity( window
, 0xff );
204 for (i
=0; i
<num
; i
++)
205 update( &contexts
[i
] );
207 while (events
->GetEvent( events
, DFB_EVENT(&evt
) ) == DFB_OK
) {
210 switch (evt
.key_symbol
) {
226 events
->Release( events
);
228 for (i
=0; i
<num
; i
++) {
229 contexts
[i
].gl
->Release( contexts
[i
].gl
);
230 contexts
[i
].surface
->Release( contexts
[i
].surface
);
231 contexts
[i
].window
->Release( contexts
[i
].window
);
234 font
->Release( font
);
235 layer
->Release( layer
);