Get me outta here!

Wednesday, February 16, 2022

Computer Graphics Basic (With Code)

 A pixel is one of the many tiny dots that make up the representation of a picture in a computer's memory.

Computer graphics can be created as either raster or vector images

1.      Raster Image - Pixel Based

2.      Vector Image - Mathematical Based

Raster image drawbacks –

·        Dpi(dots per inch)

·        Larger than vector in size

·        Less economical

Raster image advantages – User end friendly

Raster image formats – Tiff, Jpeg, Gif, Pcx, Bmp

Vector image drawbacks- Not suitable for complex graphic displays. Rasterization required for display.

Vector image advantages-

·        More malleable

·        More versatile

·        No upper or lower limit for sizing

Vector image formats- Ai, Eps, Cgm, Wmf, Pict(macOS)

Color Models- RGB and CMYK

Code

Color

W

White

R

Red

G

Green

B

Blue

C

Cyan

M

Magenta

Y

Yellow

K

Black

RGB – Additive Color

CMYK – Subtractive Color



C=G+B=W-R

M=R+B=W-G

Y=R+G=W-B

3 bit RGB = (21)3 = 8 ; [1 bit each color]

6 bit RGB = (22)3 = 64 ; [2 bit each color]

Color Code

RGB

B

001

G

010

R

110

C

011

*RGB intensity value 0 to 255
                          

Color Palette: Color palette is a finite set of colors. CMYK range is 0 to 100%.

Example:

Color

RGB

CMYK

White

255,255,255

0,0,0,0

 


(Code for understanding and comment for describe what are the works of fucntion)
#include<GL/gl.h>
#include<GL/glut.h>
void display(void)
{
    glClear (GL_COLOR_BUFFER_BIT); //clear the pixels of previous code
    glColor3f(1.0,1.0,1.0);
    glBegin(GL_TRIANGLES); //Beginning of drawing triangle
    //2d Shape
    glVertex3f(0.5f,0.7f,0.0f);
    glVertex3f(0.9f,0.75f,0.0f);
    glVertex3f(0.54f,0.73f,0.0f);
    glEnd(); //End of drawing triangle
    glFlush(); //force execution of GL commands in finite time


}
void init (void) //new function
{

    glClearColor(0.0,0.0,0.0,0.0); //Select clearing (Background) Color
    glMatrixMode(GL_PROJECTION); //The value we use, it will be initialized through this function
    glLoadIdentity(); //replaces the current matrix with the identity matrix
    glOrtho(0.0,1.0,0.0,1.0,-10.0,10.0); //size of x-y-z axis like graph paper

}
int main(int argc, char** argv) //argc stands for argument count and argv stands for argument values. These are variables passed to the main function when it starts executing
{
    glutInit(&argc, argv); //is used to initialize the GLUT library
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); //display modes: Single and RGB
    glutInitWindowSize(600,600); //windows size
    glutCreateWindow("Hello"); //title of windows
    init(); //call and commit the function
    glutDisplayFunc(display); //call the display function
    glutMainLoop(); //use for change shape by keyboard
    return 0;
}

 

 

 

 

 

 

0 comments:

Post a Comment