首先给大家分享一个巨牛巨牛的人工智能教程,是我无意中发现的。教程不仅零基础,通俗易懂,而且非常风趣幽默,还时不时有内涵段子,像看小说一样,哈哈~我正在学习中,觉得太牛了,所以分享给大家!点这里可以跳转到教程
1. 保存全局变量的数据结构
以下例子程序均基于Linux平台。
typedef struct _escontext{
void* userData; // Put your user data here... GLint width; // Window width GLint height; // Window height EGLNativeWindowType hWnd; // Window handle EGLDisplay eglDisplay; // EGL display EGLContext eglContext; // EGL context EGLSurface eglSurface; // EGL surface // Callbacks void (ESCALLBACK *drawFunc) ( struct _escontext * ); void (ESCALLBACK *keyFunc) ( struct _escontext *, unsigned char, int, int ); void (ESCALLBACK *updateFunc) ( struct _escontext *, float deltaTime );}ESContext;
typedef struct{
// Handle to a program object GLuint programObject; // Atrribute Location GLint positionLoc; GLint textureLoc; // Uniform location GLint matrixModeLoc; GLint matrixViewLoc; GLint matrixPerspectiveLoc; // Sampler location GLint samplerLoc; // texture GLuint texture;} UserData;
2. 初始化EGL渲染环境和相关元素(第一步曲)
int InitEGL(ESContext * esContext){ NativeWindowType eglWindow = NULL; EGLDisplay display; EGLContext context; EGLSurface surface; EGLConfig configs[2]; EGLBoolean eRetStatus; EGLint majorVer, minorVer; EGLint context_attribs[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE}; EGLint numConfigs; EGLint cfg_attribs[] = {EGL_BUFFER_SIZE, EGL_DONT_CARE, EGL_DEPTH_SIZE, 16, EGL_RED_SIZE, 5, EGL_GREEN_SIZE, 6, EGL_BLUE_SIZE, 5, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_NONE}; // Get default display connection display = eglGetDisplay((EGLNativeDisplayType)EGL_DEFAULT_DISPLAY); if ( display == EGL_NO_DISPLAY ) { return EGL_FALSE; } // Initialize EGL display connection eRetStatus = eglInitialize(display, &majorVer, &minorVer); if( eRetStatus != EGL_TRUE ) { return EGL_FALSE; } //Get a list of all EGL frame buffer configurations for a display eRetStatus = eglGetConfigs (display, configs, 2, &numConfigs); if( eRetStatus != EGL_TRUE ) { return EGL_FALSE; } // Get a list of EGL frame buffer configurations that match specified attributes eRetStatus = eglChooseConfig (display, cfg_attribs, configs, 2, &numConfigs); if( eRetStatus != EGL_TRUE || !numConfigs) { return EGL_FALSE; } // Create a new EGL window surface surface