Changeset 639
- Timestamp:
- Feb 12, 2011, 12:53:45 AM (10 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/monsterz/board.cpp
r633 r639 155 155 data->scoretext = new Text(NULL, "monsterz/gfx/font2.png"); 156 156 data->scoretext->SetAlign(Text::ALIGN_RIGHT); 157 data->scoretext->SetPos(int3(624, 432, 1));157 data->scoretext->SetPos(int3(624, 432, 20)); 158 158 Ticker::Ref(data->scoretext); 159 159 data->score = 0; -
trunk/monsterz/interface.cpp
r633 r639 104 104 { 105 105 int2 m = mouse + int2(-6, 6 - 48); 106 Scene::GetDefault()->AddTile((data->tiles << 16) | 22, m.x, m.y, 20, 0);106 Scene::GetDefault()->AddTile((data->tiles << 16) | 22, m.x, m.y, 30, 0); 107 107 } 108 108 } -
trunk/monsterz/thumbs.cpp
r633 r639 86 86 data->text[n] = new Text(NULL, "monsterz/gfx/font1.png"); 87 87 Ticker::Ref(data->text[n]); 88 int3 p = int3(492, 374 - 27 * n, 1);88 int3 p = int3(492, 374 - 27 * n, 20); 89 89 data->text[n]->SetPos(p); 90 90 } -
trunk/src/font.cpp
r328 r639 13 13 #endif 14 14 15 #ifdef WIN32 16 # define WIN32_LEAN_AND_MEAN 17 # include <windows.h> 18 #endif 19 #if defined __APPLE__ && defined __MACH__ 20 # include <OpenGL/gl.h> 21 #else 22 # define GL_GLEXT_PROTOTYPES 23 # include <GL/gl.h> 24 #endif 25 26 #include <SDL.h> 27 #include <SDL_image.h> 15 #include <string.h> 16 #include <stdio.h> 28 17 29 18 #include "core.h" … … 39 28 private: 40 29 char *name; 41 42 SDL_Surface *img; 30 int tiler; 43 31 int2 size; 44 float tx, ty;45 GLuint texture;46 32 }; 47 33 … … 53 39 : data(new FontData()) 54 40 { 55 data->name = strdup(path);56 data->img = NULL;41 data->name = (char *)malloc(7 + strlen(path) + 1); 42 sprintf(data->name, "<font> %s", path); 57 43 58 for (char const *name = path; *name; name++) 59 if ((data->img = IMG_Load(name))) 60 break; 61 62 if (!data->img) 63 { 64 #if !FINAL_RELEASE 65 fprintf(stderr, "ERROR: could not load %s\n", path); 66 #endif 67 SDL_Quit(); 68 exit(1); 69 } 70 71 data->size = int2(data->img->w, data->img->h) / 16; 72 data->tx = (float)data->size.x / PotUp(data->img->w); 73 data->ty = (float)data->size.y / PotUp(data->img->h); 44 data->tiler = Tiler::Register(path, 0, 16, 1.0f); 45 data->size = Tiler::GetSize(data->tiler); 74 46 75 47 drawgroup = DRAWGROUP_BEFORE; … … 78 50 Font::~Font() 79 51 { 52 Tiler::Deregister(data->tiler); 53 free(data->name); 80 54 delete data; 81 55 } … … 84 58 { 85 59 Entity::TickDraw(deltams); 86 87 if (IsDestroying())88 {89 if (data->img)90 SDL_FreeSurface(data->img);91 else92 glDeleteTextures(1, &data->texture);93 }94 else if (data->img)95 {96 GLuint format = data->img->format->Amask ? GL_RGBA : GL_RGB;97 int planes = data->img->format->Amask ? 4 : 3;98 99 int w = PotUp(data->img->w);100 int h = PotUp(data->img->h);101 102 uint8_t *pixels = (uint8_t *)data->img->pixels;103 if (w != data->img->w || h != data->img->h)104 {105 uint8_t *tmp = (uint8_t *)malloc(planes * w * h);106 for (int line = 0; line < data->img->h; line++)107 memcpy(tmp + planes * w * line,108 pixels + planes * data->img->w * line,109 planes * data->img->w);110 pixels = tmp;111 }112 113 glGenTextures(1, &data->texture);114 glBindTexture(GL_TEXTURE_2D, data->texture);115 116 glTexImage2D(GL_TEXTURE_2D, 0, planes, w, h, 0,117 format, GL_UNSIGNED_BYTE, pixels);118 119 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);120 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);121 122 if (pixels != data->img->pixels)123 free(pixels);124 SDL_FreeSurface(data->img);125 data->img = NULL;126 }127 60 } 128 61 … … 134 67 void Font::Print(int3 pos, char const *str) 135 68 { 136 if (data->img) 137 return; 69 Scene *scene = Scene::GetDefault(); 138 70 139 glBindTexture(GL_TEXTURE_2D, data->texture);140 glBegin(GL_QUADS);141 71 while (*str) 142 72 { 143 73 uint32_t ch = (uint8_t)*str++; 144 float tx = data->tx * (ch & 0xf);145 float ty = data->ty * ((ch >> 4) & 0xf);146 74 147 75 if (ch != ' ') 148 { 149 glTexCoord2f(tx, ty + data->ty); 150 glVertex2f(pos.x, pos.y); 151 glTexCoord2f(tx + data->tx, ty + data->ty); 152 glVertex2f(pos.x + data->size.x, pos.y); 153 glTexCoord2f(tx + data->tx, ty); 154 glVertex2f(pos.x + data->size.x, pos.y + data->size.y); 155 glTexCoord2f(tx, ty); 156 glVertex2f(pos.x, pos.y + data->size.y); 157 } 76 scene->AddTile((data->tiler << 16) | (ch & 255), 77 pos.x, pos.y, pos.z, 0); 158 78 159 79 pos.x += data->size.x; 160 80 } 161 glEnd();162 }163 164 void Font::PrintBold(int3 pos, char const *str)165 {166 static struct { int dx, dy; float r, g, b; } tab[] =167 {168 { -1, 0, 0.0, 0.0, 0.0 },169 { 0, -1, 0.0, 0.0, 0.0 },170 { 0, 1, 0.0, 0.0, 0.0 },171 { 1, -1, 0.0, 0.0, 0.0 },172 { 1, 1, 0.0, 0.0, 0.0 },173 { 2, 0, 0.0, 0.0, 0.0 },174 { 1, 0, 0.5, 0.5, 0.5 },175 { 0, 0, 1.0, 1.0, 1.0 },176 };177 178 if (data->img)179 return;180 181 glPushAttrib(GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT);182 for (unsigned int i = 0; i < sizeof(tab) / sizeof(*tab); i++)183 {184 glColor3f(tab[i].r, tab[i].g, tab[i].b);185 Print(pos + int3(tab[i].dx, tab[i].dy, 0), str);186 }187 glPopAttrib();188 81 } 189 82 -
trunk/src/font.h
r326 r639 35 35 /* New methods */ 36 36 void Print(int3 pos, char const *str); 37 void PrintBold(int3 pos, char const *str);38 37 int2 GetSize() const; 39 38 -
trunk/src/ticker.cpp
r620 r639 316 316 } 317 317 318 Scene::GetDefault()->Render(); 318 319 Scene::Reset(); 319 320
Note: See TracChangeset
for help on using the changeset viewer.