Jump to content
  • Advertisement
Sign in to follow this  

A problem with altered Lesson 17 + others modifications

This topic is 4963 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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:
void glPrintf(double x, double y, char* font, char* text, ...)
	char Output[256];
	va_list ap;

	if(text == NULL)

	va_start(ap, text);
	vsprintf(Output, text, ap);

//	printf(Output);
//	printf("\n");

	Font* Using;
	if(font == NULL) // Get the default font...
		Using = cFontManager.GetFont("Default");
		Using = cFontManager.GetFont(font);

	// We should have a font by now...

	glBindTexture(GL_TEXTURE_2D, Using->Tex);

	glBlendFunc(GL_ONE, GL_ONE);




	glTranslated(x * 640,y * 480,0);

	int set = 1;

	glListBase(Using->base - 32 + (128 * set));// - (7 * 16));

	glCallLists(strlen(Output), GL_UNSIGNED_BYTE, Output);






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]

Share this post

Link to post
Share on other sites
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. ;)

Share this post

Link to post
Share on other sites
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.

class Font
virtual ~Font();
Font(char* filename, char* name);
GLuint base;
PyObject* name;
unsigned int Tex;

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);
glBindTexture(GL_TEXTURE_2D, this->Tex);
for(int loop=0;loop<256;loop++)
glNewList(this->base + loop,GL_COMPILE);

// printf("loop: %i, %f\n", loop, (double)loop / 255);
/// glColor3f((double)loop / 255, (double)loop / 255, (double)loop / 255);

// glColor3f((double)loop / 255, (double)loop / 255, (double)loop / 255);

// glColor3f((double)loop / 255, (double)loop / 255, (double)loop / 255);

// glColor3f((double)loop / 255, (double)loop / 255, (double)loop / 255);



Share this post

Link to post
Share on other sites
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,


Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!