Posts

OpenGL Texture

#include <GL/gl.h> #include <GL/glu.h> #include <GL/glut.h> #include <stdlib.h> #include <stdio.h> /*  Create checkerboard texture  */ #define checkImageWidth 64 #define checkImageHeight 64 static GLubyte checkImage[checkImageHeight][checkImageWidth][4]; static GLuint texName; GLfloat _angle=45; void makeCheckImage(void) {    int i, j, c;    for (i = 0; i < checkImageHeight; i++) {       for (j = 0; j < checkImageWidth; j++) {          //c = ((((i&0x8)==0)^((j&0x8))==0))*255; //checks         // c=((((i&0X15)==0)^((j&0x15))==0))*120;//border         //c=((((i&0X2)==0)^((j&0x2))==0))*200; //more checks          c=((((i&0x22)==0)^((j&0x22))==0))*200; //flag          checkImage[i][j][0] = (GLubyte) c;          checkImage[i][j][1] = (GLubyte) c;          checkImage[i][j][2] = (GLubyte) c;          checkImage[i][j][3] = (GLubyte) 200;       }    } } void init(void) {    glClearColor (0.0, 0.

GL_PATTERNS

CHECKS: GLubyte checks[] = { 0xC3, 0xC3, 0xC3, 0xC3,/* 11….11 11….11 11….11 11….11*/ 0xC3, 0xC3, 0xC3, 0xC3,/* 11….11 11….11 11….11 11….11*/ 0xC3, 0xC3, 0xC3, 0xC3,/* 11….11 11….11 11….11 11….11*/ 0xC3, 0xC3, 0xC3, 0xC3,/* 11….11 11….11 11….11 11….11*/ 0x3C, 0x3C, 0x3C, 0x3C,/* ..1111.. ..1111.. ..1111.. ..1111..*/ 0x3C, 0x3C, 0x3C, 0x3C,/* ..1111.. ..1111.. ..1111.. ..1111..*/ 0x3C, 0x3C, 0x3C, 0x3C,/* ..1111.. ..1111.. ..1111.. ..1111..*/ 0x3C, 0x3C, 0x3C, 0x3C,/* ..1111.. ..1111.. ..1111.. ..1111..*/ 0xC3, 0xC3, 0xC3, 0xC3,/* 11….11 11….11 11….11 11….11*/ 0xC3, 0xC3, 0xC3, 0xC3,/* 11….11 11….11 11….11 11….11*/ 0xC3, 0xC3, 0xC3, 0xC3,/* 11….11 11….11 11….11 11….11*/ 0xC3, 0xC3, 0xC3, 0xC3,/* 11….11 11….11 11….11 11….11*/ 0x3C, 0x3C, 0x3C, 0x3C,/* ..1111.. ..1111.. ..1111.. ..1111..*/ 0x3C, 0x3C, 0x3C, 0x3C,/* ..1111.. ..1111.. ..1111.. ..1111..*/ 0x3C, 0x3C, 0x3C, 0x3C,/* ..1111.. ..1111.. ..1111.. ..1111..*/ 0x3C, 0x3C, 0x3C, 0x3C,/* ..1111.. ..1111.. ..1111.. ..1111..*/ 0xC3, 0

OUTPUT PRIMITIVES

Basic structure glBegin (mode); glVertex* (…); //Triangle=3Vertex, Quads=4Vertex etc glVertex* (…); glEnd (); POINTS: one vertex glBegin(GL_POINTS); glVertex2f(x1, y1); glEnd(); LINES:two vertex(starting and ending point) glBegin(GL_LINES); glVertex2f(x1, y1); glVertex2f(x2, y2); glEnd(); LINE STRIP glBegin(GL_LINE_STRIP); glVertex2f(x1, y1); glVertex2f(x2, y2); glVertex2f(x3, y3); glEnd(); LINE LOOP glBegin(GL_LINE_LOOP); glVertex2f(x1, y1); glVertex2f(x2, y2); glVertex2f(x3, y3); glEnd(); TRIANGLES: cconcist of 3 vertex glBegin(GL_TRIANGLES); glVertex2f(x1, y1); glVertex2f(x2, y2); glVertex2f(x3, y3); glEnd(); TRIANGLE STRIP glBegin(GL_TRIANGLE_STRIP); glVertex2f(x1, y1); glVertex2f(x2, y2); glVertex2f(x3, y3); glVertex2f(x4, y4); glEnd(); TRIANGLE FAN glBegin(GL_TRIANGLE_FAN); glVertex2f(x1, y1); glVertex2f(x2, y2); glVertex2f(x3, y3); glVertex2f(x4, y4); glEnd();

OPENGL COLOR CODES

for Background color: glClearColor(float red, float green, float blue, float alpha) glClearColor(0.0,0.0,1.0,0.0);//dark blue fill color: glColor4f(1.0f, 0.0f, 0.0f, 0.0f);//red glColor4f(1.0f, 1.0f, 1.0f, 0.0f);//white glColor4f(1.0f, 1.0f, 0.0f, 0.0f);//yellow glColor4f(1.0f, 0.0f, 1.0f, 0.0f);//purple glColor4f(0.0f, 1.0f, 1.0f, 1.0f);//light blue glColor4f(1.0f, 0.5f, 0.0f, 0.0f);//orange/brown glColor3f(0.0f, 1.0f, 0.0f);//Green glColor3f(0.0f, 0.0f, 1.0f);//Blue glColor3f(0.5f, 1.0f, 1.0f);//cyan glColor3f(0.0f, 0.0f, 0.0f);//Black glColor3f(1.0f, 0.0f, 1.0f);//Purple glColor3f(1.0f, 0.5f, 0.0f);//Orange glColor3f(0.5f, 0.5f, 0.5f);//Violet glColor3f(0.0f, 0.5f, 0.5f);//Blue-Green glColor3f(0.0f, 0.5f, 1.0f);//baby Blue glColor3f(2.0f, 0.5f, 1.0f);//Lilac glColor3f(0.1f, 0.1f, 0.1f);//Dark grey glColor3f(0.1f, 0.0f, 0.1f);//Dark Purple glColor3f(0.1f, 0.1f, 0.0f);//Bronze glColor3f(0.0f, 0.1f, 0.1f);//Dark blue glColor3f(0.0f, 0

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