Changeset 87


Ignore:
Timestamp:
Jul 14, 2010, 2:14:35 AM (10 years ago)
Author:
sam
Message:

Naive font renderer prototype.

Location:
trunk/src
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/Makefile

    r79 r87  
    11
    22SRC = test-map.cpp \
    3       game.cpp video.cpp tiler.cpp tileset.cpp scene.cpp layer.cpp map.cpp
     3      game.cpp video.cpp tiler.cpp tileset.cpp scene.cpp \
     4      font.cpp layer.cpp map.cpp
    45
    56all: test-map
  • trunk/src/game.cpp

    r79 r87  
     1
     2#include <cstdio>
    13
    24#include "game.h"
    35#include "map.h"
     6#include "font.h"
    47
    58/*
     
    1316private:
    1417    Map *map;
     18    Font *font;
    1519    int x, y;
    1620    int mousex, mousey;
     21
     22    int frame;
    1723};
    1824
     
    2531    data = new GameData();
    2632    data->map = new Map(mapname);
     33    data->font = new Font("gfx/font/ascii.png");
    2734    data->x = data->y = 0;
     35    data->frame = 0;
    2836}
    2937
    3038Game::~Game()
    3139{
     40    delete data->font;
    3241    delete data->map;
    3342    delete data;
     
    4857    scene->Render();
    4958    delete scene;
     59
     60    char buf[1024];
     61    sprintf(buf, "Frame %i", data->frame++);
     62    data->font->Print(10, 10, buf);
    5063}
    5164
  • trunk/src/tileset.cpp

    r81 r87  
    4040    int ntiles;
    4141
     42    SDL_Surface *img;
    4243    GLuint texture[1];
    4344};
     
    4950TileSet::TileSet(char const *path)
    5051{
    51     SDL_Surface *img = NULL;
    52 
    5352    data = new TileSetData();
    5453    data->name = strdup(path);
     
    5655    data->tiles = NULL;
    5756    data->ntiles = 0;
     57    data->img = NULL;
    5858
    59     /* One tile texture */
    6059    for (char const *name = path; *name; name++)
    61         if ((img = IMG_Load(name)))
     60        if ((data->img = IMG_Load(name)))
    6261            break;
    6362
    64     if (!img)
     63    if (!data->img)
    6564    {
    6665        SDL_Quit();
     
    7170    glBindTexture(GL_TEXTURE_2D, data->texture[0]);
    7271
    73     glTexImage2D(GL_TEXTURE_2D, 0, 4, img->w, img->h, 0,
    74                  GL_RGBA, GL_UNSIGNED_BYTE, img->pixels);
     72    glTexImage2D(GL_TEXTURE_2D, 0, 4, data->img->w, data->img->h, 0,
     73                 GL_RGBA, GL_UNSIGNED_BYTE, data->img->pixels);
    7574
    7675    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
Note: See TracChangeset for help on using the changeset viewer.