Posts

Showing posts from November, 2014

WAP to use KeyBoard Key

Image
#include<GL/glu.h> #include<GL/glut.h> #include<GL/gl.h> float left=0.0; float right=0.0; float up=0.0; float down=0.0; int x1=-1; int x2=1; float x=0; void display() {      glClear(GL_COLOR_BUFFER_BIT);      glClearColor(0.0,1.0,0.0,0);      glColor3f(1.0,0.0,0.0);      glPointSize(5);      glRectf(-0.1,-0.1,0.1,0.1);      glLineWidth(5);     if(x<10)     {      glBegin(GL_POINTS);      glTranslatef(left+right,0,0);          for(float i=-100;i<=100;i+=0.1)          {                    glVertex2f(i+left+right,0.3);               glVertex2f(i+left+right,-0.3);               }          }                             else if(x<20)               {                    glBegin(GL_POINTS);                    glTranslatef(left+right,0,0);                                      for(float i=-100;i<=100;i+=0.1)                  {  glVertex2f(i+left+right,0.3);                    glVertex2f(i+left+right+0.05,0.3);                    glVertex2f(i+left+right,-0.3);        

WAP to draw a 3D Sphere

Image
 #include <GL/glut.h> #include <GL/glu.h> #include <GL/gl.h> static GLfloat rotAngle = 0.0; static GLfloat rotAngle1 = 0.0; void display() {   glClear(GL_COLOR_BUFFER_BIT);   glPushMatrix();   glRotatef(rotAngle, 0.0, 1.0, 0.0);   glutWireSphere(2,50,50);   glPopMatrix();   glFlush();   glutSwapBuffers();   glutPostRedisplay(); } void init() {   glClearColor(0.5, 0.55, .13, 1.0);   glColor3f(1.0, 0.0, 0.0);   glMatrixMode(GL_PROJECTION);   glLoadIdentity();   gluPerspective(80.0, 4.0/3.0, 1, 10);   glMatrixMode(GL_MODELVIEW);   glLoadIdentity();  gluLookAt(0, 4, 0, 0, 0, 0, 0, 0, 1); } void keyboard(unsigned char k, int x, int y) {     switch (k)     {     case 'a':     {     rotAngle += 1;     rotAngle1 -= 1;     }     break;     case 'l':     {     rotAngle -= 1;     rotAngle1 += 1;     }     break;     case 'q':     exit(0);     }     glutPostRedisplay(); } int main(int argc, char** argv) {   glutInit(&argc, argv);   glutInitDisplayMode

WAP for Bouncing Balls in OpenGl

Image
#include<GL/glu.h> #include<GL/glut.h> #include<GL/gl.h> int flag=1; float tx=0; void display() {   glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);   glClearColor(1, 0, 0, 1.0);   glColor3f(1.0, 0.0, 0.0);   glMatrixMode(GL_PROJECTION);   glLoadIdentity();   gluPerspective(80.0, 4.0/3.0, 1, 10);   glMatrixMode(GL_MODELVIEW);   glLoadIdentity();   gluLookAt(4, 4, 4, 0, 0, 0, 0, 1, 0);   glColor3f(1.0, 1.0, 1.0);   glBegin(GL_LINES);   for (float i =-9; i <= 9; i += 0.5)    {     glVertex3f(i, 0,-9); glVertex3f(i, 0, 9);     glVertex3f(-9, 0, i); glVertex3f(9, 0, i);   }   glEnd();   glPushMatrix();   glMatrixMode(GL_PROJECTION);   glLoadIdentity();   gluPerspective(80.0, 1.0/1.0, 1, 60);   gluLookAt(0, 0, 10, 0,0,0, 1, 1, 0);   glColor3f(1.0,1.0,0);   glTranslatef(tx+2.5,tx+2.5,0);   glutSolidSphere(1,50,50);   glPopMatrix();     glPushMatrix();   glLoadIdentity();   gluPerspective(80.0, 4.0/3.0, 1, 80);   gluLookAt(0, 0, 10,4,-4,0, 1, 1 ,0);   glColor3f(1.0,0.0