axyd icon

Lab_14

axyd | PRO | 05/09/19 04:40:55 PM UTC | 0 ⭐ | 8182 👁️ | Never ⏰ | []
OpenGL Shading |

0 B

|

None

|

0 👍

/

0 👎

//CS334 - Lab 14, Group 5
 
 
#include <GL/gl.h>
#include <GL/glut.h>
#include <math.h>
#include <iostream>
using namespace std;
 
float segments= 360;
 
void drawEllipse() 
{ 
    glClear(GL_COLOR_BUFFER_BIT);   //flush gl
    
    float cx= 50.0f, cy= 50.0f, rx= 40.0f, ry= 30.0f; //, segments= 20.0f;
    
    float theta= 2 * 3.1415926 / segments; 
    float cos_t= cosf(theta);//precalculate the sine and cosine
    float sin_t= sinf(theta);
    float temp, x= 1, y= 0;
 
 
    glBegin(GL_LINE_LOOP); 
    for(int ctr = 0; ctr < segments; ++ctr) 
    { 
        //apply radius and offset
        glColor3f(1.0, 0.0, 0.0);   //red
        glVertex2f(x * rx + cx, y * ry + cy);//output vertex 
 
        //apply the rotation matrix
        temp = x;   //temp store
        x = cos_t * x - sin_t * y;        
        y = sin_t * temp + cos_t * y;
    } 
    glEnd(); 
    
    glFlush();
}
 
 
int main(int argc, char **argv) {   
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize(500, 500);
    glutInitWindowPosition(100, 100);
    glutCreateWindow("CS334 - lab14");
    
    glClearColor(0, 0, 0, 0);   //background
    glMatrixMode(GL_PROJECTION);
    gluOrtho2D(0, 100, -10, 100);
    
    glutDisplayFunc(drawEllipse);
    glutMainLoop();
    
    return EXIT_SUCCESS;
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