You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

640 line
18 KiB

  1. /*
  2. * libcaca Colour ASCII-Art library
  3. * Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
  4. * All Rights Reserved
  5. *
  6. * $Id$
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the Do What The Fuck You Want To
  10. * Public License, Version 2, as published by Sam Hocevar. See
  11. * http://sam.zoy.org/wtfpl/COPYING for more details.
  12. */
  13. /*
  14. * This file contains the libcaca OpenGL input and output driver
  15. */
  16. #include "config.h"
  17. #include "common.h"
  18. #if defined(USE_GL)
  19. #ifdef HAVE_OPENGL_GL_H
  20. # include <OpenGL/gl.h>
  21. # include <GLUT/glut.h>
  22. #else
  23. # include <GL/gl.h>
  24. # include <GL/glut.h>
  25. # include <GL/freeglut_ext.h>
  26. #endif
  27. #include <string.h>
  28. #include <stdlib.h>
  29. #include <stdio.h>
  30. #include "caca.h"
  31. #include "caca_internals.h"
  32. #include "cucul.h"
  33. #include "cucul_internals.h"
  34. /*
  35. * Global variables
  36. */
  37. static caca_display_t *gl_d; /* FIXME: we ought to get rid of this */
  38. /*
  39. * Local functions
  40. */
  41. static void gl_handle_keyboard(unsigned char, int, int);
  42. static void gl_handle_special_key(int, int, int);
  43. static void gl_handle_reshape(int, int);
  44. static void gl_handle_mouse(int, int, int, int);
  45. static void gl_handle_mouse_motion(int, int);
  46. #ifdef HAVE_GLUTCLOSEFUNC
  47. static void gl_handle_close(void);
  48. #endif
  49. static void _display(void);
  50. static void gl_generate_glyph(uint32_t, uint32_t, caca_display_t *);
  51. static void gl_generate_unicode_glyph(uint32_t, uint32_t, caca_display_t *);
  52. struct driver_private
  53. {
  54. int window;
  55. unsigned int width, height;
  56. unsigned int new_width, new_height;
  57. cucul_font_t *f;
  58. float font_width, font_height;
  59. float incx, incy;
  60. int id[(128 - 32)];
  61. int id_uni[8]; /* Hack, FIXME */
  62. unsigned char close;
  63. unsigned char bit;
  64. unsigned char mouse_changed, mouse_clicked;
  65. unsigned int mouse_x, mouse_y;
  66. unsigned int mouse_button, mouse_state;
  67. unsigned char key;
  68. int special_key;
  69. float sw, sh;
  70. };
  71. static int gl_init_graphics(caca_display_t *dp)
  72. {
  73. char *empty_texture;
  74. char const *geometry;
  75. char *argv[2] = { "", NULL };
  76. char const * const * fonts;
  77. unsigned int width = 0, height = 0;
  78. int argc = 1;
  79. int i;
  80. dp->drv.p = malloc(sizeof(struct driver_private));
  81. gl_d = dp;
  82. #if defined(HAVE_GETENV)
  83. geometry = getenv("CACA_GEOMETRY");
  84. if(geometry && *geometry)
  85. sscanf(geometry, "%ux%u", &width, &height);
  86. #endif
  87. if(width && height)
  88. _cucul_set_canvas_size(dp->cv, width, height);
  89. /* Load a libcucul internal font */
  90. fonts = cucul_get_font_list();
  91. if(fonts[0] == NULL)
  92. {
  93. fprintf(stderr, "error: libcucul was compiled without any fonts\n");
  94. return -1;
  95. }
  96. dp->drv.p->f = cucul_load_font(fonts[0], 0);
  97. if(dp->drv.p->f == NULL)
  98. {
  99. fprintf(stderr, "error: could not load font \"%s\"\n", fonts[0]);
  100. return -1;
  101. }
  102. dp->drv.p->font_width = cucul_get_font_width(dp->drv.p->f);
  103. dp->drv.p->font_height = cucul_get_font_height(dp->drv.p->f);
  104. dp->drv.p->width = dp->cv->width * dp->drv.p->font_width;
  105. dp->drv.p->height = dp->cv->height * dp->drv.p->font_height;
  106. #ifdef HAVE_GLUTCLOSEFUNC
  107. dp->drv.p->close = 0;
  108. #endif
  109. dp->drv.p->bit = 0;
  110. dp->drv.p->mouse_changed = dp->drv.p->mouse_clicked = 0;
  111. dp->drv.p->mouse_button = dp->drv.p->mouse_state = 0;
  112. dp->drv.p->key = 0;
  113. dp->drv.p->special_key = 0;
  114. dp->drv.p->sw = ((float)dp->drv.p->font_width) / 16.0f;
  115. dp->drv.p->sh = ((float)dp->drv.p->font_height) / 16.0f;
  116. glutInit(&argc, argv);
  117. glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
  118. glutInitWindowSize(dp->drv.p->width, dp->drv.p->height);
  119. dp->drv.p->window = glutCreateWindow("caca for GL");
  120. gluOrtho2D(0, dp->drv.p->width, dp->drv.p->height, 0);
  121. glDisable(GL_CULL_FACE);
  122. glDisable(GL_DEPTH_TEST);
  123. glutKeyboardFunc(gl_handle_keyboard);
  124. glutSpecialFunc(gl_handle_special_key);
  125. glutReshapeFunc(gl_handle_reshape);
  126. glutDisplayFunc(_display);
  127. #ifdef HAVE_GLUTCLOSEFUNC
  128. glutCloseFunc(gl_handle_close);
  129. #endif
  130. glutMouseFunc(gl_handle_mouse);
  131. glutMotionFunc(gl_handle_mouse_motion);
  132. glutPassiveMotionFunc(gl_handle_mouse_motion);
  133. glLoadIdentity();
  134. glMatrixMode(GL_PROJECTION);
  135. glPushMatrix();
  136. glLoadIdentity();
  137. gluOrtho2D(0, dp->drv.p->width, dp->drv.p->height, 0);
  138. glMatrixMode(GL_MODELVIEW);
  139. glClear(GL_COLOR_BUFFER_BIT);
  140. glEnable(GL_TEXTURE_2D);
  141. glEnable(GL_BLEND);
  142. glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
  143. empty_texture = malloc(16 * 16 * 4);
  144. if(empty_texture == NULL)
  145. return -1;
  146. memset(empty_texture, 0xff, 16 * 16 * 4);
  147. glEnable(GL_TEXTURE_2D);
  148. /* ASCII glyphes textures initialisation */
  149. for(i = 32; i < 128; i++)
  150. {
  151. glGenTextures(1, (GLuint*)&dp->drv.p->id[i - 32]);
  152. glBindTexture(GL_TEXTURE_2D, dp->drv.p->id[i - 32]);
  153. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  154. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  155. glTexImage2D(GL_TEXTURE_2D, 0, 4,
  156. 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, empty_texture);
  157. }
  158. /* Unicode (CP437) glyphes textures initialisation */
  159. for(i = 0; i < 8; i++)
  160. {
  161. glGenTextures(1, (GLuint*)&dp->drv.p->id_uni[i]);
  162. glBindTexture(GL_TEXTURE_2D, dp->drv.p->id_uni[i]);
  163. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  164. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  165. glTexImage2D(GL_TEXTURE_2D, 0, 4,
  166. 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, empty_texture);
  167. }
  168. /* Get textures for ASCII glyphs */
  169. for(i = 32; i < 128; i++)
  170. gl_generate_glyph(i, i-32, dp);
  171. gl_generate_unicode_glyph(0x00002580, 0, dp);
  172. gl_generate_unicode_glyph(0x00002584, 1, dp);
  173. gl_generate_unicode_glyph(0x00002588, 2, dp);
  174. gl_generate_unicode_glyph(0x0000258c, 3, dp);
  175. gl_generate_unicode_glyph(0x00002590, 4, dp);
  176. gl_generate_unicode_glyph(0x00002591, 5, dp);
  177. gl_generate_unicode_glyph(0x00002592, 6, dp);
  178. gl_generate_unicode_glyph(0x00002593, 7, dp);
  179. return 0;
  180. }
  181. static int gl_end_graphics(caca_display_t *dp)
  182. {
  183. glutDestroyWindow(dp->drv.p->window);
  184. free(dp->drv.p);
  185. return 0;
  186. }
  187. static int gl_set_display_title(caca_display_t *dp, char const *title)
  188. {
  189. glutSetWindowTitle(title);
  190. return 0;
  191. }
  192. static unsigned int gl_get_display_width(caca_display_t *dp)
  193. {
  194. return dp->drv.p->width;
  195. }
  196. static unsigned int gl_get_display_height(caca_display_t *dp)
  197. {
  198. return dp->drv.p->height;
  199. }
  200. static void gl_display(caca_display_t *dp)
  201. {
  202. unsigned int x, y, line;
  203. static int old_texture = 0;
  204. glClear(GL_COLOR_BUFFER_BIT);
  205. glDisable(GL_TEXTURE_2D);
  206. glDisable(GL_BLEND);
  207. line = 0;
  208. for(y = 0; y < dp->drv.p->height; y += dp->drv.p->font_height)
  209. {
  210. uint32_t *attr = dp->cv->attr + line * dp->cv->width;
  211. for(x = 0; x < dp->drv.p->width; x += dp->drv.p->font_width)
  212. {
  213. uint16_t bg = _cucul_argb32_to_rgb12bg(*attr++);
  214. glColor4b(((bg & 0xf00) >> 8) * 8,
  215. ((bg & 0x0f0) >> 4) * 8,
  216. (bg & 0x00f) * 8,
  217. 0xff);
  218. glBegin(GL_QUADS);
  219. glVertex2f(x, y);
  220. glVertex2f(x + dp->drv.p->font_width, y);
  221. glVertex2f(x + dp->drv.p->font_width,
  222. y + dp->drv.p->font_height);
  223. glVertex2f(x, y + dp->drv.p->font_height);
  224. glEnd();
  225. }
  226. line++;
  227. }
  228. /* 2nd pass, avoids changing render state too much */
  229. glEnable(GL_TEXTURE_2D);
  230. glEnable(GL_BLEND);
  231. line = 0;
  232. for(y = 0; y < dp->drv.p->height; y += dp->drv.p->font_height, line++)
  233. {
  234. uint32_t *attr = dp->cv->attr + line * dp->cv->width;
  235. uint32_t *chars = dp->cv->chars + line * dp->cv->width;
  236. for(x = 0; x < dp->drv.p->width; x += dp->drv.p->font_width, attr++)
  237. {
  238. uint32_t cv = *chars++;
  239. uint16_t fg;
  240. if(cv == ' ')
  241. continue;
  242. if(cv > 0x00000020 && cv < 0x00000080)
  243. {
  244. if(old_texture != dp->drv.p->id[cv - 32])
  245. {
  246. glBindTexture(GL_TEXTURE_2D, dp->drv.p->id[cv - 32]);
  247. old_texture = dp->drv.p->id[cv - 32];
  248. }
  249. }
  250. else switch(cv)
  251. {
  252. case 0x00002580: glBindTexture(GL_TEXTURE_2D, dp->drv.p->id_uni[0]); break;
  253. case 0x00002584: glBindTexture(GL_TEXTURE_2D, dp->drv.p->id_uni[1]); break;
  254. case 0x00002588: glBindTexture(GL_TEXTURE_2D, dp->drv.p->id_uni[2]); break;
  255. case 0x0000258c: glBindTexture(GL_TEXTURE_2D, dp->drv.p->id_uni[3]); break;
  256. case 0x00002590: glBindTexture(GL_TEXTURE_2D, dp->drv.p->id_uni[4]); break;
  257. case 0x00002591: glBindTexture(GL_TEXTURE_2D, dp->drv.p->id_uni[5]); break;
  258. case 0x00002592: glBindTexture(GL_TEXTURE_2D, dp->drv.p->id_uni[6]); break;
  259. case 0x00002593: glBindTexture(GL_TEXTURE_2D, dp->drv.p->id_uni[7]); break;
  260. default: glBindTexture(GL_TEXTURE_2D, dp->drv.p->id['?' - 32]); break;
  261. }
  262. fg = _cucul_argb32_to_rgb12fg(*attr);
  263. glColor3b(((fg & 0xf00) >> 8) * 8,
  264. ((fg & 0x0f0) >> 4) * 8,
  265. (fg & 0x00f) * 8);
  266. glBegin(GL_QUADS);
  267. glTexCoord2f(0, dp->drv.p->sh);
  268. glVertex2f(x, y);
  269. glTexCoord2f(dp->drv.p->sw, dp->drv.p->sh);
  270. glVertex2f(x + dp->drv.p->font_width, y);
  271. glTexCoord2f(dp->drv.p->sw, 0);
  272. glVertex2f(x + dp->drv.p->font_width,
  273. y + dp->drv.p->font_height);
  274. glTexCoord2f(0, 0);
  275. glVertex2f(x, y + dp->drv.p->font_height);
  276. glEnd();
  277. }
  278. }
  279. #ifdef HAVE_GLUTCHECKLOOP
  280. glutCheckLoop();
  281. #else
  282. glutMainLoopEvent();
  283. #endif
  284. glutSwapBuffers();
  285. glutPostRedisplay();
  286. }
  287. static void gl_handle_resize(caca_display_t *dp)
  288. {
  289. dp->drv.p->width = dp->drv.p->new_width;
  290. dp->drv.p->height = dp->drv.p->new_height;
  291. glMatrixMode(GL_PROJECTION);
  292. glPushMatrix();
  293. glLoadIdentity();
  294. glViewport(0, 0, dp->drv.p->width, dp->drv.p->height);
  295. gluOrtho2D(0, dp->drv.p->width, dp->drv.p->height, 0);
  296. glMatrixMode(GL_MODELVIEW);
  297. }
  298. static int gl_get_event(caca_display_t *dp, caca_event_t *ev)
  299. {
  300. #ifdef HAVE_GLUTCHECKLOOP
  301. glutCheckLoop();
  302. #else
  303. glutMainLoopEvent();
  304. #endif
  305. #ifdef HAVE_GLUTCLOSEFUNC
  306. if(dp->drv.p->close)
  307. {
  308. dp->drv.p->close = 0;
  309. ev->type = CACA_EVENT_QUIT;
  310. return 1;
  311. }
  312. #endif
  313. if(dp->resize.resized)
  314. {
  315. ev->type = CACA_EVENT_RESIZE;
  316. ev->data.resize.w = dp->cv->width;
  317. ev->data.resize.h = dp->cv->height;
  318. return 1;
  319. }
  320. if(dp->drv.p->mouse_changed)
  321. {
  322. ev->type = CACA_EVENT_MOUSE_MOTION;
  323. ev->data.mouse.x = dp->mouse.x;
  324. ev->data.mouse.y = dp->mouse.y;
  325. dp->drv.p->mouse_changed = 0;
  326. if(dp->drv.p->mouse_clicked)
  327. {
  328. _push_event(dp, ev);
  329. ev->type = CACA_EVENT_MOUSE_PRESS;
  330. ev->data.mouse.button = dp->drv.p->mouse_button;
  331. dp->drv.p->mouse_clicked = 0;
  332. }
  333. return 1;
  334. }
  335. if(dp->drv.p->key != 0)
  336. {
  337. ev->type = CACA_EVENT_KEY_PRESS;
  338. ev->data.key.ch = dp->drv.p->key;
  339. ev->data.key.utf32 = (uint32_t)dp->drv.p->key;
  340. ev->data.key.utf8[0] = dp->drv.p->key;
  341. ev->data.key.utf8[1] = '\0';
  342. dp->drv.p->key = 0;
  343. return 1;
  344. }
  345. if(dp->drv.p->special_key != 0)
  346. {
  347. switch(dp->drv.p->special_key)
  348. {
  349. case GLUT_KEY_F1 : ev->data.key.ch = CACA_KEY_F1; break;
  350. case GLUT_KEY_F2 : ev->data.key.ch = CACA_KEY_F2; break;
  351. case GLUT_KEY_F3 : ev->data.key.ch = CACA_KEY_F3; break;
  352. case GLUT_KEY_F4 : ev->data.key.ch = CACA_KEY_F4; break;
  353. case GLUT_KEY_F5 : ev->data.key.ch = CACA_KEY_F5; break;
  354. case GLUT_KEY_F6 : ev->data.key.ch = CACA_KEY_F6; break;
  355. case GLUT_KEY_F7 : ev->data.key.ch = CACA_KEY_F7; break;
  356. case GLUT_KEY_F8 : ev->data.key.ch = CACA_KEY_F8; break;
  357. case GLUT_KEY_F9 : ev->data.key.ch = CACA_KEY_F9; break;
  358. case GLUT_KEY_F10: ev->data.key.ch = CACA_KEY_F10; break;
  359. case GLUT_KEY_F11: ev->data.key.ch = CACA_KEY_F11; break;
  360. case GLUT_KEY_F12: ev->data.key.ch = CACA_KEY_F12; break;
  361. case GLUT_KEY_LEFT : ev->data.key.ch = CACA_KEY_LEFT; break;
  362. case GLUT_KEY_RIGHT: ev->data.key.ch = CACA_KEY_RIGHT; break;
  363. case GLUT_KEY_UP : ev->data.key.ch = CACA_KEY_UP; break;
  364. case GLUT_KEY_DOWN : ev->data.key.ch = CACA_KEY_DOWN; break;
  365. case GLUT_KEY_PAGE_UP : ev->data.key.ch = CACA_KEY_PAGEUP; break;
  366. case GLUT_KEY_PAGE_DOWN : ev->data.key.ch = CACA_KEY_PAGEDOWN;
  367. break;
  368. case GLUT_KEY_HOME : ev->data.key.ch = CACA_KEY_HOME; break;
  369. case GLUT_KEY_END : ev->data.key.ch = CACA_KEY_END; break;
  370. case GLUT_KEY_INSERT : ev->data.key.ch = CACA_KEY_INSERT; break;
  371. default: ev->type = CACA_EVENT_NONE; return 0;
  372. }
  373. ev->type = CACA_EVENT_KEY_PRESS;
  374. ev->data.key.utf32 = 0;
  375. ev->data.key.utf8[0] = '\0';
  376. dp->drv.p->special_key = 0;
  377. return 1;
  378. }
  379. ev->type = CACA_EVENT_NONE;
  380. return 0;
  381. }
  382. static void gl_set_mouse(caca_display_t *dp, int flag)
  383. {
  384. if(flag)
  385. glutSetCursor(GLUT_CURSOR_RIGHT_ARROW);
  386. else
  387. glutSetCursor(GLUT_CURSOR_NONE);
  388. }
  389. /*
  390. * XXX: following functions are local
  391. */
  392. static void gl_handle_keyboard(unsigned char key, int x, int y)
  393. {
  394. caca_display_t *dp = gl_d;
  395. dp->drv.p->key = key;
  396. }
  397. static void gl_handle_special_key(int key, int x, int y)
  398. {
  399. caca_display_t *dp = gl_d;
  400. dp->drv.p->special_key = key;
  401. }
  402. static void gl_handle_reshape(int w, int h)
  403. {
  404. caca_display_t *dp = gl_d;
  405. if(dp->drv.p->bit) /* Do not handle reshaping at the first time */
  406. {
  407. dp->drv.p->new_width = w;
  408. dp->drv.p->new_height = h;
  409. dp->resize.w = w / dp->drv.p->font_width;
  410. dp->resize.h = (h / dp->drv.p->font_height) + 1;
  411. dp->resize.resized = 1;
  412. }
  413. else
  414. dp->drv.p->bit = 1;
  415. }
  416. static void gl_handle_mouse(int button, int state, int x, int y)
  417. {
  418. caca_display_t *dp = gl_d;
  419. dp->drv.p->mouse_clicked = 1;
  420. dp->drv.p->mouse_button = button;
  421. dp->drv.p->mouse_state = state;
  422. dp->drv.p->mouse_x = x / dp->drv.p->font_width;
  423. dp->drv.p->mouse_y = y / dp->drv.p->font_height;
  424. dp->mouse.x = dp->drv.p->mouse_x;
  425. dp->mouse.y = dp->drv.p->mouse_y;
  426. dp->drv.p->mouse_changed = 1;
  427. }
  428. static void gl_handle_mouse_motion(int x, int y)
  429. {
  430. caca_display_t *dp = gl_d;
  431. dp->drv.p->mouse_x = x / dp->drv.p->font_width;
  432. dp->drv.p->mouse_y = y / dp->drv.p->font_height;
  433. dp->mouse.x = dp->drv.p->mouse_x;
  434. dp->mouse.y = dp->drv.p->mouse_y;
  435. dp->drv.p->mouse_changed = 1;
  436. }
  437. #ifdef HAVE_GLUTCLOSEFUNC
  438. static void gl_handle_close(void)
  439. {
  440. caca_display_t *dp = gl_d;
  441. dp->drv.p->close = 1;
  442. }
  443. #endif
  444. static void _display(void)
  445. {
  446. caca_display_t *dp = gl_d;
  447. gl_display(dp);
  448. }
  449. static void gl_generate_glyph(uint32_t c, uint32_t tid, caca_display_t *dp)
  450. {
  451. int s,d;
  452. uint8_t *glyph8 = calloc(dp->drv.p->font_width*dp->drv.p->font_height, 1);
  453. uint8_t *glyph32 = calloc(16*16*4, 1);
  454. cucul_render_glyph(dp->drv.p->f, c, glyph8, dp->drv.p->font_width);
  455. /* Convert resulting 8bbp glyph to 32bits, 16x16*/
  456. for(s=0;s<(dp->drv.p->font_height<=16?dp->drv.p->font_height:16);s++)
  457. {
  458. for(d=0;d<dp->drv.p->font_width;d++)
  459. {
  460. uint32_t offset = d*4+(15-s)*16*4;
  461. uint8_t c = glyph8[d+s*(int)dp->drv.p->font_width];
  462. glyph32[offset] = c;
  463. glyph32[1+offset] = c;
  464. glyph32[2+offset] = c;
  465. glyph32[3+offset] = c;
  466. }
  467. }
  468. glBindTexture(GL_TEXTURE_2D, dp->drv.p->id[tid]);
  469. glTexImage2D(GL_TEXTURE_2D,
  470. 0, 4,
  471. 16,16,
  472. 0, GL_RGBA, GL_UNSIGNED_BYTE,
  473. glyph32);
  474. glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
  475. glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
  476. free(glyph8);
  477. free(glyph32);
  478. }
  479. static void gl_generate_unicode_glyph(uint32_t c, uint32_t tid,
  480. caca_display_t *dp)
  481. {
  482. int s,d;
  483. uint8_t *glyph8 = calloc(dp->drv.p->font_width*dp->drv.p->font_height, 1);
  484. uint8_t *glyph32 = calloc(16*16*4, 1);
  485. cucul_render_glyph(dp->drv.p->f, c, glyph8, dp->drv.p->font_width);
  486. /* Convert resulting 8bbp glyph to 32bits, 16x16*/
  487. for(s=0;s<(dp->drv.p->font_height<=16?dp->drv.p->font_height:16);s++)
  488. {
  489. for(d=0;d<(dp->drv.p->font_width<=16?dp->drv.p->font_width:16);d++)
  490. {
  491. uint32_t offset = d*4+(15-s)*16*4;
  492. uint8_t c = glyph8[d+s*(int)dp->drv.p->font_width];
  493. glyph32[offset] = c;
  494. glyph32[1+offset] = c;
  495. glyph32[2+offset] = c;
  496. glyph32[3+offset] = c;
  497. }
  498. }
  499. glBindTexture(GL_TEXTURE_2D, dp->drv.p->id_uni[tid]);
  500. glTexImage2D(GL_TEXTURE_2D,
  501. 0, 4,
  502. 16,16,
  503. 0, GL_RGBA, GL_UNSIGNED_BYTE,
  504. glyph32);
  505. glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
  506. glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
  507. free(glyph8);
  508. free(glyph32);
  509. }
  510. /*
  511. * Driver initialisation
  512. */
  513. int gl_install(caca_display_t *dp)
  514. {
  515. #if defined(HAVE_GETENV) && defined(GLUT_XLIB_IMPLEMENTATION)
  516. if(!getenv("DISPLAY") || !*(getenv("DISPLAY")))
  517. return -1;
  518. #endif
  519. dp->drv.driver = CACA_DRIVER_GL;
  520. dp->drv.init_graphics = gl_init_graphics;
  521. dp->drv.end_graphics = gl_end_graphics;
  522. dp->drv.set_display_title = gl_set_display_title;
  523. dp->drv.get_display_width = gl_get_display_width;
  524. dp->drv.get_display_height = gl_get_display_height;
  525. dp->drv.display = gl_display;
  526. dp->drv.handle_resize = gl_handle_resize;
  527. dp->drv.get_event = gl_get_event;
  528. dp->drv.set_mouse = gl_set_mouse;
  529. return 0;
  530. }
  531. #endif /* USE_GL */