SlideShare una empresa de Scribd logo
1 de 48
Descargar para leer sin conexión
Simple OpenGL
Program (point & line)
       Chen Jing-Fung (2006/11/13)
        Assistant Research Fellow,
           Digital Media Center,
     National Taiwan Normal University




                           National Taiwan Normal University
Displayers
• CRT & Flat-panel Display




           http://www.plasmadepot.com/plasmatv/plasmatv101.html
                                                        2
CRT
            (Cathode ray tube)
      • Cutaway rendering of a color CRT

                                                  Display Mask
                                  Anode connection             Phospfor layer
                            Deflection coils
                         Focusing coils
                  Electron beams
                  Electron guns
                                                                  Close-up of the
                                                                  Phospfor layer




                                                                            3
http://en.wikipedia.org/wiki/Cathode_ray_tube
TFT LCD (Thin Film Transistor
    Liquid Crystal Display)
     • TFT LCD has a sandwich-like structure
       with liquid crystal filled between two glass
       plates.




                                                      4
http://www.plasma.com/classroom/what_is_tft_lcd.htm
PDP
      (Plasma Display Panel)
     • A plasma TV is sometimes called an "emissive"
       display — the panel is actually self-lighting.

     • The display consists of two transparent glass
       panels with a thin layer of pixels sandwiched in
       between.




                                                          5
http://www.plasmadepot.com/plasmatv/howplasmaworks.html
What is different?
• CRT
  – Electrostatic deflection of the electron
    beam
• LCD
  – Back light module
• PDP
  – Tiny colored fluorescent lights




                                               6
DIY your projector

                                                           USD$200




       Cutaway rendering of the projector              Fresnel Lens



                                                                       Conventional
                                                                       Lens



               5.5’’ LCD + VCD
               player = $169 USD                      http://en.wikipedia.org   7
http://www.audiovisualizers.com/madlab/lcd_proj.htm
Basic video-controller
 refresh operations
                                  Horizontal and Vertical
    Raster-Scan Generator         Deflection Voltage




    x Register   y Register



      Memory Address             Pixel Register   Intensity




                  Frame Buffer

                                                              8
Frame Buffer
• Cartesian reference frame with
  origin at the lower-left corner of a
  video monitor

                     y




                                x


                                         9
Coordinate
                    representations
                           Viewing & Projection
                               Coordinates

                                  1       1
    Modeling                                   1    Video Monitor
(local or master)
   Coordinates
                                                      Plotter
                      World           Normalized
                    (Cartesian)       Coordinates
                    Coordinates
                                                    Other Output

                                                       Device
                                                     Coordinates
                                                                    10
• Coordinates:
  – Modeling (m), World (w), Viewing (v),
    Projection (p), Normalized (n), Device (d)

    • (xmc, ymc, zmc) -> (xwc, ywc, zwc) -> (xvc, yvc, zvc)
      -> (xpc, ypc, zpc) -> (xnc, ync, znc) -> (xdc, ydc)




                                                              11
Graphs system
 • User program, Graphics system, I/O
   devices

          Function calls              Output

  User                     Graphics
                                               I/O devices
program                     system
              Data                    Input




                                                       12
Application Programming
Interface (API) Functions

• Divide API functions into seven
  groups:
  –   Primitive functions
  –   Attribute functions
  –   Transformation functions
  –   Viewing functions
  –   Input functions
  –   Control functions

                                    13
Primitive & Attribute

• Primitive functions - graphics output
  primitives
  – Character strings & geometric entities
     • Points, lines, areas and shapes (2D, 3D)
• Attribute functions - Properties of the
  output primitives
  – Describe how a particular primitive is to be
    displayed
     • Color specifications, line styles, text styles and area-
       filling patterns …

                                                              14
Viewing
• Select a view of the scene -> type of
  projection -> location on monitor
• Other routines:
  – Managing the scene display area
    • Specifying its position, size and structure
    • Identified visible objects and applied
      lighting conditions (3D)




                                                    15
Software standards - GL
 • Graphics Library (GL)
   a widely used package in the graphics community
    – Goal: fast, real-time rendering and package was being
      extended to other hardware systems.
    – International Standard Organization (ISO)
       • Graphical kernel system (GKS) 1984
           – 2D & 3D
       • Programmer’s Hierarchical Interactive Graphics Standard
         (PHICS)
           – Increase: object modeling, color specification, surface
             rendering…
           – PHICS+ (3D)




                                                                       16
Software standards -
      OpenGL

• OpenGL : a hardware-independent
  version of GL in the early 1990s.
• The graphics package is maintained
  and updated by OpenGL Architecture
  Review Board.
• Language binding
  – C and C++


                                   17
Other Graphics Packages
• Graphics libraries
  –   Java 2D (Java applets)
  –   Java 3D
  –   Mathematica
  –   Matlab
  –   Maple…




                               18
Introduction to OpenGL
• Overview OpenGL based on VC++
  – http://dev.yesky.com/424/2080424.shtml
• Basic OpenGL Syntax
  – Function names in OpenGL basic Library
     • Ex: glBegin, glClear, glCopyPixels…
  – Arguments in Function (interval: _ )
     • Ex: GL_2D, GL_RGB, GL_POLYGON…
  – Specific data types
     • Ex: GLbyte, GLshort, Glint…




                                             19
OpenGL –
    Related Libraries
• GL: basic core library (prefix: gl)
• OpenGL Utility (GLU): (prefix: glu)
  – Setting up viewing and projection matrices
  – describing complex objects with line and
    polygon
  – Displaying quadrics and B-splines
  – Processing the surface-rendering operations
  – Other complex tasks



                                                  20
OpenGL-
      Display window
• OpenGL Extension:
  – X Window System (GLX) - Prefix: plX
  – Apple GL (AGL) - Prefix: agl
  – Microsoft Windows system (WGL) -
    Prefix: wgl
  – IBM OS/2 (Presentation Manager to
    OpenGL: PGL) - Prefix: pgl



                                          21
OpenGL Utility Toolkit
      (GLUT)
– Provide a library of functions for
  interacting with any screen-windowing
  system.
  • Prefix: glut
  • Contain: describing and rendering quadric
    curves and surfaces
  • Download: (glut-3.7.6-bin.zip ~117 KB)
    http://www.xmission.com/~nate/glut.html



                                                22
How to Use GLUT?

• Put 3 files from ``glut-3.7.6-bin.zip’’
  in your project directory.
  – README-win32.txt
     • glut32.dll to %WinDir%System
     • glut32.lib to $(MSDevDir)....VC98lib
     • glut.h to $(MSDevDir)....VC98includeGL




                                                23
Setup for a OpenGL
        Program 1/5
• Microsoft Visual C++ 6.0
  – Step 1: create a Win32 Console Application project




                                                   24
Setup for a OpenGL
     Program 2/5
– Step 2:Press Alt-F7 project -> settings...->Link
– Step 3:add opengl32.lib glu32.lib glut32.lib
  into Object/library modules




                                                 25
Setup for a OpenGL
        Program 3/5
• Microsoft Visual C++ .Net
  – Step 1:create Win32 console project




                                          26
Setup for a OpenGL
    Program 4/5
– Step 2: select ―empty project‖




                                   27
Setup for a OpenGL
    Program 5/5
– Step 3:select project->property…->linker ->
  input
– Step 4: add opengl32.lib glu32.lib glut32.lib




                                                  28
Header Files             2/1

• Include the header file the OpenGL
  core library
  – #include <windows.h>
    • With Microsoft Windows
  – #include <GL/gl.h>
    • Basic core library
  – #include <GL/glu.h>
    • Object-oriented toolkit & 3D application




                                                 29
Header Files                   2/2

• Use GLUT to handle the window-managing
  operations.
  – #include <GL/glut.h>
     • gl.h, glu.h (redundant and could affect program
       portability)
• Need to include c++ code
  – #include <stdio.h> #include <stdlib.h> #include
    <math.h>…
• ISO/ANSI standard for c++
  – Include: cstdio, cstdlib and cmath


                                                         30
Display-Window
   Management Using GLUT
                           2/1
• Initialization function
   – glutInit(&argc, argv);
• Create display window (DW) and caption
   – glutCreateWindow(―An Example OpenGL Program‖);
• Assign our picture to DW – Ex: describing a line
  segment
   – glutDisplayFunc(lineSegment);
• But DW is not yet. More GLUT function -> complete
  the window-processing operations
   – glutMainLoop( ); <- the last line (check all input devices –
     mouse or keyboard)


                                                                31
Display-Window
   Management Using GLUT
                         2/2
• Top-left corner of the video display (50,100)
   – glutInitWindowPosition(50, 100);
• Display window of OpenGL: width=400 pixels and
  height= 300pixels
   – glutInitWindowSize(400, 300);           100
                                        50



                     Display window
                                                         300
                                                   400

   • A single refresh buffer & RGB mode
       – glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB)

                                                           32
A complete OpenGL
       Program 2/1
• Set background color: white
  – glClearColor(1.0, 1.0, 1.0, 0.0); <- alpha value is
    as a ``blending’’ parameter.
• Get the assigned window color displayed
  – glClear(GL_COLOR_BUFFER_BIT);
• Set object color
  – glColor3f(1.0, 0.0, 0.0);




                                                          33
A complete OpenGL
     Program 2/2
• OpenGL processes our picture (2D line)
  through the full 3D viewing operations –
  “project’’
  – glMatrixMode(GL_PROJECTION);
• Map rectangle
  – glOrtho2D(0.0, 200.0, 0.0, 150.0);
• Cartesian endpoint coordinate
  – glBegin(GL_LINES);
        glVertex2i(180, 15);
        glVertex2i(10, 145);
    glEnd();


                                             34
35
Display function

   User define




                   36
Point Specification
• OpenGL functions
  – glVertex*();<-The coordinate values
         – EX:   glBegin (GL_POINTS);
                      glVertex2iv (p1); //i: integer   y
                      glVertex2iv (p2);
                      glVertex2iv (p3);
                 glEnd ();
                                                                p2
• C++ class or structure                                   p1        p3
  – Ex: Class wcPt2D {
        Public:                    wcPt2D pointPos;                       x
                  GLfloat x, y;    pointPos.x = 120.75;
         };                        pointPos.y = 45.30;
                                   glBegin (GL_POINTS);
                                           glVertex2f (pointPos.x,
                                        pointPos.y);
                                        glEnd ();
                                                                     37
OpenGL Line functions
        glBegin (*);
             glVertex2iv (p1);
             glVertex2iv (p2);
             glVertex2iv (p3);
             glVertex2iv (p4);
             glVertex2iv (p5);
        glEnd ();
          p3                          p3                   p3

                   p1            p5         p1     p5               p1



 p2                p4            p2        p4      p2               p4
Primitive line generated     polyline generated   Closed polyline generated
 with GL_LINES               with GL_LINE_STRIP   with GL_LINE_LOOP


                                                                     38
Line-drawing algorithms
                    2/1
• A straight-line segment in a scene is
  defined by the coordinate positions for
  the endpoints of the segment.

• Line is compose of the nearest pixel
  positions along the line path between the
  two endpoints.

• Ex: point
  (10.48, 20.51)->(10,21)

                                              39
Line-drawing algorithms
                    2/2
• The Cartesian slope-intercept
  equation for a straight line
  – y=m*x+b Dy           Dx

  – slope m=(yend-y0)/(xend-x0)        yend

                                        y0
  – Intercept b=y0-m*x0
• Digital differential analyzer               x0          xend

     Dx = 1, yk+1 = yk + m Dy

     Dy = 1, xk+1 = xk + 1/m Dx
    • Steps?                    yend

    ?? Dx = -1 ? or Dy = -1 ?     yk
                                                           40
                                       xk          xend
How to a parameter
   drawing line?




          National Taiwan Normal University
Bresenham’s line algorithm
                        3/1
• Bresenham’s line is an accurate and
  efficient raster line-generating algorithm
• Use only incremental integer calculations.
• Determine at next sample point whether
  to plot.
  – The negative-slope line:
    if start point (50, 50), next point?
     • (51, 50) or (51, 49)




                                               42
Analysis Bresenham’s line
            algorithm
• The scan-conversion process:
  – Set the positive slope < 1.0 and start point (x0, y0)
  – Let the kth step in this process, therefore, the
    displayed pixel (xk, yk)
     • Next pixel (xk+1, yk) or (xk+1, yk+1)
  – The sampling position xk+1, depend on (dlow- dup)
     • The label vertical pixel separations from dlow and dup
     • Pk=Dx(dlow-dup) is the same as the sign of (dlow- dup)
         – If yk ~ line, (dlow< dup), then pk< 0
         – Next pk+1 ?                             yk+1   m
         – First parameter p0 ?                     yk
                                                                 1-m


                                                              xk+1
                                                                     43
Bresenham’s line algorithm
                        3/3(m<1.0)
• Step 1: Input left endpoint (x0, y0)
• Step 2: Set the color for frame-buffer position (x0, y0)
• Step 3: Calculate Dx, Dy, 2Dy and 2Dy-2Dx
   – If yk+1>yk, p0=2Dy-Dx, else yk+1<yk, p0=2Dy+Dx   yk+3          y = mx + b
• Step 4: The decision parameter pk+1                 yk+2
   – If pk<0 & next point is (xk+1, yk)               yk+1           y
       • pk+1= pk+2Dy                                  yk
   – Else next point is (xk+1, yk+1)                           xk xk+1 xk+2 xk+3
       • pk+1= pk+2Dy-2Dx
• Step 5: return step 4 Dx-1 times
                                            yk+1       m
                                             yk
                                                                1-m


                                                             xk+1          44
Bresenham’s line example
 • Start point: (20, 10)
 • End point: (30, 18)




                           45
Homework
• HW 1: Draw line from (30, 150) to
  (200, 10)
  – Hint : line-drawing algorithm
  – If you use one decision parameter to do,
    you will get the reward.
• HW 2: Plot the regular polygon (3, 4,
  5, cycle)


                                           46
Two important points of
      Homework
• Explain (30%)



• Program (70%)




                          47
References
• .Net Education website:
  – http://yes.nctu.edu.tw/DotNet/index.ht
    m
• Mathworld
  – http://mathworld.wolfram.com/




                                         48

Más contenido relacionado

La actualidad más candente

13th kandroid OpenGL and EGL
13th kandroid OpenGL and EGL13th kandroid OpenGL and EGL
13th kandroid OpenGL and EGL
Jungsoo Nam
 

La actualidad más candente (8)

SIGGRAPH Asia 2012 Exhibitor Talk: OpenGL 4.3 and Beyond
SIGGRAPH Asia 2012 Exhibitor Talk: OpenGL 4.3 and BeyondSIGGRAPH Asia 2012 Exhibitor Talk: OpenGL 4.3 and Beyond
SIGGRAPH Asia 2012 Exhibitor Talk: OpenGL 4.3 and Beyond
 
Implement Checkpointing for Android (ELCE2012)
Implement Checkpointing for Android (ELCE2012)Implement Checkpointing for Android (ELCE2012)
Implement Checkpointing for Android (ELCE2012)
 
Implement Checkpointing for Android
Implement Checkpointing for AndroidImplement Checkpointing for Android
Implement Checkpointing for Android
 
Android OpenGL ES Game ImageGrabber Final Report
Android OpenGL ES Game ImageGrabber Final ReportAndroid OpenGL ES Game ImageGrabber Final Report
Android OpenGL ES Game ImageGrabber Final Report
 
StateScriptingInUncharted2
StateScriptingInUncharted2StateScriptingInUncharted2
StateScriptingInUncharted2
 
13th kandroid OpenGL and EGL
13th kandroid OpenGL and EGL13th kandroid OpenGL and EGL
13th kandroid OpenGL and EGL
 
SIGGRAPH Asia 2012: GPU-accelerated Path Rendering
SIGGRAPH Asia 2012: GPU-accelerated Path RenderingSIGGRAPH Asia 2012: GPU-accelerated Path Rendering
SIGGRAPH Asia 2012: GPU-accelerated Path Rendering
 
Hardware Accelerated 2D Rendering for Android
Hardware Accelerated 2D Rendering for AndroidHardware Accelerated 2D Rendering for Android
Hardware Accelerated 2D Rendering for Android
 

Destacado

Lines and curves algorithms
Lines and curves algorithmsLines and curves algorithms
Lines and curves algorithms
Mohammad Sadiq
 
Line drawing algo.
Line drawing algo.Line drawing algo.
Line drawing algo.
Mohd Arif
 
KRUSKAL'S algorithm from chaitra
KRUSKAL'S algorithm from chaitraKRUSKAL'S algorithm from chaitra
KRUSKAL'S algorithm from chaitra
guest1f4fb3
 
Computer Graphics Practical
Computer Graphics PracticalComputer Graphics Practical
Computer Graphics Practical
Neha Sharma
 

Destacado (17)

Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...
 
Lines and curves algorithms
Lines and curves algorithmsLines and curves algorithms
Lines and curves algorithms
 
COMPUTER GRAPHICS PROJECT REPORT
COMPUTER GRAPHICS PROJECT REPORTCOMPUTER GRAPHICS PROJECT REPORT
COMPUTER GRAPHICS PROJECT REPORT
 
OpenGL Projects on SIMULATION OF WATER RIPPELS
OpenGL Projects on SIMULATION OF WATER RIPPELSOpenGL Projects on SIMULATION OF WATER RIPPELS
OpenGL Projects on SIMULATION OF WATER RIPPELS
 
Bresenham Line Drawing Algorithm
Bresenham Line Drawing AlgorithmBresenham Line Drawing Algorithm
Bresenham Line Drawing Algorithm
 
Line drawing algo.
Line drawing algo.Line drawing algo.
Line drawing algo.
 
Computer graphics
Computer graphics   Computer graphics
Computer graphics
 
CG OpenGL Shadows + Light + Texture -course 10
CG OpenGL Shadows + Light + Texture -course 10CG OpenGL Shadows + Light + Texture -course 10
CG OpenGL Shadows + Light + Texture -course 10
 
KRUSKAL'S algorithm from chaitra
KRUSKAL'S algorithm from chaitraKRUSKAL'S algorithm from chaitra
KRUSKAL'S algorithm from chaitra
 
Display types (LED, LCD, Plasma, Plotter, Virtual Reality)
Display types (LED, LCD, Plasma, Plotter, Virtual Reality)Display types (LED, LCD, Plasma, Plotter, Virtual Reality)
Display types (LED, LCD, Plasma, Plotter, Virtual Reality)
 
Computer graphics mini project on bellman-ford algorithm
Computer graphics mini project on bellman-ford algorithmComputer graphics mini project on bellman-ford algorithm
Computer graphics mini project on bellman-ford algorithm
 
Bresenham circle
Bresenham circleBresenham circle
Bresenham circle
 
Output primitives computer graphics c version
Output primitives   computer graphics c versionOutput primitives   computer graphics c version
Output primitives computer graphics c version
 
Computer Graphics Project- The Running Train
Computer Graphics Project- The Running TrainComputer Graphics Project- The Running Train
Computer Graphics Project- The Running Train
 
Computer Graphics Practical
Computer Graphics PracticalComputer Graphics Practical
Computer Graphics Practical
 
Leaky bucket algorithm
Leaky bucket algorithmLeaky bucket algorithm
Leaky bucket algorithm
 
Leaky Bucket & Tocken Bucket - Traffic shaping
Leaky Bucket & Tocken Bucket - Traffic shapingLeaky Bucket & Tocken Bucket - Traffic shaping
Leaky Bucket & Tocken Bucket - Traffic shaping
 

Similar a CG simple openGL point & line-course 2

Similar a CG simple openGL point & line-course 2 (20)

Computer graphic lecturer no 3
Computer graphic lecturer no 3Computer graphic lecturer no 3
Computer graphic lecturer no 3
 
02 direct3 d_pipeline
02 direct3 d_pipeline02 direct3 d_pipeline
02 direct3 d_pipeline
 
Gpu with cuda architecture
Gpu with cuda architectureGpu with cuda architecture
Gpu with cuda architecture
 
Developing Next-Generation Games with Stage3D (Molehill)
Developing Next-Generation Games with Stage3D (Molehill) Developing Next-Generation Games with Stage3D (Molehill)
Developing Next-Generation Games with Stage3D (Molehill)
 
CG OpneGL 2D viewing & simple animation-course 6
CG OpneGL 2D viewing & simple animation-course 6CG OpneGL 2D viewing & simple animation-course 6
CG OpneGL 2D viewing & simple animation-course 6
 
Fundamentals of Computer Graphics.pdf
Fundamentals of Computer Graphics.pdfFundamentals of Computer Graphics.pdf
Fundamentals of Computer Graphics.pdf
 
Newbie’s guide to_the_gpgpu_universe
Newbie’s guide to_the_gpgpu_universeNewbie’s guide to_the_gpgpu_universe
Newbie’s guide to_the_gpgpu_universe
 
OpenGL basics
OpenGL basicsOpenGL basics
OpenGL basics
 
Introduction of openGL
Introduction  of openGLIntroduction  of openGL
Introduction of openGL
 
Create Amazing VFX with the Visual Effect Graph
Create Amazing VFX with the Visual Effect GraphCreate Amazing VFX with the Visual Effect Graph
Create Amazing VFX with the Visual Effect Graph
 
What is OpenGL ?
What is OpenGL ?What is OpenGL ?
What is OpenGL ?
 
Java on the GPU: Where are we now?
Java on the GPU: Where are we now?Java on the GPU: Where are we now?
Java on the GPU: Where are we now?
 
Chapter-3.pdf
Chapter-3.pdfChapter-3.pdf
Chapter-3.pdf
 
The next generation of GPU APIs for Game Engines
The next generation of GPU APIs for Game EnginesThe next generation of GPU APIs for Game Engines
The next generation of GPU APIs for Game Engines
 
3 boyd direct3_d12 (1)
3 boyd direct3_d12 (1)3 boyd direct3_d12 (1)
3 boyd direct3_d12 (1)
 
Introduction to Software Defined Visualization (SDVis)
Introduction to Software Defined Visualization (SDVis)Introduction to Software Defined Visualization (SDVis)
Introduction to Software Defined Visualization (SDVis)
 
Siggraph 2016 - Vulkan and nvidia : the essentials
Siggraph 2016 - Vulkan and nvidia : the essentialsSiggraph 2016 - Vulkan and nvidia : the essentials
Siggraph 2016 - Vulkan and nvidia : the essentials
 
Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...
Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...
Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...
 
Computer graphics - Nitish Nagar
Computer graphics - Nitish NagarComputer graphics - Nitish Nagar
Computer graphics - Nitish Nagar
 
01 intro-bps-2011
01 intro-bps-201101 intro-bps-2011
01 intro-bps-2011
 

Más de fungfung Chen

CG OpenGL 3D object representations-course 8
CG OpenGL 3D object representations-course 8CG OpenGL 3D object representations-course 8
CG OpenGL 3D object representations-course 8
fungfung Chen
 

Más de fungfung Chen (20)

Tech biz patent
Tech biz patent Tech biz patent
Tech biz patent
 
Smart TV content converged service & social media
Smart TV content converged service & social mediaSmart TV content converged service & social media
Smart TV content converged service & social media
 
Tips for fulfilling patent application
Tips for fulfilling patent applicationTips for fulfilling patent application
Tips for fulfilling patent application
 
Defending your Rights
Defending your RightsDefending your Rights
Defending your Rights
 
Polishing search skills
Polishing search skillsPolishing search skills
Polishing search skills
 
Inquiry Based Approach - Patent Search
Inquiry Based Approach - Patent SearchInquiry Based Approach - Patent Search
Inquiry Based Approach - Patent Search
 
Overseas protection & patent search
Overseas protection & patent searchOverseas protection & patent search
Overseas protection & patent search
 
Patentability classification search
Patentability classification searchPatentability classification search
Patentability classification search
 
Novelty to Nonobviousness
Novelty to NonobviousnessNovelty to Nonobviousness
Novelty to Nonobviousness
 
Patentability requirement on novelty
Patentability requirement on noveltyPatentability requirement on novelty
Patentability requirement on novelty
 
2012 Smart TV - Evolution & Approaches
2012 Smart TV - Evolution & Approaches2012 Smart TV - Evolution & Approaches
2012 Smart TV - Evolution & Approaches
 
Patentability Requirements
Patentability RequirementsPatentability Requirements
Patentability Requirements
 
Working model to patentability
Working model to patentabilityWorking model to patentability
Working model to patentability
 
Evaluate your invention
Evaluate your inventionEvaluate your invention
Evaluate your invention
 
how to invention & practice it
how to invention & practice ithow to invention & practice it
how to invention & practice it
 
Digital converge - DTV service design
Digital converge - DTV service designDigital converge - DTV service design
Digital converge - DTV service design
 
Hybrid digital broadcasting methods
Hybrid digital broadcasting methodsHybrid digital broadcasting methods
Hybrid digital broadcasting methods
 
Summary the challenges of Social TV
Summary the challenges of  Social TVSummary the challenges of  Social TV
Summary the challenges of Social TV
 
CG OpenGL surface detection+illumination+rendering models-course 9
CG OpenGL surface detection+illumination+rendering models-course 9CG OpenGL surface detection+illumination+rendering models-course 9
CG OpenGL surface detection+illumination+rendering models-course 9
 
CG OpenGL 3D object representations-course 8
CG OpenGL 3D object representations-course 8CG OpenGL 3D object representations-course 8
CG OpenGL 3D object representations-course 8
 

Último

Top profile Call Girls In eluru [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In eluru [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In eluru [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In eluru [ 7014168258 ] Call Me For Genuine Models We ...
gajnagarg
 
Jual Obat Aborsi Bandung ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan ...
Jual Obat Aborsi Bandung ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan ...Jual Obat Aborsi Bandung ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan ...
Jual Obat Aborsi Bandung ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan ...
ZurliaSoop
 
How to Build a Simple Shopify Website
How to Build a Simple Shopify WebsiteHow to Build a Simple Shopify Website
How to Build a Simple Shopify Website
mark11275
 
Top profile Call Girls In Mau [ 7014168258 ] Call Me For Genuine Models We ar...
Top profile Call Girls In Mau [ 7014168258 ] Call Me For Genuine Models We ar...Top profile Call Girls In Mau [ 7014168258 ] Call Me For Genuine Models We ar...
Top profile Call Girls In Mau [ 7014168258 ] Call Me For Genuine Models We ar...
nirzagarg
 
Abortion pill for sale in Muscat (+918761049707)) Get Cytotec Cash on deliver...
Abortion pill for sale in Muscat (+918761049707)) Get Cytotec Cash on deliver...Abortion pill for sale in Muscat (+918761049707)) Get Cytotec Cash on deliver...
Abortion pill for sale in Muscat (+918761049707)) Get Cytotec Cash on deliver...
instagramfab782445
 
Design-System - FinTech - Isadora Agency
Design-System - FinTech - Isadora AgencyDesign-System - FinTech - Isadora Agency
Design-System - FinTech - Isadora Agency
Isadora Agency
 
一比一原版(WLU毕业证)罗瑞尔大学毕业证成绩单留信学历认证原版一模一样
一比一原版(WLU毕业证)罗瑞尔大学毕业证成绩单留信学历认证原版一模一样一比一原版(WLU毕业证)罗瑞尔大学毕业证成绩单留信学历认证原版一模一样
一比一原版(WLU毕业证)罗瑞尔大学毕业证成绩单留信学历认证原版一模一样
awasv46j
 
怎样办理莫纳什大学毕业证(Monash毕业证书)成绩单留信认证
怎样办理莫纳什大学毕业证(Monash毕业证书)成绩单留信认证怎样办理莫纳什大学毕业证(Monash毕业证书)成绩单留信认证
怎样办理莫纳什大学毕业证(Monash毕业证书)成绩单留信认证
ehyxf
 
Q4-Trends-Networks-Module-3.pdfqquater days sheets123456789
Q4-Trends-Networks-Module-3.pdfqquater days sheets123456789Q4-Trends-Networks-Module-3.pdfqquater days sheets123456789
Q4-Trends-Networks-Module-3.pdfqquater days sheets123456789
CristineGraceAcuyan
 
Abortion Pills in Oman (+918133066128) Cytotec clinic buy Oman Muscat
Abortion Pills in Oman (+918133066128) Cytotec clinic buy Oman MuscatAbortion Pills in Oman (+918133066128) Cytotec clinic buy Oman Muscat
Abortion Pills in Oman (+918133066128) Cytotec clinic buy Oman Muscat
Abortion pills in Kuwait Cytotec pills in Kuwait
 

Último (20)

Independent Escorts Goregaon WhatsApp +91-9930687706, Best Service
Independent Escorts Goregaon WhatsApp +91-9930687706, Best ServiceIndependent Escorts Goregaon WhatsApp +91-9930687706, Best Service
Independent Escorts Goregaon WhatsApp +91-9930687706, Best Service
 
