include EGL egl include iostream include stdio static const EGLint con

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
#include <EGL/egl.h>
#include <iostream>
#include <stdio.h>
static const EGLint configAttribs[] = {
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
EGL_BLUE_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_RED_SIZE, 8,
EGL_DEPTH_SIZE, 8,
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
EGL_NONE
};
static const int pbufferWidth = 9;
static const int pbufferHeight = 9;
static const EGLint pbufferAttribs[] = {
EGL_WIDTH, pbufferWidth,
EGL_HEIGHT, pbufferHeight,
EGL_NONE,
};
void assertEGLError(const std::string& msg) {
EGLint error = eglGetError();
if (error != EGL_SUCCESS) {
printf("ERror %X\n", error);
}
}
int main(int argc, char *argv[])
{
#if defined(_WIN32) || defined(__VC32__) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) /* Win32 and WinCE */
std::cout << "WIN32\n";
#elif defined(__WINSCW__) || defined(__SYMBIAN32__) /* Symbian */
std::cout << "WINCW\n";
#elif defined(WL_EGL_PLATFORM)
std::cout << "WL\n";
#elif defined(__GBM__)
std::cout << "GBM\n";
#elif defined(__ANDROID__) || defined(ANDROID)
std::cout << "ANDROID\n";
#elif defined(USE_OZONE)
std::cout << "OZONE\n";
#elif defined(__unix__) || defined(__APPLE__)
#if defined(MESA_EGL_NO_X11_HEADERS)
std::cout << "MESANOX11\n";
#else
std::cout << "X11\n";
#endif /* MESA_EGL_NO_X11_HEADERS */
#elif defined(__HAIKU__)
std::cout << "Haiku\n";
#else
std::cout << "ERROr\n";
#endif
// 1. Initialize EGL
EGLDisplay eglDpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
assertEGLError("1");
EGLint major, minor;
eglInitialize(eglDpy, &major, &minor);
assertEGLError("2");
// 2. Select an appropriate configuration
EGLint numConfigs;
EGLConfig eglCfg;
eglChooseConfig(eglDpy, configAttribs, &eglCfg, 1, &numConfigs);
// 3. Create a surface
EGLSurface eglSurf = eglCreatePbufferSurface(eglDpy, eglCfg,
pbufferAttribs);
// 4. Bind the API
eglBindAPI(EGL_OPENGL_API);
// 5. Create a context and make it current
EGLContext eglCtx = eglCreateContext(eglDpy, eglCfg, EGL_NO_CONTEXT,
NULL);
eglMakeCurrent(eglDpy, eglSurf, eglSurf, eglCtx);
// from now on use your OpenGL context
// 6. Terminate EGL when finished
eglTerminate(eglDpy);
return 0;
}