add colors. get ready for adding fonts. add debug() for printnig debug messages
authorDana Jansens <danakj@orodu.net>
Mon, 26 May 2003 14:20:16 +0000 (14:20 +0000)
committerDana Jansens <danakj@orodu.net>
Mon, 26 May 2003 14:20:16 +0000 (14:20 +0000)
render2/.cvsignore
render2/Makefile.am
render2/color.c [new file with mode: 0644]
render2/debug.c [new file with mode: 0644]
render2/debug.h [new file with mode: 0644]
render2/font.h [new file with mode: 0644]
render2/init.c
render2/instance.c
render2/render.h

index 806b58af982852696e851e9eb1c405fed0bc7bfe..bf0c6c54f41037d697142da6c0d3f24c7d918fa4 100644 (file)
@@ -7,3 +7,5 @@ Makefile
 libobrender2.la
 instance.lo
 init.lo
+debug.lo
+color.lo
index e5ff6960a37d0aaa4581d0a1825180d3b0cb8c72..bf38aa8dbc82f7d0abd18d92c42e4c79181c52d1 100644 (file)
@@ -8,17 +8,17 @@ CPPFLAGS=$(FC_CFLAGS) $(GLIB_CFLAGS) $(GL_CFLAGS) @CPPFLAGS@ \
          -DTHEMEDIR=\"$(themedir)\"
 
 INCLUDES=-I..
-LIBS=$(GLIB_LIBS) $(GL_LIBS) @LIBS@
+LIBS=$(GL_LIBS) @LIBS@
 
 noinst_PROGRAMS=rendertest
 rendertest_LDFLAGS=-lobrender2 -L.
 rendertest_SOURCES=test.c
 
 lib_LTLIBRARIES=libobrender2.la
-libobrender2_la_SOURCES=init.c instance.c
+libobrender2_la_SOURCES=init.c instance.c color.c debug.c
 
 
-noinst_HEADERS=render.h instance.h
+noinst_HEADERS=render.h instance.h debug.h
 
 MAINTAINERCLEANFILES=Makefile.in
 
diff --git a/render2/color.c b/render2/color.c
new file mode 100644 (file)
index 0000000..fe14e03
--- /dev/null
@@ -0,0 +1,22 @@
+#include "render.h"
+#include "instance.h"
+#include "debug.h"
+#include <X11/Xlib.h>
+
+int RrColorParse(struct RrInstance *inst, const char *colorname,
+                 struct RrColor *ret)
+{
+    XColor xcol;
+
+    if (!XParseColor(RrDisplay(inst), RrColormap(inst), colorname, &xcol)) {
+        RrDebug("unable to parse color '%s'", colorname);
+        ret->r = 0.0;
+        ret->g = 0.0;
+        ret->b = 0.0;
+        return 0;
+    }
+    ret->r = (xcol.red >> 8) / 255.0;
+    ret->g = (xcol.green >> 8) / 255.0;
+    ret->b = (xcol.blue >> 8) / 255.0;
+    return 1;
+}
diff --git a/render2/debug.c b/render2/debug.c
new file mode 100644 (file)
index 0000000..34d009a
--- /dev/null
@@ -0,0 +1,11 @@
+#include <stdio.h>
+#include <stdarg.h>
+
+void RrDebug(char *a, ...)
+{
+#ifdef DEBUG
+    va_list vl;
+    va_start(vl, a);
+    vprintf(a, vl);
+#endif
+}
diff --git a/render2/debug.h b/render2/debug.h
new file mode 100644 (file)
index 0000000..cb5413b
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef __render_debug_h
+#define __render_debug_h
+
+void RrDebug(char *a, ...);
+
+#endif
diff --git a/render2/font.h b/render2/font.h
new file mode 100644 (file)
index 0000000..87e9f1f
--- /dev/null
@@ -0,0 +1,10 @@
+#ifndef __render_font_h
+#define __render_font_h
+
+#include "glft/glft.h"
+
+struct RrFont {
+    struct GlftFont *font;
+};
+
+#endif
index 68394c3cdc93649e18dfe0c77c24b2824eae2e46..70914b07fc72db5b8ecb4e4aa22147daf783828e 100644 (file)
@@ -1,13 +1,14 @@
 #include "instance.h"
 #include "render.h"
