Starting to draw dealing with Windows which libraries? clipping

Slides:



Advertisements
Similar presentations
Chapter 2: Graphics Programming
Advertisements

© 2004, Tom Duff and George Ledin Jr1 Lectures OpenGL Introduction By Tom Duff Pixar Animation Studios Emeryville, California and George Ledin Jr Sonoma.
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 (Graphics Library) Software Interface to graphics software Allows to create interactive programs that produce color images of moving 3D objects.
Draw a Simple Object. Example 1/4 #include “ glut.h ” void display(); void reshape(GLsizei w, GLsizei h); void main(int argc, char** argv){ glutInit(&argc,
OpenGL (I). What is OpenGL (OGL)? OGL is a 3D graphics & modeling library Can also use it to draw 2D objects.
CSC 461: Lecture 51 CSC461 Lecture 5: Simple OpenGL Program Objectives: Discuss a simple program Discuss a simple program Introduce the OpenGL program.
#4: OpenGL Implementation & Project 2 CSE167: Computer Graphics TAs: Alex Kozlowski & Cameron Chrisman UCSD, Winter 2006.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Computer Science,
Computer Graphics (Fall 2005) COMS 4160, Lecture 10: OpenGL 1
ITEPC 06 - Workshop on Fractal Creation Chiew-Lan Tai and Oscar Au.
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.
Reference1. [OpenGL course slides by Rasmus Stenholt]
CS380 LAB I OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
Using Graphics Libraries Lecture 3 Mon, Sep 1, 2003.
Chi-Cheng Lin, Winona State University CS430 Computer Graphics Graphics Programming and OpenGL.
Drawing Basic Graphics Primitives Lecture 4 Wed, Sep 3, 2003.
Introduction to OpenGL and GLUT GLUT. What is OpenGL? An application programming interface (API) A (low-level) Graphics rendering API Generate high-quality.
Geometric Primitives Used in Open GL Polygons Polygon is : Flat shape with three or more straight sides. It could be either : convex or concave.
Computer Graphics using OpenGL, 3 rd Edition F. S. Hill, Jr. and S. Kelley Chapter 2 Initial Steps in Drawing Figures Ureerat Suksawatchon Faculty of Informatics.
Graphics Systems and OpenGL. Business of Generating Images Images are made up of pixels.
1 Figures are extracted from Angel's book (ISBN x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole.
Introduction to GL Geb Thomas. Example Code int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode ( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Programming with OpenGL Review.
Introduction to OpenGL and GLUT. What’s OpenGL? An Application Programming Interface (API) A low-level graphics programming API – Contains over 250 functions.
On to OpenGL Introduction to Computer Graphics and Animation (Principle of Computer Graphics) Rattapoom Waranusast.
Draw a Simple Object. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture blending.
NoufNaief.net TA: Nouf Al-harbi.
NoufNaief.net 1 TA: Nouf Al-Harbi.
Doç. Dr. Cemil Öz SAÜ Bilgisayar Mühendisliği Dr. Cemil Öz.
Geometric Primitives Used in Open GL Drawing Triangles glBegin(GL_TRIANGELS); glVertex2i(p0); glVertex2i(p1); glVertex2i(p2); glVertex2i(p3); glVertex2i(p4);
OpenGL Basic Drawing 2003 Spring Keng Shih-Ling
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 2: Introduction.
OpenGL Basic Drawing Jian-Liang Lin A Smidgen of OpenGL Code #include main() { InitializeAWindowPlease(); glClearColor (0.0, 0.0, 0.0, 0.0); glClear.
2002 by Jim X. Chen: Drawing Geometric Models.1. Objectives –OpenGL drawing primitives and attributes –OpenGL polygon face.
Introduction to OpenGL Muhammad Aamir Khan Lecturer, DCS, UOP.
Introduction to Graphics Programming. Graphics API.
Graphics Graphics Korea University kucg.korea.ac.kr Graphics Programming 고려대학교 컴퓨터 그래픽스 연구실.
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
OpenGL CS418 Computer Graphics John C. Hart. OpenGL: Event-driven How in OpenGL? Programmer registers callback functions Callback function called when.
INTRODUCTION TO OPENGL
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Computer Graphics -practical- Lecture 6. (visual c++) open gl library To use open GL with VC++ we add these files:- 1)Glut.h C:\program files\ Microsoft.
CS 480/680 Computer Graphics Programming with Open GL Part 2: Complete Programs Dr. Frederick C Harris, Jr. Fall 2011.
Program Studi S-1 Teknik Informatika FMIPA Universitas Padjadjaran
CSC Graphics Programming
The Human Visual System vs The Pinhole camera
CS380 Lab Spring Myungbae Son.
Programming with OpenGL Part 2: Complete Programs
Materi Anatomi OpenGL Fungsi GLUT Posisi Kamera Proyeksi
OpenGL API 2D Graphic Primitives
Programming with OpenGL Part 2: Complete Programs
OpenGL (Open Graphics Library) Mr. B.A.Swamy Assistant Professor Dept of CSE.
Lab 3 Geometric Drawing Lab 3 Geometric Drawing.
Class 1: First Program.
גרפיקה ממוחשבת: מבוא ל-OpenGL
Rendering Pipeline, OpenGL/GLUT
Drawing in the plane 455.
Introduction to OpenGL
drawing curved surfaces
OpenGL program.
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Starting to draw dealing with Windows which libraries? clipping
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Presentation transcript:

Starting to draw dealing with Windows which libraries? clipping program organization color geometric primitives curved objects

May be needed for some Windows Ok for all – check with class. In main, replace glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); with glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); At the end of display, replace glFlush(); with glutSwapBuffers(); note glut vs gl

First edition includes # include <iostream> # ifdef __APPLE__ # include <GLUT/glut.h> # else # include <GL/glut.h> # endif

Second edition includes #ifdef __APPLE__ # include <GL/glew.h> # include <GL/freeglut.h> # include <OpenGL/glext.h> #else # include <GL/glext.h> #pragma comment(lib, "glew32.lib") #endif

2nd edition (openGL4.3) requires other modifications of code we won't be doing yet – stick to first edition examples. Also for homework – I will not be using glew or freeglut.

square. cpp Add it to your project and get it running square.cpp Add it to your project and get it running. Make a triangle as below. glBegin(GL_POLYGON); glVertex3f(20.0, 20.0,0); glVertex3f(80.0, 20.0, 0.0); glVertex3f(80.0, 80.0, 0.0); glEnd(); square2.cpp part YYY partially outside the box in z direction. part ZZZ partially outside the box

square.cpp with clipping Modify the z value of the first vertex glBegin(GL_POLYGON); glVertex3f(20.0, 20.0,10); glVertex3f(80.0, 20.0, 0.0); glVertex3f(80.0, 80.0, 0.0); glEnd(); square2.cpp part YYY partially outside the box in z direction. part ZZZ partially outside the box

square.cpp with clipping glBegin(GL_POLYGON); glVertex3f(20.0, 20.0,10); glVertex3f(80.0, 20.0, 0.0); glVertex3f(80.0, 80.0, 0.0); glEnd(); square2.cpp part YYY partially outside the box in z direction. part ZZZ partially outside the box

Understanding the program organization: main // Main routine: defines window properties, creates window, // registers callback routines and begins processing. int main(int argc, char **argv) { // Initialize GLUT. glutInit(&argc, argv); // Set display mode as single-buffered and RGB color. glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); // Set OpenGL window size. glutInitWindowSize(500, 500); // Set position of OpenGL window upper-left corner. glutInitWindowPosition(100, 100); // Create OpenGL window with title. glutCreateWindow("square.cpp"); notice glut prefix

Modify the window title – square.cpp with modifications or something.

main (cont) // Initialize. setup(); // Register display routine. glutDisplayFunc(drawScene); // Register reshape routine. glutReshapeFunc(resize); // Register keyboard routine. glutKeyboardFunc(keyInput); // Begin processing. glutMainLoop(); return 0; } note functions without glut prefix

Add print statements to see which functions are being called. Add these lines at the top of the appropriate functions, then run. Resize window – what happens? cout << "In drawScene" << endl; cout << "In resize" << endl; cout << "In setup" << endl; cout << "In keyInput" << endl;

void setup(void); // Initialization routine. void setup(void) { // Set background (or clearing) color. glClearColor(1.0, 1.0, 1.0, 0.0); }

void drawScene(void); // Drawing (display) routine. void drawScene(void) { // Clear screen to background color. glClear(GL_COLOR_BUFFER_BIT); // Set foreground (or drawing) color. glColor3f(0.0, 0.0, 0.0);

void drawScene(void); (cont) // Draw a polygon with specified vertices. glBegin(GL_POLYGON); glVertex3f(20.0, 20.0, 0.0); glVertex3f(80.0, 20.0, 0.0); glVertex3f(80.0, 80.0, 0.0); glVertex3f(20.0, 80.0, 0.0); glEnd(); // Flush created objects to the screen, i.e., force rendering. glFlush(); }

other functions Deal with someone changing the size of the window. void resize(int w, int h); Keyboard input processing routine. void keyInput(unsigned char key, int x, int y);

Color Sensitive Cones Credit: Ron Nave

Color in OpenGL glColor3f(red, green, blue) arguments between 0 and 1

state variables glColor3f(red,green,blue); drawing color glClearColor(red, green, blue, 0.0); background color glClear(GL_COLOR_BUFFER_BIT); Sets every pixel to background color. Remove and see what happens!

Modify square: Another rectangle of a different color. Immediate mode graphics - objects are drawn and forgotten! squareV2.cpp part 1 first do part 0 – old square

Modify square: Different vertices different colors Colors bound to vertices of a primitive are interpolated throughout the interior. squareV2.cpp part 2 Discuss importance to shading

OpenGL Geometric Primitives

More OpenGL Geometric Primitives

Try some of these primitives in square.cpp May want to add: glPointSize(3.0); to make the points bigger glLineWidth(4.0): to make the lines thicker

filled in or outlines glPolygonMode(face, mode) face can be GL_FRONT GL_BACK GL_FRONT_AND_BACK mode can be GL_FILL GL_LINE GL_POINT

Try several triangles, various ways. Can do GL_TRIANGLES GL_TRIANGLE_STRIP To see triangles can use glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); To see filled in and edges, draw twice: filled in, change color, then outlines. squareV2.cpp part 3, triangle strips. squareV2.cpp part 4 added to part 3. Notice Part 4 is above part 3. Part 5 is fan Switch from FRONT_AND_BACK to two statements, one FRONT, one BACK to see if seeing front or back!

Beware of convexity! Try convexity Example.

Curved Objects Run the program circle.cpp. Observe instructions in comment and console screen global variables new version of color: glColor3ub use of rand() glutPostRedisplay in keyInput circle.cpp add as source to SquareForClass2

parametric equation of circle