PDA

View Full Version : some help regarding flickering



ankur bansal
01-22-2011, 06:22 AM
I have create a game in glut. It was flickering so I used GLUT_DOUBLE and then it was showing the transparent window then I used glutSwapBuffers(); then it was showing game without flickering but there was no movement in game i.e. the keystrokes are not working. What should I do now??

Mukund
01-22-2011, 06:25 AM
Could you paste the relevant code here?

ankur bansal
01-22-2011, 06:30 AM
void display(void)
{
glClear (GL_COLOR_BUFFER_BIT);
arena();
start(); //start the game
comments();
next_level();
glutSwapBuffers();
}


void init() {
glClearColor (0.0, 0.0, 0.0, 0.0);
// glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glShadeModel(GL_SMOOTH);
glOrtho(-1000.0, 1000.0, -1000.0, 1000.0, -1000.0, 1000.0);
glutDisplayFunc(display);
glutKeyboardFunc(processNormalKeys);
glutSpecialFunc(pressKey);


}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
// glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (700,700);
glutInitWindowPosition (100,-100);
glutCreateWindow ("BLASTERBALL 1.0");
init ();
glutMainLoop();
return 0;

}

ankur bansal
01-22-2011, 07:12 AM
please help someone!!!

dalemac
01-22-2011, 07:17 AM
glutDisplayFunc(display);
glutKeyboardFunc(processNormalKeys);
glutSpecialFunc(pressKey);


for a start, all of the above functions should be in your main function (before glutMainLoop();), NOT your init function.

also, why are you using glLoadIdentity(); in your init function?

ankur bansal
01-22-2011, 07:26 AM
I am new to this. I saw this on some site. What should I do here instead?

dalemac
01-22-2011, 07:55 AM
did moving the mouse and key functions to the main function resolve the issue.

from what i can see i your code, the glLoadIdentity() call isnt needed, thats all.

ankur bansal
01-22-2011, 08:00 AM
no its still same. The keystrokes are not working with GLUT_DOUBLE and glutSwapBuffer()

dalemac
01-22-2011, 08:09 AM
keep the functions mentioned in the main function, but remove the glLoadIdentity(); call

see if that helps.

dale

ankur bansal
01-22-2011, 08:20 AM
i did all those thing but still the issue is same.

ankur bansal
01-22-2011, 08:39 AM
I am stuck please help me out someone.

dalemac
01-22-2011, 08:51 AM
Ok, Number 1, im trying to be patient with you, but you have absolutely no patience whatsoever. I am finding you a little rude. People will help you out as and when they can, begging will get you no where.

Number 2, please post all of your code.

ankur bansal
01-22-2011, 09:05 AM
I didn't mean it that way. I am really sorry for that.
#define GLUT_DISABLE_ATEXIT_HACK


#include<string>

#include<vector>
#include <stdlib.h>
#include <GL/glut.h>
#include <math.h>
#include <GL/gl.h>
#include<stack>


#define RESUME 1
#define PAUSE 2
#define INCREASE 3
#define DECREASE 4
#define REVERSE 5
#define RESTART 6
#define NORMAL1 7
#define POWER 8
#define NEXT 9
#define QUIT 10

using namespace std;

int flag=0;
int flag1=0;
int flag2=0;
int flag3=0;
int x1=0;
int y3=-835;
int x2=-925;
int y2=100;
int xc=0;
int yc=0;
int TIMER_MS = 10;
const float root=1/1.4142;
int a=-150;
int b=-900;
int c=150;
int d=-850;
int r=50;
const float PI = 3.1415926535f;
float NORMAL;
float ANGLE=0.75*PI;
int rad=10;
int temp2=rad;
int score1=-500;
int bricks;
int bricks1;
int level=1;
int life=3;
int s=-1;
int count=0;
int font=(int)GLUT_BITMAP_TIMES_ROMAN_24 ;
int font1=(int)GLUT_BITMAP_TIMES_ROMAN_10 ;
int font2=(int)GLUT_BITMAP_HELVETICA_18 ;
bool m=true;
bool enter=false;
bool power=false;
bool start1=true;
int condition=0;
int when=0;
int xy=1;
double boundry=(rad/1.4142)+1;
int specialKey;
int sensitivity=100;
char gameModeString[40] = "640x480";
char currentMode[80];

float rBall=0.0,gBall=1.0,bBall=1.0;
float rBar=0.0,gBar=0.0,bBar=1.0;
float rBrick=0.0,gBrick=0.0,bBrick=0.0;
float rButton=1.0,gButton=1.0,bButton=0.0;
float rBackground=1,gBackground=1,bBackground=1;
float rComments=1,gComments=0,bComments=0;
float rScore=1,gScore=1,bScore=1;
float rSelected=0,gSelected=1,bSelected=1;
float rTouched=0,gTouched=0,bTouched=1;

void renderBitmapCharacher(float x, float y, void *font,char *string);
void processNormalKeys(unsigned char key, int , int );
void print_score(int );
void init();

vector< pair < pair <int ,int >,pair<int ,int > > > temp,temp1;
vector < vector< pair < pair <int ,int >,pair<int ,int > > > > input(5);
stack < pair < pair <int ,int >,pair<int ,int > > > touch_finder;
pair < pair <int ,int >,pair<int ,int > > ptouch;




void print(int xl,int yl,int xh,int yh){
glBegin(GL_POLYGON); //create the background
glVertex2f(xl,yl);
glVertex2f(xh,yl);
glVertex2f(xh,yh);
glVertex2f(xl,yh);
glEnd();
glFlush();
glColor3f(rBackground,gBackground,bBackground); // Background color
glBegin(GL_LINE_LOOP); // create the bricks boundary
glVertex2f(xl,yl);
glVertex2f(xh,yl);
glVertex2f(xh,yh);
glVertex2f(xl,yh);
glEnd();
glFlush();
}
void make(int xl,int yl,int xh,int yh){ // create the control panel

glBegin(GL_POLYGON);
glVertex2f(xl,yl);
glVertex2f(xh,yl);
glVertex2f(xh,yh);
glVertex2f(xl,yh);
glEnd();
glFlush();
}
void make_boundry(int xl,int yl,int xh,int yh){ // create the boundary in control panel

glBegin(GL_LINE_LOOP);
glVertex2f(xl,yl);
glVertex2f(xh,yl);
glVertex2f(xh,yh);
glVertex2f(xl,yh);
glEnd();
glFlush();
}
void make_bricks(void){ // create the bricks
for(int i=0;i<temp.size();i++){
glColor3f(rBrick,gBrick,bBrick);
print(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second);
}
}
float reflect(float angle, float normal) {
angle = 2 * normal - PI - angle;

while (angle < 0) {
angle += 2 * PI;
}
while (angle > 2 * PI) {
angle -= 2 * PI;
}
return angle;
}


void start(void){

if(start1==true){ //this is due to restart either through keyboard or menu function


score1=-500;
s=-1;
life=3;
level=1;
glColor3f (rBar,gBar,bBar);
print(a,b,c,d);

power=false;
rad=10;
ANGLE=0.75*PI;
boundry=(rad/1.4142)+1;
}
else{ //this is due to change of resolution
rad=temp2;
s=-1;
score1-=500;
}
int i,j;
input[0].clear();
for(i=-5;i<=5;i++){
for(j=0;j<i+1;j++){
input[0].push_back(make_pair(make_pair(-600+i*100,0+75*j),make_pair(-600+i*100+100,75+75*j)));
}
}
temp=input[0];
if(level>=4){
temp1.clear();
temp.clear();
}
if((condition==1||condition==2||condition==3||cond ition==4||condition==6)&amp;&amp;(start1==false))
temp=temp1;
make_bricks();
bricks=temp.size();
print_score(bricks);
}
void print_score(int remaining){

string score;
int t=bricks-remaining;
if(t!=s){
score1+=500;
int printer;
int i=0,abc[20];
char a[20];
printer=score1;
if(printer==0){
for(int j=0;j<1;j++)
a[j]=char(48);
}
else{
while(printer>0){
abc[i]=printer%10;
printer/=10;
i++;
}
}
for(int j=0;j<i;j++){
a[j]=char(abc[i-j-1]+'0');

}
glColor3f(0.2,0.1,0.1);
make(600,590,900,700);
glColor3f(rComments,gComments,bComments);
renderBitmapCharacher(600,700,(void *)font2,"SCORE: ");
glColor3f(rScore,gScore,bScore);
renderBitmapCharacher(600,600,(void *)font2,a);
}

char lvl[1];
for(int k=0;k<1;k++)
lvl[k]=char(level+48);
glColor3f(0.2,0.1,0.1);
make(750,375,820,500);


glColor3f(rComments,gComments,bComments);

renderBitmapCharacher(600,400,(void *)font2,"LEVEL: ");
glColor3f(rScore,gScore,bScore);
renderBitmapCharacher(800,400,(void *)font2,lvl);
glColor3f(0.2,0.1,0.1);
make(820,375,900,500);


char lyf[4];
for(int k2=0;k2<1;k2++)
lyf[k2]=char(life+48);;
glColor3f(0.2,0.1,0.1);
make(775,175,825,300);
glColor3f(rComments,gComments,bComments);

renderBitmapCharacher(600,200,(void *)font2,"LIFE: ");
glColor3f(rScore,gScore,bScore);
renderBitmapCharacher(800,200,(void *)font2,lyf);
s=t;
}
void comments(void){
glColor3f(rButton,gButton,bButton); //BUTTON COLORS
make_boundry(580,-225,920,-125); //M
make_boundry(580,-125,920,-25); //P


make_boundry(-1000,900,-715,1000); //R
make_boundry(-715,900,-520,1000); //ESC
make_boundry(-520,900,-225,1000); //N
make_boundry(-225,900,125,1000); //SPACEBAR
make_boundry(125,900,450,1000); //UP
make_boundry(450,900,1000,1000); //DOWN

glColor3f(rComments,gComments,bComments); //COMMENT COLOR

renderBitmapCharacher(-900,910,(void *)font1,"R:Restart");
renderBitmapCharacher(-700,910,(void *)font1,"ESC:Quit");
renderBitmapCharacher(-500,910,(void *)font1,"N:Next level");
renderBitmapCharacher(-200,910,(void *)font1,"SPACEBAR:Pause");
renderBitmapCharacher(200,910,(void *)font1,"UP:Inc. Speed");
renderBitmapCharacher(500,910,(void *)font1,"DOWN:Dec. Speed");
renderBitmapCharacher(600,-100,(void *)font1,"P:PowerBall");
renderBitmapCharacher(600,-200,(void *)font1,"M:Normal Ball");

}
void next_level(void){
int i,j;
input[1].clear();

for(i=-2;i<=2;i++) //level two
{
for(j=-2;j<=2;j++)
{
input[1].push_back(make_pair(make_pair(-250+i*100,j*75),make_pair(-250+i*100+100,75*j+75)));
input[1].push_back(make_pair(make_pair(-750+i*100,550+j*75),make_pair(-750+i*100+100,75*j+550+75)));
input[1].push_back(make_pair(make_pair(150+i*100,550+j*75) ,make_pair(150+i*100+100,75*j+550+75)));
input[1].push_back(make_pair(make_pair(150+i*100,-350+j*75),make_pair(150+i*100+100,75*j-350+75)));
}
}
// level 3
input[2].clear();
for(i=0;i<15;i++) //vertical line
input[2].push_back(make_pair(make_pair(-200,-600+i*100),make_pair(-200+75,-600+i*100+100)));
for(i=0;i<6;i++){ //in right bottommost
input[2].push_back(make_pair(make_pair(-50+i*100,-250),make_pair(-50+i*100+100,-250+75)));
}
for(i=0;i<3;i++){
input[2].push_back(make_pair(make_pair(50+i*150,-325),make_pair(50+i*150+150,-325+75)));
}
for(i=0;i<2;i++){
input[2].push_back(make_pair(make_pair(100+i*175,-400),make_pair(100+i*175+175,-400+75)));
}
for(i=0;i<1;i++){
input[2].push_back(make_pair(make_pair(175+i*200,-475),make_pair(175+i*200+200,-475+75)));
}
for(i=0;i<5;i++){ //in left uppermost
for(j=0;j<4;j++){
input[2].push_back(make_pair(make_pair(-800+i*100,250+75*j),make_pair(-800+i*100+100,250+75+75*j)));
}
}
for(i=0;i<3;i++) //in left bottommost
input[2].push_back(make_pair(make_pair(-850+i*100,-500),make_pair(-850+i*100+100,-500+75)));
for(i=0;i<3;i++)
input[2].push_back(make_pair(make_pair(-850+i*100,-100),make_pair(-850+i*100+100,-100+75)));
for(i=0;i<3;i++)
input[2].push_back(make_pair(make_pair(-600+i*100,-300),make_pair(-600+i*100+100,-300+75)));
for(i=0;i<4;i++) // in right uppermost
input[2].push_back(make_pair(make_pair(0+i*100,650),make_p air(0+i*100+100,650+75)));
for(i=0;i<5;i++)
input[2].push_back(make_pair(make_pair(180,650-i*100),make_pair(180+75,650-100-i*100)));
for(i=0;i<4;i++)
input[2].push_back(make_pair(make_pair(0+i*100,75),make_pa ir(0+i*100+100,75+75)));


// level 4
input[3].clear();
for(i=0;i<17;i++)
input[3].push_back(make_pair(make_pair(-250,-450+i*75),make_pair(-250+100,-450+i*75+75)));
for(i=0;i<15;i++){
///input[3].push_back(make_pair(make_pair(-350,-375+i*75),make_pair(-350+100,-375+i*75+75)));
if(i==12)
continue;
input[3].push_back(make_pair(make_pair(-350,-375+i*75),make_pair(-350+100,-375+i*75+75)));
input[3].push_back(make_pair(make_pair(-150,-375+i*75),make_pair(-150+100,-375+i*75+75)));
}
for(i=0;i<10;i++){
input[3].push_back(make_pair(make_pair(-450,-300+i*75),make_pair(-450+100,-300+i*75+75)));
input[3].push_back(make_pair(make_pair(-50,-300+i*75),make_pair(-50+100,-300+i*75+75)));
}
for(i=0;i<12;i++){
if(i==2 || i==9)
continue;
input[3].push_back(make_pair(make_pair(-550,-375+i*75),make_pair(-550+100,-375+i*75+75)));
input[3].push_back(make_pair(make_pair(50,-375+i*75),make_pair(50+100,-375+i*75+75)));
}
for(i=0;i<3;i++){
input[3].push_back(make_pair(make_pair(-650,-450+i*75),make_pair(-650+100,-450+i*75+75)));
input[3].push_back(make_pair(make_pair(150,-450+i*75),make_pair(150+100,-450+i*75+75)));
}
for(i=0;i<6;i++){
if(i==3 || i==2 || i==4)
continue;
input[3].push_back(make_pair(make_pair(-650,375+i*75),make_pair(-650+100,375+i*75+75)));
input[3].push_back(make_pair(make_pair(150,375+i*75),make_ pair(150+100,375+i*75+75)));
}
for(i=0;i<1;i++){
input[3].push_back(make_pair(make_pair(-750,750+i*75),make_pair(-750+100,750+i*75+75)));
input[3].push_back(make_pair(make_pair(250,750+i*750),make _pair(250+100,750+i*75+75)));
}
for(i=0;i<2;i++){
input[3].push_back(make_pair(make_pair(-850+i*100,675),make_pair(-850+i*100+100,675+75)));
input[3].push_back(make_pair(make_pair(250+i*100,675),make _pair(250+100+i*100,675+75)));
}
for(i=0;i<10;i++){
if(i==4 || i==5 || i==6 || i==7 || i==8 )
continue;
input[3].push_back(make_pair(make_pair(-950,-75+i*75),make_pair(-950+100,-75+i*75+75)));
input[3].push_back(make_pair(make_pair(450,-75+i*75),make_pair(450+100,-75+i*75+75)));
}


// level 5
input[4].clear();
for(i=0;i<15;i++) //horozontal line
input[4].push_back(make_pair(make_pair(-950+i*100,-675),make_pair(-950+i*100+100,-675+75)));
for(i=0;i<14;i++)
input[4].push_back(make_pair(make_pair(-895+i*100,-600),make_pair(-895+i*100+100,-600+75)));
for(i=0;i<13;i++)
input[4].push_back(make_pair(make_pair(-840+i*100,-525),make_pair(-840+i*100+100,-525+75)));
for(i=0;i<12;i++)
input[4].push_back(make_pair(make_pair(-785+i*100,-450),make_pair(-785+i*100+100,-450+75)));
for(i=0;i<11;i++)
input[4].push_back(make_pair(make_pair(-730+i*100,-375),make_pair(-730+i*100+100,-375+75)));
for(i=0;i<10;i++)
input[4].push_back(make_pair(make_pair(-675+i*100,-300),make_pair(-675+i*100+100,-300+75)));
for(i=0;i<9;i++)
input[4].push_back(make_pair(make_pair(-620+i*100,-225),make_pair(-620+i*100+100,-225+75)));
for(i=0;i<8;i++)
input[4].push_back(make_pair(make_pair(-565+i*100,-150),make_pair(-565+i*100+100,-150+75)));
for(i=0;i<7;i++)
input[4].push_back(make_pair(make_pair(-510+i*100,-75),make_pair(-510+i*100+100,-75+75)));
for(i=0;i<6;i++)
input[4].push_back(make_pair(make_pair(-455+i*100,0),make_pair(-455+i*100+100,0+75)));// lower part
for(i=0;i<5;i++)
input[4].push_back(make_pair(make_pair(-400+i*100,75),make_pair(-400+i*100+100,75+75)));
for(i=0;i<6;i++)
input[4].push_back(make_pair(make_pair(-455+i*100,150),make_pair(-455+i*100+100,150+75)));
for(i=0;i<7;i++)
input[4].push_back(make_pair(make_pair(-510+i*100,225),make_pair(-510+i*100+100,225+75)));
for(i=0;i<8;i++)
input[4].push_back(make_pair(make_pair(-565+i*100,300),make_pair(-565+i*100+100,300+75)));
for(i=0;i<9;i++)
input[4].push_back(make_pair(make_pair(-620+i*100,375),make_pair(-620+i*100+100,375+75)));
for(i=0;i<10;i++)
input[4].push_back(make_pair(make_pair(-675+i*100,450),make_pair(-675+i*100+100,450+75)));
for(i=0;i<11;i++)
input[4].push_back(make_pair(make_pair(-730+i*100,525),make_pair(-730+i*100+100,525+75)));
for(i=0;i<12;i++)
input[4].push_back(make_pair(make_pair(-785+i*100,600),make_pair(-785+i*100+100,600+75)));
for(i=0;i<13;i++)
input[4].push_back(make_pair(make_pair(-840+i*100,675),make_pair(-840+i*100+100,675+75)));
for(i=0;i<14;i++)
input[4].push_back(make_pair(make_pair(-895+i*100,750),make_pair(-895+i*100+100,750+75)));
for(i=0;i<15;i++) //horozontal line
input[4].push_back(make_pair(make_pair(-950+i*100,825),make_pair(-950+i*100+100,825+75)));

print_score(temp.size());
}


void erase_block(int a,int b,int c,int d,float e,int f){
glColor3f(rBackground,gBackground,bBackground);
make(a,b,c,d);
temp.erase(temp.begin()+f);
NORMAL=e*PI;
ANGLE=reflect(ANGLE,NORMAL);
}
void erase_block_power(int a,int b,int c,int d,float e,int f){
glColor3f(rBackground,gBackground,bBackground);
make(a,b,c,d);
temp.erase(temp.begin()+f);
}
void pause1(){
flag=0;
flag1=0;
flag3++;
}
void update(int value) {

glColor3f (rBackground,gBackground,bBackground); // update the color of background when ball leaves bar
draw(0,-835,r);

glColor3f (rBackground,gBackground,bBackground); // update the color of background when ball moves
draw(x1,y3,r);

float x,y;
x=x1+rad*cos(ANGLE);
y=y3+rad*sin(ANGLE);
glColor3f (rBall,gBall,bBall); // color of the ball when moving
draw((int)x,(int)y,(int)r);
int i;
// conditions for erasing the bricks
for(i=0;i <temp.size();i++){
if(abs((int)(x+r)-(int)temp[i].first.first)<abs((int)boundry)&amp;&amp;y>=(int)temp[i].first.second&amp;&amp;y<=(int)temp[i].second.second){
if(power==false)
erase_block(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,0,i);
if(power==true)
erase_block_power(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,0,i);
enter=true;
break;
}

if(abs((int)(x-r)-(int)temp[i].second.first)<abs((int)boundry)&amp;&amp;y>=(int)temp[i].first.second&amp;&amp;y<=(int)temp[i].second.second){
if(power==false)
erase_block(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,1,i);
if(power==true)
erase_block_power(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,1,i);
enter=true;
break;
}

if(abs((int)(y+r)-(int)temp[i].first.second)<abs((int)boundry)&amp;&amp;x>=(int)temp[i].first.first&amp;&amp;x<=(int)temp[i].second.first){
if(power==false)
erase_block(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,1.5,i);
if(power==true)
erase_block_power(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,1.5,i);
enter=true;
break;
}

if(abs((int)(y-r)-(int)temp[i].second.second)<abs((int)boundry)&amp;&amp;x>=(int)temp[i].first.first&amp;&amp;x<=(int)temp[i].second.first){
if(power==false)
erase_block(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,0.5,i);
if(power==true)
erase_block_power(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,0.5,i);
enter=true;
break;
}

if(sqrt(pow(x+r*cos(ANGLE)-temp[i].first.first,2)+pow(y+r*sin(ANGLE)-temp[i].first.second,2))<rad){
if(power==false)
erase_block(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,ANGLE/PI,i);
if(power==true)
erase_block_power(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,ANGLE/PI,i);
enter=true;
break;
}

if(sqrt(pow(x-r*cos(ANGLE)-temp[i].second.first,2)+pow(y+r*sin(ANGLE)-temp[i].first.second,2))<rad){
if(power==false)
erase_block(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,ANGLE/PI,i);
if(power==true)
erase_block_power(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,ANGLE/PI,i);
enter=true;
break;
}

if(sqrt(pow(x+r*cos(ANGLE)-temp[i].first.first,2)+pow(y-r*sin(ANGLE)-temp[i].second.second,2))<rad){
if(power==false)
erase_block(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,ANGLE/PI,i);
if(power==true)
erase_block_power(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,ANGLE/PI,i);
enter=true;
break;
}

if(sqrt(pow(x-r*cos(ANGLE)-temp[i].second.first,2)+pow(y-r*sin(ANGLE)-temp[i].second.second,2))<rad){
if(power==false)
erase_block(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,ANGLE/PI,i);
if(power==true)
erase_block_power(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,ANGLE/PI,i);
enter=true;
break;
}
}


if(enter==true)
when++;
if(when==5){
make_bricks();
enter=false;;
when=0;
}

print_score(temp.size());

if((int)(x-r+950)<abs((int)boundry)){
NORMAL=0;
ANGLE=reflect(ANGLE,NORMAL);
}
if(-y-r+900<abs((int)boundry))
{
NORMAL=1.5*PI;
ANGLE=reflect(ANGLE,NORMAL);
}
if(-x-r+950-400<abs((int)boundry))
{
NORMAL=PI;
ANGLE=reflect(ANGLE,NORMAL);
}
if(y-r+850<abs((int)boundry) &amp;&amp; a<=x&amp;&amp;c>=x) //the ball touches the bar
{
NORMAL=0.5*PI;
ANGLE=reflect(ANGLE,NORMAL);
}
if(sqrt(pow(c-x,2)+pow(y-d,2))<=r){ //the ball touches the right part of the bar
rad=(-1)*rad;
temp2=rad;
}

if(sqrt(pow(a-x,2)+pow(y-d,2))<=r){ //the ball touches the left part of the bar
rad=(-1)*rad;
temp2=rad;
}

if(y-r+875<abs((int)boundry) ) //the ball misses the bar
{
life--;
if(life<0)
return;
if(life==0){
print_score(temp.size());
glColor3f(rComments,gComments,bComments);
renderBitmapCharacher(0,800,(void *)font,"GAME OVER");
pause1();
return;
}
glColor3f (rBackground,gBackground,bBackground);
print(-950,-900,550,-800);
print(a,b,c,d);
glColor3f (rBall,gBall,bBall); // the ball is re-created
draw(0,-835,r);
ANGLE=.75*PI;
x=0;
y=-825;
a=-150;
b=-900;
c=150;
d=-850;
glColor3f (0.0, 1.0,0.0); // bar is created again after miss
print(a,b,c,d);
flag=0;
flag1=0;
flag2=0;
print_score(temp.size());

}

if(temp.size()==0){
level++;
if(level>6){
level=6;
return;
}
if(level==6){
glColor3f(rComments,gComments,bComments);
renderBitmapCharacher(-700,0,(void *)font,"YOU HAVE WON THE MATCH");
return;
temp1.clear();
}
temp=input[level-1];
bricks=temp.size();
glColor3f (rBackground,gBackground,bBackground);
draw((int)x,(int)y,(int)r);
make_bricks();

glColor3f (rBackground,gBackground,bBackground);
print(-950,-900,550,-700);
print(a,b,c,d);
glColor3f (rBall,gBall,bBall);
draw(0,-835,r);
ANGLE=.75*PI;
x=0;
y=-835;
a=-150;
b=-900;
c=150;
d=-850;
glColor3f (0.0, 1.0,0.0);
print(a,b,c,d);
flag=0;
flag1=0;
flag2=0;
flag3=0;
print_score(temp.size());
//increase_speed();
}
x1=(int)x;
y3=(int)y;
temp1=temp;
if(flag!=0)
glutTimerFunc(TIMER_MS, update, 0);
}
void move_left(void)
{

if(a<=-950){
glColor3f (rBar,gBar,bBar);
print(-950,-900,-650,-850);
}
else
{
glColor3f (rBackground,gBackground,bBackground);
print(a,b,c,d);
a-=sensitivity;
c-=sensitivity;
glColor3f (rBar,gBar,bBar);
print(a,b,c,d);
}
}
void move_right(void)
{

if(c>=550){
glColor3f (rBar,gBar,bBar);
print(650-400,-900,950-400,-850);}
else
{
glColor3f (rBackground,gBackground,bBackground);
print(a,b,c,d);
a+=sensitivity;
c+=sensitivity;
glColor3f (rBar,gBar,bBar);
print(a,b,c,d);
}

}
void increase_speed(void){
if(rad>0)
rad+=10;
if(rad<0)
rad-=10;

boundry=abs((int)(rad/1.4142))+1;
temp2=rad;
}
void decrease_speed(void){
if(rad>0){
rad-=10;
if(rad==0)
rad+=10;
}
if(rad<0){
rad+=10;
if(rad==0)
rad-=10;
}
boundry=abs((int)(rad/1.4142))+1;
temp2=rad;
}
void restart(void){
start1=true;
glutPostRedisplay();
pause1();
}
void next(void){
glColor3f(1,1,1);
for(int f=0;f<temp.size();f++)
make(temp[f].first.first,temp[f].first.second,temp[f].second.first,temp[f].second.second);
temp.clear();
condition=0;
}
void touch_stack(int txl,int tyl,int txh,int tyh){
if(!touch_finder.empty()){
ptouch=touch_finder.top();
glColor3f(rButton,gButton,bButton);
make_boundry(ptouch.first.first,ptouch.first.secon d,ptouch.second.first,ptouch.second.second);
touch_finder.pop();
}
glColor3f(rTouched,gTouched,bTouched);
make_boundry(txl,tyl,txh,tyh);
touch_finder.push(make_pair(make_pair(txl,tyl),mak e_pair(txh,tyh)));
}

