Skip to content

Instantly share code, notes, and snippets.

@zeerorg
Last active September 13, 2017 14:18
Show Gist options
  • Save zeerorg/20eb29f023eaef6f5464542b267352a9 to your computer and use it in GitHub Desktop.
Save zeerorg/20eb29f023eaef6f5464542b267352a9 to your computer and use it in GitHub Desktop.
CG File

Practical 1

Aim

To write a program which draws line using the provided function.

Description of aim and related theory

Communicating with graphics hardware and display is a daunting task. To tackle this operating systems provide graphics library which have a simple API which provide different functions for common tasks (like drawing pixel, line, triangles etc.).
In this practical we are using a standard graphics api (graphics.h or opengl) to understand how a graphics library works and helps us in writing graphics programs.

Algorithm

  1. initialize_display()
  2. draw_line(100, 100)
  3. wait_for_exit()

Code

#include <stdio.h>
#include <math.h>
#include <GL/glut.h>

int ac;
char **av;
int DETECT = 5;


void disp() {
  
  glClear(GL_COLOR_BUFFER_BIT);

  glBegin(GL_LINES);
    glVertex2i(100, 100);
    glVertex2i(200, 200);
  glEnd();

  glFlush();
}
void Init() {
  glClearColor(1.0,1.0,1.0,0);
  glColor3f(0.0,0.0,0.0);
  gluOrtho2D(0 , 640 , 0 , 480);
}

void intgraph(int *gd, int *gm, char *s) {
  glutInit(&ac,av);
  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  glutInitWindowPosition(0,0);
  glutInitWindowSize(640,480);
  glutCreateWindow("Line");
  Init();
}

void line(int x1, int y1, int x2, int y2) {
    glutDisplayFunc(disp);
}

int main(int argc, char **argv) {
  ac = argc;
  av = argv;
  int gd = DETECT, gm = 0 ;
  intgraph(&gd, &gm, "C:\\TC\\BGI");
  line(100, 100, 200, 200);
  glutMainLoop();
  return 0;
}

Output

Practical 1 Output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment