PDA

View Full Version : Text...



CorruptMind
05-30-2005, 01:11 PM
I am currently having some trouble with the text in my game. I am using orthomode for a 2d pacman like game and I can get the text to draw but I cant seem to get it to change colors... I have tried adding glColor3f() just about everywhere and it doesnt seem to want to change...

heres my code-

void DrawScene()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(0, 0, 0, 0, 0, 0 + 1, 0, 1, 0);
glRotatef(0 , 0, 1, 0);

OrthoMode(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
glColor4f(1, 1, 1, 1);

glDisable(GL_DEPTH_TEST);

if(screen2render=="MENU")
{
DrawMenu();
DrawText(0, 0, "Sample Text...");
}

SwapBuffers(g_hDC);
}

void DrawMenu()
{
glBindTexture(GL_TEXTURE_2D, g_Texture[9]);
glBegin(GL_QUADS);
glTexCoord2f(0.0f + wrap, 1.0f - wrap ); glVertex2f(0, 0);
glTexCoord2f(0.0f + wrap , 0.0f - wrap); glVertex2f(0, SCREEN_HEIGHT);
glTexCoord2f(1.0f + wrap, 0.0f - wrap); glVertex2f(SCREEN_WIDTH, SCREEN_HEIGHT);
glTexCoord2f(1.0f + wrap, 1.0f - wrap); glVertex2f(SCREEN_WIDTH, 0);
glEnd();
wrap += 0.0035f;
}

void OrthoMode(int left, int top, int right, int bottom)
{
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho( left, right, bottom, top, 0, 1 );
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

void DrawText(int x, int y, const char *strString, ...)
{
char strText[256];
va_list argumentPtr;

glColor3f(1,1,1);

if (strString == NULL)
return;

va_start(argumentPtr, strString);
vsprintf(strText, strString, argumentPtr);
va_end(argumentPtr);

glRasterPos2f(x, y);

glPushAttrib(GL_LIST_BIT);
glListBase(g_FontListID);
glCallLists(strlen(strText), GL_UNSIGNED_BYTE, strText);
glPopAttrib();
}

Ehsan Kamrani
05-30-2005, 01:23 PM
1.One of the reasons is texture mapping.When texture mapping is enabled, you may can't use from the glColor*() functions. Actually, the color of the textures can affect the color buffer.So when you don't use from the texturing, simply disable it.When you want to use from the texturing, simply enable it:
gDisable( GL_TEXTURE_2D );
glColor4f();
DrawMyText();
glEnable( GL_TEXTURE_2D );
2.Why have you disabled the depth test in your program?
-Ehsan-

CorruptMind
05-30-2005, 01:27 PM
bah why did I not think about that. thank you very much now I can move on to bigger things lol