view doodle/gtk/opengl_renderer.d @ 85:98980cee8c5b

More work trying to support OpenGL as a renderer
author daveb
date Mon, 16 Aug 2010 17:59:42 +0930
parents doodle/gtk/opengl.d@cdd4fc728d94
children
line wrap: on
line source

module doodle.gtk.opengl;

public {
    import doodle.tk.renderer;
}

private {
    import gtkglc.gl;
    import gtkglc.glu;
}

final class OpenGLRenderer : Renderer {
    void setLineStyle(LineStyle style) {
        GLint factor;
        GLushort pattern;

        switch (style) {
        case LineStyle.SOLID:
            factor = 1;
            pattern = 0xffff;
            break;
        case LineStyle.DASHED:
            factor = 1;
            pattern = 0x0f0f;
            break;
        case LineStyle.DOTTED:
            factor = 1;
            pattern = 0xefef;
            break;
        default:
            assert(0);
        }
        glLineStipple(factor, pattern);
    }

    void setLineWidth(in double width) {
        glLineWidth(width);             // FIXME must take scale into account
    }

    void setColor(in Color color) {
        glColor4d(color.r, color.g, color.b, color.a);
    }

    void translate(in Point p) {
        glTranslated(p.x, p.y, 0.0);
    }

    void scale(in double s) {
        glScaled(s, s, 1.0);
    }

    void pushState() {
        glPushAttrib(0);
    }

    void popState() {
        glPopAttrib();
    }

    void drawRectangle(in Rectangle rectangle, bool fill) {
        glBegin(fill ? GL_QUADS : GL_LINE_LOOP);
        glVertex2d(rectangle.x0, rectangle.y0);
        glVertex2d(rectangle.x0, rectangle.y1);
        glVertex2d(rectangle.x1, rectangle.y1);
        glVertex2d(rectangle.x1, rectangle.y0);
        glEnd();
    }

    void drawEllipse(in Rectangle rectangle, bool fill);
    void drawSegment(in Segment segment);
    void drawHLine(in double y, in double x0, in double x1);
    void drawVLine(in double x, in double y0, in double y1);
    void drawPoly(in Point[] points, bool fill);

    void setFontFace(in FontFace face);
    void setFontSize(in double size);
    void drawText(in string text);

    void measureText(in string text, out Rectangle logicalBounds, out Rectangle totalBounds) const;
}