Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Este es el error que me da:
- X Error of failed request: BadMatch (invalid parameter attributes)
- Major opcode of failed request: 153 (GLX)
- Minor opcode of failed request: 11 (X_GLXSwapBuffers)
- Serial number of failed request: 28
- Current serial number in output stream: 28
- */
- #include <iostream>
- #include <cstdlib>
- #include <GL/glx.h> /* this includes the necessary X headers */
- #include <GL/gl.h>
- #include <X11/X.h> /* X11 constant (e.g. TrueColor) */
- #include <X11/Xlib.h> /* X11 constant (e.g. TrueColor) */
- #include <X11/keysym.h>
- using namespace std;
- Display *dpy; //La superficie sobre la que pintar
- Window root; //La ventana
- GLint att[] = { GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None }; //Atributos de la superficie
- XVisualInfo *vi; //
- Colormap cmap; //
- XSetWindowAttributes swa; //
- Window win; //
- GLXContext glc; //
- XWindowAttributes gwa; //
- XEvent xev; //
- int main(int argc, char **argv)
- {
- //Inicializamos "dpy"
- dpy = XOpenDisplay(NULL);
- if(dpy == NULL)
- {
- cout<<"cannot connect to X server"<<endl;
- exit(0);
- }
- //Asignamos a la ventana raíz su superficie
- root = DefaultRootWindow(dpy);
- //Y la configuramos
- vi = glXChooseVisual(dpy, 0, att);
- if(vi == NULL)
- {
- cout<<"no appropriate visual found"<<endl;
- exit(0);
- }
- else
- {
- cout<<"visual "<<(void *)vi->visualid<<" selected"<<endl;
- }
- cmap = XCreateColormap(dpy, root, vi->visual, AllocNone);
- swa.colormap = cmap;
- swa.event_mask = ExposureMask | KeyPressMask;
- win = XCreateWindow(dpy, root, 0, 0, 600, 600, 0, vi->depth, InputOutput, vi->visual, CWColormap | CWEventMask, &swa);
- XMapWindow(dpy, win);
- XStoreName(dpy, win, "Hola mundo");
- glEnable(GL_DEPTH_TEST);
- while(1)
- {
- XNextEvent(dpy, &xev);
- if(xev.type == Expose)
- {
- XGetWindowAttributes(dpy, win, &gwa);
- glViewport(0, 0, gwa.width, gwa.height);
- glBegin(GL_QUADS);
- glColor3f(1., 0., 0.); glVertex3f(-.75, -.75, 0.);
- glColor3f(0., 1., 0.); glVertex3f( .75, -.75, 0.);
- glColor3f(0., 0., 1.); glVertex3f( .75, .75, 0.);
- glColor3f(1., 1., 0.); glVertex3f(-.75, .75, 0.);
- glEnd();
- glXSwapBuffers(dpy, win);
- }
- else if(xev.type == KeyPress)
- {
- glXMakeCurrent(dpy, None, NULL);
- glXDestroyContext(dpy, glc);
- XDestroyWindow(dpy, win);
- XCloseDisplay(dpy);
- exit(0);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment