15 #include <allegro/internal/aintern.h> 25 } allegro_gl_mouse = { 0, TRUE, 0, 0, 0, 0};
60 DIALOG_PLAYER *player;
62 AGL_LOG(2,
"allegro_gl_do_dialog\n");
69 player = init_dialog (dialog, focus_obj);
74 while (update_dialog (player)) {}
80 return shutdown_dialog (player);
114 DIALOG_PLAYER *player;
117 AGL_LOG(2,
"allegro_gl_popup_dialog\n");
124 glGetIntegerv(GL_READ_BUFFER, &read_buffer);
125 glReadBuffer (GL_FRONT);
126 glDisable(GL_DEPTH_TEST);
127 backdrop = malloc (SCREEN_W * SCREEN_H * 3 * 4);
128 glReadPixels (0, 0, SCREEN_W, SCREEN_H, GL_RGB, GL_UNSIGNED_BYTE, backdrop);
129 glReadBuffer(read_buffer);
131 player = init_dialog (dialog, focus_obj);
134 while (update_dialog (player)) {
137 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
138 glRasterPos2f (0., SCREEN_H-.5);
139 glDrawPixels (SCREEN_W, SCREEN_H, GL_RGB, GL_UNSIGNED_BYTE, backdrop);
140 broadcast_dialog_message (MSG_DRAW, 0);
149 glRasterPos2f (0., SCREEN_H-.5);
150 glDrawPixels (SCREEN_W, SCREEN_H, GL_RGB, GL_UNSIGNED_BYTE, backdrop);
151 glEnable(GL_DEPTH_TEST);
158 return shutdown_dialog (player);
164 static void (*__algl_user_draw_mouse)(void) = NULL;
189 AGL_LOG(2,
"allegro_gl_draw_mouse\n");
192 if (!_mouse_on || allegro_gl_mouse.hidden)
return;
194 if (__algl_user_draw_mouse) {
196 __algl_user_draw_mouse();
204 int depth_enabled = glIsEnabled (GL_DEPTH_TEST);
205 int cull_enabled = glIsEnabled (GL_CULL_FACE);
206 if (depth_enabled) glDisable (GL_DEPTH_TEST);
207 if (cull_enabled) glDisable (GL_CULL_FACE);
209 glBegin (GL_TRIANGLES);
211 #define draw(dx,dy) \ 212 glVertex2f (x + dx, y + dy); \ 213 glVertex2f (x + dx, y + dy + 10); \ 214 glVertex2f (x + dx + 7, y + dy + 7); \ 215 glVertex2f (x + dx + 1.5, y + dy + 6); \ 216 glVertex2f (x + dx + 5.5, y + dy + 14); \ 217 glVertex2f (x + dx + 7.5, y + dy + 14); \ 218 glVertex2f (x + dx + 3.5, y + dy + 6); \ 219 glVertex2f (x + dx + 1.5, y + dy + 6); \ 220 glVertex2f (x + dx + 7.5, y + dy + 14); 235 if (depth_enabled) glEnable (GL_DEPTH_TEST);
236 if (cull_enabled) glEnable (GL_CULL_FACE);
239 int x = mouse_x - allegro_gl_mouse.xfocus;
240 int y = mouse_y - allegro_gl_mouse.yfocus;
242 glPushAttrib(GL_COLOR_BUFFER_BIT);
243 glAlphaFunc(GL_GREATER, 0.5);
244 glEnable(GL_TEXTURE_2D);
245 glEnable(GL_ALPHA_TEST);
247 glBindTexture(GL_TEXTURE_2D, allegro_gl_mouse.texture);
248 glColor4f(1., 1., 1., 1.);
249 glTranslatef(-0.375, -0.375, 0);
251 glTexCoord2f(0., 1.);
253 glTexCoord2f(0., 0.);
254 glVertex2f(x, y + allegro_gl_mouse.height);
255 glTexCoord2f(1., 0.);
256 glVertex2f(x + allegro_gl_mouse.width, y + allegro_gl_mouse.height);
257 glTexCoord2f(1., 1.);
258 glVertex2f(x + allegro_gl_mouse.width, y);
260 glTranslatef(0.375, 0.375, 0);
262 glBindTexture(GL_TEXTURE_2D, 0);
263 glDisable(GL_TEXTURE_2D);
286 AGL_LOG(2,
"allegro_gl_set_mouse_drawer\n");
288 __algl_user_draw_mouse = user_draw_mouse;
295 static DIALOG alert_dialog[] =
298 { _gui_shadow_box_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
299 { _gui_ctext_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
300 { _gui_ctext_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
301 { _gui_ctext_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
302 { _gui_button_proc, 0, 0, 0, 0, 0, 0, 0, D_EXIT, 0, 0, NULL, NULL, NULL },
303 { _gui_button_proc, 0, 0, 0, 0, 0, 0, 0, D_EXIT, 0, 0, NULL, NULL, NULL },
304 { _gui_button_proc, 0, 0, 0, 0, 0, 0, 0, D_EXIT, 0, 0, NULL, NULL, NULL },
305 { d_yield_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
306 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
329 int algl_alert3(AL_CONST
char *s1, AL_CONST
char *s2, AL_CONST
char *s3, AL_CONST
char *b1, AL_CONST
char *b2, AL_CONST
char *b3,
int c1,
int c2,
int c3)
333 int len1, len2, len3;
339 AGL_LOG(2,
"allegro_gl_alert3\n");
341 #define SORT_OUT_BUTTON(x) { \ 343 alert_dialog[A_B##x].flags &= ~D_HIDDEN; \ 344 alert_dialog[A_B##x].key = c##x; \ 345 alert_dialog[A_B##x].dp = (char *)b##x; \ 346 len##x = gui_strlen(b##x); \ 347 b[buttons++] = A_B##x; \ 350 alert_dialog[A_B##x].flags |= D_HIDDEN; \ 355 usetc(tmp+usetc(tmp,
' '), 0);
357 avg_w = text_length(font, tmp);
358 avg_h = text_height(font);
360 alert_dialog[A_S1].dp = alert_dialog[A_S2].dp = alert_dialog[A_S3].dp =
361 alert_dialog[A_B1].dp = alert_dialog[A_B2].dp = empty_string;
364 alert_dialog[A_S1].dp = (
char *)s1;
365 maxlen = text_length(font, s1);
369 alert_dialog[A_S2].dp = (
char *)s2;
370 len1 = text_length(font, s2);
376 alert_dialog[A_S3].dp = (
char *)s3;
377 len1 = text_length(font, s3);
386 len1 = MAX(len1, MAX(len2, len3)) + avg_w*3;
387 if (len1*buttons > maxlen)
388 maxlen = len1*buttons;
391 alert_dialog[0].w = maxlen;
392 alert_dialog[A_S1].x = alert_dialog[A_S2].x = alert_dialog[A_S3].x =
393 alert_dialog[0].x + maxlen/2;
395 alert_dialog[A_B1].w = alert_dialog[A_B2].w = alert_dialog[A_B3].w = len1;
397 alert_dialog[A_B1].x = alert_dialog[A_B2].x = alert_dialog[A_B3].x =
398 alert_dialog[0].x + maxlen/2 - len1/2;
401 alert_dialog[b[0]].x = alert_dialog[0].x + maxlen/2 - len1*3/2 - avg_w;
402 alert_dialog[b[2]].x = alert_dialog[0].x + maxlen/2 + len1/2 + avg_w;
404 else if (buttons == 2) {
405 alert_dialog[b[0]].x = alert_dialog[0].x + maxlen/2 - len1 - avg_w;
406 alert_dialog[b[1]].x = alert_dialog[0].x + maxlen/2 + avg_w;
409 alert_dialog[0].h = avg_h*8;
410 alert_dialog[A_S1].y = alert_dialog[0].y + avg_h;
411 alert_dialog[A_S2].y = alert_dialog[0].y + avg_h*2;
412 alert_dialog[A_S3].y = alert_dialog[0].y + avg_h*3;
413 alert_dialog[A_S1].h = alert_dialog[A_S2].h = alert_dialog[A_S3].h = avg_h;
414 alert_dialog[A_B1].y = alert_dialog[A_B2].y = alert_dialog[A_B3].y = alert_dialog[0].y + avg_h*5;
415 alert_dialog[A_B1].h = alert_dialog[A_B2].h = alert_dialog[A_B3].h = avg_h*2;
417 centre_dialog(alert_dialog);
418 set_dialog_color(alert_dialog, gui_fg_color, gui_bg_color);
419 for (c = 0; alert_dialog[c].proc; c++)
420 if (alert_dialog[c].proc == _gui_ctext_proc)
421 alert_dialog[c].bg = -1;
426 }
while (gui_mouse_b());
449 int algl_alert(AL_CONST
char *s1, AL_CONST
char *s2, AL_CONST
char *s3, AL_CONST
char *b1, AL_CONST
char *b2,
int c1,
int c2)
453 AGL_LOG(2,
"allegro_gl_alert\n");
455 ret =
algl_alert3(s1, s2, s3, b1, b2, NULL, c1, c2, 0);
480 typedef int (*_callback)(BITMAP*, int, int);
481 _callback callback = (_callback) d->dp;
482 BITMAP *viewport = create_sub_bitmap(screen, d->x, d->y, d->w, d->h);
484 AGL_LOG(3,
"d_algl_viewport_proc\n");
486 if (msg == MSG_DRAW) {
488 clear_to_color(viewport, d->bg);
495 glPushAttrib(GL_SCISSOR_BIT | GL_VIEWPORT_BIT);
498 glViewport(d->x, SCREEN_H - d->y - d->h, d->w, d->h);
499 glScissor(d->x, SCREEN_H - d->y - d->h, d->w, d->h);
500 glEnable(GL_SCISSOR_TEST);
503 if (msg == MSG_DRAW) {
504 glClear(GL_DEPTH_BUFFER_BIT);
509 ret = callback(viewport, msg, c);
514 destroy_bitmap(viewport);
517 if (msg == MSG_IDLE) {
518 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
519 broadcast_dialog_message (MSG_DRAW, 0);
538 int allegro_gl_set_mouse_sprite(BITMAP *sprite,
int xfocus,
int yfocus)
543 AGL_LOG(2,
"allegro_gl_set_mouse_sprite\n");
545 glGetIntegerv(GL_TEXTURE_2D_BINDING, &old_texture);
547 bmp = create_bitmap_ex(bitmap_color_depth(sprite),
548 __allegro_gl_make_power_of_2(sprite->w),
549 __allegro_gl_make_power_of_2(sprite->h));
551 if (allegro_gl_mouse.texture) {
552 glDeleteTextures(1, &allegro_gl_mouse.texture);
553 allegro_gl_mouse.texture = 0;
556 clear_to_color(bmp, bitmap_mask_color(sprite));
557 blit(sprite, bmp, 0, 0, 0, 0, sprite->w, sprite->h);
559 save_bmp(
"mcursor.bmp",bmp,NULL);
564 if (!allegro_gl_mouse.texture) {
569 glBindTexture(GL_TEXTURE_2D, allegro_gl_mouse.texture);
570 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
571 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
574 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
575 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
578 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
579 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
582 glBindTexture(GL_TEXTURE_2D, old_texture);
584 allegro_gl_mouse.width = bmp->w;
585 allegro_gl_mouse.height = bmp->h;
586 allegro_gl_mouse.xfocus = xfocus;
587 allegro_gl_mouse.yfocus = yfocus;
595 int allegro_gl_show_mouse(BITMAP* bmp,
int x,
int y)
597 AGL_LOG(3,
"allegro_gl_show_mouse\n");
598 allegro_gl_mouse.hidden = FALSE;
604 void allegro_gl_hide_mouse(
void)
606 AGL_LOG(3,
"allegro_gl_hide_mouse\n");
607 allegro_gl_mouse.hidden = TRUE;
612 void allegro_gl_move_mouse(
int x,
int y)
614 AGL_LOG(3,
"allegro_gl_move_mouse\n");
#define AGL_TEXTURE_MASKED
Generate an alpha channel for this texture, based on the Allegro mask color.
GLuint allegro_gl_make_texture_ex(int flags, BITMAP *bmp, GLint internal_format)
Uploads an Allegro BITMAP to the GL driver as a texture.
int d_algl_viewport_proc(int msg, DIALOG *d, int c)
Creates a viewport object where OpenGL commands can be performed.
void allegro_gl_unset_allegro_mode(void)
Restores previous OpenGL settings.
void algl_draw_mouse(void)
Draws a mouse pointer on the screen.
void algl_set_mouse_drawer(void(*user_draw_mouse)(void))
Sets (or clears) a user mouse drawing callback.
void allegro_gl_flip(void)
Flips the front and back framebuffers.
struct AGL_EXTENSION_LIST_GL allegro_gl_extensions_GL
List of OpenGL extensions supported by AllegroGL.
int algl_alert(AL_CONST char *s1, AL_CONST char *s2, AL_CONST char *s3, AL_CONST char *b1, AL_CONST char *b2, int c1, int c2)
AllegroGL-friendly version of Allegro's alert.
int algl_popup_dialog(DIALOG *dialog, int focus_obj)
AllegroGL-friendly version of popup_dialog.
Main header file for AllegroGL.
void allegro_gl_set_allegro_mode(void)
Prepares for Allegro drawing to the screen.
#define AGL_TEXTURE_FLIP
Flip the texture on the x-axis.
#define AGL_TEXTURE_RESCALE
Tell AllegroGL to allow rescaling of the bitmap.
int algl_do_dialog(DIALOG *dialog, int focus_obj)
AllegroGL-friendly version of do_dialog.
int algl_alert3(AL_CONST char *s1, AL_CONST char *s2, AL_CONST char *s3, AL_CONST char *b1, AL_CONST char *b2, AL_CONST char *b3, int c1, int c2, int c3)
AllegroGL-friendly version of Allegro's alert3.