~ubuntu-branches/debian/sid/astromenace/sid

« back to all changes in this revision

Viewing changes to AstroMenaceSource/Core/Font/Font.cpp

  • Committer: Package Import Robot
  • Author(s): Boris Pek, 1
  • Date: 2013-12-19 15:37:09 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20131219153709-vs62lyk7ts7o3rf5
Tags: 1.3.2+repack-2
Add patch debian/patches/fix_work_on_intel_videocards.patch:
Mesa developers have enabled GL_ARB_texture_storage for all drivers [1], so
i915 and i965 drivers now claim the support of this OpenGL extension, but
texture storage feature does not actually work there.
.
[1] http://lists.freedesktop.org/archives/mesa-dev/2013-June/041188.html
.
This patch is just workaround to make the game work on intel videocards with
new Mesa. But real problem should be fixed in Mesa.
(Closes: #718680)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/************************************************************************************
2
2
 
3
3
        AstroMenace (Hardcore 3D space shooter with spaceship upgrade possibilities)
4
 
        Copyright © 2006-2012 Michael Kurinnoy, Viewizard
 
4
        Copyright © 2006-2013 Michael Kurinnoy, Viewizard
5
5
 
6
6
 
7
7
        AstroMenace is free software: you can redistribute it and/or modify
33
33
void vw_DetachFontChar(eFontChar* FontChar);
34
34
extern FT_Face InternalFace;
35
35
extern int InternalFontSize;
 
36
extern int GlobalFontOffsetY;
36
37
 
37
38
 
38
39
 
41
42
//------------------------------------------------------------------------------------
42
43
eFontChar* vw_LoadFontChar(unsigned UTF32)
43
44
{
44
 
        // прежде всего, пытаемся загрузить символ, а уже потом создаем структуру
 
45
        // устанавливаем размеры
 
46
        if (FT_Set_Char_Size( InternalFace, InternalFontSize <<6, InternalFontSize <<6, 96, 96 ))
 
47
        {
 
48
                fprintf(stderr, "Can't set char size %i.", InternalFontSize);
 
49
                return 0;
 
50
        }
45
51
 
46
52
 
47
53
        // загрузка глифа нужного нам символа
58
64
 
59
65
        NewChar->UTF32 = UTF32;
60
66
        NewChar->CharTexture = 0;
 
67
        NewChar->FontSize = InternalFontSize;
61
68
        NewChar->TexturePositionLeft = 0;
62
69
        NewChar->TexturePositionRight = InternalFace->glyph->bitmap.width; // в случае одной текстуры совпадают с шириной
63
70
        NewChar->TexturePositionTop = 0;
66
73
        NewChar->Height = InternalFace->glyph->bitmap.rows;
67
74
        NewChar->Left = InternalFace->glyph->bitmap_left;
68
75
        NewChar->Top = InternalFace->glyph->bitmap_top;
 
76
        NewChar->AdvanceX = InternalFace->glyph->advance.x / 64.0f;
69
77
        NewChar->Prev = 0;
70
78
        NewChar->Next = 0;
71
79
 
92
100
        sprintf(texturefilename, "%i", UTF32);
93
101
 
94
102
        vw_SetTextureProp(RI_MAGFILTER_LINEAR | RI_MINFILTER_LINEAR | RI_MIPFILTER_NONE, RI_CLAMP_TO_EDGE, true, TX_ALPHA_GREYSC, false);
95
 
        NewChar->CharTexture = vw_CreateTextureFromMemory(texturefilename, pixels, NewChar->Width, NewChar->Height, 4, false);
 
103
        NewChar->CharTexture = vw_CreateTextureFromMemory(texturefilename, pixels, NewChar->Width, NewChar->Height, 4, 0, 0, 0, false);
96
104
        // очищаем память
97
105
        delete [] pixels;
98
106
 
124
132
        int EdgingSpace = 2;
125
133
        int MaxHeightInCurrentLine = 0;
126
134
 
 
135
        // устанавливаем размеры
 
136
        if (FT_Set_Char_Size( InternalFace, InternalFontSize <<6, InternalFontSize <<6, 96, 96 ))
 
137
        {
 
138
                fprintf(stderr, "Can't set char size %i.", InternalFontSize);
 
139
                return;
 
140
        }
127
141
 
128
142
        // первый проход, формируем одну большую текстуру
129
143
        const char *CharsList2 = CharsList;
147
161
 
148
162
                NewChar->UTF32 = CurrentChar;
149
163
                NewChar->CharTexture = 0;
 
164
                NewChar->FontSize = InternalFontSize;
150
165
                NewChar->TexturePositionLeft = 0;
151
166
                NewChar->TexturePositionRight = 0;
152
167
                NewChar->TexturePositionTop = 0;
155
170
                NewChar->Height = InternalFace->glyph->bitmap.rows;
156
171
                NewChar->Left = InternalFace->glyph->bitmap_left;
157
172
                NewChar->Top = InternalFace->glyph->bitmap_top;
 
173
                NewChar->AdvanceX = InternalFace->glyph->advance.x / 64.0f;
158
174
                NewChar->Prev = 0;
159
175
                NewChar->Next = 0;
160
176
 
206
222
 
207
223
/////////////////////////////////
208
224
/*
209
 
                // выводим в bmp файл сгенерированный DIB, если нужно проверить
210
 
 
211
 
        SDL_Surface *temp;
212
 
        temp = SDL_CreateRGBSurface(SDL_SWSURFACE, FontTextureWidth, FontTextureHeight, 32,
213
 
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
214
 
        0x000000FF, 0x0000FF00, 0x00FF0000, 0
215
 
#else
216
 
        0x00FF0000, 0x0000FF00, 0x000000FF, 0
217
 
#endif
218
 
        );
219
 
                memcpy(temp->pixels, DIB, FontTextureWidth*FontTextureHeight*4);
220
 
        SDL_SaveBMP(temp, "fontgenerationtest.bmp");
221
 
        SDL_FreeSurface(temp);
 
225
        // выводим в tga файл сгенерированный DIB, если нужно проверить
 
226
 
 
227
        SDL_RWops *TgaFile = SDL_RWFromFile("fontgenerationtest.tga", "wb");
 
228
        if (TgaFile == NULL)
 
229
    {
 
230
                fprintf(stderr, "Can't open VFS file for write.\n");
 
231
        return;
 
232
    }
 
233
 
 
234
        unsigned char UselessChar = 0;  // used for useless char.
 
235
        short int UselessInt = 0;               // used for useless int.
 
236
        unsigned char ImageType = 2;    // Type of image we are saving.
 
237
        unsigned char ImageBits = 32;           // Bit depth.
 
238
        short int ImageWidth = (short int)FontTextureWidth;
 
239
        short int ImageHeight = (short int)FontTextureHeight;
 
240
 
 
241
        // пишем неиспользуемые данные
 
242
        SDL_RWwrite(TgaFile, &UselessChar, sizeof(unsigned char), 1);
 
243
        SDL_RWwrite(TgaFile, &UselessChar, sizeof(unsigned char), 1);
 
244
        // тип картинки
 
245
        SDL_RWwrite(TgaFile, &ImageType, sizeof(unsigned char), 1);
 
246
        // пишем неиспользуемые данные
 
247
        SDL_RWwrite(TgaFile, &UselessInt, sizeof(short int), 1);
 
248
        SDL_RWwrite(TgaFile, &UselessInt, sizeof(short int), 1);
 
249
        SDL_RWwrite(TgaFile, &UselessChar, sizeof(unsigned char), 1);
 
250
        SDL_RWwrite(TgaFile, &UselessInt, sizeof(short int), 1);
 
251
        SDL_RWwrite(TgaFile, &UselessInt, sizeof(short int), 1);
 
252
        // записываем параметры картинки
 
253
        SDL_RWwrite(TgaFile, &ImageWidth, sizeof(short int), 1);
 
254
        SDL_RWwrite(TgaFile, &ImageHeight, sizeof(short int), 1);
 
255
        SDL_RWwrite(TgaFile, &ImageBits, sizeof(unsigned char), 1);
 
256
        // пишем неиспользуемые данные
 
257
        SDL_RWwrite(TgaFile, &UselessChar, sizeof(unsigned char), 1);
 
258
        // пишем данные диб массива
 
259
        SDL_RWwrite(TgaFile, DIB, FontTextureWidth*FontTextureHeight*4, 1);
 
260
 
 
261
        // закрываем файл
 
262
        SDL_RWclose(TgaFile);
222
263
*/
223
264
/////////////////////////////////
224
265
 
225
266
 
226
267
        // создаем текстуру
227
268
        vw_SetTextureProp(RI_MAGFILTER_LINEAR | RI_MINFILTER_LINEAR | RI_MIPFILTER_NONE, RI_CLAMP_TO_EDGE, true, TX_ALPHA_GREYSC, false);
228
 
        eTexture* FontTexture = vw_CreateTextureFromMemory(TextureName, DIB, FontTextureWidth, FontTextureHeight, 4, false);
 
269
        eTexture* FontTexture = vw_CreateTextureFromMemory(TextureName, DIB, FontTextureWidth, FontTextureHeight, 4, 0);
229
270
        // освобождаем память
230
271
        delete [] DIB;
231
272
        if (FontTexture == 0)
272
313
        vw_GetViewport(0, 0, &W, &H);
273
314
        float AHw = H*1.0f;
274
315
 
275
 
        float RealTextYPos = AHw - 2*Y + 4 + InternalFontSize*FontScale;
276
 
        if (ASpresent) RealTextYPos = AH - 2*Y + 4 + InternalFontSize*FontScale;
277
 
 
278
316
 
279
317
        // если текст ниже чем ширина нашего окна - не рисуем
280
318
        if (ASpresent){ if (Y > AH) return;}
298
336
        if (strlen(text) == 0) return;
299
337
 
300
338
        float Xstart = X;
301
 
        // делаем пробел в 2/3 от размера фонта
302
 
        float SpaceWidth = InternalFontSize * 2 / 3;
 
339
        // сразу определяем "базовую" ширину пробела, чтобы учитывать в расчетах
 
340
        if (vw_FindFontCharByUTF32(0x020) == 0) vw_LoadFontChar(0x020);
 
341
        float SpaceWidth = vw_FindFontCharByUTF32(0x020)->AdvanceX*FontScale;
 
342
        // чтобы было более читаемо - делаем пробел не менее 2/3 ширины
 
343
        if (SpaceWidth < (InternalFontSize * 0.65f)) SpaceWidth = InternalFontSize * 0.65f;
303
344
        // коэф. изменения букв по ширине
304
345
        float FontWidthScale = 1.0f;
305
346
 
326
367
                        if (UTF32 == 0x020)
327
368
                                SpaceCount++;
328
369
                        else
329
 
                                LineWidth += DrawChar->Width + DrawChar->Left;
 
370
                                LineWidth += DrawChar->AdvanceX;
330
371
                }
331
372
 
332
373
                if (FlattenWidth > LineWidth)
349
390
 
350
391
                        // считаем длину символов с пробелами
351
392
                        if (UTF32 != 0x020)
352
 
                                LineWidth += DrawChar->Width + DrawChar->Left;
 
393
                                LineWidth += DrawChar->AdvanceX;
353
394
                        else
354
395
                                LineWidth += SpaceWidth;
355
396
                }
