Last active
December 16, 2024 02:22
Simple way to get OpenGL renderer string with EGL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Based on https://community.khronos.org/t/offscreen-rendering-using-opengl-and-egl/109487/20 | |
#include <EGL/egl.h> | |
#include <EGL/eglext.h> | |
#include <GL/gl.h> | |
#include <stdio.h> | |
const int WIDTH = 1920; // arbitrary | |
const int HEIGHT = 1080; // arbitrary | |
int main(int argc, char *argv[]) | |
{ | |
EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); | |
EGLint major; | |
EGLint minor; | |
eglInitialize(display, &major, &minor); | |
eglBindAPI(EGL_OPENGL_API); | |
printf("EGL version: %d.%d\n", major, minor); | |
EGLint configAttribs[] = {EGL_SURFACE_TYPE, | |
EGL_PBUFFER_BIT, | |
EGL_RED_SIZE, | |
8, | |
EGL_GREEN_SIZE, | |
8, | |
EGL_BLUE_SIZE, | |
8, | |
EGL_ALPHA_SIZE, | |
8, | |
EGL_RENDERABLE_TYPE, | |
EGL_OPENGL_ES_BIT, // <- This seems to override the value in eglBindAPI | |
EGL_NONE}; | |
EGLConfig config; | |
EGLint numConfigs; | |
eglChooseConfig(display, configAttribs, &config, 1, &numConfigs); | |
EGLint contextAttribs[] = {EGL_CONTEXT_MAJOR_VERSION, | |
3, | |
EGL_CONTEXT_MINOR_VERSION, | |
0, | |
EGL_NONE}; | |
EGLContext eglContext = | |
eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttribs); | |
EGLint surfaceAttribs[] = {EGL_WIDTH, WIDTH, EGL_HEIGHT, HEIGHT, EGL_NONE}; | |
EGLSurface surface = | |
eglCreatePbufferSurface(display, config, surfaceAttribs); | |
eglMakeCurrent(display, surface, surface, eglContext); | |
/** Done initializing */ | |
int gl_major_version; | |
int gl_minor_version; | |
glGetIntegerv(GL_MAJOR_VERSION, &gl_major_version); | |
glGetIntegerv(GL_MINOR_VERSION, &gl_minor_version); | |
printf("OpenGL context created.\nOpenGL Version: %d.%d\nVendor: " | |
"%s\nRenderer: %s\nVersion String: %s\n", | |
gl_major_version, gl_minor_version, glGetString(GL_VENDOR), | |
glGetString(GL_RENDERER), glGetString(GL_VERSION)); | |
eglDestroyContext(display, eglContext); | |
eglDestroySurface(display, surface); | |
eglTerminate(display); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compile with:
gcc simple-egl-render-string.c -Wall -lEGL -lGLESv2 && ./a.out