Clone of mesa.
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.

demo3.c 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. /*
  2. * Exercise EGL API functions
  3. */
  4. #define EGL_EGLEXT_PROTOTYPES
  5. #include <EGL/egl.h>
  6. #include <EGL/eglext.h>
  7. #include <GL/gl.h>
  8. #include <assert.h>
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <unistd.h>
  13. #define PIXEL_CENTER(x) ((long)(x) + 0.5)
  14. #define GAP 10
  15. #define ROWS 3
  16. #define COLS 4
  17. #define OPENGL_WIDTH 48
  18. #define OPENGL_HEIGHT 13
  19. GLenum rgb, doubleBuffer, windType;
  20. GLint windW, windH;
  21. GLenum mode1, mode2;
  22. GLint boxW, boxH;
  23. GLubyte OpenGL_bits[] = {
  24. 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
  25. 0x7f, 0xfb, 0xff, 0xff, 0xff, 0x01,
  26. 0x7f, 0xfb, 0xff, 0xff, 0xff, 0x01,
  27. 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
  28. 0x3e, 0x8f, 0xb7, 0xf9, 0xfc, 0x01,
  29. 0x63, 0xdb, 0xb0, 0x8d, 0x0d, 0x00,
  30. 0x63, 0xdb, 0xb7, 0x8d, 0x0d, 0x00,
  31. 0x63, 0xdb, 0xb6, 0x8d, 0x0d, 0x00,
  32. 0x63, 0x8f, 0xf3, 0xcc, 0x0d, 0x00,
  33. 0x63, 0x00, 0x00, 0x0c, 0x4c, 0x0a,
  34. 0x63, 0x00, 0x00, 0x0c, 0x4c, 0x0e,
  35. 0x63, 0x00, 0x00, 0x8c, 0xed, 0x0e,
  36. 0x3e, 0x00, 0x00, 0xf8, 0x0c, 0x00,
  37. };
  38. static void Init(void)
  39. {
  40. mode1 = GL_TRUE;
  41. mode2 = GL_TRUE;
  42. }
  43. static void Reshape(int width, int height)
  44. {
  45. windW = (GLint)width;
  46. windH = (GLint)height;
  47. }
  48. #if 0
  49. static void RotateColorMask(void)
  50. {
  51. static GLint rotation = 0;
  52. rotation = (rotation + 1) & 0x3;
  53. switch (rotation) {
  54. case 0:
  55. glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
  56. glIndexMask( 0xff );
  57. break;
  58. case 1:
  59. glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_TRUE);
  60. glIndexMask(0xFE);
  61. break;
  62. case 2:
  63. glColorMask(GL_TRUE, GL_FALSE, GL_TRUE, GL_TRUE);
  64. glIndexMask(0xFD);
  65. break;
  66. case 3:
  67. glColorMask(GL_TRUE, GL_TRUE, GL_FALSE, GL_TRUE);
  68. glIndexMask(0xFB);
  69. break;
  70. }
  71. }
  72. #endif
  73. static void Viewport(GLint row, GLint column)
  74. {
  75. GLint x, y;
  76. boxW = (windW - (COLS + 1) * GAP) / COLS;
  77. boxH = (windH - (ROWS + 1) * GAP) / ROWS;
  78. x = GAP + column * (boxW + GAP);
  79. y = GAP + row * (boxH + GAP);
  80. glViewport(x, y, boxW, boxH);
  81. glMatrixMode(GL_PROJECTION);
  82. glLoadIdentity();
  83. glOrtho(-boxW/2, boxW/2, -boxH/2, boxH/2, 0.0, 1.0);
  84. glMatrixMode(GL_MODELVIEW);
  85. glEnable(GL_SCISSOR_TEST);
  86. glScissor(x, y, boxW, boxH);
  87. }
  88. enum {
  89. COLOR_BLACK = 0,
  90. COLOR_RED,
  91. COLOR_GREEN,
  92. COLOR_YELLOW,
  93. COLOR_BLUE,
  94. COLOR_MAGENTA,
  95. COLOR_CYAN,
  96. COLOR_WHITE
  97. };
  98. static float RGBMap[9][3] = {
  99. {0, 0, 0},
  100. {1, 0, 0},
  101. {0, 1, 0},
  102. {1, 1, 0},
  103. {0, 0, 1},
  104. {1, 0, 1},
  105. {0, 1, 1},
  106. {1, 1, 1},
  107. {0.5, 0.5, 0.5}
  108. };
  109. static void SetColor(int c)
  110. {
  111. glColor3fv(RGBMap[c]);
  112. }
  113. static void Point(void)
  114. {
  115. GLint i;
  116. glBegin(GL_POINTS);
  117. SetColor(COLOR_WHITE);
  118. glVertex2i(0, 0);
  119. for (i = 1; i < 8; i++) {
  120. GLint j = i * 2;
  121. SetColor(COLOR_BLACK+i);
  122. glVertex2i(-j, -j);
  123. glVertex2i(-j, 0);
  124. glVertex2i(-j, j);
  125. glVertex2i(0, j);
  126. glVertex2i(j, j);
  127. glVertex2i(j, 0);
  128. glVertex2i(j, -j);
  129. glVertex2i(0, -j);
  130. }
  131. glEnd();
  132. }
  133. static void Lines(void)
  134. {
  135. GLint i;
  136. glPushMatrix();
  137. glTranslatef(-12, 0, 0);
  138. for (i = 1; i < 8; i++) {
  139. SetColor(COLOR_BLACK+i);
  140. glBegin(GL_LINES);
  141. glVertex2i(-boxW/4, -boxH/4);
  142. glVertex2i(boxW/4, boxH/4);
  143. glEnd();
  144. glTranslatef(4, 0, 0);
  145. }
  146. glPopMatrix();
  147. glBegin(GL_LINES);
  148. glVertex2i(0, 0);
  149. glEnd();
  150. }
  151. static void LineStrip(void)
  152. {
  153. glBegin(GL_LINE_STRIP);
  154. SetColor(COLOR_RED);
  155. glVertex2f(PIXEL_CENTER(-boxW/4), PIXEL_CENTER(-boxH/4));
  156. SetColor(COLOR_GREEN);
  157. glVertex2f(PIXEL_CENTER(-boxW/4), PIXEL_CENTER(boxH/4));
  158. SetColor(COLOR_BLUE);
  159. glVertex2f(PIXEL_CENTER(boxW/4), PIXEL_CENTER(boxH/4));
  160. SetColor(COLOR_WHITE);
  161. glVertex2f(PIXEL_CENTER(boxW/4), PIXEL_CENTER(-boxH/4));
  162. glEnd();
  163. glBegin(GL_LINE_STRIP);
  164. glVertex2i(0, 0);
  165. glEnd();
  166. }
  167. static void LineLoop(void)
  168. {
  169. glBegin(GL_LINE_LOOP);
  170. SetColor(COLOR_RED);
  171. glVertex2f(PIXEL_CENTER(-boxW/4), PIXEL_CENTER(-boxH/4));
  172. SetColor(COLOR_GREEN);
  173. glVertex2f(PIXEL_CENTER(-boxW/4), PIXEL_CENTER(boxH/4));
  174. SetColor(COLOR_BLUE);
  175. glVertex2f(PIXEL_CENTER(boxW/4), PIXEL_CENTER(boxH/4));
  176. SetColor(COLOR_WHITE);
  177. glVertex2f(PIXEL_CENTER(boxW/4), PIXEL_CENTER(-boxH/4));
  178. glEnd();
  179. glEnable(GL_LOGIC_OP);
  180. glLogicOp(GL_XOR);
  181. glEnable(GL_BLEND);
  182. glBlendFunc(GL_ONE, GL_ONE);
  183. SetColor(COLOR_MAGENTA);
  184. glBegin(GL_LINE_LOOP);
  185. glVertex2f(PIXEL_CENTER(-boxW/8), PIXEL_CENTER(-boxH/8));
  186. glVertex2f(PIXEL_CENTER(-boxW/8), PIXEL_CENTER(boxH/8));
  187. glEnd();
  188. glBegin(GL_LINE_LOOP);
  189. glVertex2f(PIXEL_CENTER(-boxW/8), PIXEL_CENTER(boxH/8+5));
  190. glVertex2f(PIXEL_CENTER(boxW/8), PIXEL_CENTER(boxH/8+5));
  191. glEnd();
  192. glDisable(GL_LOGIC_OP);
  193. glDisable(GL_BLEND);
  194. SetColor(COLOR_GREEN);
  195. glBegin(GL_POINTS);
  196. glVertex2i(0, 0);
  197. glEnd();
  198. glBegin(GL_LINE_LOOP);
  199. glVertex2i(0, 0);
  200. glEnd();
  201. }
  202. static void Bitmap(void)
  203. {
  204. glBegin(GL_LINES);
  205. SetColor(COLOR_GREEN);
  206. glVertex2i(-boxW/2, 0);
  207. glVertex2i(boxW/2, 0);
  208. glVertex2i(0, -boxH/2);
  209. glVertex2i(0, boxH/2);
  210. SetColor(COLOR_RED);
  211. glVertex2i(0, -3);
  212. glVertex2i(0, -3+OPENGL_HEIGHT);
  213. SetColor(COLOR_BLUE);
  214. glVertex2i(0, -3);
  215. glVertex2i(OPENGL_WIDTH, -3);
  216. glEnd();
  217. SetColor(COLOR_GREEN);
  218. glPixelStorei(GL_UNPACK_LSB_FIRST, GL_TRUE);
  219. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  220. glRasterPos2i(0, 0);
  221. glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, 0, 3, 0.0, 0.0, OpenGL_bits);
  222. }
  223. static void Triangles(void)
  224. {
  225. glBegin(GL_TRIANGLES);
  226. SetColor(COLOR_GREEN);
  227. glVertex2i(-boxW/4, -boxH/4);
  228. SetColor(COLOR_RED);
  229. glVertex2i(-boxW/8, -boxH/16);
  230. SetColor(COLOR_BLUE);
  231. glVertex2i(boxW/8, -boxH/16);
  232. SetColor(COLOR_GREEN);
  233. glVertex2i(-boxW/4, boxH/4);
  234. SetColor(COLOR_RED);
  235. glVertex2i(-boxW/8, boxH/16);
  236. SetColor(COLOR_BLUE);
  237. glVertex2i(boxW/8, boxH/16);
  238. glEnd();
  239. glBegin(GL_TRIANGLES);
  240. glVertex2i(0, 0);
  241. glVertex2i(-100, 100);
  242. glEnd();
  243. }
  244. static void TriangleStrip(void)
  245. {
  246. glBegin(GL_TRIANGLE_STRIP);
  247. SetColor(COLOR_GREEN);
  248. glVertex2i(-boxW/4, -boxH/4);
  249. SetColor(COLOR_RED);
  250. glVertex2i(-boxW/4, boxH/4);
  251. SetColor(COLOR_BLUE);
  252. glVertex2i(0, -boxH/4);
  253. SetColor(COLOR_WHITE);
  254. glVertex2i(0, boxH/4);
  255. SetColor(COLOR_CYAN);
  256. glVertex2i(boxW/4, -boxH/4);
  257. SetColor(COLOR_YELLOW);
  258. glVertex2i(boxW/4, boxH/4);
  259. glEnd();
  260. glBegin(GL_TRIANGLE_STRIP);
  261. glVertex2i(0, 0);
  262. glVertex2i(-100, 100);
  263. glEnd();
  264. }
  265. static void TriangleFan(void)
  266. {
  267. GLint vx[8][2];
  268. GLint x0, y0, x1, y1, x2, y2, x3, y3;
  269. GLint i;
  270. y0 = -boxH/4;
  271. y1 = y0 + boxH/2/3;
  272. y2 = y1 + boxH/2/3;
  273. y3 = boxH/4;
  274. x0 = -boxW/4;
  275. x1 = x0 + boxW/2/3;
  276. x2 = x1 + boxW/2/3;
  277. x3 = boxW/4;
  278. vx[0][0] = x0; vx[0][1] = y1;
  279. vx[1][0] = x0; vx[1][1] = y2;
  280. vx[2][0] = x1; vx[2][1] = y3;
  281. vx[3][0] = x2; vx[3][1] = y3;
  282. vx[4][0] = x3; vx[4][1] = y2;
  283. vx[5][0] = x3; vx[5][1] = y1;
  284. vx[6][0] = x2; vx[6][1] = y0;
  285. vx[7][0] = x1; vx[7][1] = y0;
  286. glBegin(GL_TRIANGLE_FAN);
  287. SetColor(COLOR_WHITE);
  288. glVertex2i(0, 0);
  289. for (i = 0; i < 8; i++) {
  290. SetColor(COLOR_WHITE-i);
  291. glVertex2iv(vx[i]);
  292. }
  293. glEnd();
  294. glBegin(GL_TRIANGLE_FAN);
  295. glVertex2i(0, 0);
  296. glVertex2i(-100, 100);
  297. glEnd();
  298. }
  299. static void Rect(void)
  300. {
  301. SetColor(COLOR_GREEN);
  302. glRecti(-boxW/4, -boxH/4, boxW/4, boxH/4);
  303. }
  304. static void PolygonFunc(void)
  305. {
  306. GLint vx[8][2];
  307. GLint x0, y0, x1, y1, x2, y2, x3, y3;
  308. GLint i;
  309. y0 = -boxH/4;
  310. y1 = y0 + boxH/2/3;
  311. y2 = y1 + boxH/2/3;
  312. y3 = boxH/4;
  313. x0 = -boxW/4;
  314. x1 = x0 + boxW/2/3;
  315. x2 = x1 + boxW/2/3;
  316. x3 = boxW/4;
  317. vx[0][0] = x0; vx[0][1] = y1;
  318. vx[1][0] = x0; vx[1][1] = y2;
  319. vx[2][0] = x1; vx[2][1] = y3;
  320. vx[3][0] = x2; vx[3][1] = y3;
  321. vx[4][0] = x3; vx[4][1] = y2;
  322. vx[5][0] = x3; vx[5][1] = y1;
  323. vx[6][0] = x2; vx[6][1] = y0;
  324. vx[7][0] = x1; vx[7][1] = y0;
  325. glBegin(GL_POLYGON);
  326. for (i = 0; i < 8; i++) {
  327. SetColor(COLOR_WHITE-i);
  328. glVertex2iv(vx[i]);
  329. }
  330. glEnd();
  331. glBegin(GL_POLYGON);
  332. glVertex2i(0, 0);
  333. glVertex2i(100, 100);
  334. glEnd();
  335. }
  336. static void Quads(void)
  337. {
  338. glBegin(GL_QUADS);
  339. SetColor(COLOR_GREEN);
  340. glVertex2i(-boxW/4, -boxH/4);
  341. SetColor(COLOR_RED);
  342. glVertex2i(-boxW/8, -boxH/16);
  343. SetColor(COLOR_BLUE);
  344. glVertex2i(boxW/8, -boxH/16);
  345. SetColor(COLOR_WHITE);
  346. glVertex2i(boxW/4, -boxH/4);
  347. SetColor(COLOR_GREEN);
  348. glVertex2i(-boxW/4, boxH/4);
  349. SetColor(COLOR_RED);
  350. glVertex2i(-boxW/8, boxH/16);
  351. SetColor(COLOR_BLUE);
  352. glVertex2i(boxW/8, boxH/16);
  353. SetColor(COLOR_WHITE);
  354. glVertex2i(boxW/4, boxH/4);
  355. glEnd();
  356. glBegin(GL_QUADS);
  357. glVertex2i(0, 0);
  358. glVertex2i(100, 100);
  359. glVertex2i(-100, 100);
  360. glEnd();
  361. }
  362. static void QuadStrip(void)
  363. {
  364. glBegin(GL_QUAD_STRIP);
  365. SetColor(COLOR_GREEN);
  366. glVertex2i(-boxW/4, -boxH/4);
  367. SetColor(COLOR_RED);
  368. glVertex2i(-boxW/4, boxH/4);
  369. SetColor(COLOR_BLUE);
  370. glVertex2i(0, -boxH/4);
  371. SetColor(COLOR_WHITE);
  372. glVertex2i(0, boxH/4);
  373. SetColor(COLOR_CYAN);
  374. glVertex2i(boxW/4, -boxH/4);
  375. SetColor(COLOR_YELLOW);
  376. glVertex2i(boxW/4, boxH/4);
  377. glEnd();
  378. glBegin(GL_QUAD_STRIP);
  379. glVertex2i(0, 0);
  380. glVertex2i(100, 100);
  381. glVertex2i(-100, 100);
  382. glEnd();
  383. }
  384. static void Draw(EGLDisplay dpy, EGLSurface surf)
  385. {
  386. glViewport(0, 0, windW, windH);
  387. glDisable(GL_SCISSOR_TEST);
  388. glPushAttrib(GL_COLOR_BUFFER_BIT);
  389. glColorMask(1, 1, 1, 1);
  390. glIndexMask(~0);
  391. glClearColor(0.0, 0.0, 0.0, 0.0);
  392. glClear(GL_COLOR_BUFFER_BIT);
  393. glPopAttrib();
  394. if (mode1) {
  395. glShadeModel(GL_SMOOTH);
  396. } else {
  397. glShadeModel(GL_FLAT);
  398. }
  399. if (mode2) {
  400. glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  401. } else {
  402. glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  403. }
  404. Viewport(0, 0); Point();
  405. Viewport(0, 1); Lines();
  406. Viewport(0, 2); LineStrip();
  407. Viewport(0, 3); LineLoop();
  408. Viewport(1, 0); Bitmap();
  409. Viewport(1, 1); TriangleFan();
  410. Viewport(1, 2); Triangles();
  411. Viewport(1, 3); TriangleStrip();
  412. Viewport(2, 0); Rect();
  413. Viewport(2, 1); PolygonFunc();
  414. Viewport(2, 2); Quads();
  415. Viewport(2, 3); QuadStrip();
  416. glFlush();
  417. if (doubleBuffer) {
  418. eglSwapBuffers(dpy, surf);
  419. }
  420. }
  421. static void
  422. write_ppm(const char *filename, const GLubyte *buffer, int width, int height)
  423. {
  424. const int binary = 0;
  425. FILE *f = fopen( filename, "w" );
  426. if (f) {
  427. int i, x, y;
  428. const GLubyte *ptr = buffer;
  429. if (binary) {
  430. fprintf(f,"P6\n");
  431. fprintf(f,"# ppm-file created by osdemo.c\n");
  432. fprintf(f,"%i %i\n", width,height);
  433. fprintf(f,"255\n");
  434. fclose(f);
  435. f = fopen( filename, "ab" ); /* reopen in binary append mode */
  436. for (y=height-1; y>=0; y--) {
  437. for (x=0; x<width; x++) {
  438. i = (y*width + x) * 4;
  439. fputc(ptr[i], f); /* write red */
  440. fputc(ptr[i+1], f); /* write green */
  441. fputc(ptr[i+2], f); /* write blue */
  442. }
  443. }
  444. }
  445. else {
  446. /*ASCII*/
  447. int counter = 0;
  448. fprintf(f,"P3\n");
  449. fprintf(f,"# ascii ppm file created by osdemo.c\n");
  450. fprintf(f,"%i %i\n", width, height);
  451. fprintf(f,"255\n");
  452. for (y=height-1; y>=0; y--) {
  453. for (x=0; x<width; x++) {
  454. i = (y*width + x) * 4;
  455. fprintf(f, " %3d %3d %3d", ptr[i], ptr[i+1], ptr[i+2]);
  456. counter++;
  457. if (counter % 5 == 0)
  458. fprintf(f, "\n");
  459. }
  460. }
  461. }
  462. fclose(f);
  463. }
  464. }
  465. int
  466. main(int argc, char *argv[])
  467. {
  468. int maj, min;
  469. EGLContext ctx;
  470. EGLSurface screen_surf;
  471. EGLConfig configs[10];
  472. EGLScreenMESA screen;
  473. EGLModeMESA mode;
  474. EGLint numConfigs, count;
  475. EGLBoolean b;
  476. const GLubyte *bitmap;
  477. EGLint screenAttribs[32];
  478. EGLint i;
  479. EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY);
  480. assert(d);
  481. if (!eglInitialize(d, &maj, &min)) {
  482. printf("demo: eglInitialize failed\n");
  483. exit(1);
  484. }
  485. printf("EGL version = %d.%d\n", maj, min);
  486. printf("EGL_VENDOR = %s\n", eglQueryString(d, EGL_VENDOR));
  487. if (!strstr(eglQueryString(d, EGL_EXTENSIONS),
  488. "EGL_MESA_screen_surface")) {
  489. printf("EGL_MESA_screen_surface is not supported\n");
  490. exit(1);
  491. }
  492. eglGetConfigs(d, configs, 10, &numConfigs);
  493. eglGetScreensMESA(d, &screen, 1, &count);
  494. eglGetModesMESA(d, screen, &mode, 1, &count);
  495. eglBindAPI(EGL_OPENGL_API);
  496. ctx = eglCreateContext(d, configs[0], EGL_NO_CONTEXT, NULL);
  497. if (ctx == EGL_NO_CONTEXT) {
  498. printf("failed to create context\n");
  499. return 0;
  500. }
  501. i = 0;
  502. screenAttribs[i++] = EGL_WIDTH;
  503. eglGetModeAttribMESA(d, mode, EGL_WIDTH, &screenAttribs[i++]);
  504. screenAttribs[i++] = EGL_HEIGHT;
  505. eglGetModeAttribMESA(d, mode, EGL_HEIGHT, &screenAttribs[i++]);
  506. screenAttribs[i] = EGL_NONE;
  507. screen_surf = eglCreateScreenSurfaceMESA(d, configs[0], screenAttribs);
  508. if (screen_surf == EGL_NO_SURFACE) {
  509. printf("failed to create screen surface\n");
  510. return 0;
  511. }
  512. eglShowScreenSurfaceMESA(d, screen, screen_surf, mode);
  513. b = eglMakeCurrent(d, screen_surf, screen_surf, ctx);
  514. if (!b) {
  515. printf("make current failed\n");
  516. return 0;
  517. }
  518. glViewport(0, 0, 1024, 768);
  519. Init();
  520. Reshape(1024, 768);
  521. /* some drivers crash when rendering to front buffer */
  522. #if 0
  523. glDrawBuffer( GL_FRONT );
  524. glClearColor( 0, 1.0, 0, 1);
  525. glClear( GL_COLOR_BUFFER_BIT );
  526. #endif
  527. doubleBuffer = 1;
  528. glDrawBuffer( GL_BACK );
  529. Draw(d, screen_surf);
  530. sleep(2);
  531. /* TODO EGL_KHR_lock_surface */
  532. bitmap = NULL;
  533. if (bitmap)
  534. write_ppm("dump.ppm", bitmap, 1024, 768);
  535. eglDestroySurface(d, screen_surf);
  536. eglDestroyContext(d, ctx);
  537. eglTerminate(d);
  538. return 0;
  539. }