Monday, March 8, 2021

مرجع للرسم بالحاسب Computer Graphics


موقع مرجع للرسم بالحاسب 



Introduction

  1. Applications of Computer Graphics
  2. Computer Graphics and Image Processing
    The fields of computer graphics and image procesing are blending together more each year.
  3. Computer Graphics -- create pictures and images, synthesize them on the basis of some description, or model in a computer
  4. Image Processing -- improve or alter images that were created elsewhere
     

  5. Art, Entertainment, and publishing
    movie production, animation, special effects

    browsing on the World Wide Web
    slide, book, and magazine design

  6. Video Games
    latest computer graphics technologies are rapidly incorporated into latest video games

     
    Warcraft Halo 3
  7. Monitoring a Process



  8. Displaying Simulations
    e.g. virtual reality


  9. Computer-aided Design
    e.g. Computer-aided Architectural Design, Electrical Circuit Design

  10. Scientific Analysis and Visualization
    presenting scientific information in the right way let you gain new insights into the investigating process

  11. Eduction Animation

  12. Digital shape sampling and processing (DSSP)
    DSSP describes the ability to use scanning hardware and processing software to digitally capture physical objects and automatically create accurate 3D models with associated structural properties for design, engineering, inspection and custom manufacturing. What digital signal processing (DSP) is to audio, DSSP is to 3D geometry.

    A Perceptron laser scanner scanned the original fan blade, and generated a point cloud with around 2.2 million points that was brought into DSSP software.

    DSSP software was used to automatically generate a NURBS surface model, which could be imported into Pro/ENGINEER software.

    see http://www.geomagic.com/en

  13. Video Compression
      MPEG-4 Visual specifies support for animated face and body models within the Simple Face Animation and simple FBA ( Face and Body A nimation )

      a face model described by Facial Definition Parameters ( FDPs ) and animated using Facial Animation Parameters ( FAPs ).
      body is described by body animation parameters ( BAP )

      See also http://coven.lancs.ac.uk/mpeg4/


  14. What is OpenGL?
  15. Application programming interface ( API )
    a collection of routines that the programmer can call, along with a model of how the routines work together to produce graphics
    250 distinct commands ( about 200 core, 50 utility )  

  16. Device-independent graphics programming
    • produce nearly identical outputs in various hardware platforms
    • no user-input commands in core
    • no high-level commands for 3-D objects, one must build model from primitives -- points, lines, and polygons
    • OpenGL Utility Library ( GLU ) provides many modeling features,

  17. Basics of OpenGL Code
  18. Rendering -- the process by which a computer creates images from models.
  19. Models or objects are constructed from geometric primitives such as points, lines, polylines, polygons which are defined by one or more vertices.
  20. Functions calls between glBegin() and glEnd()
  21. Example -- drawing 3 points
    glBegin( GL_POINTS );
    glVertex2i( 100, 40 );
    glVertex2i( 120, 50 );
    glEnd();
    glVertex2i( 140, 80 );
    glVertex2i(...)
    gl
    gl
    library  
    Vertex
    basic
    command  
    2
    number of
    arguments  
    i
    type of
    arguments  

  22. Data Types:
    Suffix   Data TypeCorresponding  
    C type
    OpenGL Type  
    Deinfition
    b8-bit Integersigned charGLbyte
    s16-bit IntegershortGLshort
    i32-bit Integerint or longGLint, GLsizei
    f32-bit Floating-pointfloatGLfloat, GLclampf
    d64-bit IntegerdoubleGLdouble, GLclampd
    ub8-bit Unsigned Integerunsigned charGLubyte, GLboolean
    us16-bit Unsigned Integersigned shortGLushort
    ui32-bit Unsigned Integer   unsigned int or
    unsigned long
    GLuint, GLenum, GLbitfield
      glVertex2i ( 7, 11 );
      glVertex2f ( 7.0, 11.0 );
      are the same

  23. Number of Arguments: 2, 3, 4

  24. Formats:
    • 'v' indicates vector format
    • absence of 'v' indicates scalar format
    • Example:
      glColor3f( 1.0, 0.0, 0.0 );

      GLfloat color_array[] = {1.0, 0.0, 0.0};
      glColor3fv( color_array );

  25. The Event Loop
    • OpenGL programs often run in an event loop.
    • After initialization, the program falls into an infinite loop accepting and handling events, such as displaying, mouse movement, window reshaping ..

  26. OpenGL as a State Machine
    • OpenGL can be viewed as a state machine.
    • state variables: color, line width, line stipple pattern, shading method, object positions ...
    • On-Off state variables
      can be set to GL_FALSE ( off ) or GL_TRUE ( on )
      glEnable ( .. ),       glDisable( .. )
      GL_LINE_SMOOTH -- if enabled draw lines with correct filtering, otherwise draw lines with aliasing
    • Mode state variables
      require command specific to the state variable in order to change it
      e.g. glShadeModel ( GL_SMOOTH ) -- smooth shading
          glShadeModel ( GL_FLAT ) -- flat shading ( default )
    • Value state variables
      require command specific to the state variable in order to change it
      e.g. glColor3f( 0.5, 0.5, 0.5 )

    • Query current state
      At any point, the programmer can query the system for any variable's current value. Typically, one of the four following commands is used glGetBooleanv(), glGetDoublev(), glGetFloatv(), or glGetIntegerv()
    • Save current state in stack
      A collection of state variables can be saved on an attribute stack.
      glPushAttrib()
      glPopAttrib()

  27. Demo Programs
    • Simple Drawing
      //draw.cpp : demo program for drawing 3 dots, two lines, ploylines, rectangles
      #include <GL/glut.h>
      
      //initialization
      void init( void )
      {
        glClearColor( 1.0, 1.0, 1.0, 0.0 );	//get white background color
        glColor3f( 0.0f, 0.0f, 0.0f );	//set drawing color
        glPointSize( 4.0 );			//a dot is 4x4
        glMatrixMode( GL_PROJECTION );	//subsequent calls affect projection matrices
        glLoadIdentity();			//replace current matrix with identity matrix
        gluOrtho2D( 0.0, 500.0, 0.0, 500.0 );
      }
      
      void display( void )
      {
        glClear( GL_COLOR_BUFFER_BIT );	//clear screen
        glBegin( GL_POINTS );			//draw points
          glVertex2i( 100, 50 );		//draw a point
          glVertex2i( 100, 150 );		//draw a point
          glVertex2i( 200, 200 );		//draw a point
        glEnd();
        glBegin( GL_LINES );			//draw lines
          glVertex2i( 20, 20 );		//horizontal line
          glVertex2i( 400, 20 );
          glVertex2i( 20, 10 );		//vertical line
          glVertex2i( 20, 400 );
        glEnd();
        glBegin( GL_LINE_STRIP );		//draw polyline
          glVertex2i( 200, 100 );
          glVertex2i( 300, 100 );
          glVertex2i( 450, 200 );
          glVertex2i( 200, 100 );
        glEnd();
        glColor3f( 0.6, 0.6, 0.6 );		//bright grey
        glRecti( 400, 400, 450, 480 );
        glColor3f( 1.0, 0.0, 0.0 );		//red
        glRecti( 350, 350, 380, 390 );
      
        glFlush();				//send all output to screen
      }
      ------------------------------------------------------------------------------
      
      //draw_main.cpp: main loop of drawing program
      
      #include <GL/glut.h>
      #include <math.h>
      #include <stdlib.h>
      #include <stdio.h>
      
      //initialization
      void init(void);
      //does the drawing 
      void display(void);
      
      /*  Main Loop
       *  Open window with initial window size, title bar, 
       *  RGBA display mode, depth buffer.
       */
      int main(int argc, char** argv)
      {
        glutInit(&argc, argv);	//initialize toolkit
        glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB );	//set display mode: single bufferring, RGBA model
        glutInitWindowSize(500, 500);		//set window size on screen
        glutInitWindowPosition( 100, 150 ); 	//set window position on screen
        glutCreateWindow(argv[0]);		//open screen window
        init();
        glutDisplayFunc (display);		//points to display function
        glutMainLoop();			//go into perpetual loop
        return 0;
      }


      -------------------------------
      How to Install Dev-C++ and the GLUT Libraries for Compiling OpenGL Programs with ANSI C

No comments:

Post a Comment