Output Text in AllegroGL
James Stanley

You may remember my other thread about AllegroGL. Well, that went a little off topic, so for my newest problem I'm having another thread.

I've got my button drawn properly in the window now, and when I click it, I've got my ship flying around the screen and it's all fine and dandy and running at 800fps (as opposed to 24 with just Allegro). But then I tried to put some writing on the screen and I got stuck. Here's a stripped down version of the offending code:

1 font = allegro_gl_convert_allegro_font(font, AGL_FONT_TYPE_TEXTURED, 1);
2 //Window is 640x480, OpenGL screen size thing is -320 to 320 and -240 to 240.
3 
4 while(1) {
5 //Update logic
6 ////////////////////////////////////////////////////////////////////////
7 //Removed because there's no OpenGL, graphics, or text calls in here
8 
9 //Now update graphics
10 ////////////////////////////////////////////////////////////////////////
11 glClear(GL_COLOR_BUFFER_BIT);
12 opengl_mouse_coords();//My function to convert mouse co-ordinates
13 allegro_gl_printf(font, 200, 8, 0, white, "Apero!");
14 draw_gl_bitmap(pointer_images[pointer], gl_mousex, gl_mousey - 16, 16, 16);
15 allegro_gl_flip();
16 }

EDIT:
opengl_init() sets up the OpenGL settings:

void opengl_init(void) {
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrtho(-320, 320, -240, 240, -1, 1);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  glDisable(GL_DEPTH_TEST);
  glEnable(GL_TEXTURE_2D);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  glEnable(GL_BLEND);
}

LordHolNapul

try this:

/* First, draw the text alpha blended */
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    allegro_gl_printf(demofont, 1, 8, 0, makeacol(255,255,255,255),
                     "Hello World!");
    glBlendFunc(GL_ONE, GL_ZERO);
    glDisable(GL_BLEND);

remember to erase the color afther this, because otherwise you damage the further outputs.
ciao8-)

James Stanley

Yes!
That works!
Thank you very much!

EDIT:
Ah!
Upon further inspection, I'd already got the GL_BLEND and GlBlendFunc set up in opengl_init(). The reason my code wasn't working is because the variable white is makecol(255,255,255) - it does not have an alpha channel. Thanky you for showing me!

Thread #591683. Printed from Allegro.cc