We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › Whilst text in opengl doesnt work...
Page Index Toggle Pages: 1
Whilst text in opengl doesnt work... (Read 510 times)
Whilst text in opengl doesnt work...
Apr 2nd, 2006, 8:57pm
 
A busy Sunday desperately trying to get some form of text for my show which is going up tomorrow. As you may or may not know there is an annoying PFont problem in OPENGL at the moment owing to OPENGL garbling images. A PImage can be maintained as can a texture with updatePixels() but the PFont.images[] array is presented differently I guess.

So I came up with a rather extreme way round the problem. And made my work look a lot better in the process!

It's an isometric character set, which just happens to be ordered in unicode. This sort of thing has certainly been done before but I post it so I can get to it online and so that people know there's a creative route around some of the holes in OPENGL.
Code:

static Character and;
String showText = "";
static final int [][] charTable = {
{0, 0, 2, 0, 2, 3, 0, 3, 0, 0},// 0
{0, 1, 1, 0, 1, 3}, // 1
{0, 0, 2, 0, 2, 1, 0, 3, 2, 3}, // 2
{0, 0, 2, 0, 0, 1, 2, 3, 0, 3}, // 3
{2, 2, 0, 2, 1, 0, 1, 3}, // 4
{2, 0, 0, 0, 0, 1, 2, 2, 2, 3, 0, 3}, // 5
{2, 0, 0, 0, 0, 3, 2, 3, 2, 1, 0, 1}, // 6
{0, 0, 2, 0, 0, 3}, // 7
{0, 0, 2, 0, 0, 3, 2, 3, 0, 0}, // 8
{0, 3, 2, 3, 2, 0, 0, 0, 0, 2, 2, 2}, // 9
{2, 3, 2, 1, 0, 1, 0, 3, 2, 1}, // a (10)
{0, 0, 0, 3, 2, 3, 2, 1, 0, 1}, // b (11)
{2, 1, 0, 1, 0, 3, 2, 3}, // c (12)
{2, 0, 2, 3, 0, 3, 0, 1, 2, 1}, // d (13)
{0, 2, 2, 2, 2, 1, 0, 1, 0, 3, 2, 3}, // e (14)
{0, 3, 0, 0, 2, 0, 0, 1, 2, 1}, // f (15)
{2, 3, 0, 3, 0, 1, 2, 1, 2, 4, 0, 4}, // g (16)
{0, 0, 0, 3, 1, 1, 2, 1, 2, 3}, // h (17)
{1, 1, 1, 3}, // i (18)
{1, 0, 1, 4, 0, 4}, // j (19)
{0, 0, 0, 3, 2, 3, 0, 2, 2, 1}, // k (20)
{1, 0, 1, 3}, // l (21)
{0, 3, 0, 1, 1, 3, 2, 1, 2, 3}, // m (22)
{0, 3, 0, 1, 2, 1, 2, 3}, // n (23)
{0, 1, 2, 1, 2, 3, 0, 3, 0, 1}, // o (24)
{0, 4, 0, 1, 2, 1, 2, 3, 0, 3}, // p (25)
{2, 4, 2, 1, 0, 1, 0, 3, 2, 3}, // q (26)
{0, 3, 0, 1, 2, 1}, // r (27)
{2, 1, 0, 1, 0, 2, 2, 2, 2, 3, 0, 3}, // s (28)
{1, 3, 1, 0, 0, 1, 2, 1}, // t (29)
{0, 1, 0, 3, 2, 3, 2, 1}, // u (30)
{0, 1, 1, 3, 2, 1}, // v (31)
{0, 1, 0, 3, 1, 1, 2, 3, 2, 1}, // w (32)
{0, 1, 2, 3, 0, 3, 2, 1}, // x (33)
{0, 1, 0, 3, 2, 1, 2, 4, 0, 4}, // y (34)
{0, 1, 2, 1, 0, 3, 2, 3} // z (35)
};
QuadChar [] alphabet = new QuadChar[36];
void setup(){
size(800, 400, P3D);
and = new Character('0');
for(int i = 0; i < alphabet.length; i++){
alphabet[i] = new QuadChar(i, 20);
}
}
void draw(){
background(0);
stroke(150);
quadText(showText, mouseX, mouseY);
//noFill();
}
void keyPressed(){
showText += and.toString(key);
}
void quadText(String text, int x, int y){
text.toLowerCase();
char [] letter = text.toCharArray();
int sizeOf = alphabet[1].size * 2;
for(int i = 0; i < letter.length; i++){
int getValue = and.getNumericValue(letter[i]);
if(getValue > -1 && getValue < 36){
alphabet[getValue].draw(x + i * (sizeOf + 5), y);
}
}
}
class QuadChar{
int size;
IsoLine [] lines;
QuadChar(int id, int size){
int i = id;
this.size = size;
lines = new IsoLine[(charTable[i].length - 2) / 2];
for(int j = 0; j < lines.length; j++){
lines[j] = new IsoLine(charTable[i][j * 2] * size, charTable[i][(j *2)+ 1] * size, charTable[i][(j *2)+ 2] * size, charTable[i][(j *2)+ 3] * size, size);
}
}
void draw(int x, int y){
pushMatrix();
translate(x, y, 0);
for(int i = 0; i < lines.length; i++){
lines[i].draw();
}
popMatrix();
}
}
class IsoLine{
Vec3 [] points;
IsoLine(int x1, int y1, int x2, int y2, int depth){
points = new Vec3[4];
points[3] = new Vec3(x1, y1, 0);
points[2] = new Vec3(x2, y2, 0);
points[1] = points[2].iso(depth);
points[0] = points[3].iso(depth);
}
void draw(){
beginShape(QUADS);
for(int i = 0; i < points.length; i++){
vertex(points[i].x, points[i].y, points[i].z);
}
endShape();
}
}
static class Vec3{
int x,y,z;
Vec3(int x, int y, int z){
this.x = x;
this.y = y;
this.z = z;
}
Vec3 iso(int depth){
return new Vec3(x - (depth >> 1), y - (depth >> 1), z - depth);
}
}
Page Index Toggle Pages: 1