From 5c1d8bca3ee289959fd4bd4f154490467f160e42 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Mon, 26 May 2003 14:20:16 +0000 Subject: [PATCH] add colors. get ready for adding fonts. add debug() for printnig debug messages --- render2/.cvsignore | 2 ++ render2/Makefile.am | 6 ++--- render2/color.c | 22 ++++++++++++++++++ render2/debug.c | 11 +++++++++ render2/debug.h | 6 +++++ render2/font.h | 10 +++++++++ render2/init.c | 15 +++++++------ render2/instance.c | 13 ++++++----- render2/render.h | 55 ++++++++++++++++++++++++++++++++++++++------- 9 files changed, 116 insertions(+), 24 deletions(-) create mode 100644 render2/color.c create mode 100644 render2/debug.c create mode 100644 render2/debug.h create mode 100644 render2/font.h diff --git a/render2/.cvsignore b/render2/.cvsignore index 806b58af..bf0c6c54 100644 --- a/render2/.cvsignore +++ b/render2/.cvsignore @@ -7,3 +7,5 @@ Makefile libobrender2.la instance.lo init.lo +debug.lo +color.lo diff --git a/render2/Makefile.am b/render2/Makefile.am index e5ff6960..bf38aa8d 100644 --- a/render2/Makefile.am +++ b/render2/Makefile.am @@ -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 index 00000000..fe14e030 --- /dev/null +++ b/render2/color.c @@ -0,0 +1,22 @@ +#include "render.h" +#include "instance.h" +#include "debug.h" +#include + +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 index 00000000..34d009ab --- /dev/null +++ b/render2/debug.c @@ -0,0 +1,11 @@ +#include +#include + +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 index 00000000..cb5413b1 --- /dev/null +++ b/render2/debug.h @@ -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 index 00000000..87e9f1ff --- /dev/null +++ b/render2/font.h @@ -0,0 +1,10 @@ +#ifndef __render_font_h +#define __render_font_h + +#include "glft/glft.h" + +struct RrFont { + struct GlftFont *font; +}; + +#endif diff --git a/render2/init.c b/render2/init.c index 68394c3c..70914b07 100644 --- a/render2/init.c +++ b/render2/init.c @@ -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; diff --git a/render2/instance.c b/render2/instance.c index 59ffbd45..b694721e 100644 --- a/render2/instance.c +++ b/render2/instance.c @@ -1,5 +1,6 @@ #include "instance.h" -#include +#include +#include /* 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); } } diff --git a/render2/render.h b/render2/render.h index 806f04e3..5a955d4c 100644 --- a/render2/render.h +++ b/render2/render.h @@ -4,15 +4,9 @@ #include #include -/* -#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 -- 2.34.1