Subversion Repositories Kolibri OS

Rev

Rev 4472 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4464 Serge 1
#include 
2
#include 
3
#include 
4
#include 
5
 
6
#define EGL_EGLEXT_PROTOTYPES
7
#include "EGL/egl.h"
8
#include "EGL/eglext.h"
9
#include "GL/gl.h"
10
#include "gbm.h"
11
#include 
12
#include 
13
 
14
int main()
15
{
16
    struct gbm_device *gbm;
17
    struct gbm_surface  *gs;
18
 
19
    EGLDisplay dpy;
20
    EGLint major, minor;
21
 
22
    EGLContext context;
23
    EGLSurface surface;
24
    EGLConfig config;
25
 
26
    EGLint config_attribs[32];
27
    EGLint num_configs, i;
28
    GLint list;
29
 
30
    int fd;
31
 
32
    fd = get_service("DISPLAY");
33
    gbm = gbm_create_device(fd);
34
    if( gbm == NULL){
35
        printf("failed to initialize GBM device");
36
        return 1;
37
    };
38
 
39
    dpy = eglGetDisplay((EGLNativeDisplayType)gbm);
40
 
41
    if (!eglInitialize(dpy, &major, &minor))
42
        printf("failed to initialize EGL display");
43
 
44
    printf("EGL_VERSION = %s\n", eglQueryString(dpy, EGL_VERSION));
45
    printf("EGL_VENDOR = %s\n", eglQueryString(dpy, EGL_VENDOR));
46
    printf("EGL_EXTENSIONS = %s\n", eglQueryString(dpy, EGL_EXTENSIONS));
47
    printf("EGL_CLIENT_APIS = %s\n",eglQueryString(dpy, EGL_CLIENT_APIS));
48
 
49
    i = 0;
50
    config_attribs[i++] = EGL_RED_SIZE;
51
    config_attribs[i++] = 1;
52
    config_attribs[i++] = EGL_GREEN_SIZE;
53
    config_attribs[i++] = 1;
54
    config_attribs[i++] = EGL_BLUE_SIZE;
55
    config_attribs[i++] = 1;
56
    config_attribs[i++] = EGL_DEPTH_SIZE;
57
    config_attribs[i++] = 1;
58
 
59
    config_attribs[i++] = EGL_SURFACE_TYPE;
60
    config_attribs[i++] = EGL_WINDOW_BIT;
61
 
62
    config_attribs[i++] = EGL_RENDERABLE_TYPE;
63
    config_attribs[i++] = EGL_OPENGL_BIT;
64
    config_attribs[i] = EGL_NONE;
65
 
66
    if (!eglChooseConfig(dpy,config_attribs, &config, 1, &num_configs) || !num_configs)
67
        printf("failed to choose a config");
68
 
69
    eglBindAPI(EGL_OPENGL_API);
70
    context = eglCreateContext(dpy, config, EGL_NO_CONTEXT, NULL);
71
    if (!context)
72
        printf("failed to create context");
73
 
74
    gs = gbm_surface_create(gbm, 400, 300, GBM_BO_FORMAT_ARGB8888, GBM_BO_USE_RENDERING);
75
 
76
 
77
    BeginDraw();
78
    DrawWindow(20, 20, 400+9, 300+24, "gl-render", 0x000000, 0x74);
79
    EndDraw();
80
 
81
    surface = eglCreateWindowSurface(dpy,config, (EGLNativeWindowType)gs, NULL);
82
    if (surface == EGL_NO_SURFACE)
83
        printf("failed to create surface");
84
 
85
    if (!eglMakeCurrent(dpy, surface, surface, context))
86
        printf("failed to make window current");
87
 
88
    glClearColor( 0, 0, 0, 1);
89
 
90
    list = glGenLists(1);
91
    glNewList(list, GL_COMPILE);
92
 
93
   /* XXX: this state-change will only be executed if list is called
94
    * from outside a begin/end pair:
95
    */
96
    glShadeModel( GL_FLAT );
97
    glBegin(GL_TRIANGLES);
98
    glColor3f(0,0,.7);
99
    glVertex3f( -0.9,  0.9, -30.0);
100
    glColor3f(0,.9,0);
101
    glVertex3f( -0.9, -0.9, -30.0);
102
    glColor3f(.8,0,0);
103
    glVertex3f(  0.9,  0.0, -30.0);
104
    glEnd();
105
 
106
   /* This statechange is potentially NOT redundant:
107
    */
108
    glShadeModel( GL_FLAT );
109
    glBegin(GL_TRIANGLES);
110
    glColor3f(0,1,0);
111
    glVertex3f( -0.5,  0.5, -30.0);
112
    glColor3f(0,0,1);
113
    glVertex3f( -0.5, -0.5, -30.0);
114
    glColor3f(1,0,0);
115
    glVertex3f(  0.5,  0.0, -30.0);
116
    glEnd();
117
 
118
    glEndList();
119
 
120
    glDrawBuffer(GL_BACK);
121
 
122
    glViewport(0, 0, (GLint)400, (GLint)300);
123
 
124
    glMatrixMode(GL_PROJECTION);
125
    glLoadIdentity();
126
    glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
127
    glMatrixMode(GL_MODELVIEW);
128
 
129
   asm volatile ("int3");
130
 
131
 
132
//    glClear(GL_COLOR_BUFFER_BIT);
133
 
134
    glShadeModel( GL_SMOOTH );
135
 
136
    glBegin(GL_TRIANGLES);
137
 
138
   /* Note: call the list from inside a begin/end pair.  The end is
139
    * provided by the display list...
140
    */
141
    glCallList(list);
142
    glFlush();
143
 
144
  asm volatile ("int3");
145
 
146
    eglSwapBuffers(dpy, surface);
147
 
148
    glFinish();
149
    eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
150
    eglDestroySurface(dpy, surface);
151
    gbm_surface_destroy(gs);
152
    eglDestroyContext(dpy, context);
153
    eglTerminate(dpy);
154
 
155
    while(1)
156
    {
157
        delay(1);
158
    }
159
    return 0;
160
}