Skip to main content

Posts

Showing posts with the label OpenGL

3D to 2D object Transform source code in c++ with OpenGL

Here is the implementation of 3d to 2d conversion algorithm in c. INPUT:   OUTPUT: SOURCE CODE : #include <windows.h> #include <GL/glut.h> #include <stdlib.h> #include <stdio.h> #include <iostream> #include <math.h> using namespace std; int x,y,z,sx[100],sy[100],sz[100],ex,ey,ez; void drawLine(int x1, int y1,int x2,int y2) {     glBegin(GL_LINES);     glVertex2i(x1,y1);     glVertex2i(x2,y2);     glEnd(); } static void display(void) {     int i,dis,xx[100],yy[100],px,py;     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);     glColor3d(0,255,255);    /* drawLine(100,200,200,100);     drawLine(200,100,300,200);     drawLine(300,200,200,300);     drawLine(100,200,200,300);*/     //glReadPixels(20...

Object Transformation source code in c++ with Glut/opengl

In this algorithm one rectangle has been transformed 30-degree angle and it also move from the current object by x 100 and y 100. Here the white rectangle is input and red one is output.         INPUT:             OUTPUT:       #include <windows.h> #include <GL/glut.h> #include <stdlib.h> #include <iostream> #include <string> #include <string> #include <ctype.h> #include <math.h> #include <stdio.h> #include <map> #include <vector> using namespace std; int trans_x,trans_y; #define pi 2.0*acos(0) long x_min,x_max,y_min,y_max; vector <int>x_cor; vector <int>y_cor; long draw_line(long x_start , long y_start , long x_end, long y_end) {     glBegin(GL_LINES);     glVertex2f(x_start,y_start); //start points     glVertex2f(x_end,y_end); // end...

Line Clipping or Liang Bersky Algorithm source code in c++ with openGL

#include <windows.h> #include <GL/glut.h> #include <stdlib.h> #include <iostream> #include <string> #include <string> #include <ctype.h> #include <math.h> #include <stdio.h> #include <map> #include <vector> double xmin=50,ymin=50,xmax=100,ymax=100; double xvmin=150,yvmin=150,xvmax=400,yvmax=400; double x2,y2,x3,y3; int test(double p,double q,double *t1,double *t2) {     double t=q/p;     if(p<0.0)     {         if(t> *t1) *t1=t;         if(t> *t2) return(false);     }     else if(p>0.0)     {         if(t< *t2) *t2=t;         if(t< *t1) return(false);     }     else if(p==0.0)     {    ...