Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GL/glut.h>
- void shapes (void) {
- /*glColor3f(1.0, 1.0, 1.0); //this will set a color of the square.
- glBegin(GL_LINES); // write shape u want to create
- glVertex3f(-0.5, -0.5, 0.0);
- glVertex3f(-0.5, 0.5, 0.0);
- glVertex3f(0.5, 0.5, 0.0);
- glVertex3f(0.5, -0.5, 0.0);*/
- /*glBegin(GL_POINTS);
- glVertex3f(.5,.5,0);
- glVertex3f(-.5,-.5,0);
- glVertex3f(0,.5,0);
- glVertex3f(.5,0,0);
- glVertex3f(0,0,0);*/
- /*glBegin(GL_LINE_STRIP);
- glVertex3f(0,0,0);
- glVertex3f(-.5,0,0);
- glVertex3f(.5,.5,0);
- glVertex3f(-.5,.5,0);
- glVertex3f(.5,0,0);*/
- /*glBegin(GL_POLYGON);
- glColor3f(1, 0, 0);
- glVertex3f(-0.6, -0.75, 0);
- glColor3f(0, 1, 0);
- glVertex3f(0.6, -0.75, 0);
- glColor3f(0, 0, 1);
- glVertex3f(0, 0.75, 0);*/
- // Triangle 01
- float x1=-0.8; float x2=0; float x3=0.8;
- float y1=-0.5; float y2=1; float y3=-0.5;
- glBegin(GL_TRIANGLES);
- glColor3f(1, 0, 0);
- glVertex3f(x1, y1, 0);
- glVertex3f(x2, y2, 0);
- glVertex3f(x3, y3, 0);
- // Triangle 02
- float x4=(x1+x2)/2; float x5=(x1+x3)/2; float x6=(x3+x2)/2;
- float y4=(y1+y2)/2; float y5=-y2/2; float y6=(y3+y2)/2;
- glBegin(GL_TRIANGLES);
- glColor3f(0, 1, 0);
- glVertex3f(x4, y4, 0);
- glVertex3f(x5, y5, 0);
- glVertex3f(x6, y6, 0);
- // Triangle 03
- float x7=(x4+x2)/2; float x8=(x1+x3)/2; float x9=(x2+(x2+x3)/2)/2;
- float y7=(((y1+y2)/2)+y2)/2; float y8=(y2/2)/2; float y9=(y2+(y2+y3)/2)/2;
- glBegin(GL_TRIANGLES);
- glColor3f(0, 0, 1);
- glVertex3f(x7, y7, 0);
- glVertex3f(x8, y8, 0);
- glVertex3f(x9, y9, 0);
- // Triangle 04
- float x10= (x4+x1)/2 ; float x11= (x1+x5)/2; float x12= (x4+x8)/2;
- float y10= (y4+y1)/2 ; float y11= (y1+y5)/2; float y12= (y1+y8)/2;
- glBegin(GL_TRIANGLES);
- glColor3f(1, 1, 0);
- glVertex3f(x10, y10, 0);
- glVertex3f(x11, y11, 0);
- glVertex3f(x12, y12, 0);
- // Triangle 05
- float x13= (x6+x3)/2 ; float x14= (x3+x5)/2; float x15= (x6+x8)/2;
- float y13= (y6+y3)/2 ; float y14= (y3+y5)/2; float y15= (y3+y8)/2;
- glBegin(GL_TRIANGLES);
- glColor3f(0, 1, 1);
- glVertex3f(x13, y13, 0);
- glVertex3f(x14, y14, 0);
- glVertex3f(x15, y15, 0);
- // Triangle 06
- float x16= (x10+x1)/2 ; float x17= (x1+x11)/2 ; float x18= (x10+x11)/2 ;
- float y16= (y10+y1)/2 ; float y17= (y1+y11)/2 ; float y18= (y10+y11)/2 ;
- glBegin(GL_TRIANGLES);
- glColor3f(1, 1, 1);
- glVertex3f(x16, y16, 0);
- glVertex3f(x17, y17, 0);
- glVertex3f(x18, y18, 0);
- // Triangle 07
- float x19= ; float x20= ; float x21= ;
- float y19= ; float y20= ; float y21= ;
- glBegin(GL_TRIANGLES);
- glColor3f(1, 1, 1);
- glVertex3f(x19, y19, 0);
- glVertex3f(x20, y20, 0);
- glVertex3f(x21, y21, 0);
- /*glBegin(GL_QUADS);
- glVertex3f(-0.5, -0.5, 0.0);
- glVertex3f(-0.5, 0.5, 0.0);
- glVertex3f(0.5, 0.5, 0.0);
- glVertex3f(0.5, -0.5, 0.0);*/
- /*glBegin(GL_TRIANGLE_FAN);
- glColor3f(1,0,0);
- glVertex2f(0,0.5);
- glVertex2f(-0.4,0);
- glVertex2f(0.4,0);
- glVertex2f(0,-0.5);
- */
- glEnd();
- }
- void display (void) {
- // clearing the window with black color, 1st 3 parameter are for R,G,B. last one for opacity
- glClearColor (0.0,0.0,0.0,1.0);
- glClear (GL_COLOR_BUFFER_BIT);
- glLoadIdentity();
- //viewing transformation
- //glulookat() positions the camera towards the object
- //camera position, camera target, upvector
- gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
- shapes();
- glFlush();
- }
- void reshape (int w, int h) {
- // 1st 2 parameters for lower left corner of the viewport rectangle. the default is 0,0
- // the next coordinates are width and hight of the viewport
- //Set the viewport to be the entire window
- glViewport (0, 0, (GLsizei)w, (GLsizei)h);
- // setting the camera
- glMatrixMode (GL_PROJECTION);
- glLoadIdentity ();
- //perspective transform
- //gluPerspective (30, (GLfloat)w / (GLfloat)h, 1.0, 100.0);
- gluPerspective (30, 1, 1.0, 100.0);
- glMatrixMode (GL_MODELVIEW); //switch back the the model editing mode.
- }
- int main (int argc, char **argv) {
- glutInit (&argc, argv);
- glutInitDisplayMode (GLUT_SINGLE); // single buffering.. (double buffering for animation)
- // full screen is 1000,1000
- // this 0,0 or 1000,1000 are world co ordinates
- glutInitWindowSize (700, 700);
- glutInitWindowPosition (100, 100);
- glutCreateWindow ("A basic OpenGL Window");
- // registering callback functions
- glutDisplayFunc (display);
- glutReshapeFunc (reshape);
- glutMainLoop ();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement