Posts

Second Assignment DDA algorithm for line drawing using Mouse

Image
Draw the polygons by using the mouse. Choose colors by clicking on the designed color pane. Use window port to draw. (Use DDA algorithm for line drawing) #include<string.h> #include<GL/glut.h> #define ROUND(x)((int)(x+0.5)) struct Point { GLint x; GLint y; }; struct Color { GLfloat r; GLfloat g; GLfloat b; }; Color getPixelColor(GLint x, GLint y)  //Fun for getting color of pixel {  Color color; glReadPixels(x,y,1,1,GL_RGB, GL_FLOAT, &color); return color; } void setPixelColor(GLint x, GLint y, Color color)   //set color of pixel {    glColor3f(color.r, color.g, color.b); glBegin(GL_POINTS); glVertex2i(x,y); glEnd(); glFlush(); } void floodFill(GLint x, GLint y, Color oldColor, Color newColor)//seed fill algorithm { Color color; color= getPixelColor(x,y); if(color.r == oldColor.r && color.g == oldColor.g && color.b == oldColor.b) { setPixelColor(x,y, newColor); floodFill(x+1,y, oldColor, newColor); floodFill(x,y+1, oldCol...

C program for Bresenham algorithm for Circle

C program for Bresenham algorithm for Circle #include <stdio.h> //#include <math.h> #include <GL/gl.h> #include <GL/glu.h> #include <GL/glut.h> // Center of the cicle = (320, 240) int xc = 320, yc = 240; // Plot eight points using circle's symmetrical property void plot_point(int x, int y) {   glBegin(GL_POINTS);   glVertex2i(xc+x, yc+y);   glVertex2i(xc+x, yc-y);   glVertex2i(xc+y, yc+x);   glVertex2i(xc+y, yc-x);   glVertex2i(xc-x, yc-y);   glVertex2i(xc-y, yc-x);   glVertex2i(xc-x, yc+y);   glVertex2i(xc-y, yc+x);   glEnd(); } // Function to draw a circle using bresenham's // circle drawing algorithm void bresenham_circle(int r) {   int x=0,y=r;   float s=3-(2*r);   /* Plot the points */   /* Plot the first point */   plot_point(x,y);   int k;   /* Find all vertices till x=y */   while(x <= y)   {     //x = x + 1;     //s...

SPPU computer graphics Laboratory Syllabus

Image

Bresenham Line drawing C program with output

Image
Bresenham line drawing program   #include<stdio.h> #include<GL/glut.h> #define sign(x) ((x>0)?1:(x<0)?-1:0); void setPixel(GLint x, GLint y) {  glBegin(GL_POINTS); //The basic shapes are referred to as primitives.and glbegin is used to delimit these primitives   // GL_POINTS is an argument of glBegin which consider each vertex as a single points  glVertex2i(x,y);    /* Plot the first point *///it is use to specify vertex  glEnd(); } void init() {  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); //single buffer window  glutInitWindowPosition(0,0);  glutInitWindowSize(0,0);  glutCreateWindow("My Window");  glClearColor(0.0,0.0,0.0,0.0); /* Set clear color to black */  glColor3f(1.0,1.0,1.0);     /* Set fill color to white */ //used to specify color & 3f stand for float red , green, blue  gluOrtho2D(0,640,0,480);    //multiply the current matrix with an...

Bresenham Algorithm for line drawing

Image
 

DDA Algorithm

#include <stdio.h> #include <math.h> #include <GL/glut.h> //#include <GL/glu.h> //#include <GL/gl.h> double X1, Y1, X2, Y2; float round_value(float v) {   floor(v + 0.5);// This function is used to roundup the values   return v; } void LineDDA(void) {   double dx=(X2-X1);   double dy=(Y2-Y1);   double steps;   float xInc,yInc,x=X1,y=Y1;   /* Find out whether to increment x or y */   //steps=(abs(dx)>abs(dy))?(abs(dx)):(abs(dy));   if(abs(dx)>abs(dy))   steps=abs(dx);   else   steps=abs(dy);   xInc=dx/(float)steps;   yInc=dy/(float)steps;   /* Clears buffers to preset values */   glClear(GL_COLOR_BUFFER_BIT);//glClear is predefine function used to clear buffer and                   //GL_COLOR_BUFFER_BIT Indicates the buffers currently enabled for color writing.         ...

Installation steps for openGL on ubuntu

 GLUT it is open GL_U tility _T oolkit for openGL programming we need to install glut (pronounce as glat). Following are the steps to install GLUT on Ubuntu operating system. Step 1: sudo apt-get update               For updation of basic packages Step 2: sudo apt-get install build-essential               For installing essential packages. Step 3: sudo apt-get install freeglut3 freeglut3-dev               // its GL utility toolkit Step 4: sudo apt-get install binutils-gold             It is GNU gold linker utility.  Gold is a new linker, which is faster than the current linker included in binutils Step 5: sudo apt-get install g++ cmake         its a  Command-Line Reference.Users build a project b...