#include <stdlib.h>
#include <GL/glut.h>
void Myinit (void)
{
Glclearcolor (0.2,0.8,0.8,0.0)//Set Background to Lake Blue
Glenable (gl_blend);//Activate Gl_blend
Glblendfunc (Gl_src_alpha,gl_one_minus_src_alpha);//The mathematical algorithm for specifying pixels
Glenable (Gl_flat);
}
void Mydisplay (void)
{
Glclear (Gl_color_buffer_bit);
/* Draw a green rectangle alpha = 1.0*/
glcolor4f (0.0,1.0,0.0,1.0);
Glbegin (Gl_polygon);
glvertex3f ( -0.75,0.5,0.0);
glvertex3f ( -0.75,-0.75,0.0);
glvertex3f (0.5,-0.75,0.0);
glvertex3f (0.5,0.5,0.0);
Glend ();
/* Draw a red rectangle alpha = 0.5*/
glcolor4f (1.0,0.0,0.0,0.5);
Glbegin (Gl_polygon);
glvertex3f ( -0.25,1.0,0.0);
glvertex3f ( -0.25,-0.25,0.0);
glvertex3f (1.0,-0.25,0.0);
glvertex3f (1.0,1.0,0.0);
Glend ();
/* Draw a blue rectangle alpha = 0.5*/
glcolor4f (0.0,0.0,1.0,0.5);
Glbegin (Gl_polygon);
glvertex3f (0.25,1.5,0.0);
glvertex3f (0.25,0.25,0.0);
glvertex3f (1.5,0.25,0.0);
glvertex3f (1.5,1.5,0.0);
Glend ();
Glflush ();
}
void Myreshape (int w,int h)
{
Glviewport (0,0,W,H);
Glmatrixmode (gl_projection);
Glloadidentity ();
if (w
Glortho ( -1.5,1.5,-1.5* (glfloat) h/(glfloat) w,1.5* glfloat (h/) glfloat);
Else
Glortho ( -1.5* (glfloat) w/(glfloat) h,1.5* glfloat (w/) glfloat);
Glmatrixmode (Gl_modelview);
Glloadidentity ();
Gltranslatef ( -0.4,0.0,0.0);
}
int main (int argc,char * * argv)
{
/* Initialize * *
Glutinit (&ARGC,ARGV);
Glutinitdisplaymode (glut_single| GLUT_RGB);
Glutinitwindowsize (300,400);
Glutinitwindowposition (200,200);
/* Create window * *
Glutcreatewindow ("BLEND POLYGON");
/* Draw and display * *
Myinit ();
Glutreshapefunc (Myreshape);
Glutdisplayfunc (Mydisplay);
/* Enter GLUT event handling cycle * *
Glutmainloop ();
return (0);
} |