Note that there are some explanatory texts on larger screens.

plurals
  1. POscreenshot using openGL and/or X11
    primarykey
    data
    text
    <p>i am trying to get a screenshot of the screen or a window. I tried using functions from X11 and it works fine. The problem is that getting the pixels from XImage takes a lot of time. Than i tried to look for some answers on how to do it using openGL. Here's what i've got:</p> <pre><code>#include &lt;stdlib.h&gt; #include &lt;stdio.h&gt; #include &lt;cstdio&gt; #include &lt;GL/glut.h&gt; #include &lt;GL/gl.h&gt; #include &lt;GL/glx.h&gt; #include &lt;X11/Xlib.h&gt; int main(int argc, char **argv) { int width=1200; int height=800; //_____________________________---- Display *dpy; Window root; GLint att[] = { GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None }; XVisualInfo *vi; GLXContext glc; dpy = XOpenDisplay(NULL); if ( !dpy ) { printf("\n\tcannot connect to X server\n\n"); exit(0); } root = DefaultRootWindow(dpy); vi = glXChooseVisual(dpy, 0, att); if (!vi) { printf("\n\tno appropriate visual found\n\n"); exit(0); } glXMakeCurrent(dpy, root, glc); glc = glXCreateContext(dpy, vi, NULL, GL_TRUE); printf("vendor: %s\n", (const char*)glGetString(GL_VENDOR)); //____________________________________________ glXMakeCurrent(dpy, root, glc); glEnable(GL_DEPTH_TEST); GLubyte* pixelBuffer = new GLubyte[sizeof(GLubyte)*width*height*3*3]; glReadBuffer(GL_FRONT); GLint ReadBuffer; glGetIntegerv(GL_READ_BUFFER,&amp;ReadBuffer); glPixelStorei(GL_READ_BUFFER,GL_RGB); GLint PackAlignment; glGetIntegerv(GL_PACK_ALIGNMENT,&amp;PackAlignment); glPixelStorei(GL_PACK_ALIGNMENT,1); glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_INT, pixelBuffer); int i; for (i=0;i&lt;100;i++) printf("%u\n",((unsigned int *)pixelBuffer)[i]); return 0; } </code></pre> <p>when i run the program it returns an error: X Error of failed request: BadAccess (attempt to access private resource denied) Major opcode of failed request: 199 () Minor opcode of failed request: 26 Serial number of failed request: 20 Current serial number in output stream: 20</p> <p>if i comment the line with glXMakeCurrent(dpy, root, glc); before glc = glXCreateContext(dpy, vi, NULL, GL_TRUE); it returns no erros, but all the pixels are 0.</p> <p>How should i go about this problem? I am new to openGL and maybe i am missing something important here. Maybe also another way of getting pixels from the screen or specific window exists?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload