Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Problem: Allegro 5 & Opengl text drawing

This thread is locked; no one can reply to it. rss feed Print
Problem: Allegro 5 & Opengl text drawing
Ghost101
Member #14,190
April 2012

I have a problem with the allegro 5 and opengl combination

I want to use al_draw_textf for my fps counter. But it is always behind the perspective of opengl.

I use the functions in given sequence.
Can somebody please help me???

Code:

#SelectExpand
1void Renderer::InitOpenGL() 2 { 3 glMatrixMode( GL_PROJECTION ); 4 glLoadIdentity(); 5 gluPerspective(45.0f,(GLfloat)WIDTH/(GLfloat)HEIGHT,0.1f,100.0f); 6 7 glMatrixMode(GL_MODELVIEW); 8 9 glEnable(GL_TEXTURE_2D); 10 glEnable(GL_CULL_FACE); 11 glEnable(GL_DEPTH_TEST); 12 glShadeModel(GL_SMOOTH); 13 14 glDepthMask(GL_TRUE); 15 16 //glPolygonMode(GL_FRONT,GL_LINE); 17 glPolygonMode(GL_FRONT,GL_FILL); 18 19 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 20 }

#SelectExpand
1void Renderer::RenderBlock(float x, float y, float z, ALLEGRO_BITMAP* texture) 2 { 3 glPushMatrix(); 4 glTranslatef(x,y,z); 5 glBindTexture(GL_TEXTURE_2D, al_get_opengl_texture(texture)); 6 7 glBegin(GL_QUADS); 8 // Front Face 9 //glNormal3f( 0.0f, 0.0f, 1.0f); 10 glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); 11 glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); 12 glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); 13 glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); 14 // Back Face 15 //glNormal3f( 0.0f, 0.0f,-1.0f); 16 glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); 17 glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); 18 glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); 19 glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); 20 21 // All the other faces :D 22 glEnd(); 23 glPopMatrix(); 24 }

#SelectExpand
1 void Renderer::DrawFPS(ALLEGRO_FONT *font, int fps) 2 { 3 al_draw_textf(font, al_map_rgb(255, 255, 255), 5, 5, 0, "FPS: %i", fps); 4 }

Elias
Member #358
May 2000

Easiest way will be a brute foce method like:

// Just pseudocode, look up documentationf or all functions.

// right after al_create_display
glGetDoublev(GL_MODELVIEW_MATRIX, modelview)
glGetDoublev(GL_PROJECTION_MATRIX, projection)
glGetDoublev(GL_VIEWPORT, viewport)

// then later, before using Allegro functions
glViewport(viewport[0], viewport[1], viewport[2], viewport[3])
glMatrixMode(GL_PROJECTION)
gLoadMatrixd(projection)
glMatrixMode(GL_MODELVIEW)
gLoadMatrixd(modelview)

Basically, store whatever is the current transformation setup Allegro uses, then restore to that whenever using Allegro functions.

Alternatively you could check Allegro's source code and just set up the same matrices.

--
"Either help out or stop whining" - Evert

Ghost101
Member #14,190
April 2012

ok thanks for the reaction but is there no way to not brute force it I wass thinking something like making one viewport transparant

or else is there a way to use text in opengl

Elias
Member #358
May 2000

If you want the text to not be affected by the perspective transform, you need to disable that transform, no matter how you draw it.

--
"Either help out or stop whining" - Evert

SiegeLord
Member #7,827
October 2006
avatar

Why not just push and pop the relevant matrices?

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Ghost101
Member #14,190
April 2012

ok that is something I am going to try :D

Go to: