1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
/* Includes */
#include "windows.h"
#include "mmsystem.h"
#include "stdio.h"
#include "gl/gl.h"
#include "gl/glut.h"
/* -------- */
void Display( ) ;
void Reshape( int, int ) ;
void DrawBitmapText( int Posx, int Posy, int Cr, int Cg, int Cb, char Texte[ ] ) ;
int main(int argc, char** argv)
{
glutInit( &argc, argv ) ;
glutInitDisplayMode( GLUT_RGBA | GLUT_SINGLE ) ;
glutInitWindowSize( 640, 480 ) ;
glutInitWindowPosition( 150, 150 ) ;
glutCreateWindow( "Essais" ) ;
glutDisplayFunc( Display ) ;
glutReshapeFunc( Reshape ) ;
glutMainLoop( ) ;
return 0 ;
}
void Display( )
{
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ) ;
glClear( GL_COLOR_BUFFER_BIT ) ;
char Tps[ 50 ] ;
sprintf( Tps, "Temps écoulé: %f secondes.", glutGet( GLUT_ELAPSED_TIME ) / 1000.0f ) ;
DrawBitmapText( -1, 0, 10, 200, 50, Tps ) ;
glFlush( );
}
void Reshape(int w, int h)
{
glViewport( 0, 0, w, h ) ;
glMatrixMode( GL_PROJECTION ) ;
glLoadIdentity( ) ;
gluPerspective( 65.0, ( float ) w / ( float ) h, 1.0, 20.0 ) ;
glMatrixMode( GL_MODELVIEW ) ;
glLoadIdentity( ) ;
glTranslatef ( 0.0, 0.0, -5.0 ) ;
}
void DrawBitmapText( int Posx, int Posy, int Cr, int Cg, int Cb, char Texte[ ] )
{
// On prépare des floats pour la conversion RGB => OpenGlColor
float r, g, b ;
r = Cr ; g = Cg ; b = Cb ;
// On fixe la couleur
glColor3f( ( r / 255 ), ( g / 255 ), ( b / 255 ) ) ;
// On rasterize
glRasterPos2d( Posx, Posy ) ;
int t ;
for ( t = 0 ; t < strlen( Texte ) ; t++ )
{
// On écrit les lettres une par une
glutBitmapCharacter( GLUT_BITMAP_9_BY_15, Texte[ t ] ) ;
} ;
} |
Partager