2013-04-18 03:29:41 +00:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-06-13 22:08:01 +00:00
|
|
|
#include "GLUtil.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-10-13 06:12:58 +00:00
|
|
|
#include "RasterFont.h"
|
2012-12-27 23:52:44 +00:00
|
|
|
#include "ProgramShaderCache.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
// globals
|
|
|
|
|
2012-12-27 23:52:44 +00:00
|
|
|
namespace OGL {
|
2012-12-11 11:37:08 +00:00
|
|
|
|
|
|
|
static const u32 char_width = 8;
|
|
|
|
static const u32 char_height = 13;
|
|
|
|
static const u32 char_offset = 32;
|
|
|
|
static const u32 char_count = 95;
|
|
|
|
|
|
|
|
const u8 rasters[char_count][char_height] = {
|
2013-04-15 20:28:55 +00:00
|
|
|
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18},
|
|
|
|
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0x36},
|
|
|
|
{0x00, 0x00, 0x00, 0x66, 0x66, 0xff, 0x66, 0x66, 0xff, 0x66, 0x66, 0x00, 0x00},
|
|
|
|
{0x00, 0x00, 0x18, 0x7e, 0xff, 0x1b, 0x1f, 0x7e, 0xf8, 0xd8, 0xff, 0x7e, 0x18},
|
|
|
|
{0x00, 0x00, 0x0e, 0x1b, 0xdb, 0x6e, 0x30, 0x18, 0x0c, 0x76, 0xdb, 0xd8, 0x70},
|
|
|
|
{0x00, 0x00, 0x7f, 0xc6, 0xcf, 0xd8, 0x70, 0x70, 0xd8, 0xcc, 0xcc, 0x6c, 0x38},
|
|
|
|
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x1c, 0x0c, 0x0e},
|
|
|
|
{0x00, 0x00, 0x0c, 0x18, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x18, 0x0c},
|
|
|
|
{0x00, 0x00, 0x30, 0x18, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x18, 0x30},
|
|
|
|
{0x00, 0x00, 0x00, 0x00, 0x99, 0x5a, 0x3c, 0xff, 0x3c, 0x5a, 0x99, 0x00, 0x00},
|
|
|
|
{0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0xff, 0xff, 0x18, 0x18, 0x18, 0x00, 0x00},
|
|
|
|
{0x00, 0x00, 0x30, 0x18, 0x1c, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0x00, 0x00, 0x00, 0x38, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0x00, 0x60, 0x60, 0x30, 0x30, 0x18, 0x18, 0x0c, 0x0c, 0x06, 0x06, 0x03, 0x03},
|
|
|
|
{0x00, 0x00, 0x3c, 0x66, 0xc3, 0xe3, 0xf3, 0xdb, 0xcf, 0xc7, 0xc3, 0x66, 0x3c},
|
|
|
|
{0x00, 0x00, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x78, 0x38, 0x18},
|
|
|
|
{0x00, 0x00, 0xff, 0xc0, 0xc0, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x03, 0xe7, 0x7e},
|
|
|
|
{0x00, 0x00, 0x7e, 0xe7, 0x03, 0x03, 0x07, 0x7e, 0x07, 0x03, 0x03, 0xe7, 0x7e},
|
|
|
|
{0x00, 0x00, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0xff, 0xcc, 0x6c, 0x3c, 0x1c, 0x0c},
|
|
|
|
{0x00, 0x00, 0x7e, 0xe7, 0x03, 0x03, 0x07, 0xfe, 0xc0, 0xc0, 0xc0, 0xc0, 0xff},
|
|
|
|
{0x00, 0x00, 0x7e, 0xe7, 0xc3, 0xc3, 0xc7, 0xfe, 0xc0, 0xc0, 0xc0, 0xe7, 0x7e},
|
|
|
|
{0x00, 0x00, 0x30, 0x30, 0x30, 0x30, 0x18, 0x0c, 0x06, 0x03, 0x03, 0x03, 0xff},
|
|
|
|
{0x00, 0x00, 0x7e, 0xe7, 0xc3, 0xc3, 0xe7, 0x7e, 0xe7, 0xc3, 0xc3, 0xe7, 0x7e},
|
|
|
|
{0x00, 0x00, 0x7e, 0xe7, 0x03, 0x03, 0x03, 0x7f, 0xe7, 0xc3, 0xc3, 0xe7, 0x7e},
|
|
|
|
{0x00, 0x00, 0x00, 0x38, 0x38, 0x00, 0x00, 0x38, 0x38, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0x00, 0x00, 0x30, 0x18, 0x1c, 0x1c, 0x00, 0x00, 0x1c, 0x1c, 0x00, 0x00, 0x00},
|
|
|
|
{0x00, 0x00, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0x60, 0x30, 0x18, 0x0c, 0x06},
|
|
|
|
{0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0x00, 0x00, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x03, 0x06, 0x0c, 0x18, 0x30, 0x60},
|
|
|
|
{0x00, 0x00, 0x18, 0x00, 0x00, 0x18, 0x18, 0x0c, 0x06, 0x03, 0xc3, 0xc3, 0x7e},
|
|
|
|
{0x00, 0x00, 0x3f, 0x60, 0xcf, 0xdb, 0xd3, 0xdd, 0xc3, 0x7e, 0x00, 0x00, 0x00},
|
|
|
|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 0xc3},
|
|
|
|
{0x00, 0x00, 0xff, 0xc0, 0xc0, 0x60, 0x30, 0x7e, 0x0c, 0x06, 0x03, 0x03, 0xff},
|
|
|
|
{0x00, 0x00, 0x3c, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x3c},
|
|
|
|
{0x00, 0x03, 0x03, 0x06, 0x06, 0x0c, 0x0c, 0x18, 0x18, 0x30, 0x30, 0x60, 0x60},
|
|
|
|
{0x00, 0x00, 0x3c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x3c},
|
|
|
|
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0x66, 0x3c, 0x18},
|
|
|
|
{0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x38, 0x30, 0x70},
|
|
|
|
{0x00, 0x00, 0x7f, 0xc3, 0xc3, 0x7f, 0x03, 0xc3, 0x7e, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0x00, 0x00, 0xfe, 0xc3, 0xc3, 0xc3, 0xc3, 0xfe, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0},
|
|
|
|
{0x00, 0x00, 0x7e, 0xc3, 0xc0, 0xc0, 0xc0, 0xc3, 0x7e, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0x00, 0x00, 0x7f, 0xc3, 0xc3, 0xc3, 0xc3, 0x7f, 0x03, 0x03, 0x03, 0x03, 0x03},
|
|
|
|
{0x00, 0x00, 0x7f, 0xc0, 0xc0, 0xfe, 0xc3, 0xc3, 0x7e, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0x00, 0x00, 0x30, 0x30, 0x30, 0x30, 0x30, 0xfc, 0x30, 0x30, 0x30, 0x33, 0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c0, 0x7f, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0x00, 0x00, 0x1c, 0x36, 0x30, 0x30, 0x30, 0x30, 0xfc, 0x30, 0x30, 0x30, 0x00},
|
|
|
|
{0x00, 0x00, 0x7e, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0x00, 0x00, 0x18, 0x3c, 0x3c, 0x66, 0x66, 0xc3, 0xc3, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0x00, 0x00, 0xc3, 0xe7, 0xff, 0xdb, 0xc3, 0xc3, 0xc3, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0x00, 0x00, 0xc3, 0x66, 0x3c, 0x18, 0x3c, 0x66, 0xc3, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0xc0, 0x60, 0x60, 0x30, 0x18, 0x3c, 0x66, 0x66, 0xc3, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0x00, 0x00, 0xff, 0x60, 0x30, 0x18, 0x0c, 0x06, 0xff, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0x00, 0x00, 0x0f, 0x18, 0x18, 0x18, 0x38, 0xf0, 0x38, 0x18, 0x18, 0x18, 0x0f},
|
|
|
|
{0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18},
|
|
|
|
{0x00, 0x00, 0xf0, 0x18, 0x18, 0x18, 0x1c, 0x0f, 0x1c, 0x18, 0x18, 0x18, 0xf0},
|
|
|
|
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x8f, 0xf1, 0x60, 0x00, 0x00, 0x00}
|
2008-12-08 05:25:12 +00:00
|
|
|
};
|
|
|
|
|
2012-12-27 23:52:44 +00:00
|
|
|
static const char *s_vertexShaderSrc =
|
2012-12-28 10:46:00 +00:00
|
|
|
"uniform vec2 charSize;\n"
|
2013-04-08 12:50:58 +00:00
|
|
|
"ATTRIN vec2 rawpos;\n"
|
|
|
|
"ATTRIN vec2 tex0;\n"
|
|
|
|
"VARYOUT vec2 uv0;\n"
|
2012-12-11 21:08:53 +00:00
|
|
|
"void main(void) {\n"
|
2013-01-11 20:24:59 +00:00
|
|
|
" gl_Position = vec4(rawpos,0,1);\n"
|
2013-01-14 21:59:08 +00:00
|
|
|
" uv0 = tex0 * charSize;\n"
|
2012-12-11 21:08:53 +00:00
|
|
|
"}\n";
|
|
|
|
|
2012-12-27 23:52:44 +00:00
|
|
|
static const char *s_fragmentShaderSrc =
|
2013-01-18 23:39:31 +00:00
|
|
|
"uniform sampler2D samp8;\n"
|
2012-12-11 21:08:53 +00:00
|
|
|
"uniform vec4 color;\n"
|
2013-04-08 12:50:58 +00:00
|
|
|
"VARYIN vec2 uv0;\n"
|
|
|
|
"COLOROUT(ocol0)\n"
|
2012-12-11 21:08:53 +00:00
|
|
|
"void main(void) {\n"
|
2013-01-19 10:07:06 +00:00
|
|
|
" ocol0 = texture(samp8,uv0) * color;\n"
|
2012-12-11 21:08:53 +00:00
|
|
|
"}\n";
|
|
|
|
|
2013-02-13 12:12:19 +00:00
|
|
|
static SHADER s_shader;
|
2012-12-27 23:52:44 +00:00
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
RasterFont::RasterFont()
|
|
|
|
{
|
2012-12-11 11:37:08 +00:00
|
|
|
// generate the texture
|
|
|
|
glGenTextures(1, &texture);
|
2013-01-18 23:39:31 +00:00
|
|
|
glActiveTexture(GL_TEXTURE0+8);
|
2012-12-28 10:46:00 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, texture);
|
2012-12-11 11:37:08 +00:00
|
|
|
u32* texture_data = new u32[char_width*char_count*char_height];
|
|
|
|
for(u32 y=0; y<char_height; y++) {
|
|
|
|
for(u32 c=0; c<char_count; c++) {
|
|
|
|
for(u32 x=0; x<char_width; x++) {
|
|
|
|
bool pixel = rasters[c][y] & (1<<(char_width-x-1));
|
|
|
|
texture_data[char_width*char_count*y+char_width*c+x] = pixel ? -1 : 0;
|
|
|
|
}
|
|
|
|
}
|
2009-02-28 16:33:59 +00:00
|
|
|
}
|
2012-12-28 10:46:00 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, char_width*char_count, char_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture_data);
|
2012-12-11 11:37:08 +00:00
|
|
|
delete [] texture_data;
|
2013-04-15 20:28:55 +00:00
|
|
|
|
2012-12-11 21:08:53 +00:00
|
|
|
// generate shader
|
2013-02-13 12:12:19 +00:00
|
|
|
ProgramShaderCache::CompileShader(s_shader, s_vertexShaderSrc, s_fragmentShaderSrc);
|
2013-04-15 20:28:55 +00:00
|
|
|
|
2012-12-11 21:08:53 +00:00
|
|
|
// bound uniforms
|
2013-02-13 12:12:19 +00:00
|
|
|
glUniform2f(glGetUniformLocation(s_shader.glprogid,"charSize"), 1.0f / GLfloat(char_count), 1.0f);
|
|
|
|
uniform_color_id = glGetUniformLocation(s_shader.glprogid,"color");
|
2012-12-28 10:46:00 +00:00
|
|
|
glUniform4f(uniform_color_id, 1.0f, 1.0f, 1.0f, 1.0f);
|
2012-12-11 21:08:53 +00:00
|
|
|
cached_color = -1;
|
2013-04-15 20:28:55 +00:00
|
|
|
|
2012-12-25 11:22:02 +00:00
|
|
|
// generate VBO & VAO
|
|
|
|
glGenBuffers(1, &VBO);
|
|
|
|
glGenVertexArrays(1, &VAO);
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
|
|
|
glBindVertexArray(VAO);
|
2013-01-11 10:59:42 +00:00
|
|
|
glEnableVertexAttribArray(SHADER_POSITION_ATTRIB);
|
|
|
|
glVertexAttribPointer(SHADER_POSITION_ATTRIB, 2, GL_FLOAT, 0, sizeof(GLfloat)*4, NULL);
|
|
|
|
glEnableVertexAttribArray(SHADER_TEXTURE0_ATTRIB);
|
|
|
|
glVertexAttribPointer(SHADER_TEXTURE0_ATTRIB, 2, GL_FLOAT, 0, sizeof(GLfloat)*4, (GLfloat*)NULL+2);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RasterFont::~RasterFont()
|
|
|
|
{
|
2012-12-11 11:37:08 +00:00
|
|
|
glDeleteTextures(1, &texture);
|
|
|
|
glDeleteBuffers(1, &VBO);
|
|
|
|
glDeleteVertexArrays(1, &VAO);
|
2013-02-13 12:12:19 +00:00
|
|
|
s_shader.Destroy();
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
2012-12-11 11:37:08 +00:00
|
|
|
void RasterFont::printMultilineText(const char *text, double start_x, double start_y, double z, int bbWidth, int bbHeight, u32 color)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2012-12-28 10:46:00 +00:00
|
|
|
size_t length = strlen(text);
|
2013-01-31 10:30:44 +00:00
|
|
|
GLfloat *vertices = new GLfloat[length*6*4];
|
2013-04-15 20:28:55 +00:00
|
|
|
|
2012-12-11 11:37:08 +00:00
|
|
|
int usage = 0;
|
2012-12-28 10:46:00 +00:00
|
|
|
GLfloat delta_x = GLfloat(2*char_width)/GLfloat(bbWidth);
|
|
|
|
GLfloat delta_y = GLfloat(2*char_height)/GLfloat(bbHeight);
|
|
|
|
GLfloat border_x = 2.0/GLfloat(bbWidth);
|
|
|
|
GLfloat border_y = 4.0/GLfloat(bbHeight);
|
2013-04-15 20:28:55 +00:00
|
|
|
|
2012-12-28 10:46:00 +00:00
|
|
|
GLfloat x = GLfloat(start_x);
|
|
|
|
GLfloat y = GLfloat(start_y);
|
2013-04-15 20:28:55 +00:00
|
|
|
|
2012-12-28 10:46:00 +00:00
|
|
|
for(size_t i=0; i<length; i++) {
|
2012-12-11 11:37:08 +00:00
|
|
|
u8 c = text[i];
|
2013-04-15 20:28:55 +00:00
|
|
|
|
2012-12-11 11:37:08 +00:00
|
|
|
if(c == '\n') {
|
2009-02-28 16:33:59 +00:00
|
|
|
x = start_x;
|
2012-12-11 11:37:08 +00:00
|
|
|
y -= delta_y + border_y;
|
|
|
|
continue;
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2013-04-15 20:28:55 +00:00
|
|
|
|
2013-04-19 13:21:45 +00:00
|
|
|
// do not print spaces, they can be skipped easily
|
2012-12-11 11:37:08 +00:00
|
|
|
if(c == ' ') {
|
|
|
|
x += delta_x + border_x;
|
|
|
|
continue;
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2013-04-15 20:28:55 +00:00
|
|
|
|
2012-12-11 11:37:08 +00:00
|
|
|
if(c < char_offset || c >= char_count+char_offset) continue;
|
2013-04-15 20:28:55 +00:00
|
|
|
|
2012-12-11 11:37:08 +00:00
|
|
|
vertices[usage++] = x;
|
|
|
|
vertices[usage++] = y;
|
2012-12-28 10:46:00 +00:00
|
|
|
vertices[usage++] = GLfloat(c-char_offset);
|
|
|
|
vertices[usage++] = 0.0f;
|
2013-04-15 20:28:55 +00:00
|
|
|
|
2012-12-11 11:37:08 +00:00
|
|
|
vertices[usage++] = x+delta_x;
|
|
|
|
vertices[usage++] = y;
|
2012-12-28 10:46:00 +00:00
|
|
|
vertices[usage++] = GLfloat(c-char_offset+1);
|
|
|
|
vertices[usage++] = 0.0f;
|
2013-04-15 20:28:55 +00:00
|
|
|
|
2012-12-11 11:37:08 +00:00
|
|
|
vertices[usage++] = x+delta_x;
|
|
|
|
vertices[usage++] = y+delta_y;
|
2012-12-28 10:46:00 +00:00
|
|
|
vertices[usage++] = GLfloat(c-char_offset+1);
|
|
|
|
vertices[usage++] = 1.0f;
|
2013-04-15 20:28:55 +00:00
|
|
|
|
2012-12-11 11:37:08 +00:00
|
|
|
vertices[usage++] = x;
|
|
|
|
vertices[usage++] = y;
|
2012-12-28 10:46:00 +00:00
|
|
|
vertices[usage++] = GLfloat(c-char_offset);
|
|
|
|
vertices[usage++] = 0.0f;
|
2013-04-15 20:28:55 +00:00
|
|
|
|
2012-12-11 11:37:08 +00:00
|
|
|
vertices[usage++] = x+delta_x;
|
|
|
|
vertices[usage++] = y+delta_y;
|
2012-12-28 10:46:00 +00:00
|
|
|
vertices[usage++] = GLfloat(c-char_offset+1);
|
|
|
|
vertices[usage++] = 1.0f;
|
2013-04-15 20:28:55 +00:00
|
|
|
|
2012-12-11 11:37:08 +00:00
|
|
|
vertices[usage++] = x;
|
|
|
|
vertices[usage++] = y+delta_y;
|
2012-12-28 10:46:00 +00:00
|
|
|
vertices[usage++] = GLfloat(c-char_offset);
|
|
|
|
vertices[usage++] = 1.0f;
|
2013-04-15 20:28:55 +00:00
|
|
|
|
2012-12-11 11:37:08 +00:00
|
|
|
x += delta_x + border_x;
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2013-04-15 20:28:55 +00:00
|
|
|
|
2013-01-31 10:30:44 +00:00
|
|
|
if(!usage) {
|
|
|
|
delete [] vertices;
|
|
|
|
return;
|
|
|
|
}
|
2013-04-15 20:28:55 +00:00
|
|
|
|
2013-01-31 10:30:44 +00:00
|
|
|
glBindVertexArray(VAO);
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, usage*sizeof(GLfloat), vertices, GL_STREAM_DRAW);
|
|
|
|
|
|
|
|
delete [] vertices;
|
2009-02-28 16:33:59 +00:00
|
|
|
|
2013-02-13 12:12:19 +00:00
|
|
|
s_shader.Bind();
|
2012-12-11 21:08:53 +00:00
|
|
|
|
|
|
|
if(color != cached_color) {
|
2013-01-15 11:25:06 +00:00
|
|
|
glUniform4f(uniform_color_id, GLfloat((color>>16)&0xff)/255.f,GLfloat((color>>8)&0xff)/255.f,GLfloat((color>>0)&0xff)/255.f,GLfloat((color>>24)&0xff)/255.f);
|
2012-12-11 21:08:53 +00:00
|
|
|
cached_color = color;
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2012-12-11 21:08:53 +00:00
|
|
|
|
2013-01-18 23:39:31 +00:00
|
|
|
glActiveTexture(GL_TEXTURE0+8);
|
2012-12-11 11:37:08 +00:00
|
|
|
glDrawArrays(GL_TRIANGLES, 0, usage/4);
|
2008-08-24 21:50:41 +00:00
|
|
|
}
|
2012-12-27 23:52:44 +00:00
|
|
|
|
2013-01-07 19:11:26 +00:00
|
|
|
}
|