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

Problem with colors...

Started by klutch Dec 31, 2003 at 3:10 PM 10 replies 900+ views
Original Post
klutch
klutch
I've been working on a simple little program.. it started out as me trying to make a class that read tga files.. well, I finished that, and now I've been trying to get fonts working. I used the tutorial at www.gametutorials.com to do it, it's pretty much the exact same at NeHe's... everything works just fine, except... my font, and my spinning cube are always the same color. This is how the program works.. It shows a spinning cube. By pressing 1, 2, and 3, you can toggle on and off blending, lighting, and textures (in that order). This is what the font looks like with no blending, lighting, or texturing enabled: This is with blending, lighting, and textures: See how the text I'm working on in the top left corner changes colors with the cube? Does anyone have any ideas how to change this? I've tried placing glColor3f() right in front of the glCallLists() and my DrawCube() functions... but they're always the same. I'll post a link to my code, it might help. http://xtc.sixstudios.com/x/main.cpp http://xtc.sixstudios.com/x/main.h http://xtc.sixstudios.com/x/texture.tga http://xtc.sixstudios.com/x/GLTexture1.exe Thanks in advance (texture.tga must be in the same folder as GLTexture1.exe) [edited by - Klutch on December 31, 2003 4:12:14 PM]
DarkNebula
DarkNebula
I think you are applying the lighting effects to your text, and that is changing the colors, try enabling the and disabling the effects when you want them to be applied to the cube and when the text part comes up disable them.

- DarkNebula

 
glDisable(GL_LIGHTING);
if(blend == true)

DrawOpenGLText(0, fontHeight*2, "GL_BLEND: Enabled");

else if(blend == false)
DrawOpenGLText(0, fontHeight*2, "GL_BLEND: Disabled");
if(lighting==true)
glEnable(GL_LIGHTING);


Make your code something like that, you can prob. make it better too...

[edited by - DarkNebula on December 31, 2003 4:35:00 PM]

[edited by - DarkNebula on December 31, 2003 4:36:23 PM]
Thunder_Hawk
Thunder_Hawk
Make sure that lighting is disabled and that you set the correct color immediatiately before drawing your text.

______________________________________________________________
The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ
MySite
______________________________________________________________
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Forma
klutch
klutch
I just tried placing glDisable(GL_LIGHTING) before glCallLists() and glEnable(GL_LIGHTING) after... now it doesn't show any text at all, and the cube is a very, very dark grey.

EDIT: In reply to Dark Nebula, I am not sure if it is lighting. I tried what you said, and it works just the same as what I'm doing now. Even when GL_LIGHTING is disabled, the font has a slight blueish tint (if texturing is enabled).. that makes it seem like it's just copying the colors.

Another Edit: Is there any alternative to doing fonts this way? (A better one, maybe? )

[edited by - Klutch on December 31, 2003 4:47:22 PM]
Thunder_Hawk
Thunder_Hawk
You could always go the route of creating a font texture and using tex coords to draw the correct letter. It''s a rather lengthy route, but it''s satisfying when complete.

______________________________________________________________
The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ
MySite
______________________________________________________________
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Forma
Enigma
Enigma
The problem is that your text is being blended, lit and textured along with your cube. Remember that OpenGL is a state machine, so when you enable a state it affects everything until you turn it off. Your code should look something like:

if (blend){
glEnable(GL_BLEND);
}
if (light){
glEnable(GL_LIGHTING);
}
if (tex){
glEnable(GL_TEXTURE_2D);
}
// draw cube
glDisable(GL_BLEND);
glDisable(GL_LIGHTING);
glDisable(GL_TEXTURE_2D);
// draw text


Enigma
DarkNebula
DarkNebula
Opps I fogot to put my disable and enable blends in there...

- DarkNebula
klutch
klutch
Another Edit: Err.. I'm retarded. Thanks Enigma

[edited by - Klutch on December 31, 2003 6:30:48 PM]
Enigma
Enigma
''tis your CheckStates function. You''re using if/else if/else if, so only one of the three can ever be enabled at any one time. It should be:

void CheckStates(){
if(blend == true){
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
}
if(light == true){
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
}
if(tex == true){
glEnable(GL_TEXTURE_2D);
}
}


Enigma
Trienco
Trienco
as the problem seems to be solved, call me a code raping minimalist (edit: as its built to work like printf, making things even easier including a little "over the top"):

DrawOpenGLText(0,fontHeight*2, "GL_BLEND: %sabled", blend ? "En":"Dis");

instead of:

if(blend == true)
DrawOpenGLText(0, fontHeight*2, "GL_BLEND: Enabled");
else if(blend == false)
DrawOpenGLText(0, fontHeight*2, "GL_BLEND: Disabled");

[edited by - Trienco on January 1, 2004 5:28:35 AM]
f@dzhttp://festini.device-zero.de
klutch
klutch
That''s ingenius. I was trying something like that, but didn''t know how to do it. thanks a lot!
Enigma
Enigma
And to further tidy up, you could move the glEnable/Disable stuff from CheckStates back into KeyEvents, get rid of CheckStates and the glEnable/Disable stuff in DrawOpenGLText and add a glPushAttrib(GL_ENABLE_BIT) before KeyEvents and a glPopAttrib() after DrawCube().

Enigma

Topic Locked

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

Sign in to reply to this topic.