source: trunk/sys/TinyGL/examples/soclibfb_almOS.c @ 266

Last change on this file since 266 was 1, checked in by alain, 7 years ago

First import

File size: 2.2 KB
Line 
1/*
2 * Demonstration program for SOCLIB FB graphics on ALMOS.
3 */
4#include <stdlib.h>
5#include <stdio.h>
6#include <sys/mman.h>
7#include <GL/gl.h> 
8#include <GL/oscontext.h> 
9#include "ui.h"
10
11void tkSwapBuffers(void)
12{
13    nglXSwapBuffers(w1);
14}
15
16static ostgl_context *ctx;
17
18int ui_loop(int argc, char **argv, const char *name)
19{
20  void *dsiplay;
21  size_t xsize;
22  size_t ysize;
23  size_t mode;
24  size_t pgsize;
25  size_t size;
26  clock_t tm_tmp;
27  clock_t tm_now;
28  int fd;
29 
30  pgsize = sysconf(_SC_PAGE_SIZE);
31
32  if(pgsize < 0)
33  {
34    fprintf(stderr, "ERROR: sysconf pgsize got %u\n", pgsize);
35    exit(1);
36  }
37
38  int fd = open("/ETC/FBRC", O_RDONLY, 420);
39
40  if(fd < 0)
41  {
42    fprintf(stderr, "ERROR: cannot read /etc/fbrc configuration file\n");
43    exit(2);
44  }
45
46  xsize = 0;
47  ysize = 0;
48
49  fscanf(fd, "XSIZE=%u\n", &xsize);
50  fscanf(fd, "YSIZE=%u\n", &ysize);
51  fscanf(fd, "MODE=%u\n", &mode);
52
53  close(fd);
54 
55  if((xsize == 0) || (ysize == 0) || (mode != 16))
56  {
57    fprintf(stderr, "ERROR: dont like these info: xsize %d, ysize %d, mode %d\n", 
58            xsize,
59            ysize,
60            mode);
61
62    exit(3);
63  }
64 
65  size = xsize * ysize * 2;
66
67  size = (size & (pgsize - 1)) ? (size & ~(pgsize - 1)) + pgsize : pgsize;
68
69  if((fd = open("/DEV/FB0",O_WRONLY,420)) == -1)
70  {
71    fprintf(stderr, "ERROR: cannot open /dev/fb0\n");
72    exit(4);
73  }
74
75  display = mmap(NULL, 
76                 size,
77                 PROT_WRITE | PROT_READ, 
78                 MAP_SHARED | MAP_FILE, 
79                 fd, 0);
80 
81  close(fd);
82
83  if(display == MAP_FAILED) 
84  {
85    perror("mmap dest file");
86    exit(5);
87  }
88 
89  ctx = ostgl_create_context(xsize, ysize, 16, &display, 1);
90
91  if(ctx == NULL)
92  {
93    fprintf(stderr, "ERROR: failed to create ostgl ctx\n");
94    exit(6);
95  }
96 
97  if(ostgl_make_current(ctx,0) != 0)
98  {
99    fprintf(stderr, "ERROR: failed to make current ctx\n");
100    exit(7);
101  }
102 
103  fprintf(stderr, "Initializing scene ..");
104  tm_tmp = clock();
105  init();
106  tm_now = clock();
107  fprintf(stderr, " done [%llu]\n", tm_now - tm_tmp);
108
109  fprintf(stderr, "Shape scene ..");
110  tm_tmp = clock();
111  reshape(xsize,ysize);
112  tm_now = clock();
113  fprintf(stderr, " done [%llu]\n", tm_now - tm_tmp);
114
115  while (1) 
116  {
117    idle();
118    fprintf(stderr, "Time now %llu\n", clock());
119  }
120   
121  return 0;
122}
Note: See TracBrowser for help on using the repository browser.