VPN termux about China.net

glCallList && glDeleteLists



#ifdef __APPLE__
#include<GLUT/glut.h>
#include<openGL/openGL.h>

#else
#include<GL/glut.h>
#endif
#include <stdlib.h>


#define  LIST_OBJECT  1
#define  LIST_OBJECT2  2
#define  LIST_OBJECT3  3
#define  LIST_OBJECT4  4
#define  LIST_OBJECT5  5
#define  LIST_OBJECT6  6
#define  LIST_OBJECT7  7
#define  LIST_OBJECT8  8

                                                                                                                     
GLfloat d = 0.1;

GLfloat y2=-0.7f;
int refreshMillis = 30; 

//struct in opengl

struct kulka
{  
                   
GLfloat x;
GLfloat y ;

} kulka , wall= {1.0 , 1.0} , speed= {0.04, 0.07};
            
struct point
{
GLfloat x;
GLfloat y;
} point[20];



void CreateList(void)
{
 glNewList(LIST_OBJECT, GL_COMPILE);
{
glColor3f(1.0,1.0,.0);
    glTranslatef(0.1, 0.0 ,0.0);
    glutSolidSphere(d,4,4);
glFlush ();

}
  glEndList();

 glNewList(LIST_OBJECT2, GL_COMPILE);
{
glColor3f(1.0,1.0,.0);
    glTranslatef(0.1, 0.0 ,0.0);
    glutSolidSphere(d,4,4);
glFlush ();

}
  glEndList();

 glNewList(LIST_OBJECT3, GL_COMPILE);
{
glColor3f(1.0,1.0,.0);
    glTranslatef(0.1, 0.0 ,0.0);
    glutSolidSphere(d,4,4);
glFlush ();

}
 glEndList();

 glNewList(LIST_OBJECT4, GL_COMPILE);
{
glColor3f(1.0,1.0,.0);
    glTranslatef(0.1, 0.0 ,0.0);
    glutSolidSphere(d,4,4);
glFlush ();

}
 glEndList();

 glNewList(LIST_OBJECT5, GL_COMPILE);
{
glColor3f(1.0,1.0,.0);
    glTranslatef(0.1, 0.0 ,0.0);
    glutSolidSphere(d,4,4);
glFlush ();

}
 glEndList();

glNewList(LIST_OBJECT6, GL_COMPILE);
{
glColor3f(1.0,1.0,.0);
    glTranslatef(0.0, 0.0 ,0.0);
    glutSolidSphere(d,4,4);
glFlush ();

}
 glEndList();

glNewList(LIST_OBJECT7, GL_COMPILE);
{
glColor3f(1.0,1.0,.0);
    glTranslatef(0.0, 0.0 ,0.0);
    glutSolidSphere(d,4,4);
glFlush ();

}
 glEndList();

glNewList(LIST_OBJECT8, GL_COMPILE);
{
glColor3f(1.0,1.0,.0);
    glTranslatef(0.0, 0.0 ,0.0);
    glutSolidSphere(d,4,4);
glFlush ();

}
  glEndList();

}





void drawBall2(GLfloat *x2)
{

    glColor3f(1.0,0.0,.0);

    glPushMatrix();

    glTranslatef(*x2, y2,0.0);

    glutSolidSphere(d,20,20);

    glPopMatrix();


}
void keyboard (unsigned char key, int x, int y )   //core dumpted p.
{
GLfloat *x2;
switch (key) {
case 'd':
*x2=*x2+0.1;
glutPostRedisplay();
break;
case 'a':
*x2=*x2-0.1;
glutPostRedisplay();
break;
}
}



void initRendering()
{
    glEnable(GL_DEPTH_TEST);    //que ce se?? p
}

void reshape(int w,int h)
{
    glViewport(0,0,w,h);

    glMatrixMode(GL_PROJECTION);
 glLoadIdentity();
  
 
glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
}                                                                      //p.



void drawBall1()
{

    glColor3f(0.0,1.0,.0);

    glPushMatrix();

    glTranslatef(kulka.x,kulka.y,0.0);

    glutSolidSphere(d,20,20);

    glPopMatrix();
}


void update()
{



kulka.x+=speed.x;
kulka.y+=speed.y;
if (kulka.x>wall.x)
{
speed.x=-speed.x;
}
if ( kulka.y>wall.y)
{
speed.y=-speed.y;
}
  if(kulka.x<-wall.x)
 {
speed.x=-speed.x;
}
if  ( kulka.y<-wall.y)
{
speed.y=-speed.y;
}

}


void display()
{
    glClear(GL_COLOR_BUFFER_BIT);

    glMatrixMode(GL_MODELVIEW);

    glLoadIdentity();

 glShadeModel(GL_SMOOTH);


GLfloat *x2;
 update();

 drawBall1();                    
 drawBall2(x2); 
  glLoadIdentity();
point[0].x=-0.7;
point[1].x=-0.5;
point[2].x=-0.3;
point[3].x=-0.1;
point[4].x=0.1;

point[5].x=0.3;
point[6].x=0.5;
point[7].x=0.7;
point[8].x=0.9;

glPushMatrix();
glTranslatef(point[0].x, 0.7,0.0);
  glCallList(LIST_OBJECT);
 glPopMatrix();

glPushMatrix();
glTranslatef(point[1].x, 0.7,0.0);
  glCallList(LIST_OBJECT2);
 glPopMatrix();

glPushMatrix();
glTranslatef(point[2].x, 0.7,0.0);
  glCallList(LIST_OBJECT3);
 glPopMatrix();

glPushMatrix();
glTranslatef(point[3].x, 0.7,0.0);
  glCallList(LIST_OBJECT4);
 glPopMatrix();

glPushMatrix();
glTranslatef(point[4].x, 0.7,0.0);
  glCallList(LIST_OBJECT5);
 glPopMatrix();

glPushMatrix();
glTranslatef(point[5].x, 0.7,0.0);
  glCallList(LIST_OBJECT6);
 glPopMatrix();

glPushMatrix();
glTranslatef(point[6].x, 0.7,0.0);
  glCallList(LIST_OBJECT7);
 glPopMatrix();

glPushMatrix();
glTranslatef(point[7].x, 0.7,0.0);
  glCallList(LIST_OBJECT8);
 glPopMatrix();



 if ((0.7-kulka.y<d) &&   (kulka.x-point[0].x<d )&& (point[0].x-kulka.x<d) )
{
glDeleteLists(LIST_OBJECT, 1);

}   
  if ((0.7-kulka.y<d) &&   (kulka.x-point[1].x<d )&& (point[1].x-kulka.x<d) )
{
glDeleteLists(LIST_OBJECT2, 1);

}   
 if ((0.7-kulka.y<d) &&   (kulka.x-point[2].x<d )&& (point[2].x-kulka.x<d) )
{
glDeleteLists(LIST_OBJECT3, 1);

}  
  if ((0.7-kulka.y<d) &&   (kulka.x-point[3].x<d )&& (point[3].x-kulka.x<d) )
{
glDeleteLists(LIST_OBJECT4, 1);

}  
   if ((0.7-kulka.y<d) &&   (kulka.x-point[4].x<d )&& (point[4].x-kulka.x<d) )
{
glDeleteLists(LIST_OBJECT5, 1);

}   
   if ((0.7-kulka.y<d) &&   (kulka.x-point[5].x<d )&& (point[5].x-kulka.x<d) )
{
glDeleteLists(LIST_OBJECT6, 1);

}  
    if ((0.7-kulka.y<d) &&   (kulka.x-point[6].x<d )&& (point[6].x-kulka.x<d) )
{
glDeleteLists(LIST_OBJECT7, 1);

}

    if ((0.7-kulka.y<d) &&   (kulka.x-point[7].x<d )&& (point[7].x-kulka.x<d) )
{
glDeleteLists(LIST_OBJECT8, 1);

}
 glFlush ();
if((  kulka.y-y2<d ) && (kulka.x-*x2<d )&& (*x2-kulka.x<d) )
{

speed.y=-speed.y;
}


    glutSwapBuffers();
}




void Timer(int value)          //kopjuj wklej p.
 {
   glutPostRedisplay();    // Post a paint request to activate display()
   glutTimerFunc(refreshMillis, Timer, 0); // subsequent timer call at milliseconds
}


int main(int argc,char **argv)                   //kopjuj wklej p.

{

    glutInit(&argc,argv);

    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);

    glutInitWindowSize(400,400);

    glutCreateWindow("gra Q");

  initRendering();
    CreateList();                                       //TRY THIS


    glutReshapeFunc(reshape);

  glutKeyboardFunc(keyboard);

glutTimerFunc(0, Timer, 0); 

   glutDisplayFunc(display);
    glutMainLoop();

    return 0;

}

No comments:

Post a Comment