EasyGL Tutorial - Introduction


Introduction:
----------------
EasyGL is a frontend to OpenGL, this means that it acts as a middleman making the whole OpenGL process much easier (hence the name). EasyGL takes care of all the 'hard' aspects of OpenGL and leaves everything else to the programmer without taking away any of the abilities of OpenGL! This means that you can use EasyGL and use true OpenGL programming at the same time.

Note: if you have a compiler different than VC++ (Ex/ CodeWarrior or Borland) and can not get EasyGL to work Email me and I will help you get it all sorted out.

To run the programs included with these tutorials you will have to make a new Project in VC++. Make sure to specify a Win32 Console application with no files. Next add the LesssonX.cpp file to the project. That's it.

Basic Program: This is the most basic EasyGL program you can write.
#include <iostream.h>
#include "easygl.h"

void EasyRender()
{
   clearGraph();
   update();
}

int main()
{
   initEasyGL();
   return 0;
}


Explanation:
----------------
#include "easygl.h" tells the compiler where to find all of EasyGL's functions and the "" rather than <> tell the compiler that it was made and did not come with the compiler.

void initEasyGL() is a function that uses Win32 API calls to set up the Window
and hardware contexts, and then setup OpenGL to a basic starting point that
most programs/games use.

void EasyRender() is a function that EasyGL calls (it must have this exact
name!) when it is looking for something to render. This function is called
right after you call initEasyGL()! After that it is called everytime it exits
(Think of it that EasyRender() draws one 'frame' exits, and then is called to
draw the next frame).

void clearGraph() is simply a function that clears the screen to black by
defualt or a different color if specified.

void update() swaps the screen buffer with the actuall screen or frame that we
see. This is called dubble buffering and solves the problem most Qbasic users
had when making games with the screen flashing. This was because you are
drawing/erasing the screen while the user watches and, however fast, they see
it. So instead you draw to a frame offscreen and when its done you swap it
(using update()) with the one currently being displayed.


The Fun Stuff!:
----------------------
void color(float Red, float Green, float Blue, float Alpha) sets the defualt
color to draw in. Like most EasyGL functions it takes 4 parameters that
determine the color. The range of each parameter is from 0.0 to 1.0 (0 being
no color, 1 being all of that color and anything inbetween is a shade). The
last parameter 'Alpha' is how opaque the color is or rather if it is see
through or not (0 being completly see through, 1 being completly opaque)!

EX/ color(1.0, 1.0, 0.0, 1.0); //Default color yellow and 100% opaque.
...
color(1.0, 0.0, 1.0, 0.5); //Default color magenta and half transpar

void print(int x, int y, char[] string, float Red, float Green, float Blue,
float Alpha) draws defualt text at pos x,y. The x range is from 0 to screen
width, the y range is from 0 to screen height. Note that 0,0 starts at the
top left hand corner of the screen (this can be changed but most graphics
programs will do it this way!). The next four parameters are the color
parameters. You can specify an override to the default draw color (see color
() function above) which will only effect this only object, if nothing is
given and only the first three parameters are passed the defualt color is
used!

EX/ color(0.0, 0.0, 1.0, 1.0); //Blue and 100% opaque
...
print(100, 100, "Hello World", 1.0, 1.0, 1.0, 1.0); //White

print(200, 250, "Hello Blue"); //Prints 'Hello Blue' in blue

void line(int x1, int y1, int x2, int y2, float Red, float Green, float Blue,
float Alpha) draws a line from point x1,y1 to point x2,y2. See the color()
and print() functions to learn more about the last four optional parameters!

void square(int x1, int y1, int x2, int y2, float Red, float Green, float Blue,
float Alpha) draws a filled in square with a upper-left hand corner at x1,y1
and the bottom-right hand corner at x2,y2. See the color() and print()
functions to learn more about the last four optional parameters!

void ngon(int x, int y, int sides, int r) draws a ngon with a center at x,y and
a radius of r. The number of sides is given by the sides value. For instance
you can make a square, a hexagon, a octagon or a 100agon :p. See the color()
and print() functions to learn more about the last four optional parameters
(not shown in the description above)!

void circle(int x, int y, int r) draws a circle with a center at x,y and a
radius of r. See the color() and print() functions to learn more about the
last four optional parameters (not shown in the description above)!


Extended information (optional):
----------------------------------
Color is not Red-Yellow-Blue, but the colors of light Red-Blue-Green. In such, Blue and Red do not make purple, they make magenta! Red and Green don't make brown they make yellow! Remember this!

Any initilazation for the program should be done in main() before you call initEasyGL(), because from the point the only function that is run is EasyRender(). Also, you can do other things in EasyRender() besides graphics, like ask the user for input using scanf() or cin (this right now is done from a separate console). You may also cout or printf like normal to the console and read it by Alt-Tab to the console screen.

If you would like to get rid of the console then add this as the first line to your program code exactly:
#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" )

This will prevent the console from loading. However, I find it nice when debugging as you can 'cerr <<' values out and look at them after you close the graphics window.


What later Tutorials will cover:
---------------------------------
-Keyboard input
-Animation
-Using real OpenGL commands (don't worry :p) to draw simple objects in 3D!
-Shading


If you have any comments about what you think should be changed or added sooner please email me at DarkEyes_z@hotmail.com

 

 

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