25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

driver_gl.c 18 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  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. void gl_generate_glyph(uint32_t c, uint32_t tid, caca_display_t *dp);
  51. void gl_generate_unicode_glyph(uint32_t c, uint32_t tid, caca_display_t *dp);
  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. empty_texture = malloc(16 * 16 * 4);
  141. if(empty_texture == NULL)
  142. return -1;
  143. memset(empty_texture, 0xff, 16 * 16 * 4);
  144. glEnable(GL_TEXTURE_2D);
  145. /* ASCII glyphes textures initialisation */
  146. for(i = 32; i < 128; i++)
  147. {
  148. glGenTextures(1, (GLuint*)&dp->drv.p->id[i - 32]);
  149. glBindTexture(GL_TEXTURE_2D, dp->drv.p->id[i - 32]);
  150. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  151. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  152. glTexImage2D(GL_TEXTURE_2D, 0, 4,
  153. 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, empty_texture);
  154. }
  155. /* Unicode (CP437) glyphes textures initialisation */
  156. for(i = 0; i < 8; i++)
  157. {
  158. glGenTextures(1, (GLuint*)&dp->drv.p->id_uni[i]);
  159. glBindTexture(GL_TEXTURE_2D, dp->drv.p->id_uni[i]);
  160. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  161. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  162. glTexImage2D(GL_TEXTURE_2D, 0, 4,
  163. 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, empty_texture);
  164. }
  165. /* Get textures for ASCII glyphs */
  166. for(i = 32; i < 128; i++)
  167. gl_generate_glyph(i, i-32, dp);
  168. gl_generate_unicode_glyph(0x00002580, 0, dp);
  169. gl_generate_unicode_glyph(0x00002584, 1, dp);
  170. gl_generate_unicode_glyph(0x00002588, 2, dp);
  171. gl_generate_unicode_glyph(0x0000258c, 3, dp);
  172. gl_generate_unicode_glyph(0x00002590, 4, dp);
  173. gl_generate_unicode_glyph(0x00002591, 5, dp);
  174. gl_generate_unicode_glyph(0x00002592, 6, dp);
  175. gl_generate_unicode_glyph(0x00002593, 7, dp);
  176. return 0;
  177. }
  178. static int gl_end_graphics(caca_display_t *dp)
  179. {
  180. glutDestroyWindow(dp->drv.p->window);
  181. free(dp->drv.p);
  182. return 0;
  183. }
  184. static int gl_set_display_title(caca_display_t *dp, char const *title)
  185. {
  186. glutSetWindowTitle(title);
  187. return 0;
  188. }
  189. static unsigned int gl_get_display_width(caca_display_t *dp)
  190. {
  191. return dp->drv.p->width;
  192. }
  193. static unsigned int gl_get_display_height(caca_display_t *dp)
  194. {
  195. return dp->drv.p->height;
  196. }
  197. static void gl_display(caca_display_t *dp)
  198. {
  199. unsigned int x, y, line;
  200. glClear(GL_COLOR_BUFFER_BIT);
  201. line = 0;
  202. for(y = 0; y < dp->drv.p->height; y += dp->drv.p->font_height)
  203. {
  204. uint32_t *attr = dp->cv->attr + line * dp->cv->width;
  205. for(x = 0; x < dp->drv.p->width; x += dp->drv.p->font_width)
  206. {
  207. uint16_t bg = _cucul_argb32_to_rgb12bg(*attr++);
  208. glDisable(GL_TEXTURE_2D);
  209. glColor4b(((bg & 0xf00) >> 8) * 8,
  210. ((bg & 0x0f0) >> 4) * 8,
  211. (bg & 0x00f) * 8,
  212. 0xff);
  213. glBegin(GL_QUADS);
  214. glVertex2f(x, y);
  215. glVertex2f(x + dp->drv.p->font_width, y);
  216. glVertex2f(x + dp->drv.p->font_width,
  217. y + dp->drv.p->font_height);
  218. glVertex2f(x, y + dp->drv.p->font_height);
  219. glEnd();
  220. }
  221. line++;
  222. }
  223. /* 2nd pass, avoids changing render state too much */
  224. glEnable(GL_TEXTURE_2D);
  225. glEnable(GL_BLEND);
  226. glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
  227. line = 0;
  228. for(y = 0; y < dp->drv.p->height; y += dp->drv.p->font_height, line++)
  229. {
  230. uint32_t *attr = dp->cv->attr + line * dp->cv->width;
  231. uint32_t *chars = dp->cv->chars + line * dp->cv->width;
  232. for(x = 0; x < dp->drv.p->width; x += dp->drv.p->font_width, attr++)
  233. {
  234. uint32_t cv = *chars++;
  235. uint16_t fg;
  236. if(cv == ' ')
  237. continue;
  238. if(cv > 0x00000020 && cv < 0x00000080)
  239. {
  240. glBindTexture(GL_TEXTURE_2D, dp->drv.p->id[cv - 32]);
  241. }
  242. else switch(cv)
  243. {
  244. case 0x00002580: glBindTexture(GL_TEXTURE_2D, dp->drv.p->id_uni[0]); break;
  245. case 0x00002584: glBindTexture(GL_TEXTURE_2D, dp->drv.p->id_uni[1]); break;
  246. case 0x00002588: glBindTexture(GL_TEXTURE_2D, dp->drv.p->id_uni[2]); break;
  247. case 0x0000258c: glBindTexture(GL_TEXTURE_2D, dp->drv.p->id_uni[3]); break;
  248. case 0x00002590: glBindTexture(GL_TEXTURE_2D, dp->drv.p->id_uni[4]); break;
  249. case 0x00002591: glBindTexture(GL_TEXTURE_2D, dp->drv.p->id_uni[5]); break;
  250. case 0x00002592: glBindTexture(GL_TEXTURE_2D, dp->drv.p->id_uni[6]); break;
  251. case 0x00002593: glBindTexture(GL_TEXTURE_2D, dp->drv.p->id_uni[7]); break;
  252. default: glBindTexture(GL_TEXTURE_2D, dp->drv.p->id['?' - 32]); break;
  253. }
  254. fg = _cucul_argb32_to_rgb12fg(*attr);
  255. glColor3b(((fg & 0xf00) >> 8) * 8,
  256. ((fg & 0x0f0) >> 4) * 8,
  257. (fg & 0x00f) * 8);
  258. glBegin(GL_QUADS);
  259. glTexCoord2f(0, dp->drv.p->sh);
  260. glVertex2f(x, y);
  261. glTexCoord2f(dp->drv.p->sw, dp->drv.p->sh);
  262. glVertex2f(x + dp->drv.p->font_width, y);
  263. glTexCoord2f(dp->drv.p->sw, 0);
  264. glVertex2f(x + dp->drv.p->font_width,
  265. y + dp->drv.p->font_height);
  266. glTexCoord2f(0, 0);
  267. glVertex2f(x, y + dp->drv.p->font_height);
  268. glEnd();
  269. }
  270. }
  271. glBlendFunc(GL_ONE, GL_ZERO);
  272. glDisable(GL_BLEND);
  273. glDisable(GL_TEXTURE_2D);
  274. #ifdef HAVE_GLUTCHECKLOOP
  275. glutCheckLoop();
  276. #else
  277. glutMainLoopEvent();
  278. #endif
  279. glutSwapBuffers();
  280. glutPostRedisplay();
  281. }
  282. static void gl_handle_resize(caca_display_t *dp)
  283. {
  284. dp->drv.p->width = dp->drv.p->new_width;
  285. dp->drv.p->height = dp->drv.p->new_height;
  286. glMatrixMode(GL_PROJECTION);
  287. glPushMatrix();
  288. glLoadIdentity();
  289. glViewport(0, 0, dp->drv.p->width, dp->drv.p->height);
  290. gluOrtho2D(0, dp->drv.p->width, dp->drv.p->height, 0);
  291. glMatrixMode(GL_MODELVIEW);
  292. }
  293. static int gl_get_event(caca_display_t *dp, caca_event_t *ev)
  294. {
  295. #ifdef HAVE_GLUTCHECKLOOP
  296. glutCheckLoop();
  297. #else
  298. glutMainLoopEvent();
  299. #endif
  300. #ifdef HAVE_GLUTCLOSEFUNC
  301. if(dp->drv.p->close)
  302. {
  303. dp->drv.p->close = 0;
  304. ev->type = CACA_EVENT_QUIT;
  305. return 1;
  306. }
  307. #endif
  308. if(dp->resize.resized)
  309. {
  310. ev->type = CACA_EVENT_RESIZE;
  311. ev->data.resize.w = dp->cv->width;
  312. ev->data.resize.h = dp->cv->height;
  313. return 1;
  314. }
  315. if(dp->drv.p->mouse_changed)
  316. {
  317. ev->type = CACA_EVENT_MOUSE_MOTION;
  318. ev->data.mouse.x = dp->mouse.x;
  319. ev->data.mouse.y = dp->mouse.y;
  320. dp->drv.p->mouse_changed = 0;
  321. if(dp->drv.p->mouse_clicked)
  322. {
  323. _push_event(dp, ev);
  324. ev->type = CACA_EVENT_MOUSE_PRESS;
  325. ev->data.mouse.button = dp->drv.p->mouse_button;
  326. dp->drv.p->mouse_clicked = 0;
  327. }
  328. return 1;
  329. }
  330. if(dp->drv.p->key != 0)
  331. {
  332. ev->type = CACA_EVENT_KEY_PRESS;
  333. ev->data.key.ch = dp->drv.p->key;
  334. ev->data.key.utf32 = (uint32_t)dp->drv.p->key;
  335. ev->data.key.utf8[0] = dp->drv.p->key;
  336. ev->data.key.utf8[1] = '\0';
  337. dp->drv.p->key = 0;
  338. return 1;
  339. }
  340. if(dp->drv.p->special_key != 0)
  341. {
  342. switch(dp->drv.p->special_key)
  343. {
  344. case GLUT_KEY_F1 : ev->data.key.ch = CACA_KEY_F1; break;
  345. case GLUT_KEY_F2 : ev->data.key.ch = CACA_KEY_F2; break;
  346. case GLUT_KEY_F3 : ev->data.key.ch = CACA_KEY_F3; break;
  347. case GLUT_KEY_F4 : ev->data.key.ch = CACA_KEY_F4; break;
  348. case GLUT_KEY_F5 : ev->data.key.ch = CACA_KEY_F5; break;
  349. case GLUT_KEY_F6 : ev->data.key.ch = CACA_KEY_F6; break;
  350. case GLUT_KEY_F7 : ev->data.key.ch = CACA_KEY_F7; break;
  351. case GLUT_KEY_F8 : ev->data.key.ch = CACA_KEY_F8; break;
  352. case GLUT_KEY_F9 : ev->data.key.ch = CACA_KEY_F9; break;
  353. case GLUT_KEY_F10: ev->data.key.ch = CACA_KEY_F10; break;
  354. case GLUT_KEY_F11: ev->data.key.ch = CACA_KEY_F11; break;
  355. case GLUT_KEY_F12: ev->data.key.ch = CACA_KEY_F12; break;
  356. case GLUT_KEY_LEFT : ev->data.key.ch = CACA_KEY_LEFT; break;
  357. case GLUT_KEY_RIGHT: ev->data.key.ch = CACA_KEY_RIGHT; break;
  358. case GLUT_KEY_UP : ev->data.key.ch = CACA_KEY_UP; break;
  359. case GLUT_KEY_DOWN : ev->data.key.ch = CACA_KEY_DOWN; break;
  360. case GLUT_KEY_PAGE_UP : ev->data.key.ch = CACA_KEY_PAGEUP; break;
  361. case GLUT_KEY_PAGE_DOWN : ev->data.key.ch = CACA_KEY_PAGEDOWN;
  362. break;
  363. case GLUT_KEY_HOME : ev->data.key.ch = CACA_KEY_HOME; break;
  364. case GLUT_KEY_END : ev->data.key.ch = CACA_KEY_END; break;
  365. case GLUT_KEY_INSERT : ev->data.key.ch = CACA_KEY_INSERT; break;
  366. default: ev->type = CACA_EVENT_NONE; return 0;
  367. }
  368. ev->type = CACA_EVENT_KEY_PRESS;
  369. ev->data.key.utf32 = 0;
  370. ev->data.key.utf8[0] = '\0';
  371. dp->drv.p->special_key = 0;
  372. return 1;
  373. }
  374. ev->type = CACA_EVENT_NONE;
  375. return 0;
  376. }
  377. static void gl_set_mouse(caca_display_t *dp, int flag)
  378. {
  379. if(flag)
  380. glutSetCursor(GLUT_CURSOR_RIGHT_ARROW);
  381. else
  382. glutSetCursor(GLUT_CURSOR_NONE);
  383. }
  384. /*
  385. * XXX: following functions are local
  386. */
  387. static void gl_handle_keyboard(unsigned char key, int x, int y)
  388. {
  389. caca_display_t *dp = gl_d;
  390. dp->drv.p->key = key;
  391. }
  392. static void gl_handle_special_key(int key, int x, int y)
  393. {
  394. caca_display_t *dp = gl_d;
  395. dp->drv.p->special_key = key;
  396. }
  397. static void gl_handle_reshape(int w, int h)
  398. {
  399. caca_display_t *dp = gl_d;
  400. if(dp->drv.p->bit) /* Do not handle reshaping at the first time */
  401. {
  402. dp->drv.p->new_width = w;
  403. dp->drv.p->new_height = h;
  404. dp->resize.w = w / dp->drv.p->font_width;
  405. dp->resize.h = (h / dp->drv.p->font_height) + 1;
  406. dp->resize.resized = 1;
  407. }
  408. else
  409. dp->drv.p->bit = 1;
  410. }
  411. static void gl_handle_mouse(int button, int state, int x, int y)
  412. {
  413. caca_display_t *dp = gl_d;
  414. dp->drv.p->mouse_clicked = 1;
  415. dp->drv.p->mouse_button = button;
  416. dp->drv.p->mouse_state = state;
  417. dp->drv.p->mouse_x = x / dp->drv.p->font_width;
  418. dp->drv.p->mouse_y = y / dp->drv.p->font_height;
  419. dp->mouse.x = dp->drv.p->mouse_x;
  420. dp->mouse.y = dp->drv.p->mouse_y;
  421. dp->drv.p->mouse_changed = 1;
  422. }
  423. static void gl_handle_mouse_motion(int x, int y)
  424. {
  425. caca_display_t *dp = gl_d;
  426. dp->drv.p->mouse_x = x / dp->drv.p->font_width;
  427. dp->drv.p->mouse_y = y / dp->drv.p->font_height;
  428. dp->mouse.x = dp->drv.p->mouse_x;
  429. dp->mouse.y = dp->drv.p->mouse_y;
  430. dp->drv.p->mouse_changed = 1;
  431. }
  432. #ifdef HAVE_GLUTCLOSEFUNC
  433. static void gl_handle_close(void)
  434. {
  435. caca_display_t *dp = gl_d;
  436. dp->drv.p->close = 1;
  437. }
  438. #endif
  439. static void _display(void)
  440. {
  441. caca_display_t *dp = gl_d;
  442. gl_display(dp);
  443. }
  444. /*
  445. * Driver initialisation
  446. */
  447. int gl_install(caca_display_t *dp)
  448. {
  449. #if defined(HAVE_GETENV) && defined(GLUT_XLIB_IMPLEMENTATION)
  450. if(!getenv("DISPLAY") || !*(getenv("DISPLAY")))
  451. return -1;
  452. #endif
  453. dp->drv.driver = CACA_DRIVER_GL;
  454. dp->drv.init_graphics = gl_init_graphics;
  455. dp->drv.end_graphics = gl_end_graphics;
  456. dp->drv.set_display_title = gl_set_display_title;
  457. dp->drv.get_display_width = gl_get_display_width;
  458. dp->drv.get_display_height = gl_get_display_height;
  459. dp->drv.display = gl_display;
  460. dp->drv.handle_resize = gl_handle_resize;
  461. dp->drv.get_event = gl_get_event;
  462. dp->drv.set_mouse = gl_set_mouse;
  463. return 0;
  464. }
  465. void gl_generate_glyph(uint32_t c, uint32_t tid, caca_display_t *dp) {
  466. int s,d;
  467. uint8_t *glyph8 = calloc(dp->drv.p->font_width*dp->drv.p->font_height, 1);
  468. uint8_t *glyph32 = calloc(16*16*4, 1);
  469. cucul_render_glyph(dp->drv.p->f, c,
  470. glyph8, dp->drv.p->font_width, dp->drv.p->font_height);
  471. /* Convert resulting 8bbp glyph to 32bits, 16x16*/
  472. for(s=0;s<(dp->drv.p->font_height<=16?dp->drv.p->font_height:16);s++) {
  473. for(d=0;d<dp->drv.p->font_width;d++)
  474. {
  475. uint32_t offset = d*4+(15-s)*16*4;
  476. uint8_t c = glyph8[d+s*(int)dp->drv.p->font_width];
  477. glyph32[offset] = c;
  478. glyph32[1+offset] = c;
  479. glyph32[2+offset] = c;
  480. glyph32[3+offset] = c;
  481. }
  482. }
  483. glBindTexture(GL_TEXTURE_2D, dp->drv.p->id[tid]);
  484. glTexImage2D(GL_TEXTURE_2D,
  485. 0, 4,
  486. 16,16,
  487. 0, GL_RGBA, GL_UNSIGNED_BYTE,
  488. glyph32);
  489. glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
  490. glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
  491. free(glyph8);
  492. free(glyph32);
  493. }
  494. void gl_generate_unicode_glyph(uint32_t c, uint32_t tid, caca_display_t *dp) {
  495. int s,d;
  496. uint8_t *glyph8 = calloc(dp->drv.p->font_width*dp->drv.p->font_height, 1);
  497. uint8_t *glyph32 = calloc(16*16*4, 1);
  498. cucul_render_glyph(dp->drv.p->f, c,
  499. glyph8, dp->drv.p->font_width, dp->drv.p->font_height);
  500. /* Convert resulting 8bbp glyph to 32bits, 16x16*/
  501. for(s=0;s<(dp->drv.p->font_height<=16?dp->drv.p->font_height:16);s++) {
  502. for(d=0;d<(dp->drv.p->font_width<=16?dp->drv.p->font_width:16);d++)
  503. {
  504. uint32_t offset = d*4+(15-s)*16*4;
  505. uint8_t c = glyph8[d+s*(int)dp->drv.p->font_width];
  506. glyph32[offset] = c;
  507. glyph32[1+offset] = c;
  508. glyph32[2+offset] = c;
  509. glyph32[3+offset] = c;
  510. }
  511. }
  512. glBindTexture(GL_TEXTURE_2D, dp->drv.p->id_uni[tid]);
  513. glTexImage2D(GL_TEXTURE_2D,
  514. 0, 4,
  515. 16,16,
  516. 0, GL_RGBA, GL_UNSIGNED_BYTE,
  517. glyph32);
  518. glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
  519. glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
  520. free(glyph8);
  521. free(glyph32);
  522. }
  523. #endif /* USE_GL */