416
457
                {
417
458
 
418
459
                        float DrawX = Xstart + DrawChar->Left*FontWidthScale;
419
 
                        float DrawY = Y + 2 + (InternalFontSize - DrawChar->Top)*FontScale; // 2 доп смещение ("привет" от старого фонта)
 
460
                        float DrawY = Y + GlobalFontOffsetY + (InternalFontSize - DrawChar->Top)*FontScale;
420
461
 
421
462
                        // Вычисление поправки по У в зависимости от DrawCorner
422
463
                        // - расположения угла начала координат
455
496
                        tmp[k++] = 1.0f-Yst;
456
497
 
457
498
 
458
 
                        Xstart += (DrawChar->Width + DrawChar->Left)*FontWidthScale;
459
 
                        LineWidth += (DrawChar->Width + DrawChar->Left)*FontWidthScale;
 
499
                        Xstart += DrawChar->AdvanceX*FontWidthScale;
 
500
                        LineWidth += DrawChar->AdvanceX*FontWidthScale;
460
501
                }
461
502
                else
462
503
                {
507
548
        if (strlen(text) == 0) return 0;
508
549
 
509
550
        const char *textdraw = text;
510
 
        // делаем пробел в 2/3 от размера фонта
511
 
        float SpaceWidth = InternalFontSize * 2 / 3;
 
551
        // сразу определяем "базовую" ширину пробела
 
552
        if (vw_FindFontCharByUTF32(0x020) == 0) vw_LoadFontChar(0x020);
 
553
        float SpaceWidth = vw_FindFontCharByUTF32(0x020)->AdvanceX;
 
554
        // чтобы было более читаемо - делаем пробел не менее 2/3 ширины
 
555
        if (SpaceWidth < (InternalFontSize * 0.65f)) SpaceWidth = InternalFontSize * 0.65f;
512
556
        float LineWidth = 0;
513
557
 
514
558
        while (strlen(textdraw) > 0)
524
568
                if (UTF32 == 0x020)
525
569
                        LineWidth += SpaceWidth;
526
570
                else
527
 
                        LineWidth += DrawChar->Width + DrawChar->Left;
 
571
                        LineWidth += DrawChar->AdvanceX;
528
572
        }
529
573
 
530
574
 
556
600
 
557
601
 
558
602
        float Xstart = 0.0f;
559
 
        // делаем пробел в 2/3 от размера фонта
560
 
        float SpaceWidth = InternalFontSize * 2 / 3;
 
603
        // сразу определяем "базовую" ширину пробела
 
604
        float SpaceWidth = vw_FindFontCharByUTF32(0x020)->AdvanceX;
 
605
        // чтобы было более читаемо - делаем пробел не менее 2/3 ширины
 
606
        if (SpaceWidth < (InternalFontSize * 0.65f)) SpaceWidth = InternalFontSize * 0.65f;
561
607
 
562
608
        textdraw = text;
563
609
 
656
702
                        tmp[k++] = 1.0f-Yst;
657
703
 
658
704
 
659
 
                        Xstart += DrawChar->Width + DrawChar->Left;
 
705
                        Xstart += DrawChar->AdvanceX;
660
706
                }
661
707
                else
662
708
                {