]> icculus.org git repositories - dana/openbox.git/blob - render2/paint.c
can render.. only it doesnt work yet
[dana/openbox.git] / render2 / paint.c
1 #include "render.h"
2 #include "surface.h"
3 #include "instance.h"
4 #include "debug.h"
5 #include <assert.h>
6 #include <GL/glx.h>
7
8 /*! Paints the surface, and all its children */
9 void RrPaint(struct RrSurface *sur)
10 {
11     RrPaintArea(sur, 0, 0, RrSurfaceWidth(sur), RrSurfaceHeight(sur));
12 }
13
14 /*! Paints the surface, and all its children, but only in the given area. */
15 void RrPaintArea(struct RrSurface *sur, int x, int y, int w, int h)
16 {
17     struct RrInstance *inst;
18     int ok;
19
20     inst = RrSurfaceInstance(sur);
21
22     /* can't paint a prototype! */
23     assert(inst);
24     if (!inst) return;
25
26     assert(x >= 0 && y >= 0);
27     if (!(x >= 0 && y >= 0)) return;
28     assert(x + w <= RrSurfaceWidth(sur) && y + h <= RrSurfaceHeight(sur));
29     if (!(x + w <= RrSurfaceWidth(sur) && y + h <= RrSurfaceHeight(sur)))
30         return;
31
32     RrDebug("making %p, %p, %p current\n",
33             RrDisplay(inst), RrSurfaceWindow(sur), RrContext(inst));
34
35     ok = glXMakeCurrent(RrDisplay(inst), RrSurfaceWindow(sur),RrContext(inst));
36     assert(ok);
37
38     glMatrixMode(GL_MODELVIEW);
39     glLoadIdentity();
40     glMatrixMode(GL_PROJECTION);
41     glLoadIdentity();
42
43     glOrtho(0, RrScreenWidth(inst), RrScreenHeight(inst), 0, 0, 10);
44     glViewport(0, 0, RrScreenWidth(inst), RrScreenHeight(inst));
45     glMatrixMode(GL_MODELVIEW);
46     glTranslatef(-RrSurfaceX(sur),
47                  RrScreenHeight(inst)-RrSurfaceHeight(sur)-RrSurfaceY(sur), 0);
48     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
49
50     switch (RrSurfaceType(sur)) {
51     case RR_SURFACE_PLANAR:
52         RrPlanarPaint(sur, x, y, w, h);
53         break;
54     case RR_SURFACE_NONPLANAR:
55         assert(0);
56         break;
57     }
58
59     glXSwapBuffers(RrDisplay(inst), RrSurfaceWindow(sur));
60 }