OpenGL program.

Slides:



Advertisements
Similar presentations
Coordinate System.
Advertisements

© 2004, Tom Duff and George Ledin Jr1 Lectures OpenGL Introduction By Tom Duff Pixar Animation Studios Emeryville, California and George Ledin Jr Sonoma.
Computer Graphics using OpenGL, 3 rd Edition F. S. Hill, Jr. and S. Kelley Chapter 3 Additional Drawing Tools Ureerat Suksawatchon Department of Computer.
Informationsteknologi Monday, November 12, 2007Computer Graphics - Class 71 Today’s class Viewing transformation Menus Mandelbrot set and pixel drawing.
OpenGL (Graphics Library) Software Interface to graphics software Allows to create interactive programs that produce color images of moving 3D objects.
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,
Sierpinski Gasket Program
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. [
CAP 4703 Computer Graphic Methods Prof. Roy Levow Lecture 2.
Using Graphics Libraries Lecture 3 Mon, Sep 1, 2003.
3D coordinate systems X Y Z Right-Hand Coordinate System X Y Z Left-Hand Coordinate System OpenGL uses this! Direct3D uses this!
COS 397 Computer Graphics Assoc. Prof. Svetla Boytcheva AUBG 2013 COS 397 Computer Graphics Practical Session №1 Introduction to OpenGL, GLFW and CG.
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.
Computer Graphics, KKU. Lecture 131 Transformation and Viewing in OpenGL.
CSE 470: Computer Graphics. 10/15/ Defining a Vertex A 2D vertex: glVertex2f(GLfloat x, GLfloat y); 2D vertexfloating pointopenGL parameter type.
Graphics Systems and OpenGL. Business of Generating Images Images are made up of pixels.
Computer Graphics CS 385 January 31, Fractals Some definitions Object which is self-similar at all scales. Regardless of scale the same level of.
Homogeneous Form, Introduction to 3-D Graphics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 20,
Introduction to GL Geb Thomas. Example Code int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode ( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
DREAM PLAN IDEA IMPLEMENTATION Introduction to Computer Graphics Dr. Kourosh Kiani
Modeling with OpenGL Practice with OpenGL transformations.
2D Coordinate Systems and Drawing
Intro to OpenGL (Version 2) Geb Thomas. Setting Up GLUT You will need GLUT for opening windows We can use the version made by Nate Robins: –
Chun-Yuan Lin Introduction to OpenGL 2015/12/19 1 CG.
Projections. Viewports Windows can have separate viewports void glViewport(GLint x, GLint y, GLsizei width, GLsizei height ) x, y - Specify the lower.
Introduction to OpenGL & HW1 Announcement 劉軒銘, 網媒所 碩二 ICG 2012 Fall.
Color spaces. Draw Buffers Color models. Mathmatical Protocols for defining colors with numbers  RGB Red, Green, Blue  HSV Hue, Saturation, Value(Brightness)‏
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);
Drawing and Coordinate Systems. Coordinate Systems Screen Coordinate system World Coordinate system World window Viewport Window to viewport mapping.
Lecture 2 Review OpenGL Libraries Graphics Overview Rendering Pipeline OpenGL command structure.
CS552: Computer Graphics Lecture 6: Viewing in 2D.
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 15 Creating 3D Models.
CS559: Computer Graphics Lecture 12: OpenGL - Transformation Li Zhang Spring 2008.
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 2: Introduction.
CS559: Computer Graphics Lecture 12: OpenGL: ModelView Li Zhang Spring 2010.
OpenGL: Introduction #include main() { OpenWindow() ; glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0,
Introduction to OpenGL Muhammad Aamir Khan Lecturer, DCS, UOP.
1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 17 Animations, Loops.
Graphics Graphics Korea University kucg.korea.ac.kr Graphics Programming 고려대학교 컴퓨터 그래픽스 연구실.
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
Computer Graphics Lecture 41 Viewing Using OpenGL Taqdees A. Siddiqi
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.
Computer Graphics Lecture 34. OpenGL Programming II Taqdees A. Siddiqi
Program Studi S-1 Teknik Informatika FMIPA Universitas Padjadjaran
Programming with OpenGL Part 2: Complete Programs
Materi Anatomi OpenGL Fungsi GLUT Posisi Kamera Proyeksi
OpenGL API 2D Graphic Primitives
Advanced Graphics Algorithms Ying Zhu Georgia State University
Programming with OpenGL Part 2: Complete Programs
OpenGL (Open Graphics Library) Mr. B.A.Swamy Assistant Professor Dept of CSE.
Basic Graphics Drawing Shapes 1.
Lab 3 Geometric Drawing Lab 3 Geometric Drawing.
Starting to draw dealing with Windows which libraries? clipping
גרפיקה ממוחשבת: מבוא ל-OpenGL
Coordinate Systems and Transforming the Coordinates
Drawing in the plane 455.
Introduction to OpenGL
Line and Curve Drawing Algorithms
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
Presentation transcript:

OpenGL program

2D Drawing in opengl 2D means no depth! We should also turn off the depth buffer. glDisable(GL_DEPTH_TEST)

2D drawing principles 2D drawing in OpenGL is much like 3D drawing. We first clear the screen: glClear(GL_COLOR_BUFFER_BIT) We then draw our graphics primatives (GL_QUADS, GL_TRIANGLES, GL_LINES etc), with standard glBegin()..glEnd() blocks. (We typically use the glVertex2f instruction to specify the vertices instead of glVertex3f.) We can use all the standard OpenGL transformations if we want to (glTranslate, glScale, glRotate etc). When we've finished rendering the scene, we display it with SwapBuffers()

2D drawing principles To draw a single point glBegin(GL_POINTS) glVertex2f(x1, y1) glEnd() To draw a line glBegin(GL_LINES) glVertex2f(x1, y1): glVertex2f(x2, y2)

2D drawing principles To draw a square or rectangle Filled in: glBegin(GL_QUADS) glVertex2f(x1, y1): glVertex2f(x2, y1): glVertex2f(x2, y2): glVertex2f(x1, y2) glEnd()

2D drawing principles ‍To draw in different colours glColor3f(red, green, blue) To set the background colour glClearColor(red, green, blue, 0) Add this line before the glClear(GL_COLOR_BUFFER_BIT) line.

OpenGL program structure any OpenGL program should have the following structure: Initialization function: this function will initialize the environment of OpenGL to be ready for drawing shapes, this function will be called only once in the beginning of running the program.

OpenGL program structure Resize function: will be used to reset the OpenGL window to the desired parameters. This function will be activated whenever you resize your window. Display function: This function is responsible for rendering the OpenGL scene; this function will be repeated endlessly as long as the program is running.

OpenGL program structure Main function: this function contains instructions for creating the OpenGL window and looping for ever. The loop can be controlled by a timer function This can be shown by the following code segment

OpenGL program structure void init(void) { //initialization code will be written here } void resize (int width, int height) //resizing window code will be written here void display(void) //rendering the scene int main(int argc, char* argv[]) //The body of the program return 0;

Drawing simple shapes In this lesson will be focused on 2D applications, in the next lessons we will show how to draw objects in 3D environments. We will show what will be included in the above explained functions.

Drawing simple shapes Initialization: In this function we will set the background color of the window to black, you can select any color you want. void init(void) { glClearColor (0.0, 0.0, 0.0, 0.0); } glClearColor is the function which sets the window’s background color.

Drawing simple shapes Resizing: when the user wants to change the window size, specified calculations should be calculated. The aspect ratio should be changed due to the change in the window size void resize (int w, int h) { glViewport (0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode (GL_PROJECTION); glLoadIdentity (); gluOrtho2D (0, w, 0, h); glMatrixMode (GL_MODELVIEW); }

Drawing simple shapes glViewport is the function to specify the portion of the window which will display the OpenGL scene. In our example we selected the whole window to be our view port. The work of the glViewport can be shown in Fig. 1

glViewport with respect to the graphics window

Drawing simple shapes The functions glMatrixmode, glLoadIdentity, and gluOrtho2D define an orthogonal projection to be used to map the contents of the rectangular area (2D) of the world coordinate to the screen. And the range of x-coordinates will be from 0 to w (width) and y-coordinates from 0 to h (height). The origin will be at the lower left corner of the window. Anything in the real world will range from 0 to w and 0 to h will lie inside the window and will be displayed, anything drawn outside this range will not displayed in the window.

Drawing simple shapes Displaying: In this step we need to draw simple shapes, we are going to draw simple line and triangle. As we said in the resizing step, we need to define coordinates inside the range w, h so we will be able to display the object inside the window or the view-port.

void display(void) { glClear(GL_COLOR_BUFFER_BIT ); glLoadIdentity(); glBegin(GL_LINES); glVertex2i(180,15); glVertex2i(10,145); glEnd(); glBegin(GL_TRIANGLES); glVertex2i(200,200); glVertex2i(100,75); glVertex2i(250,100); glutSwapBuffers(); }