Top profile Call Girls In eluru [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In eluru [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In eluru [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In eluru [ 7014168258 ] Call Me For Genuine Models We ...
 
Just Call Vip call girls Kasganj Escorts ☎️8617370543 Two shot with one girl ...
Just Call Vip call girls Kasganj Escorts ☎️8617370543 Two shot with one girl ...Just Call Vip call girls Kasganj Escorts ☎️8617370543 Two shot with one girl ...
Just Call Vip call girls Kasganj Escorts ☎️8617370543 Two shot with one girl ...
 
Jual Obat Aborsi Bandung ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan ...
Jual Obat Aborsi Bandung ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan ...Jual Obat Aborsi Bandung ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan ...
Jual Obat Aborsi Bandung ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan ...
 
Abortion pills in Riyadh +966572737505 <> buy cytotec <> unwanted kit Saudi A...
Abortion pills in Riyadh +966572737505 <> buy cytotec <> unwanted kit Saudi A...Abortion pills in Riyadh +966572737505 <> buy cytotec <> unwanted kit Saudi A...
Abortion pills in Riyadh +966572737505 <> buy cytotec <> unwanted kit Saudi A...
 
How to Build a Simple Shopify Website
How to Build a Simple Shopify WebsiteHow to Build a Simple Shopify Website
How to Build a Simple Shopify Website
 
Call Girls Jalaun Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Jalaun Just Call 8617370543 Top Class Call Girl Service AvailableCall Girls Jalaun Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Jalaun Just Call 8617370543 Top Class Call Girl Service Available
 
Hackathon evaluation template_latest_uploadpdf
Hackathon evaluation template_latest_uploadpdfHackathon evaluation template_latest_uploadpdf
Hackathon evaluation template_latest_uploadpdf
 
Top profile Call Girls In Mau [ 7014168258 ] Call Me For Genuine Models We ar...
Top profile Call Girls In Mau [ 7014168258 ] Call Me For Genuine Models We ar...Top profile Call Girls In Mau [ 7014168258 ] Call Me For Genuine Models We ar...
Top profile Call Girls In Mau [ 7014168258 ] Call Me For Genuine Models We ar...
 
Abortion pill for sale in Muscat (+918761049707)) Get Cytotec Cash on deliver...
Abortion pill for sale in Muscat (+918761049707)) Get Cytotec Cash on deliver...Abortion pill for sale in Muscat (+918761049707)) Get Cytotec Cash on deliver...
Abortion pill for sale in Muscat (+918761049707)) Get Cytotec Cash on deliver...
 
LANDSCAPE ARCHITECTURE PORTFOLIO - MAREK MITACEK
LANDSCAPE ARCHITECTURE PORTFOLIO - MAREK MITACEKLANDSCAPE ARCHITECTURE PORTFOLIO - MAREK MITACEK
LANDSCAPE ARCHITECTURE PORTFOLIO - MAREK MITACEK
 
How to Create a Productive Workspace Trends and Tips.pdf
How to Create a Productive Workspace Trends and Tips.pdfHow to Create a Productive Workspace Trends and Tips.pdf
How to Create a Productive Workspace Trends and Tips.pdf
 
Design-System - FinTech - Isadora Agency
Design-System - FinTech - Isadora AgencyDesign-System - FinTech - Isadora Agency
Design-System - FinTech - Isadora Agency
 
一比一原版(WLU毕业证)罗瑞尔大学毕业证成绩单留信学历认证原版一模一样
一比一原版(WLU毕业证)罗瑞尔大学毕业证成绩单留信学历认证原版一模一样一比一原版(WLU毕业证)罗瑞尔大学毕业证成绩单留信学历认证原版一模一样
一比一原版(WLU毕业证)罗瑞尔大学毕业证成绩单留信学历认证原版一模一样
 
High Profile Escorts Nerul WhatsApp +91-9930687706, Best Service
High Profile Escorts Nerul WhatsApp +91-9930687706, Best ServiceHigh Profile Escorts Nerul WhatsApp +91-9930687706, Best Service
High Profile Escorts Nerul WhatsApp +91-9930687706, Best Service
 
NO1 Top Pakistani Amil Baba Real Amil baba In Pakistan Najoomi Baba in Pakist...
NO1 Top Pakistani Amil Baba Real Amil baba In Pakistan Najoomi Baba in Pakist...NO1 Top Pakistani Amil Baba Real Amil baba In Pakistan Najoomi Baba in Pakist...
NO1 Top Pakistani Amil Baba Real Amil baba In Pakistan Najoomi Baba in Pakist...
 
怎样办理莫纳什大学毕业证(Monash毕业证书)成绩单留信认证
怎样办理莫纳什大学毕业证(Monash毕业证书)成绩单留信认证怎样办理莫纳什大学毕业证(Monash毕业证书)成绩单留信认证
怎样办理莫纳什大学毕业证(Monash毕业证书)成绩单留信认证
 
Pondicherry Escorts Service Girl ^ 9332606886, WhatsApp Anytime Pondicherry
Pondicherry Escorts Service Girl ^ 9332606886, WhatsApp Anytime PondicherryPondicherry Escorts Service Girl ^ 9332606886, WhatsApp Anytime Pondicherry
Pondicherry Escorts Service Girl ^ 9332606886, WhatsApp Anytime Pondicherry
 
Q4-Trends-Networks-Module-3.pdfqquater days sheets123456789
Q4-Trends-Networks-Module-3.pdfqquater days sheets123456789Q4-Trends-Networks-Module-3.pdfqquater days sheets123456789
Q4-Trends-Networks-Module-3.pdfqquater days sheets123456789
 
Abortion Pills in Oman (+918133066128) Cytotec clinic buy Oman Muscat
Abortion Pills in Oman (+918133066128) Cytotec clinic buy Oman MuscatAbortion Pills in Oman (+918133066128) Cytotec clinic buy Oman Muscat
Abortion Pills in Oman (+918133066128) Cytotec clinic buy Oman Muscat
 

CG simple openGL point & line-course 2

  • 1. Simple OpenGL Program (point & line) Chen Jing-Fung (2006/11/13) Assistant Research Fellow, Digital Media Center, National Taiwan Normal University National Taiwan Normal University
  • 2. Displayers • CRT & Flat-panel Display http://www.plasmadepot.com/plasmatv/plasmatv101.html 2
  • 3. CRT (Cathode ray tube) • Cutaway rendering of a color CRT Display Mask Anode connection Phospfor layer Deflection coils Focusing coils Electron beams Electron guns Close-up of the Phospfor layer 3 http://en.wikipedia.org/wiki/Cathode_ray_tube
  • 4. TFT LCD (Thin Film Transistor Liquid Crystal Display) • TFT LCD has a sandwich-like structure with liquid crystal filled between two glass plates. 4 http://www.plasma.com/classroom/what_is_tft_lcd.htm
  • 5. PDP (Plasma Display Panel) • A plasma TV is sometimes called an "emissive" display — the panel is actually self-lighting. • The display consists of two transparent glass panels with a thin layer of pixels sandwiched in between. 5 http://www.plasmadepot.com/plasmatv/howplasmaworks.html
  • 6. What is different? • CRT – Electrostatic deflection of the electron beam • LCD – Back light module • PDP – Tiny colored fluorescent lights 6
  • 7. DIY your projector USD$200 Cutaway rendering of the projector Fresnel Lens Conventional Lens 5.5’’ LCD + VCD player = $169 USD http://en.wikipedia.org 7 http://www.audiovisualizers.com/madlab/lcd_proj.htm
  • 8. Basic video-controller refresh operations Horizontal and Vertical Raster-Scan Generator Deflection Voltage x Register y Register Memory Address Pixel Register Intensity Frame Buffer 8
  • 9. Frame Buffer • Cartesian reference frame with origin at the lower-left corner of a video monitor y x 9
  • 10. Coordinate representations Viewing & Projection Coordinates 1 1 Modeling 1 Video Monitor (local or master) Coordinates Plotter World Normalized (Cartesian) Coordinates Coordinates Other Output Device Coordinates 10
  • 11. • Coordinates: – Modeling (m), World (w), Viewing (v), Projection (p), Normalized (n), Device (d) • (xmc, ymc, zmc) -> (xwc, ywc, zwc) -> (xvc, yvc, zvc) -> (xpc, ypc, zpc) -> (xnc, ync, znc) -> (xdc, ydc) 11
  • 12. Graphs system • User program, Graphics system, I/O devices Function calls Output User Graphics I/O devices program system Data Input 12
  • 13. Application Programming Interface (API) Functions • Divide API functions into seven groups: – Primitive functions – Attribute functions – Transformation functions – Viewing functions – Input functions – Control functions 13
  • 14. Primitive & Attribute • Primitive functions - graphics output primitives – Character strings & geometric entities • Points, lines, areas and shapes (2D, 3D) • Attribute functions - Properties of the output primitives – Describe how a particular primitive is to be displayed • Color specifications, line styles, text styles and area- filling patterns … 14
  • 15. Viewing • Select a view of the scene -> type of projection -> location on monitor • Other routines: – Managing the scene display area • Specifying its position, size and structure • Identified visible objects and applied lighting conditions (3D) 15
  • 16. Software standards - GL • Graphics Library (GL) a widely used package in the graphics community – Goal: fast, real-time rendering and package was being extended to other hardware systems. – International Standard Organization (ISO) • Graphical kernel system (GKS) 1984 – 2D & 3D • Programmer’s Hierarchical Interactive Graphics Standard (PHICS) – Increase: object modeling, color specification, surface rendering… – PHICS+ (3D) 16
  • 17. Software standards - OpenGL • OpenGL : a hardware-independent version of GL in the early 1990s. • The graphics package is maintained and updated by OpenGL Architecture Review Board. • Language binding – C and C++ 17
  • 18. Other Graphics Packages • Graphics libraries – Java 2D (Java applets) – Java 3D – Mathematica – Matlab – Maple… 18
  • 19. Introduction to OpenGL • Overview OpenGL based on VC++ – http://dev.yesky.com/424/2080424.shtml • Basic OpenGL Syntax – Function names in OpenGL basic Library • Ex: glBegin, glClear, glCopyPixels… – Arguments in Function (interval: _ ) • Ex: GL_2D, GL_RGB, GL_POLYGON… – Specific data types • Ex: GLbyte, GLshort, Glint… 19
  • 20. OpenGL – Related Libraries • GL: basic core library (prefix: gl) • OpenGL Utility (GLU): (prefix: glu) – Setting up viewing and projection matrices – describing complex objects with line and polygon – Displaying quadrics and B-splines – Processing the surface-rendering operations – Other complex tasks 20
  • 21. OpenGL- Display window • OpenGL Extension: – X Window System (GLX) - Prefix: plX – Apple GL (AGL) - Prefix: agl – Microsoft Windows system (WGL) - Prefix: wgl – IBM OS/2 (Presentation Manager to OpenGL: PGL) - Prefix: pgl 21
  • 22. OpenGL Utility Toolkit (GLUT) – Provide a library of functions for interacting with any screen-windowing system. • Prefix: glut • Contain: describing and rendering quadric curves and surfaces • Download: (glut-3.7.6-bin.zip ~117 KB) http://www.xmission.com/~nate/glut.html 22
  • 23. How to Use GLUT? • Put 3 files from ``glut-3.7.6-bin.zip’’ in your project directory. – README-win32.txt • glut32.dll to %WinDir%System • glut32.lib to $(MSDevDir)....VC98lib • glut.h to $(MSDevDir)....VC98includeGL 23
  • 24. Setup for a OpenGL Program 1/5 • Microsoft Visual C++ 6.0 – Step 1: create a Win32 Console Application project 24
  • 25. Setup for a OpenGL Program 2/5 – Step 2:Press Alt-F7 project -> settings...->Link – Step 3:add opengl32.lib glu32.lib glut32.lib into Object/library modules 25
  • 26. Setup for a OpenGL Program 3/5 • Microsoft Visual C++ .Net – Step 1:create Win32 console project 26
  • 27. Setup for a OpenGL Program 4/5 – Step 2: select ―empty project‖ 27
  • 28. Setup for a OpenGL Program 5/5 – Step 3:select project->property…->linker -> input – Step 4: add opengl32.lib glu32.lib glut32.lib 28
  • 29. Header Files 2/1 • Include the header file the OpenGL core library – #include <windows.h> • With Microsoft Windows – #include <GL/gl.h> • Basic core library – #include <GL/glu.h> • Object-oriented toolkit & 3D application 29
  • 30. Header Files 2/2 • Use GLUT to handle the window-managing operations. – #include <GL/glut.h> • gl.h, glu.h (redundant and could affect program portability) • Need to include c++ code – #include <stdio.h> #include <stdlib.h> #include <math.h>… • ISO/ANSI standard for c++ – Include: cstdio, cstdlib and cmath 30
  • 31. Display-Window Management Using GLUT 2/1 • Initialization function – glutInit(&argc, argv); • Create display window (DW) and caption – glutCreateWindow(―An Example OpenGL Program‖); • Assign our picture to DW – Ex: describing a line segment – glutDisplayFunc(lineSegment); • But DW is not yet. More GLUT function -> complete the window-processing operations – glutMainLoop( ); <- the last line (check all input devices – mouse or keyboard) 31
  • 32. Display-Window Management Using GLUT 2/2 • Top-left corner of the video display (50,100) – glutInitWindowPosition(50, 100); • Display window of OpenGL: width=400 pixels and height= 300pixels – glutInitWindowSize(400, 300); 100 50 Display window 300 400 • A single refresh buffer & RGB mode – glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB) 32
  • 33. A complete OpenGL Program 2/1 • Set background color: white – glClearColor(1.0, 1.0, 1.0, 0.0); <- alpha value is as a ``blending’’ parameter. • Get the assigned window color displayed – glClear(GL_COLOR_BUFFER_BIT); • Set object color – glColor3f(1.0, 0.0, 0.0); 33
  • 34. A complete OpenGL Program 2/2 • OpenGL processes our picture (2D line) through the full 3D viewing operations – “project’’ – glMatrixMode(GL_PROJECTION); • Map rectangle – glOrtho2D(0.0, 200.0, 0.0, 150.0); • Cartesian endpoint coordinate – glBegin(GL_LINES); glVertex2i(180, 15); glVertex2i(10, 145); glEnd(); 34
  • 35. 35
  • 36. Display function User define 36
  • 37. Point Specification • OpenGL functions – glVertex*();<-The coordinate values – EX: glBegin (GL_POINTS); glVertex2iv (p1); //i: integer y glVertex2iv (p2); glVertex2iv (p3); glEnd (); p2 • C++ class or structure p1 p3 – Ex: Class wcPt2D { Public: wcPt2D pointPos; x GLfloat x, y; pointPos.x = 120.75; }; pointPos.y = 45.30; glBegin (GL_POINTS); glVertex2f (pointPos.x, pointPos.y); glEnd (); 37
  • 38. OpenGL Line functions glBegin (*); glVertex2iv (p1); glVertex2iv (p2); glVertex2iv (p3); glVertex2iv (p4); glVertex2iv (p5); glEnd (); p3 p3 p3 p1 p5 p1 p5 p1 p2 p4 p2 p4 p2 p4 Primitive line generated polyline generated Closed polyline generated with GL_LINES with GL_LINE_STRIP with GL_LINE_LOOP 38
  • 39. Line-drawing algorithms 2/1 • A straight-line segment in a scene is defined by the coordinate positions for the endpoints of the segment. • Line is compose of the nearest pixel positions along the line path between the two endpoints. • Ex: point (10.48, 20.51)->(10,21) 39
  • 40. Line-drawing algorithms 2/2 • The Cartesian slope-intercept equation for a straight line – y=m*x+b Dy Dx – slope m=(yend-y0)/(xend-x0) yend y0 – Intercept b=y0-m*x0 • Digital differential analyzer x0 xend Dx = 1, yk+1 = yk + m Dy Dy = 1, xk+1 = xk + 1/m Dx • Steps? yend ?? Dx = -1 ? or Dy = -1 ? yk 40 xk xend
  • 41. How to a parameter drawing line? National Taiwan Normal University
  • 42. Bresenham’s line algorithm 3/1 • Bresenham’s line is an accurate and efficient raster line-generating algorithm • Use only incremental integer calculations. • Determine at next sample point whether to plot. – The negative-slope line: if start point (50, 50), next point? • (51, 50) or (51, 49) 42
  • 43. Analysis Bresenham’s line algorithm • The scan-conversion process: – Set the positive slope < 1.0 and start point (x0, y0) – Let the kth step in this process, therefore, the displayed pixel (xk, yk) • Next pixel (xk+1, yk) or (xk+1, yk+1) – The sampling position xk+1, depend on (dlow- dup) • The label vertical pixel separations from dlow and dup • Pk=Dx(dlow-dup) is the same as the sign of (dlow- dup) – If yk ~ line, (dlow< dup), then pk< 0 – Next pk+1 ? yk+1 m – First parameter p0 ? yk 1-m xk+1 43
  • 44. Bresenham’s line algorithm 3/3(m<1.0) • Step 1: Input left endpoint (x0, y0) • Step 2: Set the color for frame-buffer position (x0, y0) • Step 3: Calculate Dx, Dy, 2Dy and 2Dy-2Dx – If yk+1>yk, p0=2Dy-Dx, else yk+1<yk, p0=2Dy+Dx yk+3 y = mx + b • Step 4: The decision parameter pk+1 yk+2 – If pk<0 & next point is (xk+1, yk) yk+1 y • pk+1= pk+2Dy yk – Else next point is (xk+1, yk+1) xk xk+1 xk+2 xk+3 • pk+1= pk+2Dy-2Dx • Step 5: return step 4 Dx-1 times yk+1 m yk 1-m xk+1 44
  • 45. Bresenham’s line example • Start point: (20, 10) • End point: (30, 18) 45
  • 46. Homework • HW 1: Draw line from (30, 150) to (200, 10) – Hint : line-drawing algorithm – If you use one decision parameter to do, you will get the reward. • HW 2: Plot the regular polygon (3, 4, 5, cycle) 46
  • 47. Two important points of Homework • Explain (30%) • Program (70%) 47
  • 48. References • .Net Education website: – http://yes.nctu.edu.tw/DotNet/index.ht m • Mathworld – http://mathworld.wolfram.com/ 48