View difference between Paste ID: g2fpTzkA and 8RU87abu
SHOW: | | - or go back to the newest paste.
1
/**
2
 * Org.: DefeatThePurpose Entertainment
3
 * User: Suds (Scott Drew) <suds@defeatthepurpose.net>
4
 * Date: 16/08/12
5
 * Time: 8:12 PM
6
 */
7
public class Box {
8
    public static void renderRectangle(Rectangle rectangle, float lineWidth, Colour colour)
9
    {
10
        glColor3f(colour.getR(), colour.getG(), colour.getB());
11
12
        glBegin(GL_QUADS);
13
            glVertex2i(rectangle.getX(), rectangle.getY());
14
            glVertex2i(rectangle.getX() + rectangle.getW(), rectangle.getY());
15
            glVertex2i(rectangle.getX() + rectangle.getW(), rectangle.getY() + rectangle.getH());
16
            glVertex2i(rectangle.getX(), rectangle.getY() + rectangle.getH());
17
        glEnd();
18
19
        glLineWidth(lineWidth);
20
21
	// render slightly darker border
22
        glColor3f(colour.getR() * 0.8f, colour.getG() * 0.8f, colour.getB() * 0.8f);
23
24
        glBegin(GL_LINE_LOOP);
25
            glVertex2i(rectangle.getX(), rectangle.getY());
26
            glVertex2i(rectangle.getX() + rectangle.getW(), rectangle.getY());
27
            glVertex2i(rectangle.getX() + rectangle.getW(), rectangle.getY() + rectangle.getH());
28
            glVertex2i(rectangle.getX(), rectangle.getY() + rectangle.getH());
29
        glEnd();
30
    }
31
}
32
33
// This method is found in my Button class:
34
    public void render()
35
    {
36
	// Render box
37
        Box.renderRectangle(_bounds, 2.0f, _colour);
38
39
	// render text in centre of box
40
        _font.drawString(_bounds.getX() + (_bounds.getW() / 2) - (_font.getWidth(_text) / 2),
41
                _bounds.getY() + (_bounds.getH() / 2) - (_font.getHeight(_text) / 2), _text);
42
    }
43
44
// snippet from initGL() --> Is ALL of the gl calls other than those above.
45
	glEnable(GL_BLEND);
46
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
47
48
        glViewport(0, 0, 800,480);
49
        glMatrixMode(GL_MODELVIEW);
50
51
        glMatrixMode(GL_PROJECTION);
52
        glLoadIdentity();
53
        glOrtho(0, 800, 480, 0, 1, -1);
54
        glMatrixMode(GL_MODELVIEW);
55
        glLoadIdentity();
56
57-
        glEnable(GL_TEXTURE_2D);
57+
        glEnable(GL_TEXTURE_2D);
58
59
// These screenshots highlight the problem.
60
// The code as above:
61
// https://dl.dropbox.com/u/18809996/tuvgxscreenies/darkmodderbutton.png
62
63
// Commenting out JUST line 40: the _font.drawString() call:
64
// https://dl.dropbox.com/u/18809996/tuvgxscreenies/notext.png
65
// Notice that all the colours are DIFFERENT NOW. WTF!?
66
67
// _font is an instance of org.newdawn.slick.UnicodeFont
68
// All of the code directly applied to _font:
69
	_font.addAsciiGlyphs();
70
        _font.addGlyphs(400, 600);
71
        _font.getEffects().add(new ShadowEffect(Color.BLACK, 1, 1, 1.0f));
72
        _font.getEffects().add(new ColorEffect(Color.WHITE));
73
        _font.setPaddingLeft(1);
74
        _font.setPaddingRight(1);
75
76
        try
77
        {
78
            _font.loadGlyphs();
79
        } catch (SlickException e) {
80
            e.printStackTrace();
81
        }
82
83
// The initial problem stems from all the buttons being the wrong colour in the first place. The no text
84
// screenie has all the correct colours, but they are on the wrong buttons. The code setting the colours
85
// is correct. I've checked it a half dozen times. Theres no mixing orders, or swapping an R for a G
86
// value, or anything like that. The issue is definitely somewhere in the code in this paste. :-/