Skip to main content
gamedev.net
🔒 Locked

here is the code again

Started by Fahad Salim Jan 2, 2004 at 6:22 AM 1 replies 400+ views
Original Post
Fahad Salim
Fahad Salim
Hi! On the advice of a friend,I am now posting a few functions here,this is not my exact project as it is all jumbled up because I have to display text in almost every function,but once this problem is solved,I would be really happy to share it with you guys. Anyway, this is NeHe's lesson 13,I have jsut modified the build font function to take font height as an argument.

GLvoid BuildFont(GLuint x)								// Build Our Bitmap Font

{
	HFONT	font;										// Windows Font ID

	HFONT	oldfont;									// Used For Good House Keeping


	base = glGenLists(96);								// Storage For 96 Characters


	font = CreateFont(	x,							// Height Of Font

						0,								// Width Of Font

						0,								// Angle Of Escapement

						0,								// Orientation Angle

						FW_BOLD,						// Font Weight

						FALSE,							// Italic

						FALSE,							// Underline

						FALSE,							// Strikeout

						ANSI_CHARSET,					// Character Set Identifier

						OUT_TT_PRECIS,					// Output Precision

						CLIP_DEFAULT_PRECIS,			// Clipping Precision

						ANTIALIASED_QUALITY,			// Output Quality

						FF_DONTCARE|DEFAULT_PITCH,		// Family And Pitch

						"aerial");					// Font Name


	oldfont = (HFONT)SelectObject(hDC, font);           // Selects The Font We Want

	wglUseFontBitmaps(hDC, 32, 96, base);				// Builds 96 Characters Starting At Character 32

	SelectObject(hDC, oldfont);							// Selects The Font We Want

	DeleteObject(font);									// Delete The Font

}

And,then I call the Buildfont function in drawGLScene function and after I have printed the text I want,I call the Killfont function,and when I run it,the application crashes.(If I dont use teh killfont,it creates so many fonts that ram is eaten up) I do have removed the buildfont and kill font calls from initGl(),and KillGLwindow()....... other then that,I have practiaclly done nothing at all....just taking advantage of whatever people have done so far. So, this is pretty much the whole story,if anyone can help me out please do because I have to finish it in time. [edited by - fahad salim on January 2, 2004 7:29:40 AM]
Fahad
GamerSg
GamerSg
You should do the reverse.

Only build the font in your init().

And kill your font when your app has finished. This way you only build it once and use it all you want. Even if you don''t delete, it will only leak a few kilobytes at most.

From your code i cant see the problem as to why you cant delete the fonts. Post your Createfont and killfont code and maybe also the error and line number if you can locate it when it crashes. You can try using the debugger to see which line it crashes at.
Fahad Salim
Fahad Salim
Well,the create font and killfont functions are teh same as used in lesson 13.I cant create the font once because because I am using the same variables and the functions to create fonts of different height.
I will try to follow the advice of using teh debugger,but I havent used it before so it might take time,in the menwhile,if you can develop a function or modify these ones,to build font and delete them when they are no more required,please do and tell me about it.
I know its not a big job,I am having difficulty only because I am new to all this and these lists confuse me.
Thanx
Fahad

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.