void processNormalKeys(unsigned char key, int x, int y) {
specialKey = glutGetModifiers();
if (specialKey == GLUT_ACTIVE_ALT) {
if (key == 114)
rBrick=1.0,gBrick=0.0,bBrick=0.0;

if (key == 103)
rBrick=0.0,gBrick=1.0,bBrick=0.0;

if(key == 98)
rBrick=0.0,gBrick=0.0,bBrick=1.0;
make_bricks();

}
else{

if (key == 27) //esc
exit(0);

if(key==32){ //spacebar
if(m==true){
pause1();
m=false;
}
else{
glutTimerFunc(TIMER_MS, update, 0);
flag++;
flag1++;
flag2++;
flag3=0;
m=true;
}

}
if(key==110){ //NEXT LEVEL==n
next();
}
if(key==114){ //start the game
restart();
}

if(key==113) //QUIT ==q
return;
if(key==112){ //POWERBALL=p
power=true;
rBall=1.0;
gBall=0.0;
bBall=0.0;
}
if(key==109){ //MODE NORMAL=m
power=false;
rBall=0.0;
gBall=1.0;
bBall=1.0;
}

}

}
void renderBitmapCharacher(float x, float y, void *font,char *string)
{

char *c;
glRasterPos2f(x, y);
for (c=string; *c != '\0'; c++) {
glutBitmapCharacter(font, *c);
}
}
void pressKey(int key, int x, int y) {

if(flag==0){

glutTimerFunc(TIMER_MS, update, 0);
flag++;
flag1++;
flag2++;
flag3=0;
m=true;
}

if(key==GLUT_KEY_LEFT)
move_left();
if(key==GLUT_KEY_RIGHT)
move_right();
if(key==GLUT_KEY_UP){ //increase speed
if(rad>0)
rad+=10;
if(rad<0)
rad-=10;
boundry=abs((int)(rad/1.4142))+1;
temp2=rad;
}

if(key==GLUT_KEY_DOWN){ //decrease speed
if(rad>0){
rad-=10;
if(rad==0)
rad+=10;
}
if(rad<0){
rad+=10;
if(rad==0)
rad-=10;
}
boundry=abs((int)(rad/1.4142))+1;
temp2=rad;
}


}
void display(void)
{
glClear (GL_COLOR_BUFFER_BIT);
arena();
start(); //start the game
comments();
next_level();
glutSwapBuffers();
}
void init() {
glClearColor (0.0, 0.0, 0.0, 0.0);
// glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
// glLoadIdentity();
// glShadeModel(GL_SMOOTH);
glOrtho(-1000.0, 1000.0, -1000.0, 1000.0, -1000.0, 1000.0);



}
int main(int argc, char** argv)
{
glutInit(&amp;argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (700,700);
glutInitWindowPosition (100,-100);
glutCreateWindow ("BLASTERBALL 1.1");
init ();
glutDisplayFunc(display);
glutKeyboardFunc(processNormalKeys);
glutSpecialFunc(pressKey);
glutMainLoop();
return 0;

}

ugluk
01-22-2011, 09:19 AM
Well you have 2 glutInitDisplayMode() calls and the second one specifies a GLUT_SINGLE color buffer, you need to specify GLUT_DOUBLE and delete one of the calls. If you use the depth buffer, be sure to clear it along with the color buffer.

ankur bansal
01-22-2011, 09:21 AM
I commented the 2nd glutDisplayMode() call with GLUT_SINGLE then the output screen is like pause there is no effect of keystrokes.

ankur bansal
01-22-2011, 09:33 AM
and yeah along with this there is one problem when I minimize the game window and open other one then the whole game is again from starting stage.

ugluk
01-22-2011, 02:29 PM
glutPostRedisplay() is your friend, check the docs.

ankur bansal
01-22-2011, 07:22 PM
where should I use it ??

ugluk
01-22-2011, 08:18 PM
Check the docs, call it when you want to redraw.

ankur bansal
01-22-2011, 10:22 PM
I have used glutPostRedisplay() in all functions like where I am using left arrow key and others. But still the output is just picture there is no animation.

ZbuffeR
01-23-2011, 02:03 AM
You can put printf("passed here\n"); everywhere you want to check where the program execution is currently running.

By the way, Glut is event driven, so it only reacts to events. If you want some code to be executed when nothing happens, use glutIdleFunc.

ankur bansal
01-23-2011, 02:15 AM
I tried that too and I am using devcpp in that its not showing the output from printf statement.

ZbuffeR
01-23-2011, 02:21 AM
You should build a command-line project for that.

Did you consider a better-suited toolkit for you, such as GLFW ?

ankur bansal
01-23-2011, 02:24 AM
GLFW??? what is this?? I have never heard about it.

ankur bansal
01-23-2011, 09:13 AM
help plz

ZbuffeR
01-23-2011, 09:24 AM
http://www.glfw.org/
Simple, made for games and non interactive demos, good documentation.

ugluk
01-23-2011, 10:58 AM
I think glut is sufficient for his current needs, but we can't read the docs for him, nor can we debug.

ZbuffeR
01-23-2011, 11:22 AM
Yeah it is kinda hopeless, but sometimes a paradigm shift can make things 'click' for someone stuck in a corner.

ankur bansal
01-23-2011, 11:30 AM
I read docs for glutPostRedisplay() and I used as ugluk said but still it was same as before.

ankur bansal
01-23-2011, 01:26 PM
#define GLUT_DISABLE_ATEXIT_HACK

#define GLUT_STATIC

#define RESUME 1

#define PAUSE 2

#define INCREASE 3

#define DECREASE 4

#define REVERSE 5

#define RESTART 6

#define NORMAL1 7

#define POWER 8

#define NEXT 9

#define QUIT 10

#include <iostream>

#include<string>

#include<sstream>

#include<vector>

#include <stdlib.h>

#include <GL/glut.h>

#include <math.h>

#include <GL/gl.h>

#include<stack>



using namespace std;



int flag=0;

int flag1=0;

int flag2=0;

int flag3=0;

int x1=0;

int y3=-835;

int x2=-925;

int y2=100;

int xc=0;

int yc=0;

int TIMER_MS = 10;

const float root=1/1.4142;

int a=-150;

int b=-900;

int c=150;

int d=-850;

int r=50;

const float PI = 3.1415926535f;

float NORMAL;

float ANGLE=0.75*PI;

int rad=10;

int temp2=rad;

int score1=-500;

int bricks;

int bricks1;

int level=1;

int life=3;

int s=-1;

int count=0;

int font=(int)GLUT_BITMAP_TIMES_ROMAN_24 ;

int font1=(int)GLUT_BITMAP_TIMES_ROMAN_10 ;

int font2=(int)GLUT_BITMAP_HELVETICA_18 ;

bool m=true;

bool enter=false;

bool power=false;

bool start1=true;

int condition=0;

int when=0;

int xy=1;

double boundry=(rad/1.4142)+1;

int specialKey;

int sensitivity=100;

char gameModeString[40] = "640x480";

char currentMode[80];

float rBall=0.0,gBall=1.0,bBall=1.0;

float rBar=0.0,gBar=0.0,bBar=1.0;

float rBrick=0.0,gBrick=0.0,bBrick=0.0;

float rButton=1.0,gButton=1.0,bButton=0.0;

float rBackground=1,gBackground=1,bBackground=1;

float rComments=1,gComments=0,bComments=0;

float rScore=1,gScore=1,bScore=1;

float rSelected=0,gSelected=1,bSelected=1;

float rTouched=0,gTouched=0,bTouched=1;



void renderBitmapCharacher(float x, float y, void *font,char *string);

void processNormalKeys(unsigned char key, int , int );

void print_score(int );

void init();



vector< pair < pair <int ,int >,pair<int ,int > > > temp,temp1;

vector < vector< pair < pair <int ,int >,pair<int ,int > > > > input(5);

stack < pair < pair <int ,int >,pair<int ,int > > > touch_finder;

pair < pair <int ,int >,pair<int ,int > > ptouch;



void draw(int x,int y,int r)

{

glTranslated(x,y,0);

glutSolidSphere(r,20,2);

glTranslated(-x,-y,0);

glFlush();

}

void print(int xl,int yl,int xh,int yh)

{

glBegin(GL_POLYGON); //create the background

glVertex2f(xl,yl);

glVertex2f(xh,yl);

glVertex2f(xh,yh);

glVertex2f(xl,yh);

glEnd();

glFlush();

glColor3f(rBackground,gBackground,bBackground); // Background color

glBegin(GL_LINE_LOOP); // create the bricks boundary

glVertex2f(xl,yl);

glVertex2f(xh,yl);

glVertex2f(xh,yh);

glVertex2f(xl,yh);

glEnd();

glFlush();

}

void make(int xl,int yl,int xh,int yh)

{

// create the control panel



glBegin(GL_POLYGON);

glVertex2f(xl,yl);

glVertex2f(xh,yl);

glVertex2f(xh,yh);

glVertex2f(xl,yh);

glEnd();

glFlush();

}

void make_boundry(int xl,int yl,int xh,int yh)

{ // create the boundary in control panel



glBegin(GL_LINE_LOOP);

glVertex2f(xl,yl);

glVertex2f(xh,yl);

glVertex2f(xh,yh);

glVertex2f(xl,yh);

glEnd();

glFlush();

}

void make_bricks(void)

{ // create the bricks

for(int i=0;i<temp.size();i++){

glColor3f(rBrick,gBrick,bBrick);

print(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second);

}

}

float reflect(float angle, float normal)

{

angle = 2 * normal - PI - angle;



while (angle < 0) {

angle += 2 * PI;

}

while (angle > 2 * PI) {

angle -= 2 * PI;

}

return angle;

}



/* Creating the arena */



void arena(void)

{

glColor3f (rBackground,gBackground,bBackground); //boundry

print(-950,-900,950-400,900);



glColor3f (1,0.4,0.2); //scorecard

print(950-400,-900,950,900);



glColor3f (0.2,0.1,0.1); //boundry of scoreboard

print(950-400+25,-900+25,950-25,900-25);

if(start1==true){

flag=0;

flag1=0;

flag2=0;

flag3=0;

rBar=0.0,gBar=1.0,bBar=0.0;

rBall=0.0,gBall=1.0,bBall=1.0;

rBrick=0.0,gBrick=0.0,bBrick=0.0;

a=-150;b=-900;c=150;d=-850;

glColor3f (rBackground,gBackground,bBackground);

draw(x1,y3,r);

x1=0;y3=-835;r=15;

}



glColor3f (rBar,gBar,bBar); //bar

print(a,b,c,d);



glColor3f (rBall,gBall,bBall); //ball

draw(x1,y3,r);

}



void start(void)

{



if(start1==true){ //this is due to restart either through keyboard or menu function





score1=-500;

s=-1;

life=3;

level=1;

glColor3f (rBar,gBar,bBar);

print(a,b,c,d);



power=false;

rad=10;

ANGLE=0.75*PI;

boundry=(rad/1.4142)+1;

}

else{ //this is due to change of resolution

rad=temp2;

s=-1;

score1-=500;

}

int i,j;

input[0].clear();

for(i=-5;i<=5;i++){

for(j=0;j<i+1;j++){

input[0].push_back(make_pair(make_pair(-600+i*100,0+75*j),make_pair(-600+i*100+100,75+75*j)));

}

}

temp=input[0];

if(level>=4){

temp1.clear();

temp.clear();

}

if((condition==1||condition==2||condition==3||cond ition==4||condition==6)&amp;&amp;(start1==false))

temp=temp1;

make_bricks();

bricks=temp.size();

print_score(bricks);

}



// Printing Score, level and life



void print_score(int remaining){



string score;

int t=bricks-remaining;

if(t!=s){

score1+=500;

int printer;

int i=0,abc[20];

// char a[20];

printer=score1;

while(printer>0){

abc[i]=printer%10;

printer/=10;

i++;

}

char a[i];

for(int j=0;j<i;j++)

a[j]=char('0'+ abc[i-j-1]);

glColor3f(0.2,0.1,0.1);

make(600,590,900,700);

glColor3f(rComments,gComments,bComments);

renderBitmapCharacher(600,700,(void *)font2,"SCORE: ");

glColor3f(rScore,gScore,bScore);

renderBitmapCharacher(600,600,(void *)font2,a);

}



char lyf[1];

lyf[0]=char(life+48);

glColor3f(0.2,0.1,0.1);

make(775,175,825,300);

glColor3f(rComments,gComments,bComments);

renderBitmapCharacher(600,200,(void *)font2,"LIFE: ");

// glColor3f(rScore,gScore,bScore);
glColor3f(1,1,0);

renderBitmapCharacher(800,200,(void *)font2,lyf);



char lvl[1];

lvl[0]=char(level+48);

glColor3f(0.2,0.1,0.1);

make(750,375,820,500);

glColor3f(rComments,gComments,bComments);

renderBitmapCharacher(600,400,(void *)font2,"LEVEL: ");

glColor3f(1,1,0);

renderBitmapCharacher(800,400,(void *)font2,lvl);
glColor3f(0.2,0.1,0.1);

make(820,375,900,500);







s=t;

}

void comments(void){

glColor3f(rButton,gButton,bButton); //BUTTON COLORS

make_boundry(580,-125,920,-125); //P

make_boundry(580,-225,920,-25); //M

make_boundry(580,-325,920,-125); //Red bricks

make_boundry(580,-425,920,-125); //Green bricks

make_boundry(580,-525,920,-125); //Blue bricks

make_boundry(-1000,900,-715,1000); //R

make_boundry(-715,900,-520,1000); //ESC

make_boundry(-520,900,-225,1000); //N

make_boundry(-225,900,125,1000); //SPACEBAR

make_boundry(125,900,450,1000); //UP

make_boundry(450,900,1000,1000); //DOWN



glColor3f(rComments,gComments,bComments); //COMMENT COLOR



renderBitmapCharacher(-900,910,(void *)font1,"R:Restart");

renderBitmapCharacher(-700,910,(void *)font1,"ESC:Quit");

renderBitmapCharacher(-500,910,(void *)font1,"N:Next level");

renderBitmapCharacher(-200,910,(void *)font1,"SPACEBAR:Pause");

renderBitmapCharacher(200,910,(void *)font1,"UP:Inc. Speed");

renderBitmapCharacher(500,910,(void *)font1,"DOWN:Dec. Speed");

renderBitmapCharacher(600,-100,(void *)font1,"P:PowerBall");

renderBitmapCharacher(600,-200,(void *)font1,"M:Normal Ball");

renderBitmapCharacher(600,-300,(void *)font1,"Alt+r:Red Bricks");

renderBitmapCharacher(600,-400,(void *)font1,"Alt+g:Green Bricks");

renderBitmapCharacher(600,-500,(void *)font1,"Alt+b:Blue Bricks");

}



/* Creating Different levels */



void next_level(void){

int i,j;

input[1].clear();



for(i=-2;i<=2;i++) //level two

{

for(j=-2;j<=2;j++)

{

input[1].push_back(make_pair(make_pair(-250+i*100,j*75),make_pair(-250+i*100+100,75*j+75)));

input[1].push_back(make_pair(make_pair(-750+i*100,550+j*75),make_pair(-750+i*100+100,75*j+550+75)));

input[1].push_back(make_pair(make_pair(150+i*100,550+j*75) ,make_pair(150+i*100+100,75*j+550+75)));

// input[1].push_back(make_pair(make_pair(150+i*100,-350+j*75),make_pair(150+i*100+100,75*j-350+75)));

}

}

// level 3

input[2].clear();

for(i=0;i<15;i++) //vertical line

input[2].push_back(make_pair(make_pair(-200,-600+i*100),make_pair(-200+75,-600+i*100+100)));

for(i=0;i<6;i++){ //in right bottommost

input[2].push_back(make_pair(make_pair(-50+i*100,-250),make_pair(-50+i*100+100,-250+75)));

}

for(i=0;i<3;i++){

input[2].push_back(make_pair(make_pair(50+i*150,-325),make_pair(50+i*150+150,-325+75)));

}

for(i=0;i<2;i++){

input[2].push_back(make_pair(make_pair(100+i*175,-400),make_pair(100+i*175+175,-400+75)));

}

// for(i=0;i<1;i++){

// input[2].push_back(make_pair(make_pair(175+i*200,-475),make_pair(175+i*200+200,-475+75)));

// }

// for(i=0;i<5;i++){ //in left uppermost

// for(j=0;j<4;j++){

// input[2].push_back(make_pair(make_pair(-800+i*100,250+75*j),make_pair(-800+i*100+100,250+75+75*j)));

// }

// }

for(i=0;i<3;i++) //in left bottommost

input[2].push_back(make_pair(make_pair(-850+i*100,-500),make_pair(-850+i*100+100,-500+75)));

// for(i=0;i<3;i++)

// input[2].push_back(make_pair(make_pair(-850+i*100,-100),make_pair(-850+i*100+100,-100+75)));

// for(i=0;i<3;i++)

// input[2].push_back(make_pair(make_pair(-600+i*100,-300),make_pair(-600+i*100+100,-300+75)));

for(i=0;i<4;i++) // in right uppermost

input[2].push_back(make_pair(make_pair(0+i*100,650),make_p air(0+i*100+100,650+75)));

// for(i=0;i<5;i++)

// input[2].push_back(make_pair(make_pair(180,650-i*100),make_pair(180+75,650-100-i*100)));

for(i=0;i<4;i++)

input[2].push_back(make_pair(make_pair(0+i*100,75),make_pa ir(0+i*100+100,75+75)));





// level 4

input[3].clear();

for(i=0;i<17;i++)

input[3].push_back(make_pair(make_pair(-250,-450+i*75),make_pair(-250+100,-450+i*75+75)));

for(i=0;i<15;i++){

///input[3].push_back(make_pair(make_pair(-350,-375+i*75),make_pair(-350+100,-375+i*75+75)));

if(i==12)

continue;

input[3].push_back(make_pair(make_pair(-350,-375+i*75),make_pair(-350+100,-375+i*75+75)));

input[3].push_back(make_pair(make_pair(-150,-375+i*75),make_pair(-150+100,-375+i*75+75)));

}

//for(i=0;i<10;i++){

// input[3].push_back(make_pair(make_pair(-450,-300+i*75),make_pair(-450+100,-300+i*75+75)));

// input[3].push_back(make_pair(make_pair(-50,-300+i*75),make_pair(-50+100,-300+i*75+75)));

// }

for(i=0;i<12;i++){

if(i==2 || i==9)

continue;

input[3].push_back(make_pair(make_pair(-550,-375+i*75),make_pair(-550+100,-375+i*75+75)));

input[3].push_back(make_pair(make_pair(50,-375+i*75),make_pair(50+100,-375+i*75+75)));

}

//for(i=0;i<3;i++){

// input[3].push_back(make_pair(make_pair(-650,-450+i*75),make_pair(-650+100,-450+i*75+75)));

// input[3].push_back(make_pair(make_pair(150,-450+i*75),make_pair(150+100,-450+i*75+75)));

// }

for(i=0;i<6;i++){

if(i==3 || i==2 || i==4)

continue;

input[3].push_back(make_pair(make_pair(-650,375+i*75),make_pair(-650+100,375+i*75+75)));

input[3].push_back(make_pair(make_pair(150,375+i*75),make_ pair(150+100,375+i*75+75)));

}

for(i=0;i<1;i++){

input[3].push_back(make_pair(make_pair(-750,750+i*75),make_pair(-750+100,750+i*75+75)));

input[3].push_back(make_pair(make_pair(250,750+i*750),make _pair(250+100,750+i*75+75)));

}

//for(i=0;i<2;i++){

// input[3].push_back(make_pair(make_pair(-850+i*100,675),make_pair(-850+i*100+100,675+75)));

// input[3].push_back(make_pair(make_pair(250+i*100,675),make _pair(250+100+i*100,675+75)));

// }

for(i=0;i<10;i++){

if(i==4 || i==5 || i==6 || i==7 || i==8 )

continue;

input[3].push_back(make_pair(make_pair(-950,-75+i*75),make_pair(-950+100,-75+i*75+75)));

input[3].push_back(make_pair(make_pair(450,-75+i*75),make_pair(450+100,-75+i*75+75)));

}





// level 5

input[4].clear();

for(i=0;i<15;i++) //horozontal line

input[4].push_back(make_pair(make_pair(-950+i*100,-675),make_pair(-950+i*100+100,-675+75)));

for(i=0;i<14;i++)

input[4].push_back(make_pair(make_pair(-895+i*100,-600),make_pair(-895+i*100+100,-600+75)));

for(i=0;i<13;i++)

input[4].push_back(make_pair(make_pair(-840+i*100,-525),make_pair(-840+i*100+100,-525+75)));

for(i=0;i<12;i++)

input[4].push_back(make_pair(make_pair(-785+i*100,-450),make_pair(-785+i*100+100,-450+75)));

//for(i=0;i<11;i++)

// input[4].push_back(make_pair(make_pair(-730+i*100,-375),make_pair(-730+i*100+100,-375+75)));

// for(i=0;i<10;i++)

// input[4].push_back(make_pair(make_pair(-675+i*100,-300),make_pair(-675+i*100+100,-300+75)));

// for(i=0;i<9;i++)

// input[4].push_back(make_pair(make_pair(-620+i*100,-225),make_pair(-620+i*100+100,-225+75)));

// for(i=0;i<8;i++)

// input[4].push_back(make_pair(make_pair(-565+i*100,-150),make_pair(-565+i*100+100,-150+75)));

// for(i=0;i<7;i++)

// input[4].push_back(make_pair(make_pair(-510+i*100,-75),make_pair(-510+i*100+100,-75+75)));

for(i=0;i<6;i++)

input[4].push_back(make_pair(make_pair(-455+i*100,0),make_pair(-455+i*100+100,0+75)));// lower part

for(i=0;i<5;i++)

input[4].push_back(make_pair(make_pair(-400+i*100,75),make_pair(-400+i*100+100,75+75)));

for(i=0;i<6;i++)

input[4].push_back(make_pair(make_pair(-455+i*100,150),make_pair(-455+i*100+100,150+75)));

for(i=0;i<7;i++)

input[4].push_back(make_pair(make_pair(-510+i*100,225),make_pair(-510+i*100+100,225+75)));

//for(i=0;i<8;i++)

// input[4].push_back(make_pair(make_pair(-565+i*100,300),make_pair(-565+i*100+100,300+75)));

// for(i=0;i<9;i++)

// input[4].push_back(make_pair(make_pair(-620+i*100,375),make_pair(-620+i*100+100,375+75)));

// for(i=0;i<10;i++)

// input[4].push_back(make_pair(make_pair(-675+i*100,450),make_pair(-675+i*100+100,450+75)));

for(i=0;i<11;i++)

input[4].push_back(make_pair(make_pair(-730+i*100,525),make_pair(-730+i*100+100,525+75)));

for(i=0;i<12;i++)

input[4].push_back(make_pair(make_pair(-785+i*100,600),make_pair(-785+i*100+100,600+75)));

for(i=0;i<13;i++)

input[4].push_back(make_pair(make_pair(-840+i*100,675),make_pair(-840+i*100+100,675+75)));

for(i=0;i<14;i++)

input[4].push_back(make_pair(make_pair(-895+i*100,750),make_pair(-895+i*100+100,750+75)));

for(i=0;i<15;i++) //horozontal line

input[4].push_back(make_pair(make_pair(-950+i*100,825),make_pair(-950+i*100+100,825+75)));



print_score(temp.size());

}



/* Erasing Bricks with normal ball */



void erase_block(int a,int b,int c,int d,float e,int f)

{

glColor3f(rBackground,gBackground,bBackground);

make(a,b,c,d);

temp.erase(temp.begin()+f);

NORMAL=e*PI;

ANGLE=reflect(ANGLE,NORMAL);

}



/* Erasing Bricks with Power ball */



void erase_block_power(int a,int b,int c,int d,float e,int f)

{

glColor3f(rBackground,gBackground,bBackground);

make(a,b,c,d);

temp.erase(temp.begin()+f);

}

void pause1()

{

flag=0;

flag1=0;

flag3++;

}

void update(int value)

{



glColor3f (rBackground,gBackground,bBackground); // update the color of background when ball leaves bar

draw(0,-835,r);



glColor3f (rBackground,gBackground,bBackground); // update the color of background when ball moves

draw(x1,y3,r);



float x,y;

x=x1+rad*cos(ANGLE);

y=y3+rad*sin(ANGLE);

glColor3f (rBall,gBall,bBall); // color of the ball when moving

draw((int)x,(int)y,(int)r);

int i;

// conditions for erasing the bricks

for(i=0;i <temp.size();i++){

if(abs((int)(x+r)-(int)temp[i].first.first)<abs((int)boundry)&amp;&amp;y>=(int)temp[i].first.second&amp;&amp;y<=(int)temp[i].second.second){

if(power==false)

erase_block(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,0,i);

if(power==true)

erase_block_power(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,0,i);

enter=true;

break;

}



if(abs((int)(x-r)-(int)temp[i].second.first)<abs((int)boundry)&amp;&amp;y>=(int)temp[i].first.second&amp;&amp;y<=(int)temp[i].second.second){

if(power==false)

erase_block(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,1,i);

if(power==true)

erase_block_power(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,1,i);

enter=true;

break;

}



if(abs((int)(y+r)-(int)temp[i].first.second)<abs((int)boundry)&amp;&amp;x>=(int)temp[i].first.first&amp;&amp;x<=(int)temp[i].second.first){

if(power==false)

erase_block(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,1.5,i);

if(power==true)

erase_block_power(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,1.5,i);

enter=true;

break;

}



if(abs((int)(y-r)-(int)temp[i].second.second)<abs((int)boundry)&amp;&amp;x>=(int)temp[i].first.first&amp;&amp;x<=(int)temp[i].second.first){

if(power==false)

erase_block(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,0.5,i);

if(power==true)

erase_block_power(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,0.5,i);

enter=true;

break;

}



if(sqrt(pow(x+r*cos(ANGLE)-temp[i].first.first,2)+pow(y+r*sin(ANGLE)-temp[i].first.second,2))<rad){

if(power==false)

erase_block(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,ANGLE/PI,i);

if(power==true)

erase_block_power(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,ANGLE/PI,i);

enter=true;

break;

}



if(sqrt(pow(x-r*cos(ANGLE)-temp[i].second.first,2)+pow(y+r*sin(ANGLE)-temp[i].first.second,2))<rad){

if(power==false)

erase_block(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,ANGLE/PI,i);

if(power==true)

erase_block_power(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,ANGLE/PI,i);

enter=true;

break;

}



if(sqrt(pow(x+r*cos(ANGLE)-temp[i].first.first,2)+pow(y-r*sin(ANGLE)-temp[i].second.second,2))<rad){

if(power==false)

erase_block(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,ANGLE/PI,i);

if(power==true)

erase_block_power(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,ANGLE/PI,i);

enter=true;

break;

}



if(sqrt(pow(x-r*cos(ANGLE)-temp[i].second.first,2)+pow(y-r*sin(ANGLE)-temp[i].second.second,2))<rad){

if(power==false)

erase_block(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,ANGLE/PI,i);

if(power==true)

erase_block_power(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,ANGLE/PI,i);

enter=true;

break;

}

}





if(enter==true)

when++;

if(when==5){

make_bricks();

enter=false;;

when=0;

}



print_score(temp.size());



if((int)(x-r+950)<abs((int)boundry)){

NORMAL=0;

ANGLE=reflect(ANGLE,NORMAL);

}

if(-y-r+900<abs((int)boundry))

{

NORMAL=1.5*PI;

ANGLE=reflect(ANGLE,NORMAL);

}

if(-x-r+950-400<abs((int)boundry))

{

NORMAL=PI;

ANGLE=reflect(ANGLE,NORMAL);

}

if(y-r+850<abs((int)boundry) &amp;&amp; a<=x&amp;&amp;c>=x) //the ball touches the bar

{

NORMAL=0.5*PI;

ANGLE=reflect(ANGLE,NORMAL);

}

if(sqrt(pow(c-x,2)+pow(y-d,2))<=r){ //the ball touches the right part of the bar

rad=(-1)*rad;

temp2=rad;

}



if(sqrt(pow(a-x,2)+pow(y-d,2))<=r){ //the ball touches the left part of the bar

rad=(-1)*rad;

temp2=rad;

}



if(y-r+875<abs((int)boundry) ) //the ball misses the bar

{

life--;

if(life<0)

return;

if(life==0){

print_score(temp.size());

glColor3f(rComments,gComments,bComments);

renderBitmapCharacher(0,800,(void *)font,"GAME OVER");

pause1();

return;

}

glColor3f (rBackground,gBackground,bBackground);

print(-950,-900,550,-800);

print(a,b,c,d);

glColor3f (rBall,gBall,bBall); // the ball is re-created

draw(0,-835,r);

ANGLE=.75*PI;

x=0;

y=-825;

a=-150;

b=-900;

c=150;

d=-850;

glColor3f (0.0, 1.0,0.0); // bar is created again after miss

print(a,b,c,d);

flag=0;

flag1=0;

flag2=0;

print_score(temp.size());



}



if(temp.size()==0){

level++;

if(level>6){

level=6;

return;

}

if(level==6){

glColor3f(rComments,gComments,bComments);

renderBitmapCharacher(-700,0,(void *)font,"YOU HAVE WON THE MATCH");

return;

temp1.clear();

}

temp=input[level-1];

bricks=temp.size();

glColor3f (rBackground,gBackground,bBackground);

draw((int)x,(int)y,(int)r);

make_bricks();



glColor3f (rBackground,gBackground,bBackground);

print(-950,-900,550,-700);

print(a,b,c,d);

glColor3f (rBall,gBall,bBall);

draw(0,-835,r);

ANGLE=.75*PI;

x=0;

y=-835;

a=-150;

b=-900;

c=150;

d=-850;

glColor3f (0.0, 1.0,0.0);

print(a,b,c,d);

flag=0;

flag1=0;

flag2=0;

flag3=0;

print_score(temp.size());

//increase_speed();

}

x1=(int)x;

y3=(int)y;

temp1=temp;

if(flag!=0)

glutTimerFunc(TIMER_MS, update, 0);

}

// Function to move bar to left

void move_left(void)

{



if(a<=-950){

glColor3f (rBar,gBar,bBar);

print(-950,-900,-650,-850);

}

else

{

glColor3f (rBackground,gBackground,bBackground);

print(a,b,c,d);

a-=sensitivity;

c-=sensitivity;

glColor3f (rBar,gBar,bBar);

print(a,b,c,d);

}

}

// Function to move bar to left

void move_right(void)

{



if(c>=550){

glColor3f (rBar,gBar,bBar);

print(650-400,-900,950-400,-850);}

else

{

glColor3f (rBackground,gBackground,bBackground);

print(a,b,c,d);

a+=sensitivity;

c+=sensitivity;

glColor3f (rBar,gBar,bBar);

print(a,b,c,d);

}



}

void increase_speed(void)

{

if(rad>0)

rad+=10;

if(rad<0)

rad-=10;



boundry=abs((int)(rad/1.4142))+1;

temp2=rad;

}

void decrease_speed(void)

{

if(rad>0){

rad-=10;

if(rad==0)

rad+=10;

}

if(rad<0){

rad+=10;

if(rad==0)

rad-=10;

}

boundry=abs((int)(rad/1.4142))+1;

temp2=rad;

}

void restart(void)

{

start1=true;

// glutPostRedisplay();

pause1();

}

void next(void)

{

glColor3f(1,1,1);

for(int f=0;f<temp.size();f++)

make(temp[f].first.first,temp[f].first.second,temp[f].second.first,temp[f].second.second);

temp.clear();

condition=0;

}

void touch_stack(int txl,int tyl,int txh,int tyh){

if(!touch_finder.empty()){

ptouch=touch_finder.top();

glColor3f(rButton,gButton,bButton);

make_boundry(ptouch.first.first,ptouch.first.secon d,ptouch.second.first,ptouch.second.second);

touch_finder.pop();

}

glColor3f(rTouched,gTouched,bTouched);

make_boundry(txl,tyl,txh,tyh);

touch_finder.push(make_pair(make_pair(txl,tyl),mak e_pair(txh,tyh)));

}



// function for keyboard keys processing (Normal keys)



void processNormalKeys(unsigned char key, int x, int y) {

specialKey = glutGetModifiers(); // for key combination like Alt + a

if (specialKey == GLUT_ACTIVE_ALT) {

if (key == 114) // Alt + r

rBrick=1.0,gBrick=0.0,bBrick=0.0;



if (key == 103) // Alt + b

rBrick=0.0,gBrick=1.0,bBrick=0.0;



if(key == 98) // Alt + g

rBrick=0.0,gBrick=0.0,bBrick=1.0;

make_bricks();



}

else{



if (key == 27) //esc

exit(0);glClearColor (0.0, 0.0, 0.0, 0.0);

glMatrixMode(GL_PROJECTION);

// glLoadIdentity();

glOrtho(-1000.0, 1000.0, -1000.0, 1000.0, -1000.0, 1000.0);



if(key==32){ //spacebar

if(m==true){

pause1();

m=false;

}

else{

glutTimerFunc(TIMER_MS, update, 0);

flag++;

flag1++;

flag2++;

flag3=0;

m=true;

}



}

if(key==110){ //NEXT LEVEL==n

next();

}

if(key==114){ //restart the game

restart();

}



if(key==112){ //POWERBALL=p

power=true;

rBall=1.0;

gBall=0.0;

bBall=0.0;

}

if(key==109){ //MODE NORMAL=m

power=false;

rBall=0.0;

gBall=1.0;

bBall=1.0;

}



}

glutPostRedisplay();

}

void renderBitmapCharacher(float x, float y, void *font,char *string)

{



char *c;

glRasterPos2f(x, y);

for (c=string; *c != '\0'; c++) {

glutBitmapCharacter(font, *c);

}

}

void pressKey(int key, int x, int y) {



if(flag==0){



glutTimerFunc(TIMER_MS, update, 0);

flag++;

flag1++;

flag2++;

flag3=0;

m=true;

}



if(key==GLUT_KEY_LEFT)

move_left();

if(key==GLUT_KEY_RIGHT)

move_right();

if(key==GLUT_KEY_UP){ //increase speed

if(rad>0)

rad+=10;

if(rad<0)

rad-=10;

boundry=abs((int)(rad/1.4142))+1;

temp2=rad;

}



if(key==GLUT_KEY_DOWN){ //decrease speed

if(rad>0){

rad-=10;

if(rad==0)

rad+=10;

}

if(rad<0){

rad+=10;

if(rad==0)

rad-=10;

}

boundry=abs((int)(rad/1.4142))+1;

temp2=rad;

}

glutPostRedisplay();



}



void display(void)

{

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

arena();

start(); //start the game

comments();

next_level();



glutSwapBuffers();



}

void idle(void)

{

glutPostRedisplay();

}



int main(int argc, char** argv)

{



glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);



glutInitWindowPosition (100,-100);

glutInitWindowSize (700,700);

glutInit(&amp;argc, argv);

// glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);

glutCreateWindow ("Ball Breaker for Gameloft By Ankur Bansal");

glutDisplayFunc(display);

glutKeyboardFunc(processNormalKeys);

glutIdleFunc(idle);

glutSpecialFunc(pressKey);

glClearColor (0.0, 0.0, 0.0, 0.0);

glMatrixMode(GL_PROJECTION);

// glLoadIdentity();

glOrtho(-1000.0, 1000.0, -1000.0, 1000.0, -1000.0, 1000.0);

glutMainLoop();

// printf("passed here\n");

// system("pause");

return 0;



}


I have used now glutPostRedisplay() in this but I am getting the still no animation in it.

ugluk
01-23-2011, 01:44 PM
If nothing is moving, then check if the variables controlling your animation are changing. If not, you have a bug somewhere, display the variables by debugging or by printing them out.

ankur bansal
01-23-2011, 01:49 PM
They are changing and also the program is taking keystrokes as I printing them on screen but there is no animation. I getting animation if use only GLUT_SINGLE

dalemac
01-23-2011, 02:35 PM
I just had a quick look over your code.

first off - why did you completely remove your init function?

Second - i cannot get anything to animate in single or double buffering.

your key presses are working and it is calling glPostRedisplay.

Your bug is elsewhere!

Dale

ankur bansal
01-23-2011, 02:45 PM
I simply put all the calls of init() in the main function.

I did not get your 2nd question.

dalemac
01-23-2011, 02:59 PM
What i am saying, is that with your current code, i cannot get your game to work with single or double buffering. it is not an issue with double buffering, but something else.

Im still trying it out. got to get on with my own stuff soon though!

Dale

ankur bansal
01-23-2011, 03:16 PM
see this one, I have commented glutPostRedisplay() and its with single buffer.


#define GLUT_DISABLE_ATEXIT_HACK

#define GLUT_STATIC

#define RESUME 1

#define PAUSE 2

#define INCREASE 3

#define DECREASE 4

#define REVERSE 5

#define RESTART 6

#define NORMAL1 7

#define POWER 8

#define NEXT 9

#define QUIT 10

#include <iostream>

#include<string>

#include<sstream>

#include<vector>

#include <stdlib.h>

#include <GL/glut.h>

#include <math.h>

#include <GL/gl.h>

#include<stack>



using namespace std;



int flag=0;

int flag1=0;

int flag2=0;

int flag3=0;

int x1=0;

int y3=-835;

int x2=-925;

int y2=100;

int xc=0;

int yc=0;

int TIMER_MS = 10;

const float root=1/1.4142;

int a=-150;

int b=-900;

int c=150;

int d=-850;

int r=50;

const float PI = 3.1415926535f;

float NORMAL;

float ANGLE=0.75*PI;

int rad=10;

int temp2=rad;

int score1=-500;

int bricks;

int bricks1;

int level=1;

int life=3;

int s=-1;

int count=0;

int font=(int)GLUT_BITMAP_TIMES_ROMAN_24 ;

int font1=(int)GLUT_BITMAP_TIMES_ROMAN_10 ;

int font2=(int)GLUT_BITMAP_HELVETICA_18 ;

bool m=true;

bool enter=false;

bool power=false;

bool start1=true;

int condition=0;

int when=0;

int xy=1;

double boundry=(rad/1.4142)+1;

int specialKey;

int sensitivity=100;

char gameModeString[40] = "640x480";

char currentMode[80];

float rBall=0.0,gBall=1.0,bBall=1.0;

float rBar=0.0,gBar=0.0,bBar=1.0;

float rBrick=0.0,gBrick=0.0,bBrick=0.0;

float rButton=1.0,gButton=1.0,bButton=0.0;

float rBackground=1,gBackground=1,bBackground=1;

float rComments=1,gComments=0,bComments=0;

float rScore=1,gScore=1,bScore=1;

float rSelected=0,gSelected=1,bSelected=1;

float rTouched=0,gTouched=0,bTouched=1;



void renderBitmapCharacher(float x, float y, void *font,char *string);

void processNormalKeys(unsigned char key, int , int );

void print_score(int );

void init();



vector< pair < pair <int ,int >,pair<int ,int > > > temp,temp1;

vector < vector< pair < pair <int ,int >,pair<int ,int > > > > input(5);

stack < pair < pair <int ,int >,pair<int ,int > > > touch_finder;

pair < pair <int ,int >,pair<int ,int > > ptouch;



void draw(int x,int y,int r)

{

glTranslated(x,y,0);

glutSolidSphere(r,20,2);

glTranslated(-x,-y,0);

glFlush();

}

void print(int xl,int yl,int xh,int yh)

{

glBegin(GL_POLYGON); //create the background

glVertex2f(xl,yl);

glVertex2f(xh,yl);

glVertex2f(xh,yh);

glVertex2f(xl,yh);

glEnd();

glFlush();

glColor3f(rBackground,gBackground,bBackground); // Background color

glBegin(GL_LINE_LOOP); // create the bricks boundary

glVertex2f(xl,yl);

glVertex2f(xh,yl);

glVertex2f(xh,yh);

glVertex2f(xl,yh);

glEnd();

glFlush();

}

void make(int xl,int yl,int xh,int yh)

{

// create the control panel



glBegin(GL_POLYGON);

glVertex2f(xl,yl);

glVertex2f(xh,yl);

glVertex2f(xh,yh);

glVertex2f(xl,yh);

glEnd();

glFlush();

}

void make_boundry(int xl,int yl,int xh,int yh)

{ // create the boundary in control panel



glBegin(GL_LINE_LOOP);

glVertex2f(xl,yl);

glVertex2f(xh,yl);

glVertex2f(xh,yh);

glVertex2f(xl,yh);

glEnd();

glFlush();

}

void make_bricks(void)

{ // create the bricks

for(int i=0;i<temp.size();i++){

glColor3f(rBrick,gBrick,bBrick);

print(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second);

}

}

float reflect(float angle, float normal)

{

angle = 2 * normal - PI - angle;



while (angle < 0) {

angle += 2 * PI;

}

while (angle > 2 * PI) {

angle -= 2 * PI;

}

return angle;

}



/* Creating the arena */



void arena(void)

{

glColor3f (rBackground,gBackground,bBackground); //boundry

print(-950,-900,950-400,900);



glColor3f (1,0.4,0.2); //scorecard

print(950-400,-900,950,900);



glColor3f (0.2,0.1,0.1); //boundry of scoreboard

print(950-400+25,-900+25,950-25,900-25);

if(start1==true){

flag=0;

flag1=0;

flag2=0;

flag3=0;

rBar=0.0,gBar=1.0,bBar=0.0;

rBall=0.0,gBall=1.0,bBall=1.0;

rBrick=0.0,gBrick=0.0,bBrick=0.0;

a=-150;b=-900;c=150;d=-850;

glColor3f (rBackground,gBackground,bBackground);

draw(x1,y3,r);

x1=0;y3=-835;r=15;

}



glColor3f (rBar,gBar,bBar); //bar

print(a,b,c,d);



glColor3f (rBall,gBall,bBall); //ball

draw(x1,y3,r);

}



void start(void)

{



if(start1==true){ //this is due to restart either through keyboard or menu function





score1=-500;

s=-1;

life=3;

level=1;

glColor3f (rBar,gBar,bBar);

print(a,b,c,d);



power=false;

rad=10;

ANGLE=0.75*PI;

boundry=(rad/1.4142)+1;

}

else{ //this is due to change of resolution

rad=temp2;

s=-1;

score1-=500;

}

int i,j;

input[0].clear();

for(i=-5;i<=5;i++){

for(j=0;j<i+1;j++){

input[0].push_back(make_pair(make_pair(-600+i*100,0+75*j),make_pair(-600+i*100+100,75+75*j)));

}

}

temp=input[0];

if(level>=4){

temp1.clear();

temp.clear();

}

if((condition==1||condition==2||condition==3||cond ition==4||condition==6)&amp;&amp;(start1==false))

temp=temp1;

make_bricks();

bricks=temp.size();

print_score(bricks);

}



// Printing Score, level and life



void print_score(int remaining){



string score;

int t=bricks-remaining;

if(t!=s){

score1+=500;

int printer;

int i=0,abc[20];



printer=score1;

while(printer>0){

abc[i]=printer%10;

printer/=10;

i++;

}

char a[i];

for(int j=0;j<i;j++)

a[j]=char('0'+ abc[i-j-1]);

glColor3f(0.2,0.1,0.1);

make(600,590,900,700);

glColor3f(rComments,gComments,bComments);

renderBitmapCharacher(600,700,(void *)font2,"SCORE: ");

glColor3f(rScore,gScore,bScore);

renderBitmapCharacher(600,600,(void *)font2,a);

}



char lyf[1];

lyf[0]=char(life+48);

glColor3f(0.2,0.1,0.1);

make(775,175,825,300);

glColor3f(rComments,gComments,bComments);



renderBitmapCharacher(600,200,(void *)font2,"LIFE: ");

glColor3f(rScore,gScore,bScore);

renderBitmapCharacher(800,200,(void *)font2,lyf);

char lvl[1];

lvl[0]=char(level+48);

glColor3f(0.2,0.1,0.1);

make(750,375,820,500);

glColor3f(rComments,gComments,bComments);

renderBitmapCharacher(600,400,(void *)font2,"LEVEL: ");

glColor3f(rScore,gScore,bScore);

renderBitmapCharacher(800,400,(void *)font2,lvl);

glColor3f(0.2,0.1,0.1);

make(820,375,900,500);







s=t;

}

void comments(void){

glColor3f(rButton,gButton,bButton); //BUTTON COLORS

make_boundry(580,-125,920,-125); //P

make_boundry(580,-225,920,-25); //M

make_boundry(580,-325,920,-125); //Red bricks

make_boundry(580,-425,920,-125); //Green bricks

make_boundry(580,-525,920,-125); //Blue bricks

make_boundry(-1000,900,-715,1000); //R

make_boundry(-715,900,-520,1000); //ESC

make_boundry(-520,900,-225,1000); //N

make_boundry(-225,900,125,1000); //SPACEBAR

make_boundry(125,900,450,1000); //UP

make_boundry(450,900,1000,1000); //DOWN



glColor3f(rComments,gComments,bComments); //COMMENT COLOR



renderBitmapCharacher(-900,910,(void *)font1,"R:Restart");

renderBitmapCharacher(-700,910,(void *)font1,"ESC:Quit");

renderBitmapCharacher(-500,910,(void *)font1,"N:Next level");

renderBitmapCharacher(-200,910,(void *)font1,"SPACEBAR:Pause");

renderBitmapCharacher(200,910,(void *)font1,"UP:Inc. Speed");

renderBitmapCharacher(500,910,(void *)font1,"DOWN:Dec. Speed");

renderBitmapCharacher(600,-100,(void *)font1,"P:PowerBall");

renderBitmapCharacher(600,-200,(void *)font1,"M:Normal Ball");

renderBitmapCharacher(600,-300,(void *)font1,"Alt+r:Red Bricks");

renderBitmapCharacher(600,-400,(void *)font1,"Alt+g:Green Bricks");

renderBitmapCharacher(600,-500,(void *)font1,"Alt+b:Blue Bricks");

}



/* Creating Different levels */



void next_level(void){

int i,j;

input[1].clear();



for(i=-2;i<=2;i++) //level two

{

for(j=-2;j<=2;j++)

{

input[1].push_back(make_pair(make_pair(-250+i*100,j*75),make_pair(-250+i*100+100,75*j+75)));

input[1].push_back(make_pair(make_pair(-750+i*100,550+j*75),make_pair(-750+i*100+100,75*j+550+75)));

input[1].push_back(make_pair(make_pair(150+i*100,550+j*75) ,make_pair(150+i*100+100,75*j+550+75)));

// input[1].push_back(make_pair(make_pair(150+i*100,-350+j*75),make_pair(150+i*100+100,75*j-350+75)));

}

}

// level 3

input[2].clear();

for(i=0;i<15;i++) //vertical line

input[2].push_back(make_pair(make_pair(-200,-600+i*100),make_pair(-200+75,-600+i*100+100)));

for(i=0;i<6;i++){ //in right bottommost

input[2].push_back(make_pair(make_pair(-50+i*100,-250),make_pair(-50+i*100+100,-250+75)));

}

for(i=0;i<3;i++){

input[2].push_back(make_pair(make_pair(50+i*150,-325),make_pair(50+i*150+150,-325+75)));

}

for(i=0;i<2;i++){

input[2].push_back(make_pair(make_pair(100+i*175,-400),make_pair(100+i*175+175,-400+75)));

}

// for(i=0;i<1;i++){

// input[2].push_back(make_pair(make_pair(175+i*200,-475),make_pair(175+i*200+200,-475+75)));

// }

// for(i=0;i<5;i++){ //in left uppermost

// for(j=0;j<4;j++){

// input[2].push_back(make_pair(make_pair(-800+i*100,250+75*j),make_pair(-800+i*100+100,250+75+75*j)));

// }

// }

for(i=0;i<3;i++) //in left bottommost

input[2].push_back(make_pair(make_pair(-850+i*100,-500),make_pair(-850+i*100+100,-500+75)));

// for(i=0;i<3;i++)

// input[2].push_back(make_pair(make_pair(-850+i*100,-100),make_pair(-850+i*100+100,-100+75)));

// for(i=0;i<3;i++)

// input[2].push_back(make_pair(make_pair(-600+i*100,-300),make_pair(-600+i*100+100,-300+75)));

for(i=0;i<4;i++) // in right uppermost

input[2].push_back(make_pair(make_pair(0+i*100,650),make_p air(0+i*100+100,650+75)));

// for(i=0;i<5;i++)

// input[2].push_back(make_pair(make_pair(180,650-i*100),make_pair(180+75,650-100-i*100)));

for(i=0;i<4;i++)

input[2].push_back(make_pair(make_pair(0+i*100,75),make_pa ir(0+i*100+100,75+75)));





// level 4

input[3].clear();

for(i=0;i<17;i++)

input[3].push_back(make_pair(make_pair(-250,-450+i*75),make_pair(-250+100,-450+i*75+75)));

for(i=0;i<15;i++){

///input[3].push_back(make_pair(make_pair(-350,-375+i*75),make_pair(-350+100,-375+i*75+75)));

if(i==12)

continue;

input[3].push_back(make_pair(make_pair(-350,-375+i*75),make_pair(-350+100,-375+i*75+75)));

input[3].push_back(make_pair(make_pair(-150,-375+i*75),make_pair(-150+100,-375+i*75+75)));

}

//for(i=0;i<10;i++){

// input[3].push_back(make_pair(make_pair(-450,-300+i*75),make_pair(-450+100,-300+i*75+75)));

// input[3].push_back(make_pair(make_pair(-50,-300+i*75),make_pair(-50+100,-300+i*75+75)));

// }

for(i=0;i<12;i++){

if(i==2 || i==9)

continue;

input[3].push_back(make_pair(make_pair(-550,-375+i*75),make_pair(-550+100,-375+i*75+75)));

input[3].push_back(make_pair(make_pair(50,-375+i*75),make_pair(50+100,-375+i*75+75)));

}

//for(i=0;i<3;i++){

// input[3].push_back(make_pair(make_pair(-650,-450+i*75),make_pair(-650+100,-450+i*75+75)));

// input[3].push_back(make_pair(make_pair(150,-450+i*75),make_pair(150+100,-450+i*75+75)));

// }

for(i=0;i<6;i++){

if(i==3 || i==2 || i==4)

continue;

input[3].push_back(make_pair(make_pair(-650,375+i*75),make_pair(-650+100,375+i*75+75)));

input[3].push_back(make_pair(make_pair(150,375+i*75),make_ pair(150+100,375+i*75+75)));

}

for(i=0;i<1;i++){

input[3].push_back(make_pair(make_pair(-750,750+i*75),make_pair(-750+100,750+i*75+75)));

input[3].push_back(make_pair(make_pair(250,750+i*750),make _pair(250+100,750+i*75+75)));

}

//for(i=0;i<2;i++){

// input[3].push_back(make_pair(make_pair(-850+i*100,675),make_pair(-850+i*100+100,675+75)));

// input[3].push_back(make_pair(make_pair(250+i*100,675),make _pair(250+100+i*100,675+75)));

// }

for(i=0;i<10;i++){

if(i==4 || i==5 || i==6 || i==7 || i==8 )

continue;

input[3].push_back(make_pair(make_pair(-950,-75+i*75),make_pair(-950+100,-75+i*75+75)));

input[3].push_back(make_pair(make_pair(450,-75+i*75),make_pair(450+100,-75+i*75+75)));

}





// level 5

input[4].clear();

for(i=0;i<15;i++) //horozontal line

input[4].push_back(make_pair(make_pair(-950+i*100,-675),make_pair(-950+i*100+100,-675+75)));

for(i=0;i<14;i++)

input[4].push_back(make_pair(make_pair(-895+i*100,-600),make_pair(-895+i*100+100,-600+75)));

for(i=0;i<13;i++)

input[4].push_back(make_pair(make_pair(-840+i*100,-525),make_pair(-840+i*100+100,-525+75)));

for(i=0;i<12;i++)

input[4].push_back(make_pair(make_pair(-785+i*100,-450),make_pair(-785+i*100+100,-450+75)));

//for(i=0;i<11;i++)

// input[4].push_back(make_pair(make_pair(-730+i*100,-375),make_pair(-730+i*100+100,-375+75)));

// for(i=0;i<10;i++)

// input[4].push_back(make_pair(make_pair(-675+i*100,-300),make_pair(-675+i*100+100,-300+75)));

// for(i=0;i<9;i++)

// input[4].push_back(make_pair(make_pair(-620+i*100,-225),make_pair(-620+i*100+100,-225+75)));

// for(i=0;i<8;i++)

// input[4].push_back(make_pair(make_pair(-565+i*100,-150),make_pair(-565+i*100+100,-150+75)));

// for(i=0;i<7;i++)

// input[4].push_back(make_pair(make_pair(-510+i*100,-75),make_pair(-510+i*100+100,-75+75)));

for(i=0;i<6;i++)

input[4].push_back(make_pair(make_pair(-455+i*100,0),make_pair(-455+i*100+100,0+75)));// lower part

for(i=0;i<5;i++)

input[4].push_back(make_pair(make_pair(-400+i*100,75),make_pair(-400+i*100+100,75+75)));

for(i=0;i<6;i++)

input[4].push_back(make_pair(make_pair(-455+i*100,150),make_pair(-455+i*100+100,150+75)));

for(i=0;i<7;i++)

input[4].push_back(make_pair(make_pair(-510+i*100,225),make_pair(-510+i*100+100,225+75)));

//for(i=0;i<8;i++)

// input[4].push_back(make_pair(make_pair(-565+i*100,300),make_pair(-565+i*100+100,300+75)));

// for(i=0;i<9;i++)

// input[4].push_back(make_pair(make_pair(-620+i*100,375),make_pair(-620+i*100+100,375+75)));

// for(i=0;i<10;i++)

// input[4].push_back(make_pair(make_pair(-675+i*100,450),make_pair(-675+i*100+100,450+75)));

for(i=0;i<11;i++)

input[4].push_back(make_pair(make_pair(-730+i*100,525),make_pair(-730+i*100+100,525+75)));

for(i=0;i<12;i++)

input[4].push_back(make_pair(make_pair(-785+i*100,600),make_pair(-785+i*100+100,600+75)));

for(i=0;i<13;i++)

input[4].push_back(make_pair(make_pair(-840+i*100,675),make_pair(-840+i*100+100,675+75)));

for(i=0;i<14;i++)

input[4].push_back(make_pair(make_pair(-895+i*100,750),make_pair(-895+i*100+100,750+75)));

for(i=0;i<15;i++) //horozontal line

input[4].push_back(make_pair(make_pair(-950+i*100,825),make_pair(-950+i*100+100,825+75)));



print_score(temp.size());

}



/* Erasing Bricks with normal ball */



void erase_block(int a,int b,int c,int d,float e,int f)

{

glColor3f(rBackground,gBackground,bBackground);

make(a,b,c,d);

temp.erase(temp.begin()+f);

NORMAL=e*PI;

ANGLE=reflect(ANGLE,NORMAL);

}



/* Erasing Bricks with Power ball */



void erase_block_power(int a,int b,int c,int d,float e,int f)

{

glColor3f(rBackground,gBackground,bBackground);

make(a,b,c,d);

temp.erase(temp.begin()+f);

}

void pause1()

{

flag=0;

flag1=0;

flag3++;

}

void update(int value)

{



glColor3f (rBackground,gBackground,bBackground); // update the color of background when ball leaves bar

draw(0,-835,r);



glColor3f (rBackground,gBackground,bBackground); // update the color of background when ball moves

draw(x1,y3,r);



float x,y;

x=x1+rad*cos(ANGLE);

y=y3+rad*sin(ANGLE);

glColor3f (rBall,gBall,bBall); // color of the ball when moving

draw((int)x,(int)y,(int)r);

int i;

// conditions for erasing the bricks

for(i=0;i <temp.size();i++){

if(abs((int)(x+r)-(int)temp[i].first.first)<abs((int)boundry)&amp;&amp;y>=(int)temp[i].first.second&amp;&amp;y<=(int)temp[i].second.second){

if(power==false)

erase_block(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,0,i);

if(power==true)

erase_block_power(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,0,i);

enter=true;

break;

}



if(abs((int)(x-r)-(int)temp[i].second.first)<abs((int)boundry)&amp;&amp;y>=(int)temp[i].first.second&amp;&amp;y<=(int)temp[i].second.second){

if(power==false)

erase_block(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,1,i);

if(power==true)

erase_block_power(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,1,i);

enter=true;

break;

}



if(abs((int)(y+r)-(int)temp[i].first.second)<abs((int)boundry)&amp;&amp;x>=(int)temp[i].first.first&amp;&amp;x<=(int)temp[i].second.first){

if(power==false)

erase_block(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,1.5,i);

if(power==true)

erase_block_power(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,1.5,i);

enter=true;

break;

}



if(abs((int)(y-r)-(int)temp[i].second.second)<abs((int)boundry)&amp;&amp;x>=(int)temp[i].first.first&amp;&amp;x<=(int)temp[i].second.first){

if(power==false)

erase_block(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,0.5,i);

if(power==true)

erase_block_power(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,0.5,i);

enter=true;

break;

}



if(sqrt(pow(x+r*cos(ANGLE)-temp[i].first.first,2)+pow(y+r*sin(ANGLE)-temp[i].first.second,2))<rad){

if(power==false)

erase_block(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,ANGLE/PI,i);

if(power==true)

erase_block_power(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,ANGLE/PI,i);

enter=true;

break;

}



if(sqrt(pow(x-r*cos(ANGLE)-temp[i].second.first,2)+pow(y+r*sin(ANGLE)-temp[i].first.second,2))<rad){

if(power==false)

erase_block(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,ANGLE/PI,i);

if(power==true)

erase_block_power(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,ANGLE/PI,i);

enter=true;

break;

}



if(sqrt(pow(x+r*cos(ANGLE)-temp[i].first.first,2)+pow(y-r*sin(ANGLE)-temp[i].second.second,2))<rad){

if(power==false)

erase_block(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,ANGLE/PI,i);

if(power==true)

erase_block_power(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,ANGLE/PI,i);

enter=true;

break;

}



if(sqrt(pow(x-r*cos(ANGLE)-temp[i].second.first,2)+pow(y-r*sin(ANGLE)-temp[i].second.second,2))<rad){

if(power==false)

erase_block(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,ANGLE/PI,i);

if(power==true)

erase_block_power(temp[i].first.first,temp[i].first.second,temp[i].second.first,temp[i].second.second,ANGLE/PI,i);

enter=true;

break;

}

}





if(enter==true)

when++;

if(when==5){

make_bricks();

enter=false;;

when=0;

}



print_score(temp.size());



if((int)(x-r+950)<abs((int)boundry)){

NORMAL=0;

ANGLE=reflect(ANGLE,NORMAL);

}

if(-y-r+900<abs((int)boundry))

{

NORMAL=1.5*PI;

ANGLE=reflect(ANGLE,NORMAL);

}

if(-x-r+950-400<abs((int)boundry))

{

NORMAL=PI;

ANGLE=reflect(ANGLE,NORMAL);

}

if(y-r+850<abs((int)boundry) &amp;&amp; a<=x&amp;&amp;c>=x) //the ball touches the bar

{

NORMAL=0.5*PI;

ANGLE=reflect(ANGLE,NORMAL);

}

if(sqrt(pow(c-x,2)+pow(y-d,2))<=r){ //the ball touches the right part of the bar

rad=(-1)*rad;

temp2=rad;

}



if(sqrt(pow(a-x,2)+pow(y-d,2))<=r){ //the ball touches the left part of the bar

rad=(-1)*rad;

temp2=rad;

}



if(y-r+875<abs((int)boundry) ) //the ball misses the bar

{

life--;

if(life<0)

return;

if(life==0){

print_score(temp.size());

glColor3f(rComments,gComments,bComments);

renderBitmapCharacher(0,800,(void *)font,"GAME OVER");

pause1();

return;

}

glColor3f (rBackground,gBackground,bBackground);

print(-950,-900,550,-800);

print(a,b,c,d);

glColor3f (rBall,gBall,bBall); // the ball is re-created

draw(0,-835,r);

ANGLE=.75*PI;

x=0;

y=-825;

a=-150;

b=-900;

c=150;

d=-850;

glColor3f (0.0, 1.0,0.0); // bar is created again after miss

print(a,b,c,d);

flag=0;

flag1=0;

flag2=0;

print_score(temp.size());



}



if(temp.size()==0){

level++;

if(level>6){

level=6;

return;

}

if(level==6){

glColor3f(rComments,gComments,bComments);

renderBitmapCharacher(-700,0,(void *)font,"YOU HAVE WON THE MATCH");

return;

temp1.clear();

}

temp=input[level-1];

bricks=temp.size();

glColor3f (rBackground,gBackground,bBackground);

draw((int)x,(int)y,(int)r);

make_bricks();



glColor3f (rBackground,gBackground,bBackground);

print(-950,-900,550,-700);

print(a,b,c,d);

glColor3f (rBall,gBall,bBall);

draw(0,-835,r);

ANGLE=.75*PI;

x=0;

y=-835;

a=-150;

b=-900;

c=150;

d=-850;

glColor3f (0.0, 1.0,0.0);

print(a,b,c,d);

flag=0;

flag1=0;char lyf[1];

lyf[0]=char(life+48);

glColor3f(0.2,0.1,0.1);

make(775,175,825,300);

glColor3f(rComments,gComments,bComments);



renderBitmapCharacher(600,200,(void *)font2,"LIFE: ");

glColor3f(rScore,gScore,bScore);

renderBitmapCharacher(800,200,(void *)font2,lyf);

flag2=0;

flag3=0;

print_score(temp.size());

//increase_speed();

}

x1=(int)x;

y3=(int)y;

temp1=temp;

if(flag!=0)

glutTimerFunc(TIMER_MS, update, 0);

}

// Function to move bar to left

void move_left(void)

{



if(a<=-950){

glColor3f (rBar,gBar,bBar);

print(-950,-900,-650,-850);

}

else

{

glColor3f (rBackground,gBackground,bBackground);

print(a,b,c,d);

a-=sensitivity;

c-=sensitivity;

glColor3f (rBar,gBar,bBar);

print(a,b,c,d);

}

}

// Function to move bar to left

void move_right(void)

{



if(c>=550){

glColor3f (rBar,gBar,bBar);

print(650-400,-900,950-400,-850);}

else

{

glColor3f (rBackground,gBackground,bBackground);

print(a,b,c,d);

a+=sensitivity;

c+=sensitivity;

glColor3f (rBar,gBar,bBar);

print(a,b,c,d);

}



}

void increase_speed(void)

{

if(rad>0)

rad+=10;

if(rad<0)

rad-=10;



boundry=abs((int)(rad/1.4142))+1;

temp2=rad;

}

void decrease_speed(void)

{

if(rad>0){

rad-=10;

if(rad==0)

rad+=10;

}

if(rad<0){

rad+=10;

if(rad==0)

rad-=10;

}

boundry=abs((int)(rad/1.4142))+1;

temp2=rad;

}

void restart(void)

{

start1=true;

glutPostRedisplay();

pause1();

}

void next(void)

{

glColor3f(1,1,1);

for(int f=0;f<temp.size();f++)

make(temp[f].first.first,temp[f].first.second,temp[f].second.first,temp[f].second.second);

temp.clear();

condition=0;

}

void touch_stack(int txl,int tyl,int txh,int tyh){

if(!touch_finder.empty()){

ptouch=touch_finder.top();

glColor3f(rButton,gButton,bButton);

make_boundry(ptouch.first.first,ptouch.first.secon d,ptouch.second.first,ptouch.second.second);

touch_finder.pop();

}

glColor3f(rTouched,gTouched,bTouched);

make_boundry(txl,tyl,txh,tyh);

touch_finder.push(make_pair(make_pair(txl,tyl),mak e_pair(txh,tyh)));

}



// function for keyboard keys processing (Normal keys)



void processNormalKeys(unsigned char key, int x, int y) {

specialKey = glutGetModifiers(); // for key combination like Alt + a

if (specialKey == GLUT_ACTIVE_ALT) {

if (key == 114) // Alt + r

rBrick=1.0,gBrick=0.0,bBrick=0.0;



if (key == 103) // Alt + b

rBrick=0.0,gBrick=1.0,bBrick=0.0;



if(key == 98) // Alt + g

rBrick=0.0,gBrick=0.0,bBrick=1.0;

make_bricks();



}

else{



if (key == 27) //esc

exit(0);



if(key==32){ //spacebar

if(m==true){

pause1();

m=false;

}

else{

glutTimerFunc(TIMER_MS, update, 0);

flag++;

flag1++;

flag2++;

flag3=0;

m=true;

}



}

if(key==110){ //NEXT LEVEL==n

next();

}

if(key==114){ //restart the game

restart();

}



if(key==112){ //POWERBALL=p

power=true;

rBall=1.0;

gBall=0.0;

bBall=0.0;

}

if(key==109){ //MODE NORMAL=m

power=false;

rBall=0.0;

gBall=1.0;

bBall=1.0;

}



}

// glutPostRedisplay();

}

void renderBitmapCharacher(float x, float y, void *font,char *string)

{



char *c;

glRasterPos2f(x, y);

for (c=string; *c != '\0'; c++) {

glutBitmapCharacter(font, *c);

}

}

void pressKey(int key, int x, int y) {



if(flag==0){



glutTimerFunc(TIMER_MS, update, 0);

flag++;

flag1++;

flag2++;

flag3=0;

m=true;

}



if(key==GLUT_KEY_LEFT)

move_left();

if(key==GLUT_KEY_RIGHT)

move_right();

if(key==GLUT_KEY_UP){ //increase speed

if(rad>0)

rad+=10;

if(rad<0)

rad-=10;

boundry=abs((int)(rad/1.4142))+1;

temp2=rad;

}



if(key==GLUT_KEY_DOWN){ //decrease speed

if(rad>0){

rad-=10;

if(rad==0)

rad+=10;

}

if(rad<0){

rad+=10;

if(rad==0)

rad-=10;

}

boundry=abs((int)(rad/1.4142))+1;

temp2=rad;

}

// glutPostRedisplay();



}



void display(void)

{

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

arena();

start(); //start the game

comments();

next_level();



// glutSwapBuffers();



}



int main(int argc, char** argv)

{



// glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);



glutInitWindowPosition (100,-100);

glutInitWindowSize (700,700);

glutInit(&amp;argc, argv);

glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);

glutCreateWindow ("Ball Breaker for Gameloft By Ankur Bansal");

glutDisplayFunc(display);

glutKeyboardFunc(processNormalKeys);

// glutIdleFunc(idle);

glutSpecialFunc(pressKey);

glClearColor (0.0, 0.0, 0.0, 0.0);

glMatrixMode(GL_PROJECTION);

// glLoadIdentity();

glOrtho(-1000.0, 1000.0, -1000.0, 1000.0, -1000.0, 1000.0);

glutMainLoop();

// printf("passed here\n");

// system("pause");

return 0;



}

Alfonse Reinheart
01-23-2011, 03:28 PM
If your code is that long, post a link to it. Don't just dump thousands of lines of code onto the forum. And especially don't double space it. And even moreso, don't do it twice.

dalemac
01-23-2011, 04:06 PM
Your main problem is your understanding of glFlush.

glFlush should be called once, at the end of your display function, like how glutSwapBuffers is used (use glFlush for single buffering, and glutSwapBuffers for double buffering).

by calling glFlush everytime you are drawing an object you are basically forcing all buffers to be drawn as quickly as possible by openGL.

how you are rendering your single buffering is to constantly empty the buffers after each object, and hence you are getting the animation when you should not be. (and the flickering of the objects)

When you have come to use double buffering, you have changed how openGL is flushing the scene to the screen, because double buffering essentially stores everything until the call to glutSwapBuffers is made, when everything is outputted to the screen (as opposed to how you are rendering your game, but NOT single buffering)


Basically, the flickering to begin with was caused by incorrect use of glFlush, this just didnt become apparent until you tried to use double buffering, which was completely the wrong thing to do, as you issue is not with double buffering.

your current single buffering state would look like this:
draw object
flush contents to screen
draw object
flush contents to screen
etc

hence the flickering effect which you can see. even in single buffering, you would not see this flickering as you should always be outputting all of your objects to the screen at the same time.

What you need to do is remove these glFlush calls, and replace them with a single glFlush call at the end of your display function.

Unfortunately for you, i have just tried this, which results in no animation in single buffering mode either, confirming my suspicions that this is not a double buffering issue.


The issue is solely on how you draw your scene to begin with.

Your game technically should not work in single or double buffering mode.

you can either:

continue to render the game incorrectly and put up with the flickering

sort out your drawing,variables and logic so that it works like any openGL application should!

ankur bansal
01-23-2011, 04:17 PM
I did with single glFlush there is no change

dalemac
01-23-2011, 04:44 PM
Did you actually read what i said?

The problem is not double buffering, it is the fact that you are constantly calling glFlush after drawing each object. This is giving the FALSE amination. This is what is causing your flickering to begin with, none of your objects should be flickering, not even with single buffering.

forget about double buffering entirely for a few minutes. It is having no effect on your application what so ever.

As i said above, i have tried changing your game back to single buffering, and how it should be done. this results in no animation in your scene because your functions in your display functions are wrong.

When you first reported the flickering problem, this is becuase of the recursive calls to glFlush. glFlush writes everything to the screen. You are constantly writing different objects the the sceen, which is causing the flickering problem. This would not even happen with single buffering if you were using it correctly, and the animation you are getting (currently) is a bi-product of your incorrect glFlush calls.


Like i said, you need to either put up with the flickering or solve the problem all together by rendering your objects correctly!

forget about double buffering, it is only confusing you and is NOT the solution to your flickering problem.


Dale

ankur bansal
01-23-2011, 04:55 PM
Okay!! I am getting what you are saying and yes none of the objects are flickering. And also one more problem I found now that when the application is running and if I minimize it then again maximize, it restarts again automatically and how can I make the bar in bottom to move smoothly?

dalemac
01-23-2011, 05:12 PM
That is because you have no resize function!

go and look up glutResizeFunc

to make the bar smoother, you simply neet to translate it at smaller intervals.


You need to learn how to identify problems, even if it is just comparing a basic openGL application with your own. Try to learn something new about openGL every day! then you wont need to rely on others so much to pick at your mistakes.

Dale

ankur bansal
01-23-2011, 05:23 PM
Its because I have started to work on openGL recently and I have seen some tutorials on net. Can you tell me a book which covers all these basic points?

ankur bansal
01-23-2011, 05:27 PM
If I translate it at smaller interval then its moving too slow

dalemac
01-23-2011, 05:28 PM
I have only just started using openGL too, i.e the last month. The key to learning anything is to study it.

search online for the red book, it has lots of information, just be sure that you understand what it is trying to tell you.


P.s a "thankyou for your time & help" goes a long way.

Dale

dalemac
01-23-2011, 05:30 PM
If I translate it at smaller interval then its moving too slow

so find the balance! also, i noticed that you are using glutIdleFunc and glutTimerFunc, these may be impacting on that.


Dale

ankur bansal
01-23-2011, 05:33 PM
I really appreciate you gave so much time for my problems. Thanks alot for your valuable time. :)