Computer Stars -- Lesson #2 --Color
Exercises (if you get stuck, e-mail firstname.lastname@example.org)
In the following exercises, double-click on adraw.txt to enter the Notepad editor. Modify the program to answer each exercise. then click the x to exit Notepad. Double-click mc.exe to start the application, then type .adraw to try out your answer. If you get a COMPILE ERROR, delete the error line and try again. If necessary, go back to the original adraw.txt and start afresh. You can also copy adraw.txt to bdraw.txt etc. Just type .bdraw to run the copy.
What library includes glClearColor?
Give the correct syntax (language format) for a glClearColor statement? opengl::glClearColor(0,0,1,1);
Set the window color to red. Note that if you make even a tiny mistake in syntax, you will get a message like <--COMPILE ERROR that indicates the approximate point of error. The appropriate action is to delete the offending statement (or statements) until no error occurs. Copy an example of a correct statement. Look at an on-line reference for the statement. OpenGL is extraordinarily well documented. Just type glClearColor in Google.
Set the window color to orange-red. Hint: convert the red/green/blue hexadecimal values from the table to decimal values. HintHint: If you select Start/All_Programs?Accessories/Calculator, then select View/Scientific. The result is an application that can be used to convert from hex to decimal. However, it would be much nicer if the programming language had support for the hexadecimal notation. Lucky you!! The 0x prefix indicates a hexadecimal constant, e.g. 0x5a == 90 etc. For example, the color crimson dc143c would be coded as glClearColor(0xdc/255, 0x14/255, 0x3c/255, 1.0).
Set the window color to fire-brick. Did you remember to divide each <red> <green> <blue> value by 255?
The glColor3f(<red>,<green>,<blue>) method sets the drawing color. It can be placed before or after a glBegin. Note that there are only 3 numbers, not 4 as with glClearColor.
What library includes this method?
Set the triangle color to green by typing a line prior to glBegin. opengl::glColor3f(0,1,0);
Try adding a fourth vertex method call after the first three. What is the result? A fifth vertex method? A sixth vertex method?
Try placing one glColor3f method call (each with a different color) prior to each of the three glVertex calls. In programming, engineering, science and mathematics, it is important to have a mental model of what you think will happen when testing the unknown. Such a guess is called a hypothesis. Each time you execute a program, you are performing an experiment that may prove, or disprove, your hypothesis. In the physical world, repetitions of the same experiment with the same conditions may produce different results. In the computer world, every effort is made to insure that improbable results are extremely rare.
Challenge Problem: E-mail me an mc program that draws an animal made from 9 triangles or less. The best entries will be posted here with your initials as credit. Creative coloring would be nice. Hint: draw on graph paper to plan your design.
Challenge Problem: E-mail me an mc program that draws the following
using the minimum number of triangles. The best entries will be
posted here with your initials as credit. Creative coloring would be nice.