lab1 – part iii

23
Lab1 – Part III CSE 581 Roger Crawfis

Upload: kaseem-watts

Post on 03-Jan-2016

44 views

Category:

Documents


2 download

DESCRIPTION

Lab1 – Part III. CSE 581 Roger Crawfis. To Do. We have the basic framework, but need to: Add the ability to open and read an image. Generate pseudo-random numbers. Add the remaining GUI elements Add the rendering algorithm to provide the impressionistic effect. Reading Images. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Lab1 – Part III

Lab1 – Part III

CSE 581

Roger Crawfis

Page 2: Lab1 – Part III

To Do

• We have the basic framework, but need to:

1. Add the ability to open and read an image.

2. Generate pseudo-random numbers.

3. Add the remaining GUI elements

4. Add the rendering algorithm to provide the impressionistic effect.

Page 3: Lab1 – Part III

Reading Images

• To read an image, we will use the DevIL library (http://openil.sourceforge.net/).

• Download the DevIL libraries from the links on the course web site.

Page 4: Lab1 – Part III

Set-up the DevIL library

• Add the reference for the Tao library:– Tao.DevIl– Initialize the library

//// Initialize the DevIL library//ilInit();ilOriginFunc( IL_ORIGIN_LOWER_LEFT );ilEnable( IL_ORIGIN_SET );

Page 5: Lab1 – Part III

Creating a Texture Map

• The Ilut library has an advanced feature that will automatically scale an image, build mip-maps (whatever those are), and then create the OpenGL texture maps.

• Once the ShowDialog for OpenFileDialog1 returns,– Ilut.ilutGLLoadImage(_fileName);

Page 6: Lab1 – Part III

Using the Texture

• We will go over texture mapping in more detail later in the class, for now, you simply need to turn it on (enable it) and set the texture coordinates for each vertex you draw.

• Initialization: glEnable(GL_TEXTURE_2D);

• Texture Coordinates – use the vertex positions:glTexCoord2d( x, y );

glVertex2d( x, y );

Page 7: Lab1 – Part III

Random Numbers

• Go back to the rendering method, DrawLines.

• Type in Random( and then examine the Intellisense (tooltips) listing of the possible constructor choices. Add a close paren and a semi-colon.

• Now, click or or move the insert caret over to the Random string and hit the F1 key.

Page 8: Lab1 – Part III

Getting Help in VS Studio

• The F1 key brings up context sensitive help (help that is cognizant or sensitive to the current insertion point or window).

• In this case, it should bring up the member methods of the .NET class Random. Browse thru these methods.

• At the bottom, click on the Random Class hyperlink.• Read thru the Remarks section.• Under Requirements, note the namespace that

Random is included in.

Page 9: Lab1 – Part III

Random

• What may not be obvious from the documentation is that the Random class does not represent a random number, but a random number generator.

• You will want to create an instance of Random and then call the NextDouble() method when you need a random number (or more precisely, the next number in the psuedo-random sequence of numbers).

• Go back to the help on Random and look at the description for NextDouble().

Page 10: Lab1 – Part III

2D Viewport Mapping

• Recall, that when we implemented the Resize event, we set-up a mapping that would go from zero to one in both the x and the y direction on the screen.

• Thus, the lower-left corner of our panel is at coordinate (0,0) and the upper-right corner is at (1,1).

Page 11: Lab1 – Part III

More GUI elements

• Add another TrackBar or NumericUpDown control for the line thickness or point size.

• Well, this should be the same process as when we added the number of lines GUI element right?

• Not quite. There is a fundamental difference between our data elements, and the GUI needs to either reflect this or take care of it.

Page 12: Lab1 – Part III

LineWidth control

• What is this difference?

• Go back and look at how you declared each of these entities.

Page 13: Lab1 – Part III

Handling Numeric types

• Number of primitives was an integer, and has a simpler representation and presentation to the user.

• The line thickness is a floating point value.• NumericUpDown control has a properties

for Number of Decimal places. This allows for a fixed point representation, which is good enough.

Page 14: Lab1 – Part III

Floating-point TrackBar

• Since the TrackBar does not display a value, you should really think of it as a percentage from min to max.

• You can use a TrackBar for the lineWidth by providing a mapping from the trackbar’s value to your min and max values.

• The NumericUpDown will work as is provided you set the properties to handle your fixed-point numbers.

Page 15: Lab1 – Part III

Color Selection

• Adding the color picker is very easy, provided you like the built in color dialog.

• Drag a ColorDialog control from the toolbox onto your form.

• Like the OpenFileDialog, this will create an instance, but the control will not be visible.

• One dialog will suffice for determining the two colors we need for the lab.

Page 16: Lab1 – Part III

Color Selection

• Add two more buttons to you GUI design and set their properties.

• Add the click event to each of these (double-click in the Form designer) and in the callback code, Show() the colorDialog and then set the button’s BackColor to the dialog’s Color value.

Page 17: Lab1 – Part III

Professional Touches

• For the dialog’s, we should do two critical things:

1. Initialize the dialog’s settings.

2. Check to see if it returned properly (the user did not hit cancel).

Page 18: Lab1 – Part III

Dialog Initialization

• For the colorDialog, we should probably set the initial color to the current color.

• If colorButton1 is clicked, set the value of Color in the dialog to the colorButton1.BackColor.

• For the OpenFileDialog, you could fill in a recent history, but this seems to be handled automatically, as well as remembering the last directory.

Page 19: Lab1 – Part III

Checking for OK vs. Cancel

• The dialog returns a value of type DialogResult. This needs to be checked for a value of OK, like this:if( colorDialog1->ShowDialog() == DialogResult::OK )

{

//Set the BackColor and update the document.

}

Page 20: Lab1 – Part III

Build and Run

• The button color should change appropriately.

• The basic GUI is finished!!!

• Now, add the logic to update the document and hence the rendering.

Page 21: Lab1 – Part III

Invalidate()

• If you move the number of lines trackBar, and update the document’s value for this, you may not notice any change in your rendering.

• Upon resize of bringing the window back and forward, it will update and change.

• We need to invalidate the view whenever we wish to see a change.

• This is done by calling:this. simpleOpenGlControl1.Invalidate()

Page 22: Lab1 – Part III

Adding the README

• For the README panel, just drag a Rich Text Box over to the panel and dock it to FILL.

• Copy and paste your Readme.txt file into here before you submit.

Page 23: Lab1 – Part III

A Grader Panel

• More on this later (or not).