mirror of
https://github.com/tsoding/boomer
synced 2024-11-16 12:12:47 +00:00
probe/fbconfig: Texture-map a quadrangle using the "legacy" APIs
* This was... obnoxious to figure out. Need to set up a small pile of state in the context, with very little in the way of diagnostic advice when all you get for output is a white rectangle and no texture. * The legacy (no shader!) APIs are based on the fixed-function pipeline, and apparently not supported by certain OpenGL implementations such as the Intel open-source Linux drivers. * Apparently, the "modern" way to do things is to set up a "vertex buffer", store the coordinates there, and then use shaders to do the geometry mangling and texture mapping.
This commit is contained in:
parent
617f4554ba
commit
21a37af414
@ -6,6 +6,15 @@
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#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);
|
||||
|
Loading…
Reference in New Issue
Block a user