Yawin

Untitled

Apr 11th, 2014
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.93 KB | None | 0 0
  1. /* Este es el error que me da:
  2.  
  3.     X Error of failed request:  BadMatch (invalid parameter attributes)
  4.       Major opcode of failed request:  153 (GLX)
  5.       Minor opcode of failed request:  11 (X_GLXSwapBuffers)
  6.       Serial number of failed request:  28
  7.       Current serial number in output stream:  28
  8.  
  9. */
  10.  
  11. #include <iostream>
  12. #include <cstdlib>
  13.  
  14. #include <GL/glx.h>    /* this includes the necessary X headers */
  15. #include <GL/gl.h>
  16.  
  17. #include <X11/X.h>    /* X11 constant (e.g. TrueColor) */
  18. #include <X11/Xlib.h>    /* X11 constant (e.g. TrueColor) */
  19. #include <X11/keysym.h>
  20.  
  21. using namespace std;
  22.  
  23. Display                 *dpy;   //La superficie sobre la que pintar
  24. Window                  root;   //La ventana
  25. GLint                   att[] = { GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None }; //Atributos de la superficie
  26. XVisualInfo             *vi;    //
  27. Colormap                cmap;   //
  28. XSetWindowAttributes    swa;    //
  29. Window                  win;    //
  30. GLXContext              glc;    //
  31. XWindowAttributes       gwa;    //
  32. XEvent                  xev;    //
  33.  
  34. int main(int argc, char **argv)
  35. {
  36.     //Inicializamos "dpy"
  37.         dpy = XOpenDisplay(NULL);
  38.         if(dpy == NULL)
  39.         {
  40.             cout<<"cannot connect to X server"<<endl;
  41.             exit(0);
  42.         }
  43.  
  44.     //Asignamos a la ventana raíz su superficie
  45.         root = DefaultRootWindow(dpy);
  46.  
  47.         //Y la configuramos
  48.             vi = glXChooseVisual(dpy, 0, att);
  49.             if(vi == NULL)
  50.             {
  51.                 cout<<"no appropriate visual found"<<endl;
  52.                 exit(0);
  53.             }
  54.             else
  55.             {
  56.                 cout<<"visual "<<(void *)vi->visualid<<" selected"<<endl;
  57.             }
  58.  
  59.             cmap = XCreateColormap(dpy, root, vi->visual, AllocNone);
  60.             swa.colormap = cmap;
  61.             swa.event_mask = ExposureMask | KeyPressMask;
  62.  
  63.     win = XCreateWindow(dpy, root, 0, 0, 600, 600, 0, vi->depth, InputOutput, vi->visual, CWColormap | CWEventMask, &swa);
  64.     XMapWindow(dpy, win);
  65.     XStoreName(dpy, win, "Hola mundo");
  66.     glEnable(GL_DEPTH_TEST);
  67.  
  68.     while(1)
  69.     {
  70.         XNextEvent(dpy, &xev);
  71.  
  72.         if(xev.type == Expose)
  73.         {
  74.             XGetWindowAttributes(dpy, win, &gwa);
  75.             glViewport(0, 0, gwa.width, gwa.height);
  76.  
  77.             glBegin(GL_QUADS);
  78.                 glColor3f(1., 0., 0.); glVertex3f(-.75, -.75, 0.);
  79.                 glColor3f(0., 1., 0.); glVertex3f( .75, -.75, 0.);
  80.                 glColor3f(0., 0., 1.); glVertex3f( .75,  .75, 0.);
  81.                 glColor3f(1., 1., 0.); glVertex3f(-.75,  .75, 0.);
  82.             glEnd();
  83.  
  84.             glXSwapBuffers(dpy, win);
  85.         }
  86.  
  87.         else if(xev.type == KeyPress)
  88.         {
  89.             glXMakeCurrent(dpy, None, NULL);
  90.             glXDestroyContext(dpy, glc);
  91.             XDestroyWindow(dpy, win);
  92.             XCloseDisplay(dpy);
  93.             exit(0);
  94.         }
  95.     }
  96.     return 0;
  97. }
Advertisement
Add Comment
Please, Sign In to add comment