Guest User

Untitled

a guest
Feb 25th, 2013
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.24 KB | None | 0 0
  1. // EGL variables
  2. EGLDisplay eglDisplay = 0;
  3. EGLConfig eglConfigWindow = 0;
  4. EGLConfig eglConfigPbuffer = 0;
  5. EGLSurface eglSurfaceWindow = 0;
  6. EGLSurface eglSurfacePbuffer = 0;
  7. EGLContext eglContext = 0;
  8.  
  9.  
  10. const EGLint attribListWindow[] =
  11. {
  12.     EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
  13.     EGL_RED_SIZE, 5,
  14.     EGL_GREEN_SIZE, 6,
  15.     EGL_BLUE_SIZE, 5,
  16.     EGL_ALPHA_SIZE, 0,
  17.     EGL_DEPTH_SIZE, 16,
  18.     EGL_STENCIL_SIZE, 0,
  19.     EGL_NONE
  20. };
  21. const EGLint attribListPbuffer[] =
  22. {
  23.     EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
  24.     EGL_RED_SIZE, 5,
  25.     EGL_GREEN_SIZE, 6,
  26.     EGL_BLUE_SIZE, 5,
  27.     EGL_ALPHA_SIZE, 0,
  28.     EGL_DEPTH_SIZE, 16,
  29.     EGL_STENCIL_SIZE, 0,
  30.     EGL_NONE
  31. };
  32. const EGLint srfPbufferAttr[] =
  33. {
  34.     EGL_WIDTH, 1024,
  35.     EGL_HEIGHT, 1024,
  36.     EGL_COLORSPACE, GL_RGB,
  37.     EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGB,
  38.     EGL_TEXTURE_TARGET, EGL_TEXTURE_2D,
  39.     EGL_LARGEST_PBUFFER, EGL_TRUE,
  40.     EGL_NONE
  41. };
  42.  
  43.     EGLint iMajorVersion, iMinorVersion;
  44.     int iConfigs;
  45.     eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
  46.     eglInitialize(eglDisplay, &iMajorVersion, &iMinorVersion);
  47.     eglChooseConfig(eglDisplay, attribListWindow,
  48.                     &eglConfigWindow, 1, &iConfigs);
  49.     eglContext = eglCreateContext(eglDisplay,
  50.                                   eglConfigWindow, NULL, NULL);
  51.     eglSurfaceWindow = eglGetCurrentSurface(EGL_DRAW);
  52.     eglSurfacePbuffer = eglCreatePbufferSurface(eglDisplay,
  53.                         eglConfigPbuffer,srfPbufferAttr);
  54.  
  55.     eglMakeCurrent(eglDisplay, eglSurfacePbuffer, eglSurfacePbuffer, eglContext);
  56.  
  57.     glGenTextures(1, &theSource);
  58.     glBindTexture(GL_TEXTURE_2D, theSource);
  59.     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1024,
  60.                  1024, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
  61.     glTexParameterf(GL_TEXTURE_2D,
  62.                     GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  63.     glTexParameterf(GL_TEXTURE_2D,
  64.                     GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  65.     glTexParameterf(GL_TEXTURE_2D,
  66.                     GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  67.     glTexParameterf(GL_TEXTURE_2D,
  68.                     GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  69. In drawing
  70.  
  71. UserData *userData = (UserData*)esContext->userData;
  72.     GLfloat vVertices[] = { -1.0f,  -1.0f, 0.0f,  // Position 0
  73.                             0.0f,  0.0f,        // TexCoord 0
  74.                             -1.0f,  1.0f, 0.0f,  // Position 1
  75.                             0.0f,  1.0f,        // TexCoord 1
  76.                             1.0f,  1.0f, 0.0f,  // Position 2
  77.                             1.0f,  1.0f,        // TexCoord 2
  78.                             1.0f, -1.0f, 0.0f,  // Position 3
  79.                             1.0f,  0.0f         // TexCoord 3
  80.                           };
  81.     GLushort indices[] = { 0, 1, 2, 0, 2, 3 };
  82.  
  83.     // Set the viewport
  84.     glViewport ( 0, 0, esContext->width, esContext->height );
  85.     // Clear the color buffer
  86.     glClear ( GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
  87.      // Use the program object
  88.     glUseProgram ( userData->programObject );
  89.  
  90.     // Load the vertex position
  91.     glVertexAttribPointer ( userData->positionLoc, 3, GL_FLOAT,
  92.                             GL_FALSE, 5 * sizeof(GLfloat), vVertices );
  93.     // Load the texture coordinate
  94.     glVertexAttribPointer ( userData->texCoordLoc, 2, GL_FLOAT,
  95.                             GL_FALSE, 5 * sizeof(GLfloat), &vVertices[3] );
  96.  
  97.     glEnableVertexAttribArray ( userData->positionLoc );
  98.     glEnableVertexAttribArray ( userData->texCoordLoc );
  99.  
  100.     // Bind the base map
  101.     glUniform1i ( userData->baseMapLoc, 0 );
  102.     glActiveTexture ( GL_TEXTURE0 );
  103.     glBindTexture ( GL_TEXTURE_2D, userData->baseMapTexId );
  104.     glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
  105.     glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
  106.     //glCopyTexImage2D(GL_TEXTURE_2D,0,0,0,0,0, 1024, 1024);
  107.     glDrawElements ( GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices );
  108.  
  109.     eglMakeCurrent(eglDisplay, eglSurfacePbuffer, eglSurfacePbuffer, eglContext);
  110.  
  111.     eglBindTexImage(eglDisplay, eglSurfacePbuffer, EGL_BACK_BUFFER);
  112.  
  113.     glBindTexture(GL_TEXTURE_2D, theSource);
  114.  
  115.     glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, 1024, 1024, 0);
  116.     glDrawElements ( GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices );
Advertisement
Add Comment
Please, Sign In to add comment