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…
Coordinate System.
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.
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.
Computer Graphics CS 385 February 7, Fundamentals of OpenGl and Glut Today we will go through the basics of a minimal OpenGl Glut project, explaining.
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
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"
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.
OpenGL Basic Drawing 2003 Spring Keng Shih-Ling
Drawing and Coordinate Systems. Coordinate Systems Screen Coordinate system World Coordinate system World window Viewport Window to viewport mapping.
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
12/22/ :38 1 Comp 175C - Computer Graphics Dan Hebert Computer Graphics Comp 175 Chapter 3 Instructor: Dan Hebert.
OpenGL Basic Drawing Jian-Liang Lin A Smidgen of OpenGL Code #include main() { InitializeAWindowPlease(); glClearColor (0.0, 0.0, 0.0, 0.0); glClear.
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
OpenGL and GLUT Review Daniel Ritchie Monday, October 3 rd, 2011.
Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
Working with Callbacks
Introduction to the Mouse
Computer Graphics Lecture 33
Reference1. [OpenGL course slides by Rasmus Stenholt]
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
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
Introduction to OpenGL
More programming with "Processing"
Working with Symbols and Interactivity
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
Programming with OpenGL Part 2: Complete Programs
Chapter 3 arrays of vertices vertex arrays display lists drawing text
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

SquareAnnulus1.cpp as we have seen so far glBegin(GL_TRIANGLE_STRIP); glColor3f(0.0, 0.0, 0.0); glVertex3f(30.0, 30.0, 0.0); glColor3f(1.0, 0.0, 0.0); glVertex3f(10.0, 10.0, 0.0);

Arrays of vertices (and colors) squareAnnulus2.cpp vertices and colors in global arrays vertices accessed through pointers glVertex3fv(pointer to vertex) colors accessed through pointers glColor3fv(pointer to color) Look at the code.

Accessing an Array of Vertices with pointers // Draw square annulus. glBegin(GL_TRIANGLE_STRIP); for(int i = 0; i < 10; ++i) { glColor3fv(colors[i%8]); glVertex3fv(vertices[i%8]); } glEnd();

ARRAY OF VERTICES vs VERTEX ARRAY ARRAY OF VERTICES // Vertex co-ordinate vectors. static float vertices[8][3] = { {30.0, 30.0, 0.0}, {10.0, 10.0, 0.0}, {70.0, 30.0, 0.0}, {90.0, 10.0, 0.0}, {70.0, 70.0, 0.0}, {90.0, 90.0, 0.0}, {30.0, 70.0, 0.0}, {10.0, 90.0, 0.0} }; VERTEX ARRAY // Vertex co-ordinate vectors. static float vertices[] = { 30.0, 30.0, 0.0, 10.0, 10.0, 0.0, 70.0, 30.0, 0.0, 90.0, 10.0, 0.0, 70.0, 70.0, 0.0, 90.0, 90.0, 0.0, 30.0, 70.0, 0.0, 10.0, 90.0, 0.0 };

Vertex Arrays squareAnnulus3.cpp vertices in one dimensional vertex array colors in one dimensional color array vertex and color are accessed together glArrayElement(i%8); glArrayElement(location of vertex); Need info to know where that is!

To use vertex arrays you need to say you are using a vertex array and a color array. glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); say where to find the data glVertexPointer(3, GL_FLOAT, 0, vertices); glColorPointer(3, GL_FLOAT, 0, colors); (size, type, stride, *pointer) Look at code. (squareAnnulus3.cpp or roomStripe.cpp)

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.

OpenGL redefines types. Use GL types as parameters to GL functions OpenGL redefines types. Use GL types as parameters to GL functions. Sometimes you will need to declare the item using the GL type, eg. GLfloat length;

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, char *string) { 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

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)

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!