+#include "debug.h"
 
 static int glXRating(Display *display, XVisualInfo *v)
 {
     int rating = 0;
     int val;
-    g_print("evaluating visual %d\n", (int)v->visualid);
+    RrDebug("evaluating visual %d\n", (int)v->visualid);
     glXGetConfig(display, v, GLX_BUFFER_SIZE, &val);
-    g_print("buffer size %d\n", val);
+    RrDebug("buffer size %d\n", val);
 
     switch (val) {
     case 32:
@@ -22,12 +23,12 @@ static int glXRating(Display *display, XVisualInfo *v)
     }
 
     glXGetConfig(display, v, GLX_LEVEL, &val);
-    g_print("level %d\n", val);
+    RrDebug("level %d\n", val);
     if (val != 0)
         rating = -10000;
 
     glXGetConfig(display, v, GLX_DEPTH_SIZE, &val);
-    g_print("depth size %d\n", val);
+    RrDebug("depth size %d\n", val);
     switch (val) {
     case 32:
         rating += 30;
@@ -43,7 +44,7 @@ static int glXRating(Display *display, XVisualInfo *v)
     }
 
     glXGetConfig(display, v, GLX_DOUBLEBUFFER, &val);
-    g_print("double buffer %d\n", val);
+    RrDebug("double buffer %d\n", val);
     if (val)
         rating++;
     return rating;
@@ -62,7 +63,7 @@ struct RrInstance *RrInit(Display *display,
                             &vimatch, &count);
 
     if (vilist) {
-        g_print("looking for a GL visual in %d visuals\n", count);
+        RrDebug("looking for a GL visual in %d visuals\n", count);
         for (i = 0; i < count; i++) {
             glXGetConfig(display, &vilist[i], GLX_USE_GL, &val);
             if (val) {
@@ -75,7 +76,7 @@ struct RrInstance *RrInit(Display *display,
         }
     }
     if (rate > 0) {
-        g_print("picked visual %d with rating %d\n", best, rate);
+        RrDebug("picked visual %d with rating %d\n", best, rate);
         ret = RrInstanceNew(display, screen, vilist[best]);
     }
     return ret;
index 59ffbd455929511ab9d3faa643f66aa465287997..b694721e1f1f43abf53a0e77919eae652f301b88 100644 (file)
@@ -1,5 +1,6 @@
 #include "instance.h"
-#include <glib.h>
+#include <stdlib.h>
+#include <assert.h>
 
 /*
 void truecolor_startup(void)
@@ -9,7 +10,7 @@ void truecolor_startup(void)
 
   timage = XCreateImage(ob_display, render_visual, render_depth,
                         ZPixmap, 0, NULL, 1, 1, 32, 0);
-  g_assert(timage != NULL);
+  assert(timage != NULL);
   /\* find the offsets for each color in the visual's masks *\/
   render_red_mask = red_mask = timage->red_mask;
   render_green_mask = green_mask = timage->green_mask;
@@ -37,15 +38,15 @@ struct RrInstance *RrInstanceNew(Display *display,
 {
     struct RrInstance *inst;
 
-    inst = g_new(struct RrInstance, 1);
+    inst = malloc(sizeof(struct RrInstance));
     inst->display = display;
     inst->screen = screen;
     inst->visinfo = visinfo;
     inst->cmap = XCreateColormap(display, RootWindow(display, screen),
                                  RrVisual(inst), AllocNone);
-    inst->glx_context = glXCreateContext(display, &visinfo, NULL, TRUE);
+    inst->glx_context = glXCreateContext(display, &visinfo, NULL, True);
 
-    g_assert(inst->glx_context);
+    assert(inst->glx_context);
 
     return inst;
 }
@@ -55,6 +56,6 @@ void RrInstanceFree(struct RrInstance *inst)
     if (inst) {
         glXDestroyContext(inst->display, inst->glx_context);
         XFreeColormap(inst->display, inst->cmap);
-        g_free(inst);
+        free(inst);
     }
 }
index 806f04e3486c5175ca7257d0c07b21b9457ceada..5a955d4c1c036d5b3e7fb7329bacaa1bd387bf66 100644 (file)
@@ -4,15 +4,9 @@
 #include <glib.h>
 #include <X11/Xlib.h>
 
-/*
-#define RrBool gboolean
-#define RrTrue 1
-#define RrFalse 0
-*/
+/* initialization */
 
 struct RrInstance;
-struct RrRGB;
-struct RrFont;
 
 /*! Returns a struct to be used when calling members of the library.
   If the library fails to initialize, NULL is returned.
@@ -22,9 +16,54 @@ struct RrFont;
 struct RrInstance *RrInit(Display *display,
                           int screen);
 
-/*! Destroys an instance of the library.
+/*! Destroys an instance of the library. The instance should not be used after
+  calling this function.
   @param inst The instance to destroy.
 */
 void RrDestroy(struct RrInstance *inst);
 
+
+/* colors */
+
+/*! A Color (including alpha component) for the Render library. This should be
+  treated as an opaque data type, and be accessed only via the available
+  functions. */
+struct RrColor {
+    /*! The red component. */
+    float r;
+    /*! The green component. */
+    float g;
+    /*! The blue component. */
+    float b;
+    /*! The alpha component. */
+    float a;
+};
+
+/*! Returns the red component for an RrColor */
+#define RrColorRed(c) (c)->r
+/*! Returns the green component for an RrColor */
+#define RrColorGreen(c) (c)->g
+/*! Returns the blue component for an RrColor */
+#define RrColorBlue(c) (c)->b
+/*! Returns the alpha component for an RrColor */
+#define RrColorAlpha(c) (c)->a
+
+/*! Sets the values of all components for an RrColor */
+#define RrColorSet(c, w, x, y, z) (c)->r = (w), (c)->g = (x), \
+                                  (c)->b = (y), (c)->a = z
+
+
+/*! Gets color values from a colorname.
+  @param inst An instance of the library
+  @param colorname The name of the color.
+  @param ret The RrColor to set the colorvalues in.
+  @return nonzero if the colorname could be parsed; on error, it returns zero.
+*/
+int RrColorParse(struct RrInstance *inst, const char *colorname,
+                 struct RrColor *ret);
+
+/* fonts */
+
+struct RrFont;
+
 #endif