summaryrefslogtreecommitdiff
path: root/lib/glsprite.cc
blob: 31193df5ccdf0d166b3f4a9e04257a5e7e7e0f8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
 *  mogltk
 *  Copyright (C) 1999-2004 Nicolas "Pixel" Noble
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/* $Id: glsprite.cc,v 1.12 2007-07-27 14:10:20 pixel Exp $ */

#include <SDL.h>
#include "glbase.h"
#include "glsprite.h"
#include "engine.h"

#define TEXSIZE 256

mogltk::glSprite::glSprite(Handle * h, int asx, int asy) : Sprite(h, asx, asy) {
}

mogltk::glSprite::glSprite(Uint8 * p, int asx, int asy) : Sprite(p, asx, asy) {
}

mogltk::glSprite::~glSprite() {
}

void mogltk::glSprite::draw(int dx, int dy, ColorP c, float sx, float sy) {
    bool was2D;
    
    if (!(was2D = mogltk::engine::glbase_o->is2D()))
	mogltk::engine::glbase_o->Enter2DMode();

    c.Bind();

    Bind();
    glBegin(GL_TRIANGLE_STRIP);
    glTexCoord2i(GetPX()          , GetPY()          ); glVertex2i(dx               , dy               );
    glTexCoord2i(GetPX() + GetSX(), GetPY()          ); glVertex2i(dx + GetSX() * sx, dy               );
    glTexCoord2i(GetPX()          , GetPY() + GetSY()); glVertex2i(dx               , dy + GetSY() * sy);
    glTexCoord2i(GetPX() + GetSX(), GetPY() + GetSY()); glVertex2i(dx + GetSX() * sx, dy + GetSY() * sy);
    glEnd();

    if (!was2D)
	mogltk::engine::glbase_o->Leave2DMode();
}

void mogltk::glSprite::bindcorner(float fx, float fy) {
    if (fx > 1)
	fx = 1;
    if (fy > 1)
	fy = 1;
    if (fx < 0)
	fx = 0;
    if (fy < 0)
	fy = 0;
    glTexCoord2i(GetPX() + fx * GetSX(), GetPY() + fy * GetSY());
}

void mogltk::glSprite::drawrotate(int cx, int cy, double a, ColorP c) {
    bool was2D;
    
    int sx, sy;
    
    sx = GetSX() / 2;
    sy = GetSY() / 2;
    
    was2D = mogltk::engine::glbase_o->is2D();
    
    if (!was2D)
	mogltk::engine::glbase_o->Enter2DMode();

    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glTranslated(cx, cy, 0);
    glRotated(a, 0, 0, 1);
    
//    glMatrixMode(GL_TEXTURE);
//    glRotated(a, 0, 0, 1);
    
    c.Bind();

    Bind();
    glBegin(GL_TRIANGLE_STRIP);
    glTexCoord2i(GetPX()          , GetPY()          ); glVertex2i(        - sx,         - sy);
    glTexCoord2i(GetPX() + GetSX(), GetPY()          ); glVertex2i(GetSX() - sx,         - sy);
    glTexCoord2i(GetPX()          , GetPY() + GetSY()); glVertex2i(        - sx, GetSY() - sy);
    glTexCoord2i(GetPX() + GetSX(), GetPY() + GetSY()); glVertex2i(GetSX() - sx, GetSY() - sy);
    glEnd();
    
    glPopMatrix();

    if (!was2D)
	mogltk::engine::glbase_o->Leave2DMode();
}