1 / 23

Lab1 – Part III

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.

rollo
Télécharger la présentation

Lab1 – Part III

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lab1 – Part III CSE 581 Roger Crawfis

  2. 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.

  3. 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.

  4. 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 );

  5. 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);

  6. 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 ); …

  7. 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.

  8. 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.

  9. 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().

  10. 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).

  11. 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.

  12. LineWidth control • What is this difference? • Go back and look at how you declared each of these entities.

  13. 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.

  14. 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.

  15. 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.

  16. 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.

  17. Professional Touches • For the dialog’s, we should do two critical things: • Initialize the dialog’s settings. • Check to see if it returned properly (the user did not hit cancel).

  18. 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.

  19. 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. }

  20. 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.

  21. 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()

  22. 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.

  23. A Grader Panel • More on this later (or not).

More Related