Chapter 3 arrays of vertices vertex arrays display lists drawing text

Slides:



Advertisements
Similar presentations
OpenGL Open a Win32 Console Application in Microsoft Visual C++.
Advertisements

OpenGL CMSC340 3D Character Design & Animation. What is OpenGL? A low-level graphics library specification designed for use with the C and C++ provides…
CS 450: COMPUTER GRAPHICS GLUT INPUT FUNCTIONS SPRING 2015 DR. MICHAEL J. REALE.
CS 4731 Lecture 2: Intro to 2D, 3D, OpenGL and GLUT (Part I) Emmanuel Agu.
What is OpenGL? Low level 2D and 3D Graphics Library Competitor to Direct3D (the rendering part of DirectX) Used in: CAD, virtual reality, scientific.
OpenGL Basics Donghui Han. Assignment Grading Visual Studio Glut Files of four types needed: – Source code:.cpp,.h – Executable file:.exe (build in release.
CSC 461: Lecture 51 CSC461 Lecture 5: Simple OpenGL Program Objectives: Discuss a simple program Discuss a simple program Introduce the OpenGL program.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Computer Science,
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 GLUT Callback Functions.
CSC461 Lecture 9: GLUT Callbacks Objectives Introduce double buffering for smooth animations Programming event input with GLUT.
CS 480/680 Computer Graphics Programming with Open GL Part 8: Working with Callbacks Dr. Frederick C Harris, Jr. Fall 2011.
Events and Coordinates Lecture 5 Fri, Sep 5, 2003.
1 Working with Callbacks Yuanfeng Zhou Shandong University.
More on Drawing in OpenGL: Examples CSC 2141 Introduction to Computer Graphics.
WORKING WITH CALLBACKS Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico Angel: Interactive.
Interaction with Graphics System
Lecture 5: Interaction 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 
CS 450: COMPUTER GRAPHICS REVIEW: GLUT INPUT FUNCTIONS SPRING 2015 DR. MICHAEL J. REALE.
CAP 4703 Computer Graphic Methods Prof. Roy Levow Lecture 3.
CSE 470: Computer Graphics. 10/15/ Defining a Vertex A 2D vertex: glVertex2f(GLfloat x, GLfloat y); 2D vertexfloating pointopenGL parameter type.
Lecture 3 OpenGL.
1 Input and Interaction. 2 Input Devices Physical input devices Keyboard devices and pointing devices Logical input devices.
Ch 2 Graphics Programming page 1 CSC 367 Coordinate Systems (2.1.2) Device coordinates, or screen coordinates (pixels) put limitations on programmers and.
Modeling with OpenGL Practice with OpenGL transformations.
CIS 3.5 Lecture 2.2 More programming with "Processing"
Program 2 due 02/01  Be sure to document your program  program level doc  your name  what the program does  each function  describe the arguments.
Computer Graphics I, Fall 2010 Working with Callbacks.
Pop-Up Menus Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, September 26, 2003.
Mouse events, Advanced camera control George Georgiev Telerik Corporation
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Introduction to Graphics Programming. Graphics API.
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
OpenGL CS418 Computer Graphics John C. Hart. OpenGL Based on GL (graphics library) by Silicon Graphics Inc. (SGI) Advantages: Runs on everything, including.
OpenGL CS418 Computer Graphics John C. Hart. OpenGL: Event-driven How in OpenGL? Programmer registers callback functions Callback function called when.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Working with Callbacks.
INTRODUCTION TO OPENGL
Basic Program with OpenGL and GLUT
Review GLUT Callback Functions
Working with Callbacks
Introduction to the Mouse
Computer Graphics Lecture 33
Programming with OpenGL Part 2: Complete Programs
More on Graphical User Interfaces
The User Interface Lecture 2 Mon, Aug 27, 2007.
Programming with OpenGL Part 2: Complete Programs
Lab 3 Geometric Drawing Lab 3 Geometric Drawing.
Variables and Arithmetic Operations
Starting to draw dealing with Windows which libraries? clipping
Advanced Menuing, Introduction to Picking
Intro to lighting (Chapter 11)
Outline Announcements Dynamic Libraries HWII on web, due Friday
Chapter 4/5 glMatrixMode Modeling Transformations glTranslate glScale
Chapters 5/4 part2 understanding transformations working with matrices
OpenGL Basics OpenGL’s primary function – Rendering
Chapter 3 arrays of vertices vertex arrays display lists drawing text
Working with Callbacks
Project 1: Into Space! CG Concepts Needed
Coordinate Systems and Transforming the Coordinates
Chapter 3 arrays of vertices vertex arrays display lists drawing text
Display Lists & Text Glenn G. Chappell
DREAMWEAVER MX 2004 Chapter 7 Working with Layers
More programming with "Processing"
Fundamentals of Computer Graphics Part 3
Programming with OpenGL Part 2: Complete Programs
Chapter 3 arrays of vertices vertex arrays display lists drawing text
Programming with OpenGL Part 2: Complete Programs
Starting to draw dealing with Windows which libraries? clipping
Lecture #5 Interactive Input Methods
Programming with OpenGL Part 2: Complete Programs
Presentation transcript:

Chapter 3 arrays of vertices vertex arrays display lists drawing text mouse buttons

4 ways to give the vertices List the vertices between glBegin and glEnd arrays of vertices (still uses glBegin and glEnd) Vertex arrays Index arrays

squareAnnulus4.cpp In addition to vertex and color arrays (1D) there is an index array static unsigned char stripIndices[] = {0, 1, 2, 3, 4, 5, 6, 7, 0, 1}; One draw statement glDrawElements(GL_TRIANGLE_STRIP, 10, GL_UNSIGNED_BYTE, stripIndices); (primitive, count, type, *indices) Look at code.

Display Lists compiled once can save to machine running the display can be invoked by a single command Uses the values of variables at the time it compiles, not at the time it is displayed.

helixList.cpp // Globals. static unsigned int aHelix; // List index. in setup(): aHelix = glGenLists(1); // Return a list index. // Begin create a display list. glNewList(aHelix, GL_COMPILE); // Draw a helix. glBegin(GL_LINE_STRIP); for(t = -10 * PI; t <= 10 * PI; t += PI/20.0) glVertex3f(20 * cos(t), 20 * sin(t), t); glEnd(); glEndList(); // End create a display list.

helixList.cpp glCallList(aHelix); // Execute display list. in drawScene(): glCallList(aHelix); // Execute display list.

see the text for a discussion of executing multiple display lists with one call. Got to slide 12

Drawing Text - Bitmap use a glut function for drawing a char Need to go to the right pixel: glRasterPos3f(p,q,r);//object coordinates call a function to draw the string, like writeBitmapString(font, string) // Routine to draw a bitmap character string. void writeBitmapString(void *font, const char *string) { const char *c; for (c = string; *c != '\0'; c++) glutBitmapCharacter(font, *c); } use a glut function for drawing a char glutBitmapCharacter(font, *c);

Sample Letters

Available Bitmap Fonts GLUT_BITMAP_8_BY_13 GLUT_BITMAP_9_BY_15 GLUT_BITMAP_TIMES_ROMAN_10 GLUT_BITMAP_TIMES_ROMAN_24 GLUT_BITMAP_HELVETICA_10 GLUT_BITMAP_HELVETICA_12 GLUT_BITMAP_HELVETICA_18

See CircularAnnuluses.cpp for an example

Drawing Text - Stroke Works like drawing lines. Uses color, linewidth,... Assumes at the origin, use glTranslate to move to the right spot, glScale to make the right size

Available Stroke Fonts GLUT_STROKE_ROMAN GLUT_STROKE_MONO_ROMAN Run fonts.cpp

Stroke text cont. Use a glut function to draw the char Use the canonical function // Routine to draw a stroke character string. void writeStrokeString(void *font, const char *string) { const char *c; for (c = string; *c != '\0'; c++) glutStrokeCharacter(font, *c); } Use a glut function to draw the char glutStrokeCharacter(font, *c);

Bitmaps don't scale. Stroke scale, rotate.

Programming the mouse clicking a button - register with glutMouseFunc(mouseButton) dragging with a button down - register with glutMotionFunc(mouseMotion) dragging with no button down - register with glutPassiveMotionFunc(mousePassive)

void mouseButton(int button, int state, int x, int y); button can be GLUT_LEFT_BUTTON GLUT_RIGHT_BUTTON GLUT_MIDDLE_BUTTON state can be GLUT_UP GLUT_DOWN

int x, int y (x,y) is the location in the OpenGL window, measured in pixels, with origin in the upper left corner.

mouse.cpp Run. Notice the use of STL vector. Look at the mouse control function. Look at the resize function, and the resize behavior.

STL vector Point is user defined type. vector<Point> points; // Iterator to traverse a Point array. vector<Point>::iterator pointsIterator; // Store the clicked point in the points array // after correcting // from event to OpenGL co-ordinates. points.push_back( Point(x, height - y) );

drawing the points // Loop through the points array // drawing each point. pointsIterator = points.begin(); while(pointsIterator != points.end() ) { pointsIterator->drawPoint(); pointsIterator++; } Got to here class 5

mouseMotion.cpp modified point size and color for demo point is created when button is pressed. coordinates of point are modified as mouse is moved with the button down point is added to the vector when button is released currentPoint Look at code.

Using the keyboard glutKeyboardFunc(keyboardInput) - to register ordinary keyboard input glutSpecialFunc(specialkeyInput) - to register F keys, arrow keys, page up and down.

keyboard functions keyboardInput(unsigned char key, int x, int y); specialkeyInput(int key, int x, int y); Lots of values for key for example: GLUT_KEY_F4 GLUT_KEY_DOWN GLUT_KEY_HOME

menus (popup) Run menus.cpp glutCreateMenu(menuFunction) - registers menuFunction as a menu function and returns an ID number for that menu. (Must be after the glutCreateWindow.) prototype void menuFunction(int value) value is a number corresponding to the user's menu choice.

glutAddMenuEntry(tag, returnedValue); tag is what it will say returnedValue in the value that menuFunction will get as its argument. eg: glutAddMenuEntry("Quit",1);

glutAddSubMenu(tag, sub_menu) tag is what it will say sub_menu is the ID of the (sub)menu you want to pop up. Awkward: need to create the submenu before the menu that calls it.

glutAttachMenu(button) - says which button brings up this menu Run and look at code of menus.cpp Don't forget to PostRedisplay() in the menuFunction!

A state that needs to be enabled. Line Stipples A state that needs to be enabled. glEnable(GL_LINE_STIPPLE); glDisable(GL_LINE_STIPPLE); Applies to all lines until you disable it.

glLineStipple(factor, pattern) factor is a positive integer pattern is the pattern, in hexidecimal eg: - - - --- - - Reverse - - --- - - - 1001011100101010 0x972A Here factor is 1.

glLineStipple(factor, pattern) If factor is 2, instead of 1 get - - - --- - - -- -- -- ------ -- --

glut solids glutSolidSphere(radius, slices, stacks) glutWireSphere(radius, slices, stacks)

all glut solids Run glutObjects.cpp

glViewPort(x,y,w,h); (x,y) lower left corner of viewport, in pixels, within the window (w,h) width and height of viewport. origin of window at lower left glOrtho or glFrustum or ... apply to each viewport. default viewport is the whole window run viewports.cpp

canvas.cpp put it all together!

Multiple Windows run windows.cpp glutCreateWindow() returns an id glutSetWindow(id) says id is the window we will be drawing in now. in main, can register different callback functions for different windows.

Experiment to try at home Modify so pressing the 1 key makes the background of window 1 gray, and pressing 2 makes the background of window 2 yellow.

Equation of a plane ax + by + cz + d = 0 n⋅(p-p0)=0, d=-(ax0 + by0 + cz0) Modified, from mathworld.wolfram.com/Plane.html

clipping planes glClipPlane(GL_CLIP_PLANEi, *equation) equation is an array of a,b,c,d glEnable(GL_CLIP_PLANEi); glDisable(GL_CLIP_PLANEi); See (x,y,z) only if ax+by+cz+d >=0 if drawn while enabled. Run and look at clippingPlanes.cpp

gluPerspective(fovy,aspect, near, far) like glFrustum fovy - field of view angle aspect ratio - width/height near and far like glFrustum symmetric about the z axis

gluPerspective(fovy,aspect,near,far)