~ubuntu-branches/ubuntu/intrepid/blender/intrepid-updates

« back to all changes in this revision

Viewing changes to extern/bFTGL/src/FTTextureGlyph.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cyril Brulebois
  • Date: 2008-08-08 02:45:40 UTC
  • mfrom: (12.1.14 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080808024540-kkjp7ekfivzhuw3l
Tags: 2.46+dfsg-4
* Fix python syntax warning in import_dxf.py, which led to nasty output
  in installation/upgrade logs during byte-compilation, using a patch
  provided by the script author (Closes: #492280):
   - debian/patches/45_fix_python_syntax_warning

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include    "FTTextureGlyph.h"
2
 
 
3
 
 
4
 
FTTextureGlyph::FTTextureGlyph( FT_GlyphSlot glyph, int id, int xOffset, int yOffset, GLsizei width, GLsizei height)
5
 
:   FTGlyph( glyph),
6
 
    destWidth(0),
7
 
    destHeight(0),
8
 
    glTextureID(id),
9
 
    activeTextureID(0)
10
 
{
11
 
    err = FT_Render_Glyph( glyph, FT_RENDER_MODE_NORMAL);
12
 
    if( err || glyph->format != ft_glyph_format_bitmap)
13
 
    {
14
 
        return;
15
 
    }
16
 
 
17
 
    FT_Bitmap      bitmap = glyph->bitmap;
18
 
 
19
 
    destWidth  = bitmap.width;
20
 
    destHeight = bitmap.rows;
21
 
    
22
 
    if( destWidth && destHeight)
23
 
    {
24
 
        glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT);
25
 
        glPixelStorei( GL_UNPACK_LSB_FIRST, GL_FALSE);
26
 
        glPixelStorei( GL_UNPACK_ROW_LENGTH, 0);
27
 
        glPixelStorei( GL_UNPACK_ALIGNMENT, 1);
28
 
 
29
 
        glBindTexture( GL_TEXTURE_2D, glTextureID);
30
 
        glTexSubImage2D( GL_TEXTURE_2D, 0, xOffset, yOffset, destWidth, destHeight, GL_ALPHA, GL_UNSIGNED_BYTE, bitmap.buffer);
31
 
 
32
 
        glPopClientAttrib();
33
 
    }
34
 
 
35
 
 
36
 
//      0    
37
 
//      +----+
38
 
//      |    |
39
 
//      |    |
40
 
//      |    |
41
 
//      +----+
42
 
//           1
43
 
    
44
 
    uv[0].x = static_cast<float>(xOffset) / static_cast<float>(width);
45
 
    uv[0].y = static_cast<float>(yOffset) / static_cast<float>(height);
46
 
    uv[1].x = static_cast<float>( xOffset + destWidth) / static_cast<float>(width);
47
 
    uv[1].y = static_cast<float>( yOffset + destHeight) / static_cast<float>(height);
48
 
    
49
 
    pos.x = glyph->bitmap_left;
50
 
    pos.y = glyph->bitmap_top;
51
 
}
52
 
 
53
 
 
54
 
FTTextureGlyph::~FTTextureGlyph()
55
 
{}
56
 
 
57
 
#include <math.h>
58
 
 
59
 
float FTTextureGlyph::Render( const FTPoint& pen)
60
 
{
61
 
        float dx;
62
 
        
63
 
    glGetIntegerv( GL_TEXTURE_2D_BINDING_EXT, &activeTextureID);
64
 
    if( activeTextureID != glTextureID)
65
 
    {
66
 
        glBindTexture( GL_TEXTURE_2D, (GLuint)glTextureID);
67
 
    }
68
 
    
69
 
        dx= floor( (pen.x + pos.x ) );
70
 
        
71
 
    glBegin( GL_QUADS);
72
 
        glTexCoord2f( uv[0].x, uv[0].y);
73
 
        glVertex2f( dx,             pen.y + pos.y);
74
 
 
75
 
        glTexCoord2f( uv[0].x, uv[1].y);
76
 
        glVertex2f( dx,             pen.y + pos.y - destHeight);
77
 
 
78
 
        glTexCoord2f( uv[1].x, uv[1].y);
79
 
        glVertex2f( dx + destWidth, pen.y + pos.y - destHeight);
80
 
        
81
 
        glTexCoord2f( uv[1].x, uv[0].y);
82
 
        glVertex2f( dx + destWidth, pen.y + pos.y);
83
 
    glEnd();
84
 
 
85
 
    return advance;
86
 
}
87