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…
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Building Models modified by Ray Wisman Ed Angel Professor of Computer Science,
1 Building Models. 2 Objectives Introduce simple data structures for building polygonal models ­Vertex lists ­Edge lists OpenGL vertex arrays.
Data: Programming Design and Modularization IS 101Y/CMSC 101 Computational Thinking and Design Thursday, September 26, 2013 Marie desJardins University.
CS 4731 Lecture 2: Intro to 2D, 3D, OpenGL and GLUT (Part I) Emmanuel Agu.
Painterly Rendering CMPS Assignment 2. OpenGL OpenGL is a cross-language, cross- platform specification defining and API for 2D and 3D graphics.
Based on slides created by Edward Angel
OpenGL Pixel Operations, Bitmaps, Fonts and Images The Current Raster Position Current raster position: A position in window coordinates where the next.
CS 480/680 Computer Graphics Programming with Open GL Part 8: Working with Callbacks Dr. Frederick C Harris, Jr. Fall 2011.
Reference1. [OpenGL course slides by Rasmus Stenholt]
CS380 LAB I OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
1 Working with Callbacks Yuanfeng Zhou Shandong University.
WORKING WITH CALLBACKS Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico Angel: Interactive.
Triangulation Introduction to Computer Graphics and Animation (Principle of Computer Graphics) Rattapoom Waranusast.
Interaction with Graphics System
Continuous February 16, Test Review What expression represents the zip car eligibility rules of at least 18 years old and no incidents?
Lecture 3 OpenGL.
1 Input and Interaction. 2 Input Devices Physical input devices Keyboard devices and pointing devices Logical input devices.
Tutorial 11 Five windows included in the Visual Basic Startup Screen Main Form Toolbox Project Explorer (Project) Properties.
 “OpenGL (Open Graphics Library) is a standard specification defining a cross- language cross-platform API for writing applications that produce 2D and.
Modeling with OpenGL Practice with OpenGL transformations.
CIS 3.5 Lecture 2.2 More programming with "Processing"
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
Computer Graphics I, Fall 2010 Working with Callbacks.
Test 2 Review. General Info. All tests are comprehensive. You are still responsible for the material covered prior to the first exam. You will be tested.
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
Computer Science I Recap: variables & functions. Images. Pseudo-random processing.
G RAPHICS & I NTERACTIVE P ROGRAMMING Lecture 2 More Programming with Processing.
Methods Awesomeness!!!. Methods Methods give a name to a section of code Methods give a name to a section of code Methods have a number of important uses.
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
Chapter 8 Arrays and the ArrayList Class Arrays of Objects.
Basic Program with OpenGL and GLUT
A variable is a name for a value stored in memory.
Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
Test 2 Review Outline.
Computer Graphics and Visualization (06 CS 65)
3 Introduction to Classes and Objects.
Working with Callbacks
Introduction to the Mouse
Chapter 7 Top-Down Development
Computer Graphics Lecture 33
Java Programming: Guided Learning with Early Objects
The User Interface Lecture 2 Mon, Aug 27, 2007.
Variables and Arithmetic Operations
Starting to draw dealing with Windows which libraries? clipping
Intro to lighting (Chapter 11)
Building Models Ed Angel
Outline Announcements Dynamic Libraries HWII on web, due Friday
Chapter 4/5 glMatrixMode Modeling Transformations glTranslate glScale
An Introduction to Java – Part I, language basics
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
Chapter 3 arrays of vertices vertex arrays display lists drawing text
Display Lists & Text Glenn G. Chappell
Isaac Gang University of Mary Hardin-Baylor
Drawing in the plane 455.
More programming with "Processing"
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
Working with Symbols and Interactivity
Starting to draw dealing with Windows which libraries? clipping
Arrays.
C Language B. DHIVYA 17PCA140 II MCA.
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

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 };

roomStripe.cpp Room is built with a list of vertices Figure out where the room is in world coords. Decide where you want the stripe to be, get 14 points Stripe is drawn using a Vertex Array.

roomStripe.cpp Color can be solid or use a Color Array Need to set up and enable these arrays. Discuss input from a file in C++ Discuss changing Frustum/Ortho

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, 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 CircularAnuluses.c 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++; }

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.