OpenCores
URL https://opencores.org/ocsvn/orsoc_graphics_accelerator/orsoc_graphics_accelerator/trunk

Subversion Repositories orsoc_graphics_accelerator

[/] [orsoc_graphics_accelerator/] [trunk/] [sw/] [drivers/] [gfx/] [bare/] [orgfx_bitmap_font.c] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 maiden
/*
2
Bare metal OpenCores GFX IP driver for Wishbone bus.
3
 
4
Anton Fosselius, Per Lenander 2012
5
  */
6
 
7
#include "orgfx_bitmap_font.h"
8
#include "orgfx_plus.h"
9
#include "orgfx.h"
10
 
11
orgfx_bitmap_font orgfx_make_bitmap_font(orgfx_tileset *glyphs,
12
                             unsigned int glyphSpacing,
13
                             unsigned int spaceWidth)
14
{
15
    orgfx_bitmap_font font;
16
    font.glyphs = glyphs;
17
    font.glyphSpacing = glyphSpacing;
18
    font.spaceWidth = spaceWidth;
19
    return font;
20
}
21
 
22
void orgfx_put_bitmap_text(orgfx_bitmap_font* font, unsigned int x0, unsigned int y0, const wchar_t *str)
23
{
24
    orgfx_enable_tex0(1);
25
    orgfxplus_bind_tex0(font->glyphs->surface);
26
 
27
    unsigned int fontStride = font->glyphSpacing;
28
 
29
    unsigned int x = x0;
30
 
31
    int i = 0;
32
 
33
    while(1)
34
    {
35
        // Get the character in the string
36
        wchar_t c = str[i++];
37
        // Break if we reach the end of the string
38
        if(c == 0)
39
            break;
40
 
41
        // If c is a space, handle it specially
42
        if(c == ' ')
43
        {
44
            x += FIXEDW * font->spaceWidth;
45
            continue;
46
        }
47
 
48
        // Find the width of the requested character
49
        unsigned int charW = font->glyphs->rects[c].x1 - font->glyphs->rects[c].x0;
50
 
51
        // Draw the character
52
        orgfx_draw_tile(x, y0, font->glyphs, c);
53
 
54
        // Move the x-pointer to the next character position
55
        x += FIXEDW * (charW + fontStride);
56
    }
57
}
58
 
59
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.