Jump to content

  • Log In with Google      Sign In   
  • Create Account

breakout game scoring


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
12 replies to this topic

#1 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 09 March 2013 - 04:36 PM

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

 



Sponsor:

#2 Damian.   Members   -  Reputation: 272

Like
0Likes
Like

Posted 09 March 2013 - 05:34 PM

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.


Edited by Damian., 09 March 2013 - 05:35 PM.


#3 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 09 March 2013 - 10:11 PM

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



#4 JTippetts   Moderators   -  Reputation: 8492

Like
0Likes
Like

Posted 09 March 2013 - 10:15 PM

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.

#5 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 09 March 2013 - 10:20 PM

how do  you clear the buffer?



#6 Sik_the_hedgehog   Crossbones+   -  Reputation: 1747

Like
0Likes
Like

Posted 10 March 2013 - 07:08 AM

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.

#7 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 10 March 2013 - 08:07 PM

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



#8 Sik_the_hedgehog   Crossbones+   -  Reputation: 1747

Like
0Likes
Like

Posted 10 March 2013 - 08:16 PM

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.

#9 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 10 March 2013 - 08:26 PM

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



#10 JTippetts   Moderators   -  Reputation: 8492

Like
0Likes
Like

Posted 10 March 2013 - 08:31 PM

The same way you drew it in the first place.

#11 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 10 March 2013 - 09:39 PM

well I have solved my problem thanks for all the help



#12 Alpha_ProgDes   Crossbones+   -  Reputation: 4688

Like
0Likes
Like

Posted 10 March 2013 - 09:51 PM

well I have solved my problem thanks for all the help

 

Please provide the solution, so the next guy with the same problem and can learn from it. Thanks :)


Beginner in Game Development? Read here.
 
Super Mario Bros clone tutorial written in XNA 4.0 [MonoGame, ANX, and MonoXNA] by Scott Haley
 
If you have found any of the posts helpful, please show your appreciation by clicking the up arrow on those posts Posted Image
 
Spoiler

#13 phil67rpg   Members   -  Reputation: 767

Like
1Likes
Like

Posted 10 March 2013 - 09:55 PM

here is my solution

void
 
 
drawBitmapText(char *string,float x,float y,float z) 
{ 
char
 
 
*c;
glPushAttrib(
 
GL_CURRENT_BIT);
glClear(
 
GL_COLOR_BUFFER_BIT);
brick();
paddle();
ball();
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
 
 
brick_collision()
{
 
 
GLint n=0;
 
 
if(bricks[2][4]==true)
{
n+=100;
str=itoa(n,buffer,10);
drawBitmapText(str,0.0f,2.0f,0.0f);
}
 
 
if(bricks[2][3]==true)
{
n+=100;
str=itoa(n,buffer,10);
drawBitmapText(str,0.0f,2.0f,0.0f); 
}
 
 
if(bricks[2][2]==true)
{
n+=100;
str=itoa(n,buffer,10);
drawBitmapText(str,0.0f,2.0f,0.0f); 
}
 
 
if(bricks[2][1]==true)
{
n+=100;
str=itoa(n,buffer,10);
drawBitmapText(str,0.0f,2.0f,0.0f); 
}
 
 
if(bricks[2][0]==true)
{
n+=100;
str=itoa(n,buffer,10);
drawBitmapText(str,0.0f,2.0f,0.0f); 
}

basically I just redrew the screen as was suggested






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS