Foros del Web » Programación para mayores de 30 ;) » C/C++ »

Crear textura opengl usango xcomposite y GLX_EXT_texture_from_pixmap

Estas en el tema de Crear textura opengl usango xcomposite y GLX_EXT_texture_from_pixmap en el foro de C/C++ en Foros del Web. Hola, tengo un problema desarrollando una pequeña aplicacion usando XComposite con opengl, estoy tratando de crear un composite manager como compiz pero solo para, por ...
  #1 (permalink)  
Antiguo 24/02/2013, 13:45
 
Fecha de Ingreso: marzo-2009
Mensajes: 7
Antigüedad: 15 años, 2 meses
Puntos: 0
Pregunta Crear textura opengl usango xcomposite y GLX_EXT_texture_from_pixmap

Hola, tengo un problema desarrollando una pequeña aplicacion usando XComposite con opengl, estoy tratando de crear un composite manager como compiz pero solo para, por ejemplo hacer zoom en el escritorio, por ahora tengo este codigo y solo trato de conseguir la imagen de una ventana o del escritorio en su totalidad, pero solo consigo una textura en blanco y ningun error, talvez me falta algo. Estoy desarrollando en ubuntu 12.04 en una maquina virtual de vmware player.

Código C++:
Ver original
  1. //#include <iostream>
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. #include<string.h>
  5. #include<X11/Xlib.h>
  6. #include <X11/Xutil.h>
  7. #include <X11/extensions/Xcomposite.h>
  8. #include <X11/extensions/Xfixes.h>
  9. #include<GL/gl.h>
  10. #include<GL/glx.h>
  11. #include <GL/glext.h>
  12. #include<GL/glu.h>
  13. #include <GL/glut.h>
  14.  
  15.  
  16. static PFNGLXBINDTEXIMAGEEXTPROC glXBindTexImageEXT = NULL;
  17. static PFNGLXRELEASETEXIMAGEEXTPROC glXReleaseTexImageEXT = NULL;
  18.  
  19. Display  *display;
  20. Window window;
  21. int value;
  22. float top,bottom;
  23. int nfbconfigs;
  24. GLuint texture;
  25. int i;
  26. GLXFBConfig *fbconfigs;
  27.  
  28. Window getWindowIdFromName(Display *dpy, Window level, char *name)
  29. {
  30.     Window *children;
  31.     Window dmy;
  32.     Window root;
  33.     Window id;
  34.     char *window_name;
  35.     int i;
  36.     unsigned int no_of_children;
  37.  
  38.     if (0 == XQueryTree(dpy, level, &dmy, &dmy, &children, &no_of_children))
  39.         return 0;
  40.  
  41.     for (i=0; i<no_of_children; i++)
  42.     {
  43.         if (XFetchName(dpy,children[i], &window_name))
  44.         {
  45.             if (strcmp (name, window_name))
  46.                 XFree(window_name);
  47.             else
  48.             {
  49.                 XFree(window_name);
  50.                 return children[i];
  51.             }
  52.         }
  53.         else
  54.         {
  55.             if (id = getWindowIdFromName(dpy, children[i], name))
  56.                 return id;
  57.         }
  58.     }
  59.     return 0;
  60. }
  61.  
  62. void drawing(){
  63.     //sleep(1);
  64.    
  65.    
  66.         /* draw using pixmap as texture */
  67.     glClearColor(0.25, 0.25, 0.25, 0.0);
  68.     glClear(GL_COLOR_BUFFER_BIT);
  69.     glPushMatrix();
  70.    
  71.         glBegin (GL_QUADS);
  72.     glVertex3f(-1.0f,1.0f,0.0f);
  73.     glTexCoord2d(-1.0f,1.0f);
  74.     glVertex3f(1.0f,1.0f,0.0f);
  75.     glTexCoord2d(1.0f,1.0f);
  76.     glVertex3f(1.0f,-1.0f,0.0f);
  77.     glTexCoord2d(1.0f,-1.0f);
  78.     glVertex3f(-1.0f,-1.0f,0.0f);
  79.     glTexCoord2d(-1.0f,-1.0f);
  80.    
  81.         glEnd ();
  82.     glPopMatrix();
  83.     glutSwapBuffers();
  84. }
  85.  
  86.  
  87. int main(int argc, char **argv){
  88.  
  89.    
  90.  
  91.     glutInit(&argc,argv);
  92. //glutInitDisplayMode (GLUT_SINGLE | GLUT_RGBA);
  93.  
  94.       glutInitWindowPosition(0,0);
  95.  
  96.       glXBindTexImageEXT = (PFNGLXBINDTEXIMAGEEXTPROC)
  97.           glXGetProcAddress((GLubyte *) "glXBindTexImageEXT");
  98.        glXReleaseTexImageEXT = (PFNGLXRELEASETEXIMAGEEXTPROC)
  99.           glXGetProcAddress((GLubyte*) "glXReleaseTexImageEXT");
  100.  
  101.        if(!glXBindTexImageEXT || !glXReleaseTexImageEXT)
  102.            {
  103.                printf("Some extension functions missing!\n");
  104.                //return 1;
  105.          }
  106.    
  107.     display = XOpenDisplay(NULL);
  108.     window = XDefaultRootWindow(display);
  109.     XCompositeRedirectSubwindows (display, window, CompositeRedirectAutomatic);
  110.     XSelectInput (display, window, SubstructureNotifyMask);
  111.     XWindowAttributes attrib;
  112.     XGetWindowAttributes (display, window, &attrib);
  113.    
  114.         VisualID visualid = XVisualIDFromVisual (attrib.visual);
  115.        
  116.         fbconfigs = glXGetFBConfigs (display, XDefaultScreen(display), &nfbconfigs);
  117.         for (i = 0; i < nfbconfigs; i++)
  118.         {
  119.             XVisualInfo *visinfo = glXGetVisualFromFBConfig (display, fbconfigs[i]);
  120.             if (!visinfo || visinfo->visualid != visualid)
  121.                 continue;
  122.    
  123.             glXGetFBConfigAttrib (display, fbconfigs[i], GLX_DRAWABLE_TYPE, &value);
  124.             if (!(value & GLX_PIXMAP_BIT))
  125.                 continue;
  126.    
  127.             glXGetFBConfigAttrib (display, fbconfigs[i],
  128.                                   GLX_BIND_TO_TEXTURE_TARGETS_EXT,
  129.                                   &value);
  130.             if (!(value & GLX_TEXTURE_2D_BIT_EXT))
  131.                 continue;
  132.    
  133.             glXGetFBConfigAttrib (display, fbconfigs[i],
  134.                                   GLX_BIND_TO_TEXTURE_RGBA_EXT,
  135.                                   &value);
  136.             if (value == False)
  137.             {
  138.                 glXGetFBConfigAttrib (display, fbconfigs[i],
  139.                                       GLX_BIND_TO_TEXTURE_RGB_EXT,
  140.                                       &value);
  141.                 if (value == False)
  142.                     continue;
  143.             }
  144.    
  145.             glXGetFBConfigAttrib (display, fbconfigs[i],
  146.                                   GLX_Y_INVERTED_EXT,
  147.                                   &value);
  148.             if (value == True)
  149.             {
  150.                 top = 0.0f;
  151.                 bottom = 1.0f;
  152.             }
  153.             else
  154.             {
  155.                 top = 1.0f;
  156.                 bottom = 0.0f;
  157.             }
  158.    
  159.             break;
  160.         }
  161.    
  162.         if (i == nfbconfigs){
  163.             /* error 1 */
  164.         printf("error \n");
  165.     }
  166.  
  167.     //Window wind = getWindowIdFromName(display,window,"Qt");
  168.     Pixmap pixmap = XCompositeNameWindowPixmap (display, window);
  169.         const int pixmapAttribs[] = { GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT,
  170.                           GLX_TEXTURE_FORMAT_EXT, GLX_TEXTURE_FORMAT_RGBA_EXT,
  171.               GLX_MIPMAP_TEXTURE_EXT,
  172.                           None };
  173.         GLXPixmap glxpixmap = glXCreatePixmap (display, fbconfigs[i], pixmap, pixmapAttribs);
  174.    
  175.     gluOrtho2D(0,attrib.width,0,attrib.height);
  176.         glEnable(GL_TEXTURE_2D);
  177.         glGenTextures (1, &texture);
  178.         glBindTexture (GL_TEXTURE_2D, texture);
  179.     //XGrabServer(display);
  180.     printf("drawing pixmap \n");  
  181.         glXBindTexImageEXT (display, glxpixmap, GLX_FRONT_LEFT_EXT, NULL);
  182.         printf("pixmap binded\n");
  183.         glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  184.         glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  185.     //XUngrabServer(display);
  186.     //glXReleaseTexImageEXT (display,glxpixmap,GLX_FRONT_LEFT_EXT);
  187.         glutInitWindowSize(500,500);
  188.         glutCreateWindow("simplex");
  189.    
  190.     glutDisplayFunc(drawing);
  191.     //glutIdleFunc(drawing);
  192.  
  193.  
  194.     glutMainLoop();
  195.         return 0;
  196. }

cualquier ayuda estaré muy agradecido y esto servira para cualquiera que se aventure con este tipo de aplicaciones .

Última edición por odabart; 24/02/2013 a las 21:25

Etiquetas: c++, opengl
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 05:06.