Editing SimpleGL example

Warning: You are not logged in. Your IP address will be recorded in this page's edit history.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 1: Line 1:
-
This is a simple program demonstrating how to use [[OpenGL-ES#OpenGL_variants|OpenGL ES 2.0]]. It will output this animated spiral, which can be moved around on the screen:
+
This is a simple program demonstrating how to use openGL ES 2.0. It will output this animated spiral, which can be moved around on the screen:
[[Image:Egl-example_output.png]]
[[Image:Egl-example_output.png]]
-
<source lang="cpp">
 
-
/* Created by exoticorn ( http://talk.maemo.org/showthread.php?t=37356 )
 
-
* edited and commented by André Bergner [endboss]
 
-
*
 
-
* libraries needed:  libx11-dev, libgles2-dev
 
-
*
 
-
* compile with:  g++  -lX11 -lEGL -lGLESv2  egl-example.cpp
 
-
*/
 
-
#include <iostream>
+
  /* Created by exoticorn ( http://talk.maemo.org/showthread.php?t=37356 )
-
#include <cstdlib>
+
  * edited and commented by André Bergner [endboss]
-
#include  <cstring>
+
  *
-
using namespace std;
+
  * librariries needed:  libx11-dev, libgles2-dev
-
 
+
  *
-
#include  <cmath>
+
  * compile with:  g++ -lX11 -lEGL -lGLESv2  egl-example.cpp
-
#include  <sys/time.h>
+
  */
-
 
+
-
#include  <X11/Xlib.h>
+
#include  <iostream>
-
#include  <X11/Xatom.h>
+
using namespace std;
-
#include <X11/Xutil.h>
+
-
 
+
#include  <cmath>
-
#include  <GLES2/gl2.h>
+
#include  <sys/time.h>
-
#include  <EGL/egl.h>
+
-
 
+
#include  <X11/Xlib.h>
-
 
+
#include  <X11/Xatom.h>
-
 
+
   
-
const char vertex_src [] =
+
#include  <GLES2/gl2.h>
-
"                                        \
+
#include  <EGL/egl.h>
-
  attribute vec4        position;      \
+
-
  varying mediump vec2  pos;            \
+
-
  uniform vec4          offset;        \
+
-
                                        \
+
const char vertex_src [] =
-
  void main()                          \
+
"                                        \
-
  {                                    \
+
    attribute vec4        position;      \
-
      gl_Position = position + offset;  \
+
    varying mediump vec2  pos;            \
-
      pos = position.xy;                \
+
    uniform vec4          offset;        \
-
  }                                    \
+
                                          \
-
";
+
    void main()                          \
-
 
+
    {                                    \
-
 
+
      gl_Position = position + offset;  \
-
const char fragment_src [] =
+
      pos = position.xy;                \
-
"                                                      \
+
    }                                    \
-
  varying mediump vec2    pos;                        \
+
";
-
  uniform mediump float  phase;                      \
+
-
                                                      \
+
-
  void  main()                                        \
+
const char fragment_src [] =
-
  {                                                  \
+
"                                                      \
-
      gl_FragColor  =  vec4( 1., 0.9, 0.7, 1.0 ) *    \
+
    varying mediump vec2    pos;                        \
-
        cos( 30.*sqrt(pos.x*pos.x + 1.5*pos.y*pos.y)  \
+
    uniform mediump float  phase;                      \
-
            + atan(pos.y,pos.x) - phase );            \
+
                                                        \
-
  }                                                  \
+
    void  main()                                        \
-
";
+
    {                                                  \
-
//  some more formulas to play with...
+
      gl_FragColor  =  vec4( 1., 0.9, 0.7, 1.0 ) *    \
-
//      cos( 20.*(pos.x*pos.x + pos.y*pos.y) - phase );
+
        cos( 30.*sqrt(pos.x*pos.x + 1.5*pos.y*pos.y)  \
-
//      cos( 20.*sqrt(pos.x*pos.x + pos.y*pos.y) + atan(pos.y,pos.x) - phase );
+
              + atan(pos.y,pos.x) - phase );            \
-
//      cos( 30.*sqrt(pos.x*pos.x + 1.5*pos.y*pos.y - 1.8*pos.x*pos.y*pos.y)
+
    }                                                  \
-
//            + atan(pos.y,pos.x) - phase );
+
";
-
 
+
//  some more formulas to play with...
-
 
+
//      cos( 20.*(pos.x*pos.x + pos.y*pos.y) - phase );
-
void
+
//      cos( 20.*sqrt(pos.x*pos.x + pos.y*pos.y) + atan(pos.y,pos.x) - phase );
-
print_shader_info_log (
+
//      cos( 30.*sqrt(pos.x*pos.x + 1.5*pos.y*pos.y - 1.8*pos.x*pos.y*pos.y)
-
  GLuint  shader      // handle to the shader
+
//            + atan(pos.y,pos.x) - phase );
-
)
+
-
{
+
-
  GLint  length;
+
void
-
 
+
print_shader_info_log (
-
  glGetShaderiv ( shader , GL_INFO_LOG_LENGTH , &length );
+
    GLuint  shader      // handle to the shader
-
 
+
)
-
  if ( length ) {
+
{
-
      char* buffer  =  new char [ length ];
+
    GLint  length;
-
      glGetShaderInfoLog ( shader , length , NULL , buffer );
+
-
      cout << "shader info: " <<  buffer << flush;
+
    glGetShaderiv ( shader , GL_INFO_LOG_LENGTH , &length );
-
      delete [] buffer;
+
-
 
+
    if ( length ) {
-
      GLint success;
+
      char* buffer  =  new char [ length ];
-
      glGetShaderiv( shader, GL_COMPILE_STATUS, &success );
+
      glGetShaderInfoLog ( shader , length , NULL , buffer );
-
      if ( success != GL_TRUE )  exit ( 1 );
+
      cout << "shader info: " <<  buffer << flush;
-
  }
+
      delete [] buffer;
-
}
+
-
 
+
      GLint success;
-
 
+
      glGetShaderiv( shader, GL_COMPILE_STATUS, &success );
-
GLuint
+
      if ( success != GL_TRUE )  exit ( 1 );
-
load_shader (
+
    }
-
  const char  *shader_source,
+
}
-
  GLenum      type
+
-
)
+
-
{
+
GLuint
-
  GLuint  shader = glCreateShader( type );
+
load_shader (
-
 
+
    const char  *shader_source,
-
  glShaderSource  ( shader , 1 , &shader_source , NULL );
+
    GLenum      type
-
  glCompileShader ( shader );
+
)
-
 
+
{
-
  print_shader_info_log ( shader );
+
    GLuint  shader = glCreateShader( type );
-
 
+
-
  return shader;
+
    glShaderSource  ( shader , 1 , &shader_source , NULL );
-
}
+
    glCompileShader ( shader );
-
 
+
-
 
+
    print_shader_info_log ( shader );
-
Display    *x_display;
+
-
Window      win;
+
    return shader;
-
EGLDisplay  egl_display;
+
}
-
EGLContext  egl_context;
+
-
EGLSurface egl_surface;
+
-
 
+
Display    *x_display;
-
GLfloat
+
Window      win;
-
  norm_x    =  0.0,
+
EGLDisplay  egl_display;
-
  norm_y    =  0.0,
+
EGLContext  egl_context;
-
  offset_x  =  0.0,
+
   
-
  offset_y  =  0.0,
+
GLfloat
-
  p1_pos_x  =  0.0,
+
    norm_x    =  0.0,
-
  p1_pos_y  =  0.0;
+
    norm_y    =  0.0,
-
 
+
    offset_x  =  0.0,
-
GLint
+
    offset_y  =  0.0,
-
  phase_loc,
+
    p1_pos_x  =  0.0,
-
  offset_loc,
+
    p1_pos_y  =  0.0;
-
  position_loc;
+
-
 
+
GLint
-
 
+
    phase_loc,
-
bool        update_pos = false;
+
    offset_loc,
-
 
+
    position_loc;
-
const float vertexArray[] = {
+
-
  0.0,  0.5,  0.0,
+
-
  -0.5,  0.0,  0.0,
+
EGLSurface  egl_surface;
-
  0.0, -0.5,  0.0,
+
bool        update_pos = false;
-
  0.5,  0.0,  0.0,
+
-
  0.0,  0.5,  0.0  
+
const float vertexArray[] = {
-
};
+
    0.0,  0.5,  0.0,
-
 
+
  -0.5,  0.0,  0.0,
-
 
+
    0.0, -0.5,  0.0,
-
void  render()
+
    0.5,  0.0,  0.0,
-
{
+
    0.0,  0.5,  0.0  
-
  static float  phase = 0;
+
};
-
  static int    donesetup = 0;
+
-
 
+
-
  static XWindowAttributes gwa;
+
void  render()
-
 
+
{
-
  //// draw
+
    static float  phase = 0;
-
 
+
    static int    donesetup = 0;
-
  if ( !donesetup ) {
+
-
      XWindowAttributes  gwa;
+
    static XWindowAttributes gwa;
-
      XGetWindowAttributes ( x_display , win , &gwa );
+
-
      glViewport ( 0 , 0 , gwa.width , gwa.height );
+
    //// draw
-
      glClearColor ( 0.08 , 0.06 , 0.07 , 1.);    // background color
+
-
      donesetup = 1;
+
    if ( !donesetup ) {
-
  }
+
      XWindowAttributes  gwa;
-
  glClear ( GL_COLOR_BUFFER_BIT );
+
      XGetWindowAttributes ( x_display , win , &gwa );
-
 
+
      glViewport ( 0 , 0 , gwa.width , gwa.height );
-
  glUniform1f ( phase_loc , phase );  // write the value of phase to the shaders phase
+
      glClearColor ( 0.08 , 0.06 , 0.07 , 1.);    // background color
-
  phase  =  fmodf ( phase + 0.5f , 2.f * 3.141f );    // and update the local variable
+
      donesetup = 1;
-
 
+
    }
-
  if ( update_pos ) {  // if the position of the texture has changed due to user action
+
    glClear ( GL_COLOR_BUFFER_BIT );
-
      GLfloat old_offset_x  =  offset_x;
+
-
      GLfloat old_offset_y  =  offset_y;
+
    glUniform1f ( phase_loc , phase );  // write the value of phase to the shaders phase
-
 
+
    phase  =  fmodf ( phase + 0.5f , 2.f * 3.141f );    // and update the local variable
-
      offset_x  =  norm_x - p1_pos_x;
+
-
      offset_y  =  norm_y - p1_pos_y;
+
    if ( update_pos ) {  // if the position of the texture has changed due to user action
-
 
+
      GLfloat old_offset_x  =  offset_x;
-
      p1_pos_x  =  norm_x;
+
      GLfloat old_offset_y  =  offset_y;
-
      p1_pos_y  =  norm_y;
+
-
 
+
      offset_x  =  norm_x - p1_pos_x;
-
      offset_x  +=  old_offset_x;
+
      offset_y  =  norm_y - p1_pos_y;
-
      offset_y  +=  old_offset_y;
+
-
 
+
      p1_pos_x  =  norm_x;
-
      update_pos = false;
+
      p1_pos_y  =  norm_y;
-
  }
+
-
 
+
      offset_x  +=  old_offset_x;
-
  glUniform4f ( offset_loc  ,  offset_x , offset_y , 0.0 , 0.0 );
+
      offset_y  +=  old_offset_y;
-
 
+
-
  glVertexAttribPointer ( position_loc, 3, GL_FLOAT, false, 0, vertexArray );
+
      update_pos = false;
-
  glEnableVertexAttribArray ( position_loc );
+
    }
-
  glDrawArrays ( GL_TRIANGLE_STRIP, 0, 5 );
+
-
 
+
    glUniform4f ( offset_loc  ,  offset_x , offset_y , 0.0 , 0.0 );
-
  eglSwapBuffers ( egl_display, egl_surface );  // get the rendered buffer to the screen
+
-
}
+
    glVertexAttribPointer ( position_loc, 3, GL_FLOAT, false, 0, vertexArray );
-
 
+
    glEnableVertexAttribArray ( position_loc );
-
 
+
    glDrawArrays ( GL_TRIANGLE_STRIP, 0, 5 );
-
////////////////////////////////////////////////////////////////////////////////////////////
+
-
 
+
    eglSwapBuffers ( egl_display, egl_surface );  // get the rendered buffer to the screen
-
 
+
}
-
int  main()
+
-
{
+
-
  ///////  the X11 part  //////////////////////////////////////////////////////////////////
+
////////////////////////////////////////////////////////////////////////////////////////////
-
  // in the first part the program opens a connection to the X11 window manager
+
-
  //
+
-
 
+
int  main()
-
  x_display = XOpenDisplay ( NULL );  // open the standard display (the primary screen)
+
{
-
  if ( x_display == NULL ) {
+
    ///////  the X11 part  //////////////////////////////////////////////////////////////////
-
      cerr << "cannot connect to X server" << endl;
+
    // in the first part the program opens a connection to the X11 window manager
-
      return 1;
+
    //
-
  }
+
-
 
+
    x_display = XOpenDisplay ( NULL );  // open the standard display (the primary screen)
-
  Window root  =  DefaultRootWindow( x_display );  // get the root window (usually the whole screen)
+
    if ( x_display == NULL ) {
-
 
+
      cerr << "cannot connect to X server" << endl;
-
  XSetWindowAttributes  swa;
+
      return 1;
-
  swa.event_mask  =  ExposureMask | PointerMotionMask | KeyPressMask;
+
    }
-
 
+
-
  win  =  XCreateWindow (   // create a window with the provided parameters
+
    Window root  =  DefaultRootWindow( x_display );  // get the root window (usually the whole screen)
-
              x_display, root,
+
-
              0, 0, 800, 480,  0,
+
    XSetWindowAttributes  swa;
-
              CopyFromParent, InputOutput,
+
    swa.event_mask  =  ExposureMask | PointerMotionMask;
-
              CopyFromParent, CWEventMask,
+
-
              &swa );
+
    win  =  XCreateWindow (         // create a window with the provided parameters
-
 
+
              x_display, root,
-
  XSetWindowAttributes  xattr;
+
              0, 0, 800, 480,  0,
-
  Atom  atom;
+
              CopyFromParent, InputOutput,
-
  int  one = 1;
+
              CopyFromParent, CWEventMask,
-
 
+
              &swa );
-
  xattr.override_redirect = False;
+
-
  XChangeWindowAttributes ( x_display, win, CWOverrideRedirect, &xattr );
+
    XSetWindowAttributes  xattr;
-
 
+
    Atom  atom;
-
  atom = XInternAtom ( x_display, "_NET_WM_STATE_FULLSCREEN", True );
+
    int  one = 1;
-
  XChangeProperty (
+
-
      x_display, win,
+
    xattr.override_redirect = False;
-
      XInternAtom ( x_display, "_NET_WM_STATE", True ),
+
    XChangeWindowAttributes ( x_display, win, CWOverrideRedirect, &xattr );
-
      XA_ATOM,  32,  PropModeReplace,
+
-
      (unsigned char*) &atom,  1 );
+
    atom = XInternAtom ( x_display, "_NET_WM_STATE_FULLSCREEN", True );
-
 
+
    XChangeProperty (
-
  XChangeProperty (
+
      x_display, win,
-
      x_display, win,
+
      XInternAtom ( x_display, "_NET_WM_STATE", True ),
-
      XInternAtom ( x_display, "_HILDON_NON_COMPOSITED_WINDOW", False ),
+
      XA_ATOM,  32,  PropModeReplace,
-
      XA_INTEGER,  32,  PropModeReplace,
+
      (unsigned char*) &atom,  1 );
-
      (unsigned char*) &one,  1);
+
-
 
+
    XChangeProperty (
-
  XWMHints hints;
+
      x_display, win,
-
  hints.input = True;
+
      XInternAtom ( x_display, "_HILDON_NON_COMPOSITED_WINDOW", True ),
-
  hints.flags = InputHint;
+
      XA_INTEGER,  32,  PropModeReplace,
-
  XSetWMHints(x_display, win, &hints);
+
      (unsigned char*) &one,  1);
-
 
+
-
  XMapWindow ( x_display , win );            // make the window visible on the screen
+
    XMapWindow ( x_display , win );            // make the window visible on the screen
-
  XStoreName ( x_display , win , "GL test" ); // give the window a name
+
    XStoreName ( x_display , win , "GL test" ); // give the window a name
-
 
+
-
  //// get identifiers for the provided atom name strings
+
    //// get identifiers for the provided atom name strings
-
  Atom wm_state  = XInternAtom ( x_display, "_NET_WM_STATE", False );
+
    Atom wm_state  = XInternAtom ( x_display, "_NET_WM_STATE", False );
-
  Atom fullscreen = XInternAtom ( x_display, "_NET_WM_STATE_FULLSCREEN", False );
+
    Atom fullscreen = XInternAtom ( x_display, "_NET_WM_STATE_FULLSCREEN", False );
-
 
+
-
  XEvent xev;
+
    XEvent xev;
-
  memset ( &xev, 0, sizeof(xev) );
+
    memset ( &xev, 0, sizeof(xev) );
-
 
+
-
  xev.type                = ClientMessage;
+
    xev.type                = ClientMessage;
-
  xev.xclient.window      = win;
+
    xev.xclient.window      = win;
-
  xev.xclient.message_type = wm_state;
+
    xev.xclient.message_type = wm_state;
-
  xev.xclient.format      = 32;
+
    xev.xclient.format      = 32;
-
  xev.xclient.data.l[0]    = 1;
+
    xev.xclient.data.l[0]    = 1;
-
  xev.xclient.data.l[1]    = fullscreen;
+
    xev.xclient.data.l[1]    = fullscreen;
-
  XSendEvent (                // send an event mask to the X-server
+
    XSendEvent (                // send an event mask to the X-server
-
      x_display,
+
      x_display,
-
      DefaultRootWindow ( x_display ),
+
      DefaultRootWindow ( x_display ),
-
      False,
+
      False,
-
      SubstructureNotifyMask,
+
      SubstructureNotifyMask,
-
      &xev );
+
      &xev );
-
 
+
-
 
+
-
  ///////  the egl part  //////////////////////////////////////////////////////////////////
+
    ///////  the egl part  //////////////////////////////////////////////////////////////////
-
  //  egl provides an interface to connect the graphics related functionality of openGL ES
+
    //  egl provides an interface to connect the graphics related functionality of openGL ES
-
  //  with the windowing interface and functionality of the native operation system (X11
+
    //  with the windowing interface and functionality of the native operation system (X11
-
  //  in our case.
+
    //  in our case.
-
 
+
-
  egl_display  =  eglGetDisplay( (EGLNativeDisplayType) x_display );
+
    egl_display  =  eglGetDisplay( (EGLNativeDisplayType) x_display );
-
  if ( egl_display == EGL_NO_DISPLAY ) {
+
    if ( egl_display == EGL_NO_DISPLAY ) {
-
      cerr << "Got no EGL display." << endl;
+
      cerr << "Got no EGL display." << endl;
-
      return 1;
+
      return 1;
-
  }
+
    }
-
 
+
-
  if ( !eglInitialize( egl_display, NULL, NULL ) ) {
+
    if ( !eglInitialize( egl_display, NULL, NULL ) ) {
-
      cerr << "Unable to initialize EGL" << endl;
+
      cerr << "Unable to initialize EGL" << endl;
-
      return 1;
+
      return 1;
-
  }
+
    }
-
 
+
-
  EGLint attr[] = {      // some attributes to set up our egl-interface
+
    EGLint attr[] = {      // some attributes to set up our egl-interface
-
      EGL_BUFFER_SIZE, 16,
+
      EGL_BUFFER_SIZE, 16,
-
      EGL_RENDERABLE_TYPE,
+
      EGL_RENDERABLE_TYPE,
-
      EGL_OPENGL_ES2_BIT,
+
      EGL_OPENGL_ES2_BIT,
-
      EGL_NONE
+
      EGL_NONE
-
  };
+
    };
-
 
+
-
  EGLConfig  ecfg;
+
    EGLConfig  ecfg;
-
  EGLint    num_config;
+
    EGLint    num_config;
-
  if ( !eglChooseConfig( egl_display, attr, &ecfg, 1, &num_config ) ) {
+
    if ( !eglChooseConfig( egl_display, attr, &ecfg, 1, &num_config ) ) {
-
      cerr << "Failed to choose config (eglError: " << eglGetError() << ")" << endl;
+
      cerr << "Failed to choose config (eglError: " << eglGetError() << ")" << endl;
-
      return 1;
+
      return 1;
-
  }
+
    }
-
 
+
-
  if ( num_config != 1 ) {
+
    if ( num_config != 1 ) {
-
      cerr << "Didn't get exactly one config, but " << num_config << endl;
+
      cerr << "Didn't get exactly one config, but " << num_config << endl;
-
      return 1;
+
      return 1;
-
  }
+
    }
-
 
+
-
  egl_surface = eglCreateWindowSurface ( egl_display, ecfg, win, NULL );
+
    egl_surface = eglCreateWindowSurface ( egl_display, ecfg, (void*)win, NULL );
-
  if ( egl_surface == EGL_NO_SURFACE ) {
+
    if ( egl_surface == EGL_NO_SURFACE ) {
-
      cerr << "Unable to create EGL surface (eglError: " << eglGetError() << ")" << endl;
+
      cerr << "Unable to create EGL surface (eglError: " << eglGetError() << ")" << endl;
-
      return 1;
+
      return 1;
-
  }
+
    }
-
 
+
-
  //// egl-contexts collect all state descriptions needed required for operation
+
    //// egl-contexts collect all state descriptions needed required for operation
-
  EGLint ctxattr[] = {
+
    EGLint ctxattr[] = {
-
      EGL_CONTEXT_CLIENT_VERSION, 2,
+
      EGL_CONTEXT_CLIENT_VERSION, 2,
-
      EGL_NONE
+
      EGL_NONE
-
  };
+
    };
-
  egl_context = eglCreateContext ( egl_display, ecfg, EGL_NO_CONTEXT, ctxattr );
+
    egl_context = eglCreateContext ( egl_display, ecfg, EGL_NO_CONTEXT, ctxattr );
-
  if ( egl_context == EGL_NO_CONTEXT ) {
+
    if ( egl_context == EGL_NO_CONTEXT ) {
-
      cerr << "Unable to create EGL context (eglError: " << eglGetError() << ")" << endl;
+
      cerr << "Unable to create EGL context (eglError: " << eglGetError() << ")" << endl;
-
      return 1;
+
      return 1;
-
  }
+
    }
-
 
+
-
  //// associate the egl-context with the egl-surface
+
    //// associate the egl-context with the egl-surface
-
  eglMakeCurrent( egl_display, egl_surface, egl_surface, egl_context );
+
    eglMakeCurrent( egl_display, egl_surface, egl_surface, egl_context );
-
 
+
-
 
+
-
  ///////  the openGL part  ///////////////////////////////////////////////////////////////
+
    ///////  the openGL part  ///////////////////////////////////////////////////////////////
-
 
+
-
  GLuint vertexShader  = load_shader ( vertex_src , GL_VERTEX_SHADER  );    // load vertex shader
+
    GLuint vertexShader  = load_shader ( vertex_src , GL_VERTEX_SHADER  );    // load vertex shader
-
  GLuint fragmentShader = load_shader ( fragment_src , GL_FRAGMENT_SHADER );  // load fragment shader
+
    GLuint fragmentShader = load_shader ( fragment_src , GL_FRAGMENT_SHADER );  // load fragment shader
-
 
+
-
  GLuint shaderProgram  = glCreateProgram ();                // create program object
+
    GLuint shaderProgram  = glCreateProgram ();                // create program object
-
  glAttachShader ( shaderProgram, vertexShader );            // and attach both...
+
    glAttachShader ( shaderProgram, vertexShader );            // and attach both...
-
  glAttachShader ( shaderProgram, fragmentShader );          // ... shaders to it
+
    glAttachShader ( shaderProgram, fragmentShader );          // ... shaders to it
-
 
+
-
  glLinkProgram ( shaderProgram );    // link the program
+
    glLinkProgram ( shaderProgram );    // link the program
-
  glUseProgram  ( shaderProgram );    // and select it for usage
+
    glUseProgram  ( shaderProgram );    // and select it for usage
-
 
+
-
  //// now get the locations (kind of handle) of the shaders variables
+
    //// now get the locations (kind of handle) of the shaders variables
-
  position_loc  = glGetAttribLocation  ( shaderProgram , "position" );
+
    position_loc  = glGetAttribLocation  ( shaderProgram , "position" );
-
  phase_loc    = glGetUniformLocation ( shaderProgram , "phase"    );
+
    phase_loc    = glGetUniformLocation ( shaderProgram , "phase"    );
-
  offset_loc    = glGetUniformLocation ( shaderProgram , "offset"  );
+
    offset_loc    = glGetUniformLocation ( shaderProgram , "offset"  );
-
  if ( position_loc < 0  ||  phase_loc < 0  ||  offset_loc < 0 ) {
+
    if ( position_loc < 0  ||  phase_loc < 0  ||  offset_loc < 0 ) {
-
      cerr << "Unable to get uniform location" << endl;
+
      cerr << "Unable to get uniform location" << endl;
-
      return 1;
+
      return 1;
-
  }
+
    }
-
 
+
-
 
+
-
  const float
+
    const float
-
      window_width  = 800.0,
+
      window_width  = 800.0,
-
      window_height = 480.0;
+
      window_height = 480.0;
-
 
+
-
  //// this is needed for time measuring  -->  frames per second
+
    //// this is needed for time measuring  -->  frames per second
-
  struct  timezone  tz;
+
    struct  timezone  tz;
-
  timeval  t1, t2;
+
    timeval  t1, t2;
-
  gettimeofday ( &t1 , &tz );
+
    gettimeofday ( &t1 , &tz );
-
  int  num_frames = 0;
+
    int  num_frames = 0;
-
 
+
-
  bool quit = false;
+
    bool quit = false;
-
  while ( !quit ) {    // the main loop
+
    while ( !quit ) {    // the main loop
-
 
+
-
      while ( XPending ( x_display ) ) {  // check for events from the x-server
+
      while ( XPending ( x_display ) ) {  // check for events from the x-server
-
 
+
-
        XEvent  xev;
+
          XEvent  xev;
-
        XNextEvent( x_display, &xev );
+
          XNextEvent( x_display, &xev );
-
 
+
-
        if ( xev.type == MotionNotify ) {  // if mouse has moved
+
          if ( xev.type == MotionNotify ) {  // if mouse has moved
-
//            cout << "move to: << xev.xmotion.x << "," << xev.xmotion.y << endl;
+
//            cout << "move to: << xev.xmotion.x << "," << xev.xmotion.y << endl;
-
            GLfloat window_y  =  (window_height - xev.xmotion.y) - window_height / 2.0;
+
            GLfloat window_y  =  (window_height - xev.xmotion.y) - window_height / 2.0;
-
            norm_y            =  window_y / (window_height / 2.0);
+
            norm_y            =  window_y / (window_height / 2.0);
-
            GLfloat window_x  =  xev.xmotion.x - window_width / 2.0;
+
            GLfloat window_x  =  xev.xmotion.x - window_width / 2.0;
-
            norm_x            =  window_x / (window_width / 2.0);
+
            norm_x            =  window_x / (window_width / 2.0);
-
            update_pos = true;
+
            update_pos = true;
-
        }
+
          }
-
 
+
-
        if ( xev.type == KeyPress )  quit = true;
+
//        if ( xev.type == KeyPress )  quit = true; // doesn't work ???
-
      }
+
      }
-
 
+
-
      render();  // now we finally put something on the screen
+
      render();  // now we finally put something on the screen
-
 
+
-
      if ( ++num_frames % 100 == 0 ) {
+
      if ( ++num_frames % 100 == 0 ) {
-
        gettimeofday( &t2, &tz );
+
          gettimeofday( &t2, &tz );
-
        float dt  =  t2.tv_sec - t1.tv_sec + (t2.tv_usec - t1.tv_usec) * 1e-6;
+
          float dt  =  t2.tv_sec - t1.tv_sec + (t2.tv_usec - t1.tv_usec) * 1e-6;
-
        cout << "fps: " << num_frames / dt << endl;
+
          cout << "fps: " << num_frames / dt << endl;
-
        num_frames = 0;
+
          num_frames = 0;
-
        t1 = t2;
+
          t1 = t2;
-
      }
+
      }
-
//      usleep( 1000*10 );
+
//      usleep( 1000*10 );
-
  }
+
    }
-
 
+
-
 
+
-
  ////  cleaning up...
+
    ////  cleaning up...
-
  eglDestroyContext ( egl_display, egl_context );
+
    eglDestroyContext ( egl_display, egl_context );
-
  eglDestroySurface ( egl_display, egl_surface );
+
    eglDestroySurface ( egl_display, egl_surface );
-
  eglTerminate      ( egl_display );
+
    eglTerminate      ( egl_display );
-
  XDestroyWindow    ( x_display, win );
+
    XDestroyWindow    ( x_display, win );
-
  XCloseDisplay    ( x_display );
+
    XCloseDisplay    ( x_display );
-
 
+
-
  return 0;
+
    return 0;
-
}
+
}
-
</source>
+
   
   
[[Category:Development]]
[[Category:Development]]
[[Category:Fremantle]]
[[Category:Fremantle]]

Learn more about Contributing to the wiki.


Please note that all contributions to maemo.org wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see maemo.org wiki:Copyrights for details). Do not submit copyrighted work without permission!


Cancel | Editing help (opens in new window)