EasyGL Tutorial - OpenGL Commands

#include <iostream.h>
#include "easygl.h"

float alpha = 0.7;
float r=0.0, g=1.0, b=0.0;
int incs=1;          //If positive we will add, neg we sub... see Keyboard()

//-----------------------------------------------------------
void Keyboard(); //Function we will make to handel input
//-----------------------------------------------------------

//-----------------------------------------------------------
void EasyRender()
{
   clearGraph();

   //These commands are not part of EasyGL but OpenGL itself.
   //EasyGL sets the screen up as Ortho, which means that the z-axis
   //is ignored and no matter how far you zoom in or rotate the camera,
   //the object will alwasy appear 'on top' and 'in front' of the screen
   //In the next lesson we unset Ortho and begin 3D programming!

   //glBegin(); tells OpenGL that we are going to start drawing surfaces
   // GL_QUADS tells OpenGL that to link 4 points into a Quad / Square
   //glVertex2f(); Lets you set a point of the surface. Always set points
   // in a clockwise fashion! the '2f' in glVertex2f(); calls the vertext
   // function that only takes x and y. If you were to specigy depth on
   // the zaxis you would use glVertex3f();

   setOrtho();         //Call the EasyGL function to setup Ortho ourselves... //taking control :) feels good!

   glBegin(GL_TRIANGLES);       //GL_TRIANGLES will connect three points
   //Again this must be done in clock-wise fashion
   color(1.0, 0.0, 0.0, 1.0);
      glVertex2f(500.0, 200.0); //Top of Triangle
   color(r, g, b, 1.0);
      glVertex2f(900.0, 600.0); //Lower-Right of Triangle
   color(0.0, 0.0, 1.0, 1.0);
      glVertex2f(100.0, 600.0); //Lower-Left of Triangle

   glEnd(); //Stop making surfaces


   glBegin(GL_QUADS);       //The color for each point can be different
   //OpenGL will shade between the colors
   color(0.0, 0.2, 0.5, alpha);
      glVertex2f(10.0, 10.0);
   color(0.0, 0.5, 0.8, alpha);
      glVertex2f(500.0, 10.0);
   color(0.0, 0.5, 0.8, alpha);
      glVertex2f(500.0, 500.0);
   color(0.0, 0.2, 0.5, alpha);
      glVertex2f(10.0, 500.0);
    glEnd();


   Keyboard(); //Call Keyboard to check and act on input
  update();
}
//-----------------------------------------------------------

//-----------------------------------------------------------
void Keyboard()
{
   //Check to see if the key is down, and if so move the circle
   if(GetAsyncKeyState('A')) alpha-=0.05;          //Change transparency
   if(GetAsyncKeyState('D')) alpha+=0.05;

   if(GetAsyncKeyState('I')) incs = incs * -1;          //Changes if we are add/sub
   if(GetAsyncKeyState('R')) r+=0.05*incs;          //Increase/Decrease the
   if(GetAsyncKeyState('G')) g+=0.05*incs;          //Green of the one TRI Point
   if(GetAsyncKeyState('B')) b+=0.05*incs;

   //Keep the RGB values between 0.0 and 1.0
   if(r > 1.0) r = 1.0;
   else if(r < 0.0) r = 0.0;
   if(g > 1.0) g = 1.0;
   else if(g < 0.0) g = 0.0;
   if(b > 1.0) b = 1.0;
   else if(b < 0.0) b = 0.0;
}
//-----------------------------------------------------------

//-----------------------------------------------------------
int main()
{
   initEasyGL();
   return 1;
}
//-----------------------------------------------------------

 

 

All code, graphics and content
(C) Thomas A. McDonley 2003
Unless otherwise noted.