diff --git a/probe/fbconfig/fbconfig.c b/probe/fbconfig/fbconfig.c index 6dcb308..48a07ac 100644 --- a/probe/fbconfig/fbconfig.c +++ b/probe/fbconfig/fbconfig.c @@ -6,6 +6,15 @@ #include +#define CHECK_ERROR(context) \ + do { \ + int error = glGetError(); \ + if (error) { \ + fprintf(stderr, "GL error 0x%x while " context "\n", \ + error); \ + } \ + } while (0) + typedef void (APIENTRY *DEBUGPROC)(GLenum source, GLenum type, GLuint id, @@ -86,16 +95,58 @@ int main(int argc, char *argv[]) glXMakeContextCurrent(dpy, glxWin, glxWin, context); + glViewport(0, 0, 256, 256); + glEnable(GL_DEBUG_OUTPUT); glDebugMessageCallback(debug_message, NULL); GLuint textures = 0; glGenTextures(1, &textures); - glBindTexture(GL_TEXTURE_2D, textures); + CHECK_ERROR("making texture"); + + /* All texture operations function in terms of a "current + * texture". Set it here */ + glBindTexture(GL_TEXTURE_2D, textures); + CHECK_ERROR("binding texture"); + + /* Prep a test texture image, grabbing a small chunk of the root + * window */ + { + XImage *img = XGetImage(dpy, DefaultRootWindow(dpy), 0, 0, 100, 100, AllPlanes, ZPixmap); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 100, 100, 0, GL_RGBA, GL_UNSIGNED_BYTE, img->data); + CHECK_ERROR("loading texture"); + XDestroyImage(img); + } + + glEnable(GL_TEXTURE_2D); + + /* Set up the display coordinate space as orthographic */ + glOrtho(0.0d, 256.0d, 256.0d, 0.0d, -1.0d, 1.0d); + CHECK_ERROR("setting transforms"); + + /* If we don't set the mapping filters, we get a blank image */ + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + /* Use the "legacy" (deprecated, possibly no longer supported by + * open-source drivers) "immediate mode" APIs to render a + * window-sized rectangle from the texture image */ + glBegin(GL_QUADS); + /* Texture coordinates are from 0 to 1, output coordinates are + * from 0 to width/height */ + glTexCoord2i(0, 0); + glVertex2i(0, 0); + glTexCoord2i(1, 0); + glVertex2i(256, 0); + glTexCoord2i(1, 1); + glVertex2i(256, 256); + glTexCoord2i(0, 1); + glVertex2i(0, 256); + glEnd(); + CHECK_ERROR("rasterizing the quadrangle"); - glClearColor(1.0f, 0.0f, 0.0f, 1.0f); - glClear(GL_COLOR_BUFFER_BIT); glFlush(); + CHECK_ERROR("flush"); glXSwapBuffers(dpy, glxWin); sleep(10);