Skip to main content
GameDev.net gamedev.net
🔒 Locked

Color... text...

Started by OpenGLNewbie Oct 20, 2000 at 7:03 PM 6 replies 500+ views
Original Post
OpenGLNewbie
OpenGLNewbie
Ok my main problem is with text and color. I can't get text to work period, no matter what I do! I have used the tutorials here, even downloaded the source, compiled, and ran. With no more affect then my own apps have. Here is included the BuildFont, KillFont and glPrint functions from the tuturials, with a small modification being MainApp.m_hDC. This is not a global variable in my app. Secondly, in my DrawScene function, I do everything first, translate, rotate, bind texture, draw a cube, or what have you. THen after all that is done, I translate to top left, reverse the rotation so (supposedly the text will stay put - no proof since it doesn't show) it doesn't move then set the color, and print. Example: glTranslate(-3.0f, -2.0f. 0.0f); glRotate(xrot, 1.0f, 0.0f, 0.0f); glRotate(yrot, 0.0f, 1.0f, 0.0f); glColor3f(1.0f,1.0f 0.0f); glPrint("Hello World"); This results in.... Well nothing... as far as the text goes. Most unfortunatly it colors the textures and objects in my display, which I would like to know how to solve that problem, as I want the call to only effect the text(when I get text). Can anyone, please help? Below is code for my build and kill font functions, as well as Print.
    
GLvoid BuildFont(GLvoid)					// Build Our Bitmap Font

{
	HFONT	font;						// Windows Font ID

	
	base = glGenLists(96);					// Storage For 96 Characters ( NEW )
	
	
	font = CreateFont(	-24,				// Height Of Font ( NEW )
	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

	"Courier New");			// Font Name

	if(font)
	{
		SelectObject(MainApp.m_hDC, font);				// Selects The Font We Created ( NEW )
	
		wglUseFontBitmaps(MainApp.m_hDC, 32, 96, base);			// Builds 96 Characters Starting At Character 32 ( NEW )
		return;
	}

	// If were to this point, something failed. Lets display a message.
	MessageBox(NULL, "Errer in BuildFont();", "Error", MB_OK);
}

GLvoid KillFont(GLvoid)						// Delete The Font

{
	glDeleteLists(base, 96);				// Delete All 96 Characters ( NEW )
}

GLvoid glPrint(const char *fmt, ...)				// Custom GL "Print" Routine

{
	
	char		text[256];				// Holds Our String

	va_list		ap;					// Pointer To List Of Arguments

	if (fmt == NULL)					// If There's No Text

		return;						// Do Nothing

	va_start(ap, fmt);					// Parses The String For Variables

	vsprintf(text, fmt, ap);				// And Converts Symbols To Actual Numbers

	va_end(ap);						// Results Are Stored In Text

	glPushAttrib(GL_LIST_BIT);				// Pushes The Display List Bits		( NEW )
	glListBase(base - 32);					// Sets The Base Character to 32	( NEW )
	glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);	// Draws The Display List Text	( NEW )
	glPopAttrib();						// Pops The Display List Bits	( NEW )
}
    
----------------------------- What doesn't kill me today, will be there tomorrow.. Edited by - OpenGLNewbie on 10/20/00 7:17:03 PM
-----------------------------What doesn''t kill me today,will be there tomorrow..
Strylinys
Strylinys
Well, your problem might be where you are drawing it. After you have done the drawing of the original scene, push the matrix, then load identity, then translate (that way you don''t have to rotate...) then pop the matrix back.

Your second problem might be where you have drawn your text again. (It''s kinda hard to tell with this code since, first of all, we can all see this code if you just reference the lesson, second, this is not the drawing code...) Where you have drawn your font(s), I am assuming you have

glEnable(GL_COLOR_MATERIAL);

somewhere near it. This is no big deal. If you were able to pause the screen just on the very first frame that it draws, you would see that it''s all coloured properly, when it goes through the loop again, your glColor is affecting the textures. To get around this, simply call

glDisable(GL_COLOR_MATERIAL);

after you have finished drawing your fonts.

S.
OpenGLNewbie
OpenGLNewbie
Ok, heres what my drawscene looks like in short order..
Clear
LoadIdentity
Rotate
Draw2Cubes
Then I do the code for the text..
    
glPushMatrix();
glLoadIdentity();

glTranslatef(0.0f,0.0f,-1.0f);
// Move One Unit Into The Screen

glEnable(GL_COLOR_MATERIAL);

// Pulsing Colors Based On Text Position

glColor3f(1.0f,1.0f,0.0f);
// Position The Text On The Screen

glRasterPos2f(-2.0f, -2.0f);
glPrint("Active OpenGL Text With NeHe - %7.2f");
// Print GL Text To The Screen

glDisable(GL_COLOR_MATERIAL);
glPopMatrix();


This yeilds less effect then I had before. Playing around with it I got some small black text that unfortunatly still rotated with the box. However, I could only see it with lighting on, and coloring it had no effect even though it still makes my cubes yellow(Yes even with the matrix pushing popping and disabling color material).
I don''t know why, so any help would be great! Also, if I enable blending then the text actually becomes yellow, but since I can''t get it off the cube, its blended with it, and can hardly be seen.

Again, my chosen username was meant to literally reflect me in my knowlege of OGL. Please be patient!

-----------------------------
What doesn''t kill me today,
will be there tomorrow..
-----------------------------What doesn''t kill me today,will be there tomorrow..
OpenGLNewbie
OpenGLNewbie
Ok! I figured this out partially. I realized I had to turn disable texture mapping, and depth testing, to insure it stays on top + doesn''t get darkened my mapping the texture.

Heres my code which still yeilds one problem.
    
glEnable(GL_COLOR_MATERIAL);
glDisable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);
glPushMatrix();
glLoadIdentity();
glTranslatef(0.0f,0.0f,-1.0f);
glColor3f(1.0f,1.0f,0.0f);
glRasterPos2f(-1.0f, 0.0f);
glPrint("Active OpenGL Text");
glPopMatrix();
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
glDisable(GL_COLOR_MATERIAL);


This now displays the text properly, and its yellow. Unfortunatly, the two cubes I was drawing are still yellow as well!!! Originally I had the enable/disables after the call to glPushMatrix() and before the call to glPopMatrix. The cubes were still colored so I tried this way, and it has the same effect.
Can anyony tell me why the cubes are stil being colored after turning off COLOR_MATERIAL?

-----------------------------
What doesn''t kill me today,
will be there tomorrow..
-----------------------------What doesn''t kill me today,will be there tomorrow..
The Phantom
The Phantom
At the risk of sounding like I''m pointing out the simple you have changed the color back to white (or that ever you are using) when you draw the boxes haven''t u?



=============
Phantom
''Things can''t get any worse..''
They did...
=============Phantom''Things can''t get any worse..''They did...
Strylinys
Strylinys
You might want to try looking at the colour of your light... It might be yellow. Try changing the glColor to bright red after you''ve drawn your text to see if the other objects go red...

S.
penetrator
penetrator
I run in the same problem ! Did you find any solution?

MButchers
MButchers
this may help

  

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0,Width,Height,0);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glPushAttrib(GL_ENABLE_BIT);
glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST);
//all orthographic output here ie text bu generate your

//font in the same way

glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);

Topic Locked

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

Sign in to reply to this topic.