Skip to content

Instantly share code, notes, and snippets.

@shaina7837
Created October 28, 2013 12:53
Show Gist options
  • Save shaina7837/7196324 to your computer and use it in GitHub Desktop.
Save shaina7837/7196324 to your computer and use it in GitHub Desktop.
#include <GL/glut.h>
#include <cmath>
void line(float x, float y)
{
glClearColor(1.0, 1.0, 1.0, 1.0); //defining for background color
glClear(GL_COLOR_BUFFER_BIT); //assigning the defined color to background
glColor3f(0.0, 0.0, 0.0); // color of the object to be displayed
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);//representing the real world dimensions in 2D screen and defining the coordinate limits
glPointSize(2);
glBegin(GL_LINES); //start drawing polygon
glVertex2f(0.0,0.0); //defining the vertex of polygon
glVertex2f(x,y);
//glVertex2f(x+0.2,y+0.2);
glEnd();
glFlush();
}
void rotate(float *x, float *y, float *theta);
void show()
{ float angle = 90;
float a = 0.0, b = 0.4 ;
//line(a,b);
rotate(&a,&b,&angle); //calling rotation function
line(a,b); //calling function to draw a line
glEnd(); //ending the drawing
glFlush(); // for execution
}
void rotate(float *x, float *y, float *theta)
{
float *xtemp;
xtemp = x;
*x = (*x)*cos(*theta) - (*y)*sin(*theta);
*y = (*x)*sin(*theta) + (*y)*cos(*theta);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);//initiate library functions
glutInitDisplayMode(GLUT_SINGLE);
glutInitWindowSize(500,500);//defining display window size
glutInitWindowPosition(100,100);//defining display window position on the screen
glutCreateWindow("OpenGL - Sec window demo");//defining the title of display window
glutDisplayFunc(show);//calling the object drawing function
glutMainLoop(); //put the program in infinite loop
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment