Archived

This topic is now archived and is closed to further replies.

Sirlizium

NeHe Tut14 - Color Problem after glPrint-Line

Recommended Posts

Hello *, my Problem is as following: I''ve modified NeHe''s tutorial about Outline Fonts a bit, so that it doesn''t only display rotating text, but in addition the text moves forth and back and to the sides as I want it to do. That part works fine. Now to the problem: My idea was it to display a transparent triangle right in front of the moving text, so that it covers the parts of the text just behind it. I tried to give this triangle a color (cyan) as usual in the other tuts using glColor3f, but instead the desired color i get an ugly dark green triangle that isn''t transparent at all. (Additionally it doesn''t cover the text although it is positioned in front of it)... If I remove the glPrint-Line, the code works and the triangle is cyan-coloured. With Nehe''s glPrint right before it, it doesn''t. How do I get my triangle coloured now? Here is the code (Init and drawing section that are modified bye me, the rest is NeHe''s Tutorial #14):
  int InitGL(GLvoid)										// All Setup For OpenGL Goes Here

{
	glShadeModel(GL_SMOOTH);							// Enable Smooth Shading

	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);				// Black Background

	glClearDepth(1.0f);									// Depth Buffer Setup

	glEnable(GL_DEPTH_TEST);							// Enables Depth Testing

	glDepthFunc(GL_LEQUAL);								// The Type Of Depth Testing To Do

	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);	// Really Nice Perspective Calculations

	glEnable(GL_LIGHT0);								// Enable Default Light (Quick And Dirty)

	glEnable(GL_LIGHTING);								// Enable Lighting						// Enable Coloring Of Material

        glColor4f(1.0f,1.0f,1.0f,0.5f);			// Full Brightness, 50% Alpha ( NEW )

        glBlendFunc(GL_SRC_ALPHA,GL_ONE);		// Blending Function For Translucency Based On Source Alpha Value ( NEW )

        glEnable(GL_BLEND);			// Turn Blending On

        glDisable(GL_DEPTH_TEST);	// Turn Depth Testing Off

          // Materialfarbe Ambient und Verstreut

          glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
          	glEnable(GL_COLOR_MATERIAL);
	BuildFont();										// Build The Font


	return TRUE;										// Initialization Went OK

}

int DrawGLScene(GLvoid)									// Here''s Where We Do All The Drawing

{
       	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear Screen And Depth Buffer

	glLoadIdentity();									// Reset The Current Modelview Matrix

	glTranslatef(sin(rot/20.0f)*2, cos(rot/10.0f)*2,-8.0f + sin(rot/15.0f)* - 2.0f);						// Move One Unit Into The Screen

        glRotatef(rot,1.0f,0.0f,0.0f);						// Rotate On The X Axis

	//glRotatef(rot*1.5f,0.0f,1.0f,0.0f);					// Rotate On The Y Axis

	glRotatef(rot*1.4f,0.0f,0.0f,1.0f);					// Rotate On The Z Axis

	// Pulsing Colors Based On The Rotation

      	glColor4f(1.0f ,1.0f*float(cos(rot/10.0f)),1.0f*float(sin(rot/11.0f)), 1.0f);
       	glPrint("Irgendein Text %3.2f",rot/50);						// Print GL Text To The Screen

	rot+=0.7f;
        glLoadIdentity();
        glTranslatef(0.0f, 0.0f, -5.0f);
        glBegin(GL_TRIANGLES);
          glColor4f(0.0f, 1.0f, 1.0f, 0.9f);
          glVertex3f(0.0f, -1.0f, 0.0f);
          glVertex3f(-1.0f, 0.0f, 0.0f);
          glVertex3f(1.0f, 0.0f, 0.0f);
        glEnd();
	return TRUE;										// Everything Went OK

}
  
Im new to this forum, if someone tell''s me how to post an image, i''ll show you a screenshot to visualize the problem. Plz, help me before i vaporize my code Have a nice day... ... but before that, answer me please!! :D

Share this post


Link to post
Share on other sites
Oh, just read that html-tags work to paste images... so here's the screenshot:



btw if it should matter, my machine is an AMD Athlon 800, 256MB of RAM and Voodoo4 4500 AGP

Have a nice day...

... but before that, answer me please!! :D

[edited by - sirlizium on June 6, 2002 3:51:20 PM]

Share this post


Link to post
Share on other sites
You could try this:

in the glPrint function,

change the
glPushAttrib(GL_LIST_BIT);

to:
glPushAttrib(GL_LIST_BIT | GL_COLOR_BUFFER_BIT);
or:
glPushAttrib(GL_ALL_ATTRIB_BITS);


I remember a while ago I had the problem where all my back-facing polys would be drawn and my front-facing polys culled, because of the glPushAttrib/glPopAttrib in the glPrint function.
Maybe it''s also causing your problem?

Share this post


Link to post
Share on other sites
Thank you very much, you have helped me a lot. With the parameter GL_ALL_ATTRIB_BITS it works as it should. Both the colour and the transparency work now.
I don''t think I had found it out without that hint - I still don''t really know yet what the Push and Pop commands are good for so I didn''t know that.
Now I''ll go on with my project.

Happy Coding so long

Sir Lizium

Share this post


Link to post
Share on other sites