Posts

Showing posts from July, 2016

Objects using Line-Attribute, Fill-Area Attribute, Color functions of OpenGL

1. Load the libraries #include<GL/glut.h> #include<windows.h> 2. Create a display function where you will be drawing your shape and objects void display() { } 3. Give Screen color using ClearColor     glClearColor(0.0,0.1,0.0,0.0);     glClear(GL_COLOR_BUFFER_BIT); 4. Use factor and pattern to give some styles to your line. for more pattern click:  GL_Pattern     GLint factor=1;     GLushort pattern=0x0c0f; 5. Enable the Stipple     glEnable(GL_LINE_STIPPLE); // enabling the line pattern function     glLineStipple(factor,pattern); 6.Draw the shape     glColor3f(1.0,0.0,0.0);     glBegin(GL_LINES);     glVertex2f(0.0,0.0);     glVertex2f(1.0,0.0);     glEnd(); 7.disable the stipple then flush it.     glDisable(GL_LINE_STIPPLE);     glFlush(); 8. Main Function int main(int argc,char** argv) 9.  Iitialize the Arguments. glutInit(&argc,argv); 10. Create the window and define the size      glutCreateWindow("PROGRAM2"

Draw Circle in OpenGL

glColor3f(0.92,0.93,0.38); // (R,G,B) glBegin(GL_TRIANGLE_FAN); for(int ii = 0; ii < 300; ii++) { float cx = 35; //X coordinate float cy = 250; //y coordinate float r = 30.0; //radius float theta = 2.0f * 3.1415926f * float(ii) / float(300);//get the current angle float x = (r-45) * cosf(theta);//calculate the x component float y = r * sinf(theta);//calculate the y component glVertex2f(x + cx, y + cy);//output vertex } glEnd();

Stipple Pattern

Image

draw objects using OpenGL output primitive functions

1. Load the Libraries: #include<GL/glut.h> #include<windows.h> 2. Make a display function where you can draw your objects. void display() { } 3. Inside the display function give the color of your screen.     glClearColor(r,g,b);     glClear(GL_COLOR_BUFFER_BIT); where you are defining the intensity of the colors i.e the intensity of your Red, Green and Blue color. 4. Then draw you objects inside the display function. Eg:  For Line     glColor3f(r,g,b);     glBegin(GL_LINES);     glVertex2f(x,y);     glVertex2f(x,y);     glEnd(); for more click: output primitives 5. Render the Objects     glFlush();  then close the display function. 6. now comes the main function int main(int argc,char** argv) 7.  Iitialize the Arguments. glutInit(&argc,argv); 8. Create the window and define the size     glutCreateWindow("PROGRAM1");     glutInitWindowSize(320,320); 9. use the glutDisplayFunc() to display your object.     glu