00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00034
00035 #ifndef GROOVX_GFX_XBMAPRENDERER_H_UTC20050626084024_DEFINED
00036 #define GROOVX_GFX_XBMAPRENDERER_H_UTC20050626084024_DEFINED
00037
00038 #include <X11/Xlib.h>
00039
00040 namespace geom
00041 {
00042 template <class V> class vec2;
00043 }
00044
00045 namespace media
00046 {
00047 class bmap_data;
00048 }
00049
00050 namespace Gfx
00051 {
00052 class Canvas;
00053 }
00054
00056 namespace XBmapRenderer
00057 {
00058 void doRender(Display* display,
00059 Window win,
00060 int screen,
00061 Gfx::Canvas& canvas,
00062 const media::bmap_data& data,
00063 const geom::vec2<double>& world_pos,
00064 const geom::vec2<double>& zoom);
00065 };
00066
00067
00068
00069
00070
00071
00072
00073 #include "geom/vec2.h"
00074
00075 #include "gfx/canvas.h"
00076
00077 #include "media/bmapdata.h"
00078
00079 #include "rutz/error.h"
00080
00081 #include <GL/glx.h>
00082
00083 #include "rutz/trace.h"
00084 #include "rutz/debug.h"
00085 GVX_DBG_REGISTER
00086
00087 void XBmapRenderer::doRender(Display* display,
00088 Window win,
00089 int screen,
00090 Gfx::Canvas& canvas,
00091 const media::bmap_data& data,
00092 const geom::vec2<double>& world_pos,
00093 const geom::vec2<double>& )
00094 {
00095 GVX_TRACE("XBmapRenderer::doRender");
00096
00097 XWindowAttributes xwa;
00098 Status status = XGetWindowAttributes(display, win, &xwa);
00099 if (status == 0)
00100 {
00101 throw rutz::error("couldn't get X11 window attributes", SRC_POS);
00102 }
00103 Visual* visual = xwa.visual;
00104
00105 int format = (data.bits_per_pixel() == 1) ? XYBitmap : ZPixmap;
00106
00107 data.set_row_order(media::bmap_data::TOP_FIRST);
00108
00109
00110 geom::vec2i screen_pos = geom::vec2i(canvas.screenFromWorld2(world_pos));
00111
00112 dbg_dump(3, world_pos);
00113 dbg_dump(3, screen_pos);
00114
00115
00116 screen_pos.y() += data.height();
00117
00118
00119
00120
00121 screen_pos.y() = xwa.height - screen_pos.y();
00122
00123
00124 XImage* image = XCreateImage(display, visual,
00125 data.bits_per_pixel(),
00126 format,
00127 0,
00128 reinterpret_cast<char*>(data.bytes_ptr()),
00129 data.width(), data.height(),
00130 data.byte_alignment()*8,
00131 0);
00132
00133 if (image == NULL)
00134 {
00135 throw rutz::error("couldn't create an XImage", SRC_POS);
00136 }
00137
00138
00139 XGCValues gc_values;
00140
00141 gc_values.foreground = XBlackPixel(display, screen);
00142 gc_values.background = XWhitePixel(display, screen);
00143
00144 unsigned long gc_valuemask = GCForeground | GCBackground;
00145
00146 GC gfx_context_black = XCreateGC(display, win, gc_valuemask, &gc_values);
00147
00148
00149 glXWaitGL();
00150 XPutImage(display, win, gfx_context_black, image,
00151 0, 0, screen_pos.x(), screen_pos.y(),
00152 data.width(), data.height());
00153 glXWaitX();
00154
00155 XFreeGC(display, gfx_context_black);
00156 XFree(image);
00157 }
00158
00159 static const char __attribute__((used)) vcid_groovx_gfx_xbmaprenderer_h_utc20050626084024[] = "$Id: xbmaprenderer.h 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00160 #endif // !GROOVX_GFX_XBMAPRENDERER_H_UTC20050626084024_DEFINED