Skip to content

Instantly share code, notes, and snippets.

@SohanChy
Last active February 11, 2018 10:26
Show Gist options
  • Save SohanChy/392a77902e664a8a4eae850c26192cf0 to your computer and use it in GitHub Desktop.
Save SohanChy/392a77902e664a8a4eae850c26192cf0 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include<GL/gl.h>
#include <GL/glut.h>
void myDisplay(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3ub(0, 0, 0);
glPointSize(4.0);
glBegin(GL_POLYGON);
glVertex2i(200, 450);
glVertex2i(50, 350);
glVertex2i(50, 150);
glVertex2i(200, 50);
glVertex2i(400, 50);
glVertex2i(550, 150);
glVertex2i(550, 350);
glVertex2i(400, 450);
glEnd();
glColor3ub(249, 236, 49);
glBegin(GL_POLYGON);
glVertex2i(210, 440);
glVertex2i(60, 350);
glVertex2i(60, 150);
glVertex2i(210, 60);
glVertex2i(390, 60);
glVertex2i(540, 150);
glVertex2i(540, 350);
glVertex2i(390, 440);
glEnd();
glColor3ub(0, 0, 0);
glBegin(GL_POLYGON);
glVertex2i(380, 70);
glVertex2i(530, 150);
glVertex2i(530, 350);
glVertex2i(380, 430);
glEnd();
glColor3ub(0, 0, 0);
glBegin(GL_POLYGON);
glVertex2i(220, 430);
glVertex2i(70, 350);
glVertex2i(70, 150);
glVertex2i(220, 70);
glEnd();
glColor3ub(0, 0, 0);
glBegin(GL_POLYGON);
glVertex2i(70, 350);
glVertex2i(70, 150);
glVertex2i(530, 150);
glVertex2i(530, 350);
glEnd();
glBegin(GL_POLYGON);
glVertex2i(250, 400);
glVertex2i(250, 80);
glVertex2i(350, 80);
glVertex2i(350, 400);
glEnd();
glBegin(GL_POLYGON);
glVertex2i(280, 420);
glVertex2i(280, 70);
glVertex2i(330, 70);
glVertex2i(330, 420);
glVertex2i(305, 430);
glEnd();
glFlush ();
}
void myInit (void)
{
glClearColor(1, 1, 1, 0.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluOrtho2D(0.0, 640.0, 0.0, 480.0);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (640, 480);
glutInitWindowPosition (200, 150);
glutCreateWindow ("Hello World");
glutDisplayFunc(myDisplay);
myInit ();
glutMainLoop();
}
#include <stdio.h>
#include<GL/gl.h>
#include <GL/glut.h>
void myDisplay(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glPointSize(1.0);
int counter = 0;
for(int i = 0; i < 800; i = i +100){
for(int j = 0; j< 800; j = j +100){
if(counter % 2 == 0){
glColor3ub(127,140,141);
}
else {
glColor3ub(236,240,241);
}
glBegin(GL_QUADS);
glVertex2i(i,j);
glVertex2i(i+100,j);
glVertex2i(i+100,j+100);
glVertex2i(i,j+100);
glEnd();
counter++;
}
counter++;
}
glFlush ();
}
void myInit (void)
{
glClearColor(1.0, 1.0, 1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluOrtho2D(0.0, 800.0, 0.0,800.0);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (800,800);
glutInitWindowPosition (0, 0);
glutCreateWindow ("1");
glutDisplayFunc(myDisplay);
myInit ();
glutMainLoop();
}
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include<GL/gl.h>
#include <GL/glut.h>
void dda(void){
glClear (GL_COLOR_BUFFER_BIT);
int x1 = 50;
int y1 = 50;
int x2 = 400;
int y2 = 400;
float len = abs(x2 - x1);
if(abs(y2 - y1) > len){
len = abs(y2 - y1);
}
std::cout<<len;
float xinc = (x2 - x1)/len;
float yinc = (y2 - y1)/len;
float x = (float)x1 + 0.5;
float y = (float)y1 + 0.5;
glColor3ub(0, 0, 0);
glPointSize(4.0);
while(x < len){
glBegin(GL_POINTS);
glVertex2i((int) x, (int) y);
glEnd();
x = x + xinc;
y = y + yinc;
}
glFlush ();
}
void bresen(void){
glClear (GL_COLOR_BUFFER_BIT);
int x1 = 50;
int y1 = 50;
int x2 = 400;
int y2 = 400;
float len = abs(x2 - x1);
if(abs(y2 - y1) > len){
len = abs(y2 - y1);
}
std::cout<<len;
float xinc = (x2 - x1)/len;
float yinc = (y2 - y1)/len;
float x = (float)x1 + 0.5;
float y = (float)y1 + 0.5;
glColor3ub(0, 0, 0);
glPointSize(4.0);
while(x < len){
glBegin(GL_POINTS);
glVertex2i((int) x, (int) y);
glEnd();
x = x + xinc;
y = y + yinc;
}
glFlush ();
}
void myInit (void)
{
glClearColor(1, 1, 1, 0.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluOrtho2D(0.0, 640.0, 0.0, 480.0);
}
int main(int argc, char** argv)
{
std::cout<<"Enter Choice:"<<std::endl;
std::cout<<"1 DDA"<<std::endl;
std::cout<<"2 Bresenham"<<std::endl;
std::cout<<"3 Exit"<<std::endl;
// bresen();
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (640, 480);
glutInitWindowPosition (200, 150);
glutCreateWindow ("Hello World");
//glutDisplayFunc(dda);
glutDisplayFunc(bresen);
myInit ();
glutMainLoop();
}
#include <stdio.h>
#include<GL/gl.h>
#include <GL/glut.h>
void myDisplay(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3ub (84,84,68);
glPointSize(4.0);
glBegin(GL_POLYGON);
glVertex2i(80, 205);
glVertex2i(120, 155);
glVertex2i(200, 155);
glVertex2i(240, 205);
glEnd();
glColor3ub(96, 125, 139);
//glColor3ub(25,0,25);
glPointSize(2.0);
glBegin(GL_POLYGON);
glVertex2i(200, 205);
glVertex2i(200, 255);
glVertex2i(190, 255);
glVertex2i(190, 205);
glEnd();
glBegin(GL_POLYGON);
glVertex2i(130, 205);
glVertex2i(130, 255);
glVertex2i(120, 255);
glVertex2i(120, 205);
glEnd();
glBegin(GL_POLYGON);
glVertex2i(160, 205);
glVertex2i(160, 255);
glVertex2i(150, 255);
glVertex2i(150, 205);
glEnd();
glColor3ub (156,189,239);
glBegin(GL_POLYGON);
glVertex2i(0, 170);
glVertex2i(0, 0);
glVertex2i(640, 0);
glVertex2i(640, 170);
glEnd();
glColor3ub (255,0,0);
glPointSize(15.0);
glBegin(GL_POINT);
glVertex2i(300, 300);
glEnd();
glColor3ub(66, 66, 66);
glPointSize(2.0);
glBegin(GL_POLYGON);
glVertex2i(200, 265);
glVertex2i(200, 270);
glVertex2i(205, 270);
glVertex2i(205, 265);
glEnd();
glBegin(GL_POLYGON);
glVertex2i(220, 265);
glVertex2i(220, 270);
glVertex2i(210, 270);
glVertex2i(210, 265);
glEnd();
glBegin(GL_POLYGON);
glVertex2i(220, 285);
glVertex2i(220, 280);
glVertex2i(210, 280);
glVertex2i(210, 285);
glEnd();
glFlush ();
}
void myInit (void)
{
glClearColor(1, 1, 1, 0.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluOrtho2D(0.0, 640.0, 0.0, 480.0);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (640, 480);
glutInitWindowPosition (200, 150);
glutCreateWindow ("Hello World");
glutDisplayFunc(myDisplay);
myInit ();
glutMainLoop();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment