void glPrintf(double x, double y, char* font, char* text, ...)
{
char Output[256];
va_list ap;
if(text == NULL)
return;
va_start(ap, text);
vsprintf(Output, text, ap);
va_end(ap);
// printf(Output);
// printf("\n");
Font* Using;
if(font == NULL) // Get the default font...
Using = cFontManager.GetFont("Default");
else
Using = cFontManager.GetFont(font);
// We should have a font by now...
if(!Using)
return;
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, Using->Tex);
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0,640,480,0,-1,1);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glTranslated(x * 640,y * 480,0);
int set = 1;
glListBase(Using->base - 32 + (128 * set));// - (7 * 16));
glCallLists(strlen(Output), GL_UNSIGNED_BYTE, Output);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
glDisable(GL_TEXTURE_2D);
}
A problem with altered Lesson 17 + others modifications
Hello,
I have a slight and most of all anoying problem.
I've been trying to make glPrint do the same as printf (so the variable argument list thing).
Another alteration is that I'm using TGA instead of BMP and I'm using glBlendFunc(GL_ONE, GL_ONE) to remove the black background (so no messing with the Alpha channel in PSP 8 and the use of GLaux).
And the final (major) change is the usage of a Font and Font Manager class.
Now the problem.
If I print the result (of the variable argument list) to the console it says what it should say.
But if I display it, then it gives out some sort of shifted characters.
I've tried to correct the shift, but it only works with with 1 line in the texture (a power of 2 map with 16x16 cells, a tga version of the one suplied with Lesson 17), and only the first character.
Now the possitive parts. ;)
The texture loads fine (I've tested it on a textured triangle (ignore the flipped texture in the screenshot)).
The blending works perfect.
The variable argument list seems to work also fine (correction, it doesn't seem work with multiple arguments :( any idea's?).
The font uses the right characters and font.
Here is a screenshot of it.
http://www32.brinkster.com/mldaalder/Problem1.jpg
It also shows a part of the console, it displays the FPS and the some info on the texture it has loaded (which is correct).
So any idea's?
Thank you for your time,
MLeoDaalder
[EDIT] Before I forget, I did search the forums (with: "Lesson 17 problem" not the best critera), but that didn't solve my problem (apart for my PSP8 image problem I was also having at the time:)).
Then I started sifting through the forum, I got as far as page 25 before I noticed that I was skipping topics....
[EDIT2] I guess some code would help...
My glPrintf command:
The code compiles without any errors btw.
Also the glTranslated(x * 640,y * 480,0);
Is because I like to use floats for positioning (I don't know why I like them though ;)).
[EDIT3] The commented out "- (7 * 16)" was the correction try (or what I ended up with trying to get FPS to show up right).
[EDIT4] I removed the img tag, since it didn't work all the time...
[Edited by - mldaalder on November 11, 2004 4:37:12 PM]
Quote: Original post by b3rs3rk
the screenshot is not visible :/
I noticed it... And I fixed the link.
It should work (it does for me).
Apparantly Brinkster doesn't allow leaching from the images dir...
And be sure to read the text under the edits. ;)
I think some more code would be handy (it might be the list making, atleast I came up with when I tried to think where the problem could be).
It's code is part of the icon code (or so I thought at first I would do it, but it didn't got that far actually...).
Ignore the "PyObject* name" I don't like std::CString and it's variants, nor do I (really) like char arrays, this way I can put everything in it, and it won't give me any, and I mean any problems.
Icon.h
Icon.cpp
It's code is part of the icon code (or so I thought at first I would do it, but it didn't got that far actually...).
Ignore the "PyObject* name" I don't like std::CString and it's variants, nor do I (really) like char arrays, this way I can put everything in it, and it won't give me any, and I mean any problems.
Icon.h
class Font{public: Font(); virtual ~Font(); Font(char* filename, char* name); GLuint base; PyObject* name; unsigned int Tex;};
Icon.cpp
Font::Font(char* filename, char* name){ this->name = Py_BuildValue("s", name); this->Tex = cTexManager.GetTextureID(filename); if(cTexManager.GetTextureID(filename) < 0) // If we don't have a texture, then make it... this->Tex = cTexManager.LoadTexture(filename); // Now we need to build the font... float cx; float cy; this->base = glGenLists(256); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, this->Tex); for(int loop=0;loop<256;loop++) { cx=float(loop%16)/16.0f; cy=float(loop/16)/16.0f; glNewList(this->base + loop,GL_COMPILE); glBegin(GL_QUADS);// printf("loop: %i, %f\n", loop, (double)loop / 255);/// glColor3f((double)loop / 255, (double)loop / 255, (double)loop / 255); glTexCoord2f(cx,1-cy-0.0625f); glVertex2f(0,0);// glColor3f((double)loop / 255, (double)loop / 255, (double)loop / 255); glTexCoord2f(cx+0.0625f,1-cy-0.0625f); glVertex2f(float(16),0.0f);// glColor3f((double)loop / 255, (double)loop / 255, (double)loop / 255); glTexCoord2f(cx+0.0625f,1-cy); glVertex2f(float(16),float(16));// glColor3f((double)loop / 255, (double)loop / 255, (double)loop / 255); glTexCoord2f(cx,1-cy); glVertex2f(0.0f,float(16)); glEnd(); glTranslated(11,0,0); glEndList(); }}Font::~Font(){ glDeleteLists(this->base,256);}
Not very good practice, isn't it? 4 posts in a row?
Anyway, sorry to be so bother some...
Now, I have some more progress that astonishes me.
I've aplied the same things to Lesson 17 directly, and what ya know, there it works perfectly. Then I copied the changes back, made sure it uses my Texture Manager (and that one does work btw, it gives me the right texture).
The one diffrence, Lesson 17 uses a bmp image (and the glaux lib) instead of tga, and in my program I'm using SDL for the window (I forgot to mention that in the first posts, sorry about that. I'm only using it because I like my program to be portable, and I only know how to create a window in Windows).
Although I doubt it's SDL which is giving me the problem, I only use it for Window Creation and swapping the buffer.
The variable list problem also seems to be solved btw.
Thank you (again) for your time,
MLeoDaalder
Anyway, sorry to be so bother some...
Now, I have some more progress that astonishes me.
I've aplied the same things to Lesson 17 directly, and what ya know, there it works perfectly. Then I copied the changes back, made sure it uses my Texture Manager (and that one does work btw, it gives me the right texture).
The one diffrence, Lesson 17 uses a bmp image (and the glaux lib) instead of tga, and in my program I'm using SDL for the window (I forgot to mention that in the first posts, sorry about that. I'm only using it because I like my program to be portable, and I only know how to create a window in Windows).
Although I doubt it's SDL which is giving me the problem, I only use it for Window Creation and swapping the buffer.
The variable list problem also seems to be solved btw.
Thank you (again) for your time,
MLeoDaalder
Ok, I fixed it...
For some reason it loaded the last row first, and worked it's way up.
And for some very strange reason it put the characters themselfs the right way up.
After I figured that out (by using GL_COMPILE_AND_EXECUTE instead of GL_COMPILE and some commenting out and such), it was a breeze (10 minutes of trying, I've never been good at coordinates) to solve it.
Thank you for your interrest.
For some reason it loaded the last row first, and worked it's way up.
And for some very strange reason it put the characters themselfs the right way up.
After I figured that out (by using GL_COMPILE_AND_EXECUTE instead of GL_COMPILE and some commenting out and such), it was a breeze (10 minutes of trying, I've never been good at coordinates) to solve it.
Thank you for your interrest.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement