//the following code writen in C++ using openGL API
//by IT_LOVER
#include
#include
#define PI 3.14159
bool b;
void drawCircle(float radius){
static float x, y;
glBegin(GL_LINE_STRIP);
for(int i = 0; i <= 360; i++){
x = radius * sin(i * PI/180);
y = radius * cos(i * PI/180);
glVertex3f(x, y, 0);
}
glEnd();
}
void drawLine(float length){
glBegin(GL_LINE);
glVertex3f(-20, 0, 0);
glVertex3f(20, 0, 0);
glEnd();
}
void Init(){
glClearColor(0.0, 0.0, 0.0, 1.0);
}
void draw(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0, 0, 5, 0, 0, 0, 0, 1, 0);
if(b)
drawCircle(70);
else
drawLine(40);
glFlush();
}
void resize(int w, int h){
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-100, 100, -100, 100, -100, 100);
}
void keyboard(unsigned char key, int x, int y){
switch(key){
case 'c':
b = true;
break;
case 'l':
b = false;
break;
}
draw();
}
void main(int argc, char** argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
glutInitWindowPosition(0, 0);
glutInitWindowSize(800, 800);
glutCreateWindow("IT_LOVER");
glutReshapeFunc(resize);
glutDisplayFunc(draw);
glutKeyboardFunc(keyboard);
Init();
glutMainLoop();
}
|