GLFONT n'a pas l'air de march

ktangao Messages postés 1 Statut Membre -  
Char Snipeur Messages postés 10112 Date d'inscription   Statut Contributeur Dernière intervention   -
Bonjour,

Cela fait 3 mois que je me suis mis à OpenGl dans le cadre d'un projet à l'école. Il s'est avéré que j'ai eu besoin d'afficher du texte à l'intérieur d'une fenêtre openGL. J'ai donc regardé les différentes librairies qui existaient et finalement j'ai décidé d'utiliser GLFont (http://students.cs.byu.edu/~bfish/glfont.php), puisqu'il repondait à mes attentes. Voilà le code que j'ai écrit mais il n'as pas l'air de fonctionner... Quelqu'un peut-il me dire ce qui ne vas pas dans mon code, please?

#ifdef _WIN32
#include <windows.h>
#endif

#include <gl/gl.h>
#include <gl/glu.h>
#include <GL/glut.h>

#include <utility>
#include <iostream>
#include <stdio.h>

#include "glfont.h"


GLuint textureName =1;
//glGenTextures((GLsizei)1, &textureName);
PixelPerfectGLFont *myfont = new PixelPerfectGLFont();

void TestBedInit (void)
{
	//Initialize OpenGL
	glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	//Initialize the viewport
	glViewport(0, 0, 640, 480);

	//Initialize OpenGL projection matrix
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	//glOrtho(0.0f, 640.0f, 480.0f, 0.0f, -2.0f, 2.0f);

	//Try and load our font
	
	try {
		myfont->Create("me.glf", textureName);
	}
	catch(GLFontError::InvalidFile) {
		cerr << "Cannot load font\n";
		abort();
	}
}

void TestBedRender (void)
{
	//Draw some stuff
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity( );
	glEnable(GL_TEXTURE_2D);
	glColor3f(1.0f, 0.0f, 0.0f);
	glClear(GL_COLOR_BUFFER_BIT) ;

	try {
		myfont->Begin();
		myfont->TextOut("hello world", 5, 5, 0);
		//myfont->End();
	}
	catch(GLFontError::InvalidFont) {
		cerr << "Trying to draw with an uninitialized font\n";
		abort();
	}
	glDisable(GL_TEXTURE_2D);
	glLoadIdentity();
}


void display(void) {
	//glClear(GL_COLOR_BUFFER_BIT) ;
	//glColor3f(1.0F, 1.0F, 1.0F);
	//glRectf(-0.5,-0.5,0.5,0.5) ;
	//glutSwapBuffers() ;
	//TestBedInit();
	TestBedRender();
	glutSwapBuffers() ;
}

void handleResize(int w, int h) {
	glViewport(0, 0, w, h);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(45.0, (float)w / (float)h, 1.0, 200.0);
}

int main(int argc, char **argv) {
	glutInit(&argc, argv) ;
	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE) ;
	glutInitWindowSize(640, 480);
	glutCreateWindow(argv[0]) ;
	TestBedInit();
	glutDisplayFunc(display) ;
	glutReshapeFunc(handleResize);
	glutMainLoop() ;
	//delete myfont;
return 0 ;
}


Merci pour tout...
A voir également:

1 réponse

Char Snipeur Messages postés 10112 Date d'inscription   Statut Contributeur Dernière intervention   1 299
 
Salut.
Je ne suis pas très bon en OpenGL, mais je me suis déjà pris la tête avec l'affichage de texte, sans succes...
Bon, quelques remarques. Je n'ai pas vu de glBegin(). Il ne faut pas une espèce de glEnable(FONT) ?
Je te conseil dans un premier temps de virer les choses superflu et de tester.
Tu mets glDisable(GL_TEXTURE_2D); avant le swapBuffer, je trouve ça étrange, il me semblait qu'un enable tu le mettait en début de code et n'y touchai plus par la suite. essai d'afficher une figure simple en même temps que ton texte, juste pour voir.
Je suis surement à coté de la plaque, mais bon... on sai jamais
0