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_TRIANGLES);
- glColor3f(1, .0, 0);
- glVertex3f(0, 0, 0);
- glVertex3f(1, 0, 0);
- glVertex3f(0.5, 1, 0);
- glBegin(GL_TRIANGLES);
- glColor3f(.5, .0, .1);
- glVertex3f(0.500, 0.0, 0);
- glVertex3f(0.250, .500, 0);
- glVertex3f(0.750, 0.500, 0);
- glBegin(GL_TRIANGLES);
- glColor3f(1.0, 1.0, 1.0);
- glVertex3f(0.750, 0.0, 0);
- glVertex3f(0.625, .250, 0);
- glVertex3f(0.875, 0.250, 0);
- glBegin(GL_TRIANGLES);
- glColor3f(1.0, 1.0, 1.0);
- glVertex3f(0.250, 0.0, 0);
- glVertex3f(0.125, .250, 0);
- glVertex3f(0.375, 0.250, 0);
- glBegin(GL_TRIANGLES);
- glColor3f(1.0, 1.0, 1.0);
- glVertex3f(0.500, 0.500, 0);
- glVertex3f(0.375, .750, 0);
- glVertex3f(0.625, 0.750, 0);
- glBegin(GL_TRIANGLES);
- glColor3f(0.3, 1, 0.0);
- glVertex3f(0.875, 0.0, 0);
- glVertex3f(0.815, .125, 0);
- glVertex3f(0.935, 0.125, 0);
- glBegin(GL_TRIANGLES);
- glColor3f(0.3, 1, 0.0);
- glVertex3f(0.625, 0.0, 0);
- glVertex3f(0.563, .125, 0);
- glVertex3f(0.688, 0.125, 0);
- glBegin(GL_TRIANGLES);
- glColor3f(0.3, 1, 0.0);
- glVertex3f(0.625, 0.0, 0);
- glVertex3f(0.563, .125, 0);
- glVertex3f(0.688, 0.125, 0);
- glBegin(GL_TRIANGLES);
- glColor3f(0.3, 1, 0.0);
- glVertex3f(0.750, 0.250, 0);
- glVertex3f(0.688, .375, 0);
- glVertex3f(0.813, 0.375, 0);
- glBegin(GL_TRIANGLES);
- glColor3f(0.3, 1, 0.0);
- glVertex3f(0.250, 0.250, 0);
- glVertex3f(0.188, .375, 0);
- glVertex3f(0.313, 0.375, 0);
- glBegin(GL_TRIANGLES);
- glColor3f(0.3, 1, 0.0);
- glVertex3f(0.125, 0.0, 0);
- glVertex3f(0.063, .125, 0);
- glVertex3f(0.188, 0.125, 0);
- glBegin(GL_TRIANGLES);
- glColor3f(0.3, 1, 0.0);
- glVertex3f(0.375, 0.0, 0);
- glVertex3f(0.313, .125, 0);
- glVertex3f(0.438, 0.125, 0);
- glBegin(GL_TRIANGLES);
- glColor3f(0.3, 1, 0.0);
- glVertex3f(0.375, 0.0, 0);
- glVertex3f(0.313, .125, 0);
- glVertex3f(0.438, 0.125, 0);
- glBegin(GL_TRIANGLES);
- glColor3f(0.3, 1, 0.0);
- glVertex3f(0.375, 0.500, 0);
- glVertex3f(0.313, .625, 0);
- glVertex3f(0.438, 0.625, 0);
- glBegin(GL_TRIANGLES);
- glColor3f(0.3, 1, 0.0);
- glVertex3f(0.625, 0.500, 0);
- glVertex3f(0.563, .625, 0);
- glVertex3f(0.688, 0.625, 0);
- glBegin(GL_TRIANGLES);
- glColor3f(0.3, 1, 0.0);
- glVertex3f(0.500, 0.750, 0);
- glVertex3f(0.438, .875, 0);
- glVertex3f(0.563, 0.875, 0);
- //int a=6; int b=6; int c=6;
- //glBegin(GL_TRIANGLES);
- // glColor3f(a/4, a/6, a/4);
- // glVertex3f(-0.6,-0.75,0);
- // glVertex3f(0,0.75,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