Rev 4498 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4464 | Serge | 1 | #include |
2 | #include |
||
3 | #include |
||
4 | #include |
||
5 | |||
5024 | Serge | 6 | #include |
4464 | Serge | 7 | #include "gbm.h" |
8 | #include |
||
9 | |||
4498 | Serge | 10 | |
4464 | Serge | 11 | int main() |
12 | { |
||
13 | struct gbm_device *gbm; |
||
14 | struct gbm_surface *gs; |
||
4498 | Serge | 15 | struct render *render; |
4464 | Serge | 16 | |
17 | EGLDisplay dpy; |
||
18 | EGLint major, minor; |
||
19 | |||
20 | EGLContext context; |
||
21 | EGLSurface surface; |
||
4498 | Serge | 22 | |
4464 | Serge | 23 | EGLConfig config; |
24 | |||
25 | EGLint config_attribs[32]; |
||
26 | EGLint num_configs, i; |
||
5024 | Serge | 27 | int width = 400; |
28 | int height = 300; |
||
29 | int skinh; |
||
30 | int run =1; |
||
4464 | Serge | 31 | |
32 | int fd; |
||
33 | |||
34 | fd = get_service("DISPLAY"); |
||
35 | gbm = gbm_create_device(fd); |
||
36 | if( gbm == NULL){ |
||
37 | printf("failed to initialize GBM device"); |
||
38 | return 1; |
||
39 | }; |
||
40 | |||
41 | dpy = eglGetDisplay((EGLNativeDisplayType)gbm); |
||
42 | |||
43 | if (!eglInitialize(dpy, &major, &minor)) |
||
44 | printf("failed to initialize EGL display"); |
||
45 | |||
46 | printf("EGL_VERSION = %s\n", eglQueryString(dpy, EGL_VERSION)); |
||
47 | printf("EGL_VENDOR = %s\n", eglQueryString(dpy, EGL_VENDOR)); |
||
48 | printf("EGL_EXTENSIONS = %s\n", eglQueryString(dpy, EGL_EXTENSIONS)); |
||
49 | printf("EGL_CLIENT_APIS = %s\n",eglQueryString(dpy, EGL_CLIENT_APIS)); |
||
50 | |||
51 | i = 0; |
||
52 | config_attribs[i++] = EGL_RED_SIZE; |
||
53 | config_attribs[i++] = 1; |
||
54 | config_attribs[i++] = EGL_GREEN_SIZE; |
||
55 | config_attribs[i++] = 1; |
||
56 | config_attribs[i++] = EGL_BLUE_SIZE; |
||
57 | config_attribs[i++] = 1; |
||
58 | config_attribs[i++] = EGL_DEPTH_SIZE; |
||
59 | config_attribs[i++] = 1; |
||
60 | |||
61 | config_attribs[i++] = EGL_SURFACE_TYPE; |
||
62 | config_attribs[i++] = EGL_WINDOW_BIT; |
||
63 | |||
64 | config_attribs[i++] = EGL_RENDERABLE_TYPE; |
||
65 | config_attribs[i++] = EGL_OPENGL_BIT; |
||
66 | config_attribs[i] = EGL_NONE; |
||
67 | |||
68 | if (!eglChooseConfig(dpy,config_attribs, &config, 1, &num_configs) || !num_configs) |
||
69 | printf("failed to choose a config"); |
||
70 | |||
71 | eglBindAPI(EGL_OPENGL_API); |
||
72 | context = eglCreateContext(dpy, config, EGL_NO_CONTEXT, NULL); |
||
73 | if (!context) |
||
74 | printf("failed to create context"); |
||
75 | |||
5024 | Serge | 76 | gs = gbm_surface_create(gbm, width, height, GBM_BO_FORMAT_ARGB8888, GBM_BO_USE_RENDERING); |
4464 | Serge | 77 | |
5024 | Serge | 78 | skinh = get_skin_height(); |
79 | |||
4464 | Serge | 80 | BeginDraw(); |
5024 | Serge | 81 | DrawWindow(20, 20, width+TYPE_3_BORDER_WIDTH*2, |
82 | height+TYPE_3_BORDER_WIDTH+skinh, "gl-render", 0x000000, 0x74); |
||
4464 | Serge | 83 | EndDraw(); |
84 | |||
4495 | Serge | 85 | surface = eglCreateWindowSurface(dpy,config, (EGLNativeWindowType)gs, NULL); |
86 | if (surface == EGL_NO_SURFACE) |
||
87 | printf("failed to create surface"); |
||
4464 | Serge | 88 | |
4495 | Serge | 89 | if (!eglMakeCurrent(dpy, surface, surface, context)) |
4464 | Serge | 90 | printf("failed to make window current"); |
91 | |||
4472 | Serge | 92 | |
4485 | Serge | 93 | glMatrixMode(GL_PROJECTION); |
94 | glLoadIdentity(); |
||
95 | glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); |
||
96 | glMatrixMode(GL_MODELVIEW); |
||
97 | glLoadIdentity(); |
||
98 | |||
5024 | Serge | 99 | glViewport(0, 0, width, height); |
4485 | Serge | 100 | |
101 | glClearColor( 0, 0, 0, 1); |
||
102 | |||
103 | glClear(GL_COLOR_BUFFER_BIT); |
||
104 | |||
105 | glBegin(GL_QUADS); |
||
106 | glColor3f(1,0,0); |
||
107 | glVertex3f( 0.9, -0.9, -30.0); |
||
108 | glColor3f(1,1,0); |
||
109 | glVertex3f( 0.9, 0.9, -30.0); |
||
110 | |||
111 | glColor3f(1,1,1); |
||
112 | glVertex3f( 0.1, 0.9, -30.0); |
||
113 | glColor3f(1,0,1); |
||
114 | glVertex3f( 0.1, -0.9, -30.0); |
||
115 | glEnd(); |
||
116 | |||
117 | glFlush(); |
||
118 | |||
5024 | Serge | 119 | // asm volatile ("int3"); |
4485 | Serge | 120 | |
5024 | Serge | 121 | render = create_render(dpy, surface, TYPE_3_BORDER_WIDTH, skinh); |
122 | render_blit(render, PX_BACK); |
||
4464 | Serge | 123 | |
5024 | Serge | 124 | while (run) |
125 | { |
||
126 | oskey_t key; |
||
127 | int ev; |
||
4464 | Serge | 128 | |
5024 | Serge | 129 | ev = get_os_event(); |
130 | switch(ev) |
||
131 | { |
||
132 | case 1: |
||
133 | BeginDraw(); |
||
134 | DrawWindow(0,0,0,0,NULL,0,0x74); |
||
135 | EndDraw(); |
||
136 | render_blit(render, PX_BACK); |
||
137 | break; |
||
138 | |||
139 | case 2: |
||
140 | key = get_key(); |
||
141 | if (key.code == 27) |
||
142 | run = 0; |
||
143 | break; |
||
144 | |||
145 | case 3: |
||
146 | if(get_os_button()==1) |
||
147 | run = 0; |
||
148 | break; |
||
149 | }; |
||
150 | } |
||
151 | |||
152 | |||
4464 | Serge | 153 | glFinish(); |
154 | eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); |
||
4473 | Serge | 155 | // eglDestroySurface(dpy, surface); |
156 | // gbm_surface_destroy(gs); |
||
4464 | Serge | 157 | eglDestroyContext(dpy, context); |
158 | eglTerminate(dpy); |
||
159 | |||
160 | return 0; |
||
161 | } |
||
4472 | Serge | 162 | |
163 | |||
4498 | Serge | 164 | #if 0 |
4485 | Serge | 165 | GLuint create_framebuffer(int width, int height, GLuint *tex) |
166 | { |
||
167 | GLuint buffer; |
||
168 | |||
169 | glGenTextures(1, tex); |
||
170 | glBindTexture(GL_TEXTURE_2D, *tex); |
||
171 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); |
||
172 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); |
||
173 | |||
174 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, |
||
175 | GL_UNSIGNED_BYTE, NULL); |
||
176 | glBindTexture(GL_TEXTURE_2D, 0); |
||
177 | |||
178 | glGenFramebuffers(1, &buffer); |
||
179 | glBindFramebuffer(GL_FRAMEBUFFER, buffer); |
||
180 | glFramebufferTexture2D(GL_FRAMEBUFFER, |
||
181 | GL_COLOR_ATTACHMENT0, |
||
182 | GL_TEXTURE_2D, *tex,0); |
||
183 | return buffer; |
||
184 | } |
||
4498 | Serge | 185 | #endif |