OpenGL and Windows Windows Forms Programming Roger Crawfis.

Slides:



Advertisements
Similar presentations
OpenGL and Windows Windows Forms Programming Roger Crawfis.
Advertisements

Working with Tables for Page Design – Lesson 41 Working with Tables for Page Design Lesson 4.
CS0004: Introduction to Programming Visual Studio 2010 and Controls.
Chapter 1: An Introduction to Visual Basic 2012
Presented by: Benefits Systems Support. Getting Started ê Open Powerpoint, create a blank presentation. ê Select a style for your first slide from the.
Understanding Microsoft Excel
COMPREHENSIVE Windows Tutorial 3 Personalizing Your Windows Environment.
Advanced Microsoft Word Hosted by Jared Hoffman Topics Keyboard Shortcuts Customizing Toolbars and Menus Auto Format & Auto Correct Tabs Inserting Pictures.
© by Pearson Education, Inc. All Rights Reserved. continued …
 2006 Pearson Education, Inc. All rights reserved Introduction to the Visual C# 2005 Express Edition IDE.
Programming Based on Events
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
1 Introduction to the Visual Studio.NET IDE Powerpoint slides modified from Deitel & Deitel.
Fundamentals of Programming in Visual Basic 3.1 Visual basic Objects Visual Basic programs display a Windows style screen (called a form) with boxes into.
Review of last session The Weebly Dashboard The Weebly Dashboard Controls your account and your sites Controls your account and your sites From here you.
Spreadsheet. Objectives Create a new blank workbook. Create a new blank workbook. Identify user interface elements that you can use to accomplish basic.
WorkPad 4 Quick Start WorkPad 4 Quick Start  Business Optix brings the rigor and discipline of business modelling and design into.
2. Introduction to the Visual Studio.NET IDE 2. Introduction to the Visual Studio.NET IDE Ch2 – Deitel’s Book.
InDesign CS3 Lessons 1 and 2. Work Area When First Opened.
Chapter 3 Working with Symbols and Interactivity.
Tutorial: Introduction to ASP.NET Internet Technologies and Web Application 4 th February 2010.
Tutorial 6 Using Form Tools and Creating Custom Forms
05/09/ Introducing Visual Basic Sequence Programming.
Hello World In C++ and Microsoft Visual C++. Directions to begin a project 1. Go to All Programs 2. Open Visual Studio C++ 3. Click on New Project 4.
XP New Perspectives on Microsoft Access 2002 Tutorial 51 Microsoft Access 2002 Tutorial 5 – Enhancing a Table’s Design, and Creating Advanced Queries and.
Windows Forms Programming in C# Windows Forms CSE 494R (proposed course for 459 Programming in C#) Prof. Roger Crawfis.
© Ms. Masihi.  The Dreamweaver Welcome Screen first opens when you start Dreamweaver.  This screen gives you quick access to previously opened files,
PowerPoint. Basic Vocabulary Slide - Presentation - Slide layout – ► ► ► ► a single page in PowerPoint all the slides for a speech all the slides for.
XP New Perspectives on Microsoft Office FrontPage 2003 Tutorial 4 1 Microsoft Office FrontPage 2003 Tutorial 4 – Using Shared Borders and Themes.
IE 411/511: Visual Programming for Industrial Applications
Chapter 12: Using Controls. Examining the IDE’s Automatically Generated Code A new Windows Forms project has been started and given the name FormWithALabelAndAButton.
Lab1 – Part III CSE 581 Roger Crawfis. To Do We have the basic framework, but need to: 1.Add the ability to open and read an image. 2.Generate pseudo-random.
CARLSON SOFTWARE CONFERENCE DANIEL V. SYPERSMA VICTOR GRAPHICS.
© 2011 Delmar, Cengage Learning Chapter 3 Working with Symbols and Interactivity.
Project 2 Adding Web Pages, Links, and Images Dreamweaver MX 2004 Concepts and Techniques.
Lab1 – Part III CSE 581 Roger Crawfis. To Do We have the basic framework, but need to: 1.Add the ability to open and read an image. 2.Generate pseudo-random.
Chapter 9 - VB.Net by Schneider1 Chapter 9 – Additional Controls and Objects 9.1 List Boxes, Combo Boxes, and the File-Opening Control The List Box Control.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Microsoft Visual Basic 2012 CHAPTER THREE Program Design and Coding.
Dreamweaver CS4 Concepts and Techniques Chapter 2 Adding Web Pages, Links, and Images.
BIL528 – Bilgisayar Programlama II Introduction 1.
Chapter 5 Quick Links Slide 2 Performance Objectives Understanding Framesets and Frames Creating Framesets and Frames Selecting Framesets and Frames Using.
Visual Basic Programming Chapter Six Notes Repetition and the Do Statement ADDING ICONS TO YOUR FORM –It is possible to add an ______________ to your title.
Creating Graphical User Interfaces (GUI’s) with MATLAB By Jeffrey A. Webb OSU Gateway Coalition Member.
 2006 Pearson Education, Inc. All rights reserved Introduction to the Visual C# 2005 Express Edition IDE.
Chapter 2 – Introduction to the Visual Studio .NET IDE
1 Creating Windows GUIs with Visual Studio. 2 Creating the Project New Project Visual C++ Projects Windows Forms Application Give the Project a Name and.
Layers, Image Maps, and Navigation Bars
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Build-A-Button Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, October 8, 2003.
CSC 230 (Blum)1 Visual Basic 2005 Hello World Fall 2005 T. Blum.
Page Designer Storyboard J. A. Fitzpatrick December 2004.
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to the Visual Studio.NET IDE Outline 2.1Introduction 2.2Visual Studio.NET Integrated.
Video in Macromedia Flash (Optional) – Lesson 121 Video in Macromedia Flash (Optional) Lesson 12.
Lecture Set 2 Part A: Creating an Application with Visual Studio – Solutions, Projects, Files 8/10/ :35 PM.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Address Book Application Introducing Database Programming.
CSC 230 (Blum)1 Visual Basic 2005 Hello World Fall 2005 T. Blum.
XP IT INSTRUCTOR :AHMAD HIRZALLAH 1 Microsoft Office FrontPage 2003 Creating Tables and Frames.
PowerPoint Basics Tutorial 2: A Slide Show In this tutorial you’re going to create a presentation from scratch. You will have to keep this presentation.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
XP New Perspectives on Macromedia Dreamweaver MX 2004 Tutorial 5 1 Adding Shared Site Elements.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
Microsoft Visual C# 2010 Fourth Edition Chapter 3 Using GUI Objects and the Visual Studio IDE.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
 You won’t write a single line of program code.  Instead, you’ll use visual programming techniques.  Visual Studio processes your actions (such as mouse.
XP New Perspectives on Microsoft Office FrontPage 2003 Tutorial 5 1 Microsoft Office FrontPage 2003 Tutorial 5 – Creating Tables and Frames.
Chapter 1: An Introduction to Visual Basic 2015
Chapter 2 – Introduction to the Visual Studio .NET IDE
Introduction to the Visual C# 2005 Express Edition IDE
Chapter 2 – Introduction to the Visual Studio .NET IDE
Presentation transcript:

OpenGL and Windows Windows Forms Programming Roger Crawfis

OhioState::OpenGLPanel The simplest possible canvas or rendering context. No assumptions are made (single buffer, double buffer, etc.) Burden on user to provide all information and event processing. Can be used as a base-class for more intelligent classes.

OpenGLPanel : Forms::Control All of the functionality of a Control. Creates the OpenGL rendering context. Overrides: –protected OnPaintBackground –protected OnPaint –protected OnResize –public set_BackColor property

Public methods OpenGLPanel( PIXELFORMATDESCRIPTOR pfd ); void AddPreRenderCallback( OpenGLRenderCallback *callback ); void AddRenderCallback( OpenGLRenderCallback *callback ); void AddPostRenderCallback( OpenGLRenderCallback *callback ); void AddResizeCallback( OpenGLResizeCallback *callback ); int GetFrameNumber() { return frameNumber; }; void MakeCurrent(); void SwapBuffers();

The Constructor No assumptions, so the user passes in the PIXELFORMATDESCRIPTOR which indicates the number of color bits, stencil bits, etc. Make sure the dwflag entry includes PFD_SUPPORT_OPENGL. See the sample and the MSDN help for more information.

Callbacks The OpenGLPanel is structured around registered callbacks. These are pointers to a function, or delegates. Two publicly defined Delegate types: –public __delegate void OpenGLRenderCallback( const int frameNumber ); –public __delegate void OpenGLResizeCallback( const int width, const int height ); These are really type definitions: –A pointer to a function that returns void and takes one parameter of type const int.

Callbacks Like any other type, you create and instance: glPanel->AddRenderCallback( new OhioState::OpenGLRenderCallback( this, DrawScene ) ); DrawScene is a public method of this, or Form1 here. Can also use static methods, in which case, this would be replaced with the class type. thank-you garbage collection

Using OpenGLPanel Checklist: –Create a Forms::Panel (in the designer). –In the Form1 constructor: Create an OpenGLPanel and add it to the panel (call this glPanel). Put all of your drawing code into a method that returns void and takes a single const int. Create a callback instance and add it to glPanel. Create a resize function, wrap it in a callback and add it to glPanel.

Creating a nice GUI The next several slides will walk you thru a particular design that I like for my applications. The order can be a little finicky, so if you mess up, delete all files and start over!!! The design consists of a GUI panel on the left and a view panel on the right, with a status bar and a main menu.

Create a new Project Start Visual Studio.NET

Create a new Project Select a C++ Windows Forms Application

Add your GUI elements Resize the Form to be about 800 by 600, or whatever you like. In this order, add the following elements from the Toolbox->Windows Forms. –StatusBar –Panel –Splitter –Panel

GUI design In the Properties window you can make changes to the content and appearance of these controls. –Change the BackColor of the splitter. –Change the Dock property of panel1 to Left. –Change the Dock property of panel2 to Fill (the center icon). –Click on the Collections property of the statusBar and add three tabs. Type in some text. –On the StatusBar properties, set ShowPanels to true.

GUI Design Build (Build->Build Solution) and run (Debug->Start without Debugging) your application. It should look something like this:

GUI Design In the GUI panel, let’s make one large tabbed dialogue. Drag a tabControl over to the GUI panel. Set its dock to Fill. In the properties select the Collection button and add four tab panels. –Lab1 –Extra –Grading –Readme

GUI Design Your program should now look like this. New Title added Background image added

Examine the code Okay. We have the basic lay-out. Notice we have not done any programming yet. Right-click the Form1.h file in the Solution panel and select Edit Code. We have: –A public constructor –A protected Dispose –A private InitializeComponents What is this! The source code is in the.h file? Look at the Form1.cpp file.

InitializeComponents There is a tree view structure in the code views with Visual Studio. You can collapse a method, class or region of code to hide the details as you work on other parts of the code. The InitializeComponents method is collapsed by default. This is automatically generated by the Designer Window. It has all of the nitty details on setting up the controls. Uncollapse it and examine the code.

Lab1 Okay, we have the basic lay-out, now we need to embed the business logic. What are the lab requirements? More specifically, what controls do we need? –Specifying the number of lines / points. –Reading in (selecting) an image file. –Specifying the line-width or point size. –Specify two color values.

Lab1 Controls Selecting an image file. –Possible Options: 1.Add a text box and have the user type the path / filename into the textbox. (umm Yuck!!!) 2.Pre-load a set of image files and have the user select from this set. (lacks flexibility). 3.Bring up a dialog asking the user to select an image. Limit the selection to only the proper type of files. How do we bring up the dialog? What do we have to do to show the dialog?

Image file Dialogue This is why you use a higher-level API. With windows forms and.Net 1.1 this is really trivial. Follow these simple steps: 1.Drag an OpenFileDialog control to anywhere on your Form. Notice that it places it in a special window pane below your design. 2.Drag a Button control to the Lab1 tab panel. This will be used to bring up the dialog.

Image file Dialogue Adjust the Button’s properties: 1.Change the text to “Load Texture” Adjust the OpenFileDialog’s properties 1.Change the Title to “Select an image file for the texture” 2.In the Filter property add a string to aid in the right file type selection. Something like this: “All files (*.*)|*.*|Jpeg (*.jpg)|*.jpg|Png (*.png)|*.png”. Each pair here has the format (Text string to display | regular expression). Note that adding a space before the asterisk results in a different regular expression. 3.Set the Filter index to 2, such that jpeg is the default format. 4.Set the AddExtension to False. 5.Make sure the Multiselect property is False.

Image file Dialogue Okay, we have now defined everything, such that the constructor is called and the properties are set. Nothing will happen though, we need to add some logic. Double click the “Load Texture” button. This adds some template code and brings up the source code window (Form1.h). It also added this line inside the InitializeComponents: this->button1->Click += new System::EventHandler(this, button1_Click); Add the following line in button1_Click: this->openFileDialog1->ShowDialog();

Image file Dialogue Run and test the program. Clicking on the button should bring up the openFileDialog.

Image file Dialogue Note that the dialog simply selects the file, it does not open it or perform any logic yet. We will address actually opening the file, reading in the image and creating a texture map from it later.

Lab1 Controls Number of primitives –There are several choices here. Textbox (you would need to validate that it only contained numbers). Numeric Up/Down control (it has two speeds, both of which you can configure in the Properties page). Trackbar or slider control (you may need to provide a text label that indicates the current value). –The reference lab uses both a numericUpDown and a Trackbar tightly coupled together.

Accessibility Most controls have accessibility features built into them. This allows for a mouse free control. You can hit the tab key to reach the NumericUpDown and Trackbar controls and then use the arrow keys to change their values. Holding down the key accelerates the change.

Trackbar Let’s use the trackbar. Drag a trackBar control to the Lab1 tab panel. In the Properties page: –Set the Maximum value to 100,000 (or higher) –Set the (initial or current) Value to 10,000 –Set the LargeChange to 5,000 –Set the SmallChange to 1,000 –Set the Tick Frequency to 10,000 Also add a Label control (static text) above the trackBar to describe its purpose.

Trackbar We should now have something like:

Trackbar Okay, we have a control and it can change values, etc. but we do not have anything useful connected to it. Business logic: –There are many ways you can use this: 1.The lazy way – simply read the control’s value whenever you need it. This mixes the business logic and the GUI logic. 2.The global document way – Whenever the value changes, change a corresponding data value in some document class. This still mixes the logic. Bad data hiding. 3.The document/view way – Whenever the value changes, call a method on the document’s class. The document now knows it’s value has changed. Perform some action (update display, verify data, etc.) Keep a history for undo/redo.

Document Class Okay, I will admit it, I used method #1 in the reference lab. But I am going to make you follow method #3. Create and add a new class to your project. –Right-click on the solution and select Add->Add Class from the context menu. –Select a generic C++ class and give a name. –Change it to managed C++ by changing class to public __gc class in the header file. –Add the following private members: –int numPrimitives; –float lineWidth; –Color color1, color2;

Document Class Color is a managed.NET class, hence the need for __gc. You also need to include: using namespace System::Drawing; Add public methods to set (and optionally get) each of these. For instance: void SetNumPrimitives( const int nLines ) { numPrimitives = nLines; }

Document Class Okay, now we can wire that to the trackBar. Double-click the trackBar in the designer. In the code template, add something like: impressionismDoc->SetNumPrimitives( trackBar1->Value ); We need to create and add an instance of our document. Declare a private pointer to an instance. private: Impressionism *impressionismDoc; In the constructor for Form1 create a new instance. impressionismDoc = new Impressionism();

Lab1 Status Okay, we are about 1/3 of the way to having some implementation for lab1. The next presentation file will walk you through adding the OpenGLPanel and creating the OpenGL drawing calls. We still need to add the image file and texture map, as well as the other controls.