4 Copyright Luki <humbell@ethz.ch>
5 Copyright 2011 Michel Pollet <buserror@gmail.com>
7 This file is part of simavr.
9 simavr is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 simavr is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with simavr. If not, see <http://www.gnu.org/licenses/>.
23 #include "hd44780_glut.h"
26 #include <GLUT/glut.h>
31 #include "font.h" // generated with gimp
33 static GLuint font_texture;
34 static int charwidth = 5;
35 static int charheight = 7;
40 glGenTextures(1, &font_texture);
41 glBindTexture(GL_TEXTURE_2D, font_texture);
42 glTexImage2D(GL_TEXTURE_2D, 0, 4,
44 lcd_font.height, 0, GL_RGBA,
47 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
48 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
50 glMatrixMode(GL_TEXTURE);
52 glScalef(1.0f / (GLfloat) lcd_font.width, 1.0f / (GLfloat) lcd_font.height, 1.0f);
54 glMatrixMode(GL_MODELVIEW);
58 glColor32U(uint32_t color)
61 (float)((color >> 24) & 0xff) / 255.0f,
62 (float)((color >> 16) & 0xff) / 255.0f,
63 (float)((color >> 8) & 0xff) / 255.0f,
64 (float)((color) & 0xff) / 255.0f );
74 int left = index * charwidth;
75 int right = index * charwidth + charwidth;
80 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
82 glDisable(GL_TEXTURE_2D);
83 glColor32U(character);
92 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
94 glEnable(GL_TEXTURE_2D);
95 glBindTexture(GL_TEXTURE_2D, font_texture);
99 glTranslatef(.2f, .2f, 0);
101 glTexCoord2i(right, top); glVertex3i(5, 0, 0);
102 glTexCoord2i(left, top); glVertex3i(0, 0, 0);
103 glTexCoord2i(left, bottom); glVertex3i(0, 7, 0);
104 glTexCoord2i(right, bottom); glVertex3i(5, 7, 0);
110 glTexCoord2i(right, top); glVertex3i(5, 0, 0);
111 glTexCoord2i(left, top); glVertex3i(0, 0, 0);
112 glTexCoord2i(left, bottom); glVertex3i(0, 7, 0);
113 glTexCoord2i(right, bottom); glVertex3i(5, 7, 0);
130 glDisable(GL_TEXTURE_2D);
132 glColor32U(background);
133 glTranslatef(border, border, 0);
135 glVertex3f(rows * charwidth + (rows - 1) + border, -border, 0);
136 glVertex3f(-border, -border, 0);
137 glVertex3f(-border, lines * charheight + (lines - 1) + border, 0);
138 glVertex3f(rows * charwidth + (rows - 1) + border, lines * charheight
139 + (lines - 1) + border, 0);
142 glColor3f(1.0f, 1.0f, 1.0f);
143 const uint8_t offset[] = { 0, 0x40, 0x20, 0x60 };
144 for (int v = 0 ; v < b->h; v++) {
146 for (int i = 0; i < b->w; i++) {
147 glputchar(b->vram[offset[v] + i], character, text, shadow);
148 glTranslatef(6, 0, 0);
151 glTranslatef(0, 8, 0);
153 hd44780_set_flag(b, HD44780_FLAG_DIRTY, 0);