Well, for those that are interested, here's the final code;
I've tested this method, and my original method of copying the pixel array, and this one works out a good 30ms faster on my computer.
Code:
BufferedImage prepareText(String txt, PFont f){
//the idea with this is to draw Text to an offscreen buffer, then load that as an image for use as a texture
textFont(f);
int w = int(textWidth(txt)+50);
PGraphics pg;
if(w<256){
w=256;
}
pg = createGraphics(w,w,JAVA2D);
pg.beginDraw();
pg.background(0,0);
pg.fill(255);
pg.textFont(f);
pg.textAlign(CENTER);
pg.text(txt,w*0.5,w*0.5-(textDescent()*0.5));
pg.endDraw();
BufferedImage img = new BufferedImage(w, w, BufferedImage.TYPE_INT_ARGB_PRE );
Graphics2D g2d = img.createGraphics();
g2d.drawImage((java.awt.Image)pg.image, 0, 0, w, w, this);
g2d.finalize();
g2d.dispose();
return img;
}
You could extend this function to output a GL.Texture quite easily;
Code:
Texture prepareText(String txt, PFont f){
//the idea with this is to draw Text to an offscreen buffer, then load that as an image for use as a texture
textFont(f);
int w = int(textWidth(txt)+50);
PGraphics pg;
if(w<256){
w=256;
}
pg = createGraphics(w,w,JAVA2D);
pg.beginDraw();
pg.background(0,0);
pg.fill(255);
pg.textFont(f);
pg.textAlign(CENTER);
pg.text(txt,w*0.5,w*0.5-(textDescent()*0.5));
pg.endDraw();
BufferedImage img = new BufferedImage(w, w, BufferedImage.TYPE_INT_ARGB_PRE );
Graphics2D g2d = img.createGraphics();
g2d.drawImage((java.awt.Image)pg.image, 0, 0, w, w, this);
g2d.finalize();
g2d.dispose();
Texture tx = TextureIO.newTexture(img ,true);
return tx;
}
Although I think its considered good practice to wrap any calls to TextureIO.newTexture in try catch braces, that might just be for loading from a file.
From what I've been reading as I've tried to solve this problem;
Once you have a GL texture made, you should edit it using the Texture.updateSubImage method, as its much faster and avoids unnecessary cycles.
BufferedImages have lots of different modes, I've picked the one that seems to work fastest.
The question is now, is it worth it? When I've got some time, I'll see if just doing this purely in processing's API is faster/slower.
Thanks for all the help
Martin