[C++][OpenGL][FTGL]Problem z wyświetleniem tekstu
Ostatnio zmodyfikowano 2011-07-20 12:19
qba10 Temat założony przez niniejszego użytkownika |
[C++][OpenGL][FTGL]Problem z wyświetleniem tekstu » 2011-07-20 12:19:56 Witam Uczę się używać biblioteki FTGL z połączeniem z OpenGL'em; Jednak nie udaje mi się wyświetlić napisu mimo braku błedów w kompilatorze. Proszę o pomoc z poprawieniem poniższego kodu:
#include <SDL/SDL.h> #include <GL/gl.h> #include <GL/glu.h>
#include <stdio.h> #include <stdlib.h>
#include <FTGL/ftgl.h>
static GLboolean should_rotate = GL_TRUE;
static void quit_tutorial( int code ) { SDL_Quit(); exit( code ); }
static void handle_key_down( SDL_keysym * keysym ) { switch( keysym->sym ) { case SDLK_ESCAPE: quit_tutorial( 0 ); break; case SDLK_SPACE: should_rotate = !should_rotate; break; default: break; } }
static void process_events( void ) { SDL_Event event; while( SDL_PollEvent( & event ) ) { switch( event.type ) { case SDL_KEYDOWN: handle_key_down( & event.key.keysym ); break; case SDL_QUIT: quit_tutorial( 0 ); break; } } }
static void draw_screen( void ) { }
static void setup_opengl( int width, int height ) { float ratio =( float ) width /( float ) height; glShadeModel( GL_SMOOTH ); glCullFace( GL_BACK ); glFrontFace( GL_CCW ); glEnable( GL_CULL_FACE ); glClearColor( 0, 0, 0, 0 ); glViewport( 0, 0, width, height ); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); gluPerspective( 60.0, ratio, 1.0, 1024.0 ); }
int main( int argc, char * argv[] ) { const SDL_VideoInfo * info = NULL; int width = 0; int height = 0; int bpp = 0; int flags = 0; if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) { fprintf( stderr, "Video initialization failed: %s\n", SDL_GetError() ); quit_tutorial( 1 ); } info = SDL_GetVideoInfo(); if( !info ) { fprintf( stderr, "Video query failed: %s\n", SDL_GetError() ); quit_tutorial( 1 ); } width = 800; height = 600; bpp = info->vfmt->BitsPerPixel; SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 ); SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 ); SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 ); SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 ); SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); flags = SDL_OPENGL; if( SDL_SetVideoMode( width, height, bpp, flags ) == 0 ) { fprintf( stderr, "Video mode set failed: %s\n", SDL_GetError() ); quit_tutorial( 1 ); } setup_opengl( width, height ); static FTFont * font; font = new FTGLPixmapFont( "/usr/share/fonts/truetype/freefont/FreeMono.ttf" ); font->FaceSize( 24 ); while( 1 ) { process_events(); glColor3i( 233, 180, 98 ); GLfloat x = 100.0; GLfloat y = 100.0; glEnable( GL_TEXTURE_2D ); glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glPushMatrix(); { glTranslatef( x, y, 0.0 ); font->Render( "Hello World" ); glPopMatrix(); glDisable( GL_TEXTURE_2D ); glDisable( GL_BLEND ); } draw_screen(); } delete font; return 0; }
|
|
« 1 » |