breakout game scoring

Started by
11 comments, last by phil67rpg 11 years, 1 month ago

Well I am able to write the score of 100 to the screen but then I want to write a black number to the screen. Then I want to write the next highest score to the screen. Basically I am having a problem of blacking out the score so I can overwrite it. Well what it does now is it prints the score to the screen and then it overwrites it with the next highest score. I have almost solved this problem I just need someone to give me a hint.


void
 
 
drawBitmapText(char *string,float x,float y,float z) 
{ 
char
 
 
*c;
glPushAttrib(
 
GL_CURRENT_BIT);
glColor3f(1.0f,1.0f,1.0f);
glRasterPos3f(
 
x, y,z);
for
 
 
(c=string; *c != '\0'; c++) 
{
glutBitmapCharacter(
 
GLUT_BITMAP_TIMES_ROMAN_24, *c);
}
glPopAttrib();
}
void
 
 
drawBitmapText_clear(char *string,float x,float y,float z) 
{ 
char
 
 
*c;
glPushAttrib(
 
GL_CURRENT_BIT);
glColor3f(0.0f,0.0f,0.0f);
glRasterPos3f(
 
x, y,z);
for
 
 
(c=string; *c != '\0'; c++) 
{
glutBitmapCharacter(
 
GLUT_BITMAP_TIMES_ROMAN_24, *c);
}
glPopAttrib();
}
void
 
 
brick_collision()
{
 
 
GLint n=0;
 
 
if(bricks[2][4]==true)
{
n+=100;
str=itoa(n,buffer,10);
drawBitmapText_clear(str,0.0f,2.0f,0.0f); 
drawBitmapText(str,0.0f,2.0f,0.0f);
}
 
 
if(bricks[2][3]==true)
{
n+=100;
str=itoa(n,buffer,10);
drawBitmapText_clear(str,0.0f,2.0f,0.0f); 
drawBitmapText(str,0.0f,2.0f,0.0f); 
}
 
 
if(bricks[2][2]==true)
{
n+=100;
str=itoa(n,buffer,10);
drawBitmapText_clear(str,0.0f,2.0f,0.0f); 
drawBitmapText(str,0.0f,2.0f,0.0f); 
}
 
 
if(bricks[2][1]==true)
{
n+=100;
str=itoa(n,buffer,10);
drawBitmapText_clear(str,0.0f,2.0f,0.0f); 
drawBitmapText(str,0.0f,2.0f,0.0f); 
}
 
 
if(bricks[2][0]==true)
{
n+=100;
str=itoa(n,buffer,10);
drawBitmapText_clear(str,0.0f,2.0f,0.0f); 
drawBitmapText(str,0.0f,2.0f,0.0f); 
}

thanks for all the help

cleardot.gif

Advertisement

Maybe it is a little offtopic but you should use new modern OpenGL (3.2+), and also you should write your own font rendering class (Bitmap fonts, or TrueType) and it will be easier because new OpenGL is much cleaner and easier IMO.

I know, but I want to really finish this project then I can move on to shaders

Why should you need to black out the score in order to overwrite it? Clearing the buffer should take care of this. If it's not, check your clearing code.

how do you clear the buffer?

Look up glClear. GL_CLEAR_COLOR will clear the framebuffer, if you use depth (e.g. you're doing 3D stuff) you should OR it with GL_CLEAR_DEPTH too.

Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.

well I have used glClear(GL_COLOR_BUFFER_BIT); but it clears the entire screen.

You're supposed to redraw all of it.

Moreover, you aren't guaranteed that what was there before will stay there (becomes obvious when you alt+tab for a moment, you will get stuff from what was on screen at that place). In other words, clear the entire screen and redraw it all. In the long term it'll be easier too (no need to keep track of what changed).

Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.

sorry for being dense but is there an easy way to redraw the whole screen or all of it.

The same way you drew it in the first place.

This topic is closed to new replies.

Advertisement