Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SFML/OpenGl.hpp> // This includes <GL/egl.h> and <GL/nanogl.h>, on the Wiz
- #include <SFML/System.hpp>
- #include <Panel/fake_os.h>
- #include <iostream>
- #define p(a) sf::Err() << a << std::endl;
- int main( int argc, char* argv[] )
- {
- std::streambuf* coutBuf = std::cout.rdbuf();
- std::streambuf* errBuf = sf::Err().rdbuf();
- sf::Err().rdbuf( coutBuf );
- p("Creating window")
- OS_Window myWindow = OS_CreateWindow();
- if (!myWindow)
- {
- sf::Err() << "Failed to create window." << std::endl;
- return 0;
- }
- nanoGL_Init();
- p("Get the attributes of the target window")
- EGLint attrib_list[] =
- {
- EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
- EGL_BUFFER_SIZE, 0,
- EGL_DEPTH_SIZE, 16,
- EGL_NONE
- };
- ::EGLDisplay myGlDisplay;
- ::EGLConfig myGlConfig;
- ::EGLContext myGlContext;
- ::EGLSurface myGlSurface;
- p("Create the display.")
- myGlDisplay = eglGetDisplay(static_cast< NativeDisplayType >(0));
- if (myGlDisplay == EGL_NO_DISPLAY)
- {
- sf::Err() << "Failed to create display: " << glGetError() << std::endl;
- return 0;
- }
- EGLint numConfigs;
- EGLint majorVersion;
- EGLint minorVersion;
- p("Intiailize EGL")
- if (!eglInitialize(myGlDisplay, &majorVersion, &minorVersion))
- {
- sf::Err() << "Failed to init EGL: " << glGetError() << std::endl;
- return 0;
- }
- p("Choose config")
- if(!eglChooseConfig(myGlDisplay, attrib_list, &myGlConfig, 1, &numConfigs))
- {
- sf::Err() << "Failed to choose config: " << glGetError() << std::endl;
- return 0;
- }
- p("Create context")
- myGlContext = eglCreateContext( myGlDisplay, myGlConfig, NULL, NULL );
- if ( myGlContext == 0 )
- {
- sf::Err() << "Failed to create context: " << glGetError() << std::endl;
- return 0;
- }
- p("Create surface")
- myGlSurface = eglCreateWindowSurface( myGlDisplay, myGlConfig, myWindow, NULL );
- if ( myGlSurface == NULL )
- {
- sf::Err() << "Failed to create surface: " << glGetError() << std::endl;
- return 0;
- }
- p("make current")
- eglMakeCurrent( myGlDisplay, myGlSurface, myGlSurface, myGlContext );
- const char *gl_vendor;
- const char *gl_renderer;
- const char *gl_version;
- const char *gl_extensions;
- gl_vendor = (const char*)glGetString (GL_VENDOR);
- std::cout<<"GL_VENDOR: "<< gl_vendor<<std::endl;
- gl_renderer = (const char*)glGetString (GL_RENDERER);
- std::cout<<"GL_RENDERER: "<< gl_renderer<<std::endl;
- gl_version = (const char*)glGetString (GL_VERSION);
- std::cout<<"GL_VERSION: "<< gl_version<<std::endl;
- gl_extensions = (const char*)glGetString (GL_EXTENSIONS);
- std::cout<<"GL_EXTENSIONS: "<< gl_extensions<<std::endl;
- float v[] = { 0.f, 0.f,
- 1.f, 0.f,
- 0.f, 1.f,
- 1.f, 1.f,
- 0.f, 1.f,
- 1.f, 0.f };
- p("preloop")
- for ( size_t i = 0; i < 20; ++i )
- {
- p("\tstartloop")
- p("\t\tdrawstart")
- glEnableClientState(GL_VERTEX_ARRAY);
- p("\t\t\tpostenable")
- glVertexPointer(2, GL_FLOAT, 0, v);
- p("\t\t\tvpointer")
- glDrawArrays(GL_TRIANGLES, 0, 6);
- p("\t\t\tpredisable")
- glDisableClientState(GL_VERTEX_ARRAY);
- p("\t\tdrawend")
- eglSwapBuffers(myGlDisplay, myGlContext);
- p("\t\tsleepytime")
- sf::Sleep( 250 );
- p("\tendloop")
- }
- p("postloop")
- p("byebye")
- eglMakeCurrent( myGlDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT );
- eglDestroySurface( myGlDisplay, myGlSurface );
- eglDestroyContext( myGlDisplay, myGlContext );
- eglTerminate( myGlDisplay );
- nanoGL_Destroy();
- p("Done")
- std::cout.rdbuf( coutBuf );
- sf::Err().rdbuf( errBuf );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement