Project 1: Impressionist Help Session

Slides:



Advertisements
Similar presentations
Chapter 2: Graphics Programming
Advertisements

GLSL Basics Discussion Lecture for CS 418 Spring 2015 TA: Zhicheng Yan, Sushma S Kini, Mary Pietrowicz.
CS 4363/6353 BASIC RENDERING. THE GRAPHICS PIPELINE OVERVIEW Vertex Processing Coordinate transformations Compute color for each vertex Clipping and Primitive.
CSE 557: Impressionist Help Session Ian Simon. What we’ll be going over Getting Set Up The Skeleton Code OpenGL Basic FLTK How to make a new brush Good.
Lab 1: OpenGL Tutorial CS 282. What’s the plan for today? Go over our framework code. Learn some basic OpenGL! Reveal Lab 1 Answer questions.
What is OpenGL? Low level 2D and 3D Graphics Library Competitor to Direct3D (the rendering part of DirectX) Used in: CAD, virtual reality, scientific.
CSE 557: Impressionist Help Session Keith Grochow.
Project 1: Impressionist Help Session And your friendly neighborhood TA is… Young-Mi.
Painterly Rendering CMPS Assignment 2. OpenGL OpenGL is a cross-language, cross- platform specification defining and API for 2D and 3D graphics.
Modeler Help Session CSE 457, Fall 2005 Modeler Due: Oct 28, Friday Modeler Artifact Due: Oct 31, Monday Project TA: Jeremy
OpenGL Help Session CS248 Fall 2006 Zhengyun Zhang.
Project 1: Impressionist Help Session Jonathan Su
CSE 457: Impressionist Help Session...And Your Friendly TA is: Steve Martin.
CAP4730: Computational Structures in Computer Graphics Introduction to OpenGL.
COS 397 Computer Graphics Assoc. Prof. Svetla Boytcheva AUBG 2013 COS 397 Computer Graphics Practical Session №1 Introduction to OpenGL, GLFW and CG.
Basic OpenGL Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, September 10, 2003.
Drawing Basic Graphics Primitives Lecture 4 Wed, Sep 3, 2003.
OpenGL Shading Language (Advanced Computer Graphics) Ernest Tatum.
Introduction to OpenGL and GLUT GLUT. What is OpenGL? An application programming interface (API) A (low-level) Graphics rendering API Generate high-quality.
Programming with OpenGL Part 1: Background
CS 450: COMPUTER GRAPHICS PORTRAIT OF AN OPENGL PROGRAM SPRING 2015 DR. MICHAEL J. REALE.
Graphics Systems and OpenGL. Business of Generating Images Images are made up of pixels.
Modeler Help Session CSEP 557, Spring Help Session Overview The Modeler Application Modeler Code Overview Constructing Your Model Hierarchical Modeling.
به نام خدا تنظیم کننده : فرانه حدادی استاد : مهندس زمانیان تابستان 92.
1 Chapter 12 GUI C/C++ Language Programming Wanxiang Che.
Introduction to OpenGL  OpenGL is a graphics API  Software library  Layer between programmer and graphics hardware (and software)  OpenGL can fit in.
Introduction to OpenGL and GLUT. What’s OpenGL? An Application Programming Interface (API) A low-level graphics programming API – Contains over 250 functions.
CSE 381 – Advanced Game Programming GLSL. Rendering Revisited.
OpenGL-ES 3.0 And Beyond Boston Photo credit :Johnson Cameraface OpenGL Basics.
Project 1: Impressionist Help Session. The Skeleton Code.
NoufNaief.net TA: Nouf Al-harbi.
Week 3 Lecture 4: Part 2: GLSL I Based on Interactive Computer Graphics (Angel) - Chapter 9.
What are shaders? In the field of computer graphics, a shader is a computer program that runs on the graphics processing unit(GPU) and is used to do shading.
OpenGL Shading Language
Project 1: Impressionist Help Session Zinnia Zheng
Introduction to OpenGL Muhammad Aamir Khan Lecturer, DCS, UOP.
Introduction to OpenGL (INF 250) Veronika Solteszova et al., UiB Dept. of Informatics,
July FLTK The Fast Light Toolkit • A C++ graphical user interface toolkit • Can be used under X, Windows, MacOS • Supports OpenGL • Provides: – Interactive.
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
CSE 457: Impressionist Help Session...And Your Friendly TA is: Siobhan Quinn.
UMBC GDC Programming Tutorial
Hank Childs, University of Oregon Oct. 28th, 2016 CIS 441/541: Introduction to Computer Graphics Lecture 16: textures.
Programming with OpenGL Part 1: Background
Milestone 2 Overview.
FLTK The Fast Light Toolkit
Project 1: Impressionist Help Session
Project 1: Impressionist Help Session
GLSL I Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New Mexico.
Project 1: Impressionist Help Session
Help Session . . .And Your Friendly TA is: Andrew Stoneman
Project 1: Impressionist Help Session
Introduction to Computer Graphics with WebGL
Programming with OpenGL Part 1: Background
Modeler Help Session CSE 457, Autumn 2008
Introduction to Computer Graphics with WebGL
Modeler Help Session CSE 457, Spring 2006
Drawing in the plane 455.
Modeler Help Session CSE 457, Spring 2005
Modeler Help Session CSE 457, Autumn 2007
OpenGL program.
Modeler Help Session CSE 457, Spring 2008
Programming with OpenGL Part 1: Background
Modeler Code Basics CSE P 557, Autumn 2006
Modeler Help Session CSE 457, Spring 2007
Project 1: Impressionist Help Session
03 | Creating, Texturing and Moving Objects
OpenGL Background CS 4722.
Prepared by your friendly, phantom TA Jennifer
CS 480/680 Fall 2011 Dr. Frederick C Harris, Jr. Computer Graphics
Presentation transcript:

Project 1: Impressionist Help Session 557 autumn 09

What we’ll be going over: The Skeleton Code OpenGL Basic FLTK Hint #1: How to make a new brush. Hint #2+: Filter kernel Basic Photoshop (artifacts, plus check your work!) Good References for Project 1 Q&A

The Skeleton Code

The Skeleton Code cont’d ImpressionistDoc This class handles all of the document-related stuff, like loading/saving, etc. ImpressionistUI This class handles all of the UI stuff, such as getting values from sliders, setting up the window, etc. PaintView This class handles drawing the side of the window the user paints on. A lot of event handling is done here (so here look for examples). OriginalView This class handles the other side of the window. ImpBrush This is the virtual class all brushes are derived from. PointBrush This is an example brush that draws points. PointShaderBrush OpenGLShader Wrapper Class This is an example brush that draws points with a Shader

Meet your new friend (or enemy): OpenGL OpenGL is a great environment for PC 2d/3d graphics applications. It is one among many others, such as DirectX, Glide, Allegro, etc. Very easy to start working with It is extremely well documented. We will be using it throughout the quarter. Project 1 uses just the basics of OpenGL. Although you’re welcome to learn more on your own, the focus of the project is on 2d image manipulation.

How OpenGL Works OpenGL draws primitives—lines, vertexes, or polygons—subject to many selectable modes. It can be modeled as a state machine Once a mode is selected, it stays there until turned off. It is procedural—commands are executed in the order they’re specified. The coordinate system in which it draws is transformed using function calls. glRotate, and why it might be confusing (right now). The matrix stack. This will all be covered in detail in the modeler help session!

Drawing with OpenGL That said, how to draw an actual primitive? Lets do an example: a filled triangle. First, set your color: glColor3f( red, green, blue ); Now, tell openGL to begin drawing: glBegin( GL_POLYGON ); Specify vertices A, B, and C. Since we’re drawing in an image, use integers. glVertex2i( Ax, Ay ); glVertex2i( Bx, By ); glVertex2i( Cx, Cy ); Close the openGL block. glEnd(); Force openGL to draw what you specified now. glFlush(); // don't forget this!

FLTK: Diet Win32 A really handy old cross-platform windowing system. Stands for Fast Light ToolKit. A really handy old cross-platform windowing system. Completely Event-driven (via callbacks). The window setup code is run, and then the main loop is called. (we’ll look at an example in a second) All further events are handed out to callbacks. We use version 1.1.7 1.1.10

FLTK Example code This code is taken/modified directly from fltk.org: #include <put junk here> This code is executed in order: int main(int argc, char **argv) { Fl_Window *window = new Fl_Window(300,180); Fl_Box *box = new Fl_Box(20,40,260,100,"Hello, World!"); Run functions registered to Fl_Box on the box you created: box->box(FL_UP_BOX); box->labelsize(36); box->labelfont(FL_BOLD+FL_ITALIC); box->labeltype(FL_SHADOW_LABEL); window->end(); window->show(argc, argv); This is where we hand control of our program to FLTK. Anything that happens now is the result of a callback. return Fl::run(); }

How to Make a Brush Now that we’ve got all the background, lets make a brush! Presenting. . .triangleBrush! (Note: This will NOT count towards extra credit) Easiest way to do this: make a copy of pointBrush.h/cpp and rename them triangleBrush.h/cpp. Add them to the impressionist project. Go through the code and change all pointBrush labels to triangleBrush.

Brushmaking, cont’d Now, open up ImpressionistDoc.cpp Add triangleBrush.h to the includes Scroll down a bit, and add triangleBrush to the selectable brushes. Pick a constant for it. Go to ImpBrush.h and add the constant for triangleBrush to the enum. Go to impressionistUI.cpp, and add the triangle brush to the brush menu.

Brushes – another way ImpBrush is a partial interface (pure virtuals) Use a template to implement common functionality template <class DERIVED > class CBrushImpl : public ImpBrush { …. }; class LineBrush : public CBrushImpl < LineBrush > { … };

Brushmaking, cont’d again Run Impressionist. See the triangle brush. And, well, see the triangle brush make points instead of triangles. Open triangleBrush.cpp and go to BrushMove. Here’s what’s there now: glBegin( GL_POINTS ); SetColor( source ); glVertex2d( target.x, target.y ); glEnd(); Triangles need 3 vertices. Lets center ours around the target point where the user clicked. How do we do this?

Brushmaking, cont’d again We do it like so: int size = pDoc->getSize(); int Ax,Ay,Bx,By,Cx,Cy; Ax = target.x - (.5*size); Bx = target.x + (.5*size); Cx = target.x; Ay = target.y - (.5*size); By = target.y - (.5*size); Cy = target.y + (.5*size); glBegin( GL_POLYGON ); SetColor( source ); glVertex2i( Ax, Ay ); glVertex2i( Bx, By ); glVertex2i( Cx, Cy ); glEnd();

GPU Rendering Pipeline Application Call to Graphics API i.e. draw triangles GPU Geometry Shader Interpret primitives Project geometry from 3D to 2D Rasterize Combine Fragments Display Vertex Shader Pixel Shader

Shader Wrapper Class Shader Loads and compiles shaders Specify Variables Activate/deactivate the Shader

Shader Wrapper Loads and compiles shaders m_Shader.InstallShader(“fullpath/shadername”); Looks for files with the .geom .vert .frag extensions Must always have at least .vert and .frag

Shader Wrapper Variables in the shader program m_Shader.BindTexture("imgTexture", 0); The texture variable “imgTexture” is now OpenGL API texture 0 m_Shader.BindVertexAttribute( “foo”, 1); The variable “foo”, can be referenced via OpenGL with an ID of 1 glUniform1f(1, 1.0f); Set the variable ID=1 to a value of 1.0

A simple Shader Vertex Shader – emulate standard OpenGL Pixel Shader #version 120 uniform sampler2D imgTexture; uniform float rValue; void main (void) { vec4 color = texture2D(imgTexture, vec2(gl_TexCoord[0])); color.r *= rValue; gl_FragColor = color ; }

Filter Kernel Hints Remember how filter kernels are applied to an image. Look at sample program. How does it apply a filter? What could go wrong? What cases should we handle? We will be looking closely at your filter kernel. . . Very closely

OpenGL Debugging Hints One thing that might help is to be checking for errors after each call. When it seems like nothing is happening, OpenGL is often returning an error message somewhere along the line. The begin-end block is a good possibility, and if that's the problem there will be an error code returned. GLenum error_flag; error_flag = glGetError(); if (error_flag != GL_NO_ERROR) { printf("Error: %1s (%i) in %1s.\n",gluErrorString(error_flag),error_flag,"method name"); }

Basic Photoshop How to check your work. . . Filter kernel in Photoshop: Go to Filter->Other->Custom Median filter in Photoshop: Go to Filter->Noise->Median How to resize your artifact. . . Go to Image->Image Size Don’t forget to save as a jpeg!

Good References Books around the lab!! Class Web Google www.fltk.org The Red/Blue/Orange OpenGL Bibles Class Web Lots of references linked there! Google www.fltk.org www.opengl.org Your TAs

Questions. . .? Ask now