Advertisement
spacechase0

Wiz OpenGL ES

Feb 22nd, 2012
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.71 KB | None | 0 0
  1. #include <SFML/OpenGl.hpp> // This includes <GL/egl.h> and <GL/nanogl.h>, on the Wiz
  2. #include <SFML/System.hpp>
  3. #include <Panel/fake_os.h>
  4. #include <iostream>
  5.  
  6. #define p(a) sf::Err() << a << std::endl;
  7.  
  8. int main( int argc, char* argv[] )
  9. {
  10.     std::streambuf* coutBuf = std::cout.rdbuf();
  11.     std::streambuf* errBuf = sf::Err().rdbuf();
  12.     sf::Err().rdbuf( coutBuf );
  13.    
  14.     p("Creating window")
  15.     OS_Window myWindow = OS_CreateWindow();
  16.     if (!myWindow)
  17.     {
  18.         sf::Err() << "Failed to create window." << std::endl;
  19.         return 0;
  20.     }
  21.    
  22.     nanoGL_Init();
  23.    
  24.     p("Get the attributes of the target window")
  25.    
  26.     EGLint attrib_list[] =
  27.     {
  28.       EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
  29.       EGL_BUFFER_SIZE,  0,
  30.       EGL_DEPTH_SIZE,   16,
  31.       EGL_NONE
  32.     };
  33.    
  34.     ::EGLDisplay myGlDisplay;
  35.     ::EGLConfig  myGlConfig;
  36.     ::EGLContext myGlContext;
  37.     ::EGLSurface myGlSurface;
  38.    
  39.     p("Create the display.")
  40.     myGlDisplay = eglGetDisplay(static_cast< NativeDisplayType >(0));
  41.     if (myGlDisplay == EGL_NO_DISPLAY)
  42.     {
  43.         sf::Err() << "Failed to create display: " << glGetError() << std::endl;
  44.         return 0;
  45.     }
  46.    
  47.     EGLint numConfigs;
  48.     EGLint majorVersion;
  49.     EGLint minorVersion;
  50.    
  51.     p("Intiailize EGL")
  52.     if (!eglInitialize(myGlDisplay, &majorVersion, &minorVersion))
  53.     {
  54.         sf::Err() << "Failed to init EGL: " << glGetError() << std::endl;
  55.         return 0;
  56.     }
  57.    
  58.     p("Choose config")
  59.     if(!eglChooseConfig(myGlDisplay, attrib_list, &myGlConfig, 1, &numConfigs))
  60.     {
  61.         sf::Err() << "Failed to choose config: " << glGetError() << std::endl;
  62.         return 0;
  63.     }
  64.    
  65.     p("Create context")
  66.     myGlContext = eglCreateContext( myGlDisplay, myGlConfig, NULL, NULL );
  67.     if ( myGlContext == 0 )
  68.     {
  69.         sf::Err() << "Failed to create context: " << glGetError() << std::endl;
  70.         return 0;
  71.     }
  72.    
  73.     p("Create surface")
  74.     myGlSurface = eglCreateWindowSurface( myGlDisplay, myGlConfig, myWindow, NULL );
  75.     if ( myGlSurface == NULL )
  76.     {
  77.         sf::Err() << "Failed to create surface: " << glGetError() << std::endl;
  78.         return 0;
  79.     }
  80.    
  81.     p("make current")
  82.     eglMakeCurrent( myGlDisplay, myGlSurface, myGlSurface, myGlContext );    
  83.  
  84. const char *gl_vendor;
  85. const char *gl_renderer;
  86. const char *gl_version;
  87. const char *gl_extensions;
  88.     gl_vendor = (const char*)glGetString (GL_VENDOR);
  89.     std::cout<<"GL_VENDOR: "<< gl_vendor<<std::endl;
  90.     gl_renderer = (const char*)glGetString (GL_RENDERER);
  91.     std::cout<<"GL_RENDERER: "<< gl_renderer<<std::endl;
  92.  
  93.     gl_version = (const char*)glGetString (GL_VERSION);
  94.     std::cout<<"GL_VERSION: "<< gl_version<<std::endl;
  95.     gl_extensions = (const char*)glGetString (GL_EXTENSIONS);
  96.     std::cout<<"GL_EXTENSIONS: "<< gl_extensions<<std::endl;
  97.    
  98.     float v[] = { 0.f, 0.f,
  99.                   1.f, 0.f,
  100.                   0.f, 1.f,
  101.                  
  102.                   1.f, 1.f,
  103.                   0.f, 1.f,
  104.                   1.f, 0.f };
  105.    
  106.     p("preloop")
  107.     for ( size_t i = 0; i < 20; ++i )
  108.     {
  109.         p("\tstartloop")
  110.         p("\t\tdrawstart")
  111.         glEnableClientState(GL_VERTEX_ARRAY);
  112.         p("\t\t\tpostenable")
  113.         glVertexPointer(2, GL_FLOAT, 0, v);
  114.         p("\t\t\tvpointer")
  115.         glDrawArrays(GL_TRIANGLES, 0, 6);
  116.         p("\t\t\tpredisable")
  117.         glDisableClientState(GL_VERTEX_ARRAY);
  118.         p("\t\tdrawend")
  119.         eglSwapBuffers(myGlDisplay, myGlContext);
  120.         p("\t\tsleepytime")
  121.         sf::Sleep( 250 );
  122.         p("\tendloop")
  123.     }
  124.     p("postloop")
  125.  
  126.     p("byebye")
  127.     eglMakeCurrent( myGlDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT );
  128.     eglDestroySurface( myGlDisplay, myGlSurface );
  129.     eglDestroyContext( myGlDisplay, myGlContext );
  130.     eglTerminate( myGlDisplay );
  131.    
  132.     nanoGL_Destroy();
  133.    
  134.     p("Done")
  135.     std::cout.rdbuf( coutBuf );
  136.     sf::Err().rdbuf( errBuf );
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement