Hello! Here's some CODE!!! #include <iostream> #include <stdio.h> #include <assert.h> #include <string.h> #include <fcntl.h> #include <malloc.h> #include <math.h> #include <stdlib.h> //#define EGL_USE_GLES2 #include <GLES2/gl2.h> #include <EGL/egl.h> #include <GLES2/gl2ext.h> #include <EGL/eglext.h> #include <termios.h> #include <unistd.h> #include <fcntl.h> #ifdef EGL_USE_X11 #include <X11/X.h> #include <X11/Xlib.h> #endif EGLDisplay egldisplay; EGLConfig eglconfig; EGLSurface eglsurface; EGLContext eglcontext; EGLNativeWindowType eglNativeWindow; EGLNativeDisplayType eglNativeDisplayType; EGLNativeDisplayType fsl_getNativeDisplay() { EGLNativeDisplayType eglNativeDisplayType = NULL; #if (defined EGL_USE_X11) eglNativeDisplayType = XOpenDisplay(NULL); assert(eglNativeDisplayType != NULL); #elif (defined EGL_API_FB) eglNativeDisplayType = fbGetDisplayByIndex(0); //Pass the argument as required to show the framebuffer #else display = EGL_DEFAULT_DISPLAY; #endif return eglNativeDisplayType; } EGLNativeWindowType fsl_createwindow(EGLDisplay egldisplay, EGLNativeDisplayType eglNativeDisplayType) { EGLNativeWindowType native_window = (EGLNativeWindowType)0; #if (defined EGL_USE_X11) Window window, rootwindow; int screen = DefaultScreen(eglNativeDisplayType); rootwindow = RootWindow(eglNativeDisplayType,screen); window = XCreateSimpleWindow(eglNativeDisplayType, rootwindow, 0, 0, 400, 533, 0, 0, WhitePixel (eglNativeDisplayType, screen)); XMapWindow(eglNativeDisplayType, window); native_window = window; #else const char *vendor = eglQueryString(egldisplay, EGL_VENDOR); if (strstr(vendor, "Imagination Technologies")) native_window = (EGLNativeWindowType)0; else if (strstr(vendor, "AMD")) native_window = (EGLNativeWindowType) open("/dev/fb0", O_RDWR); else if (strstr(vendor, "Vivante")) //NEEDS FIX - functs don't exist on other platforms { #if (defined EGL_API_FB) native_window = fbCreateWindow(eglNativeDisplayType, 0, 0, 0, 0); #endif } else { printf("Unknown vendor [%s]\n", vendor); return 0; } #endif return native_window; } void fsl_destroywindow(EGLNativeWindowType eglNativeWindowType, EGLNativeDisplayType eglNativeDisplayType) { (void) eglNativeWindowType; #if (defined EGL_USE_X11) //close x display XCloseDisplay(eglNativeDisplayType); #endif } void GLInit (void) { static const EGLint s_configAttribs[] = { EGL_RED_SIZE, 5, EGL_GREEN_SIZE, 6, EGL_BLUE_SIZE, 5, EGL_ALPHA_SIZE, 0, EGL_SAMPLES, 0, EGL_NONE }; EGLint numconfigs; printf("1"); eglNativeDisplayType = fsl_getNativeDisplay(); printf("2"); egldisplay = eglGetDisplay(eglNativeDisplayType); printf("3"); eglInitialize(egldisplay, NULL, NULL); printf("4"); assert(eglGetError() == EGL_SUCCESS); printf("5"); eglBindAPI(EGL_OPENGL_ES_API); printf("6"); eglChooseConfig(egldisplay, s_configAttribs, &eglconfig, 1, &numconfigs); assert(eglGetError() == EGL_SUCCESS); assert(numconfigs == 1); printf("7"); eglNativeWindow = fsl_createwindow(egldisplay, eglNativeDisplayType); assert(eglNativeWindow); printf("8"); eglsurface = eglCreateWindowSurface(egldisplay, eglconfig, eglNativeWindow, NULL); assert(eglGetError() == EGL_SUCCESS); printf("9"); EGLint ContextAttribList[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; eglcontext = eglCreateContext( egldisplay, eglconfig, EGL_NO_CONTEXT, ContextAttribList ); assert(eglGetError() == EGL_SUCCESS); printf("10"); eglMakeCurrent(egldisplay, eglsurface, eglsurface, eglcontext); assert(eglGetError() == EGL_SUCCESS); } void GLEnd (void) { printf("Cleaning up...\n"); eglMakeCurrent(egldisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); assert(eglGetError() == EGL_SUCCESS); eglDestroyContext(egldisplay, eglcontext); eglDestroySurface(egldisplay, eglsurface); fsl_destroywindow(eglNativeWindow, eglNativeDisplayType); eglTerminate(egldisplay); assert(eglGetError() == EGL_SUCCESS); eglReleaseThread(); } int main (int argc, char **argv) { GLInit(); for( int i = 0; i < 100000; ++i) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer glClearColor (.0f, .0f, 1.0f, 1.0f); eglSwapBuffers (egldisplay, eglsurface); } GLEnd(); } Above code is stitched together from samples from GPU SDK. I've built an image using Yocto (dylan branch) and build the meta-toolchain-qt (and qte). Successfully managed to build above code ONLY FOR X11. Issues i am facing: 1) if build for X11 and run app on the board, window shows, but it stays white, when it should be BLUE...doesn't update no matter what color i glClear to. 2) when compiling with FB, fbCreateWindow and etc don't get recognized, i.e. undefined reference to `fbCreateWindow' .... WHAT header contains these functions???? 3) if even the basic samples don't work, how the hell is anybody supposed to build a GL application on this board?? --- more rhetorical than a real question, just frustrated here... what did i do wrong? 4) please show me a working tutorial or some code on how to get this EGL context initialized...i'm running at wit's end here...
記事全体を表示