COMP-GRAPH.ppt

  • Upload
    gkhn-kc

  • View
    216

  • Download
    0

Embed Size (px)

Citation preview

  • 7/30/2019 COMP-GRAPH.ppt

    1/101

    COMPUTER GRAPHICS

    Assoc. Prof. Dr. Mutlu AVCI

    ukurova UniversityComputer Engineering Department

  • 7/30/2019 COMP-GRAPH.ppt

    2/101

    Contents

    Lecture 1:

    Introduction to OpenGL and OpenGLUT

    DEVC++ development environment Working window creation

    Dot drawing in the window

    Line drawing in the window

    Dashed line drawing in the window Coordinate system

    Dashed line in the coordinate system

  • 7/30/2019 COMP-GRAPH.ppt

    3/101

    Introduction

    What is OpenGL ?

    - OpenGL is a software interface to

    graphics hardware.

    - This interface consists of about 120

    distinct commands, which you use to

    specify the objects and operations needed toproduce interactive three-dimensional

    applications.

  • 7/30/2019 COMP-GRAPH.ppt

    4/101

    What are the requirements for OpenGL?

    OpenGL is designed as a streamlined,

    hardware-independent interface to beimplemented on many different hardware

    platforms.

    To achieve these qualities, no commands for

    performing windowing tasks or obtaining userinput are included in OpenGL; instead, you

    must work through whatever windowing

    system controls the particular hardware you're

    using.

  • 7/30/2019 COMP-GRAPH.ppt

    5/101

  • 7/30/2019 COMP-GRAPH.ppt

    6/101

    Development of OpenGL

    Silicon Graphics (SGI) revolutionized the

    graphics workstation by implementing thepipeline in hardware (1982)

    To access the system, application programmers

    used a library called GL

    With GL, it was relatively simple to program

    three dimensional interactive applications

  • 7/30/2019 COMP-GRAPH.ppt

    7/101

    The success of GL lead to OpenGL (1992), aplatform-independent API that was

    - Easy to use- Close enough to the hardware to get

    excellent performance

    - Focus on rendering- Omitted windowing and input to avoidwindow system dependencies

  • 7/30/2019 COMP-GRAPH.ppt

    8/101

  • 7/30/2019 COMP-GRAPH.ppt

    9/101

    What are the OpenGL core and utility libraries? OpenGL core libraries:

    - OpenGL32 on Windows (opengl32.lib)

    - GL on most unix/linux systems

    - OpenGL Utility Library (GLU) (glu32.lib)

    - Provides functionality in OpenGL core but avoidshaving to rewrite code (ie. spheres)

    - Links with window system- GLX for X window systems- WGL for Windows (windows.h)

    - AGL for Macintosh

  • 7/30/2019 COMP-GRAPH.ppt

    10/101

    OpenGL Utility Library (GLUT) (glut32.lib)

    - Provides functionality common to all windowsystems

    - Open a window- Get input from mouse and keyboard

    - Menus

    - Event-driven

    - Code is portable but GLUT lacks the functionalityof a good toolkit for a specific platform

    - Slide bars

  • 7/30/2019 COMP-GRAPH.ppt

    11/101

    OpenGL Functions

    Primitives

    - Points

    - Line Segments

    - Polygons- curves and surfaces

    Attributes

    Transformations

    - Viewing

    - Modeling Control

    Input (GLUT)

  • 7/30/2019 COMP-GRAPH.ppt

    12/101

    OpenGL is a state machine

    OpenGL functions are of two types

    - Primitive generating:

    - Can cause output if primitive is visible

    - How vertices are processed and appearanceof primitive are controlled by the state

    - State changing:

    - Transformation functionsrotate, translate,scale.

    - Attribute functionscolor, material

  • 7/30/2019 COMP-GRAPH.ppt

    13/101

    OpenGL is not object oriented so there aremultiple functions for a given logical

    functionglVertex3f

    glVertex2i

    glVertex3dvEasy to create overloaded functions in C++

    but issue is efficiency

  • 7/30/2019 COMP-GRAPH.ppt

    14/101

    OpenGL function format

  • 7/30/2019 COMP-GRAPH.ppt

    15/101

    Most constants are defined in the include files gl.h, glu.hand glut.h

    Note #include should automatically include the

    othersExamples

    glBegin(GL_POLYGON)

    glClear(GL_COLOR_BUFFER_BIT)

    often used as switches for functions include files alsodefine OpenGL data types:

    Glfloat, Gldouble,.

  • 7/30/2019 COMP-GRAPH.ppt

    16/101

  • 7/30/2019 COMP-GRAPH.ppt

    17/101

    OpenGL Programming Structure

    #include // required GL Utility library inclusion

    void mydisplay(){

    glClear(GL_COLOR_BUFFER_BIT);

    glBegin(GL_POLYGON);

    glVertex2f(-0.5, -0.5);glVertex2f(-0.5, 0.5);

    glVertex2f(0.5, 0.5);

    glVertex2f(0.5, -0.5);

    glEnd();

    glFlush();

    }

    int main(int argc, char** argv){glutCreateWindow("simple");

    glutDisplayFunc(mydisplay);

    glutMainLoop();

    }

    This kind of subroutine parts contain

    drawing properties of the specialobjects

    This main program part:

    -creates the window which will hold

    the drawings;-make adjustments of the window

    -displays objects in the window by

    calling subroutines

    -enters a loop to hold the view

  • 7/30/2019 COMP-GRAPH.ppt

    18/101

    Question

    If we write and execute an OpenGl program asshown below what happens?

    #include

    main(int argc,char** argv) {

    glutInit(&argc,argv);glutCreateWindow("yeni");

    glutMainLoop();}

  • 7/30/2019 COMP-GRAPH.ppt

    19/101

    Adjustments to overcome

    linker problems

  • 7/30/2019 COMP-GRAPH.ppt

    20/101

    Question

    What about following codes?

    #include

    void goruntu(void){

    glFlush();}

    main(int argc,char** argv) {

    glutInit(&argc,argv);

    glutCreateWindow("yeni");

    glutDisplayFunc(goruntu);glutMainLoop();

    }

  • 7/30/2019 COMP-GRAPH.ppt

    21/101

    Question

    What happens if set window position?

    #include

    void goruntu(void){

    glFlush();}

    main(int argc,char** argv) {

    glutInit(&argc,argv);

    glutInitWindowPosition(100,100);

    glutCreateWindow("yeni");glutDisplayFunc(goruntu);

    glutMainLoop();

    }

  • 7/30/2019 COMP-GRAPH.ppt

    22/101

    Question

    How can we increase size of the window?

    #include

    void goruntu(void){

    glFlush();

    }

    main(int argc,char** argv) {

    glutInit(&argc,argv);

    glutInitWindowPosition(100,100);

    glutInitWindowSize(800,800);

    glutCreateWindow("yeni");glutDisplayFunc(goruntu);

    glutMainLoop();

    }

  • 7/30/2019 COMP-GRAPH.ppt

    23/101

    Question

    How can we clear the content of the window?

    #include

    void goruntu(void){

    glClear(GL_COLOR_BUFFER_BIT);

    glFlush();}

    main(int argc,char** argv) {

    glutInit(&argc,argv);

    glutInitWindowPosition(100,100);

    glutInitWindowSize(800,800);

    glutCreateWindow("yeni");glutDisplayFunc(goruntu);

    glutMainLoop();

    }

  • 7/30/2019 COMP-GRAPH.ppt

    24/101

    Question

    If we want to have a window with red background how can we do this?

    #include

    void goruntu(void){

    glClear(GL_COLOR_BUFFER_BIT);

    glFlush();

    }main(int argc,char** argv) {

    glutInit(&argc,argv);

    glutInitWindowPosition(100,100);

    glutInitWindowSize(800,800);

    glutCreateWindow("yeni");

    glClearColor(1.0,0.0,0.0,0.0);

    glutDisplayFunc(goruntu);glutMainLoop();

    }

  • 7/30/2019 COMP-GRAPH.ppt

    25/101

    Question

    What about green background?

    #include

    void goruntu(void){

    glClear(GL_COLOR_BUFFER_BIT);

    glFlush();

    }main(int argc,char** argv) {

    glutInit(&argc,argv);

    glutInitWindowPosition(100,100);

    glutInitWindowSize(800,800);

    glutCreateWindow("yeni");

    glClearColor(0.0,1.0,0.0,0.0);

    glutDisplayFunc(goruntu);glutMainLoop();

    }

  • 7/30/2019 COMP-GRAPH.ppt

    26/101

    Question

    Blue one?

    #include

    void goruntu(void){

    glClear(GL_COLOR_BUFFER_BIT);

    glFlush();

    }main(int argc,char** argv) {

    glutInit(&argc,argv);

    glutInitWindowPosition(100,100);

    glutInitWindowSize(800,800);

    glutCreateWindow("yeni");

    glClearColor(0.0,0.0,1.0,0.0);

    glutDisplayFunc(goruntu);glutMainLoop();

    }

  • 7/30/2019 COMP-GRAPH.ppt

    27/101

    Analysis of Basic OpenGL

    Commands Lets start with analysis of main( ) part of

    the program:

    glutInit(&argc, argv);

    Initiation of the Glut routines. First parameter

    argc stands for adres of argument count and

    second parameter holds the argument valuespassing to glut routine.

  • 7/30/2019 COMP-GRAPH.ppt

    28/101

    glutInitDisplayMode(GLUT_SINGLE|

    GLUT_RGB);

    Buffer dimension and Color type of thewindow is decided.

    GLUT_SINGLE parameter shows single

    buffer memory is preferred. This selectionis done for drawing modes. In animation

    case GLUT_DOUBLE is preffered.

  • 7/30/2019 COMP-GRAPH.ppt

    29/101

    Other parameters are:

    GLUT_RGBA : a window with RGBA color

    palette is chosenGLUT_RGB : except with Alpha opaqueness

    parameter a window with RGB color palette is

    chosen

    GLUT_INDEX : chooses color sequencing case

    GLUT_ACCUM : chooses accumulating

    buffer memory

  • 7/30/2019 COMP-GRAPH.ppt

    30/101

    GLUT_ALPHA : a window with Alpha

    parameter is chosen

    GLUT_DEPTH : a window with colordeepness is chosen

    i.e. If we would like to create a window with

    double buffer, RGBA color palette and color

    depth then our DisplayMode will be:

    glutInitDisplayMode(GLUT_DOUBLE |

    GLUT_RGBA | GLUT_DEPTH)

  • 7/30/2019 COMP-GRAPH.ppt

    31/101

    glutInitWindowSize(double width, double

    length);

    If we have 800x600 window resolution, thenour maximum selection of the window size

    will be;

    glutInitWindowSize(800, 600);

  • 7/30/2019 COMP-GRAPH.ppt

    32/101

    glutCreateWindow(my first window);

    Creates a new window with my first window

    caption

  • 7/30/2019 COMP-GRAPH.ppt

    33/101

    glClearColor(R, G, B, A);

    R Red, G Green, B Blue, A Alpha

    Some color generations can be obtained as;

  • 7/30/2019 COMP-GRAPH.ppt

    34/101

    Black 0.0 0.0 0.0

    Red 1.0 0.0 0.0

    Green 0.0 1.0 0.0

    Blue 0.0 0.0 1.0

    Brown 0.6 0.4 0.12

    Purple 0.6 0.4 0.7

    White 1.0 1.0 1.0

  • 7/30/2019 COMP-GRAPH.ppt

    35/101

    glutShadeModel(GL_FLAT);

    This function decides the color domination

    approach of the object.

    If GL_FLAT is used then single color will be

    dominant

    If GL_SMOOTH is used then each corner of

    the object can have different color

  • 7/30/2019 COMP-GRAPH.ppt

    36/101

    glutDisplayFunc(goruntu);

    This function is one of the most important

    one. It calls a predefined view of objects

    All drawing actions are executed by this

    command

  • 7/30/2019 COMP-GRAPH.ppt

    37/101

    glClear(GL_COLOR_BUFFER_BIT);

    It is time to start analysis of the subroutine

    glClear(GL_COLOR_BUFFER_BIT);

    This function clears the window by painting

    the color defined by the glClearColor( )Without this command you can draw

    overlapping objects

  • 7/30/2019 COMP-GRAPH.ppt

    38/101

    glFlush( )

    This command is used with single buffered

    window, it views the created object in the

    drawing window.

  • 7/30/2019 COMP-GRAPH.ppt

    39/101

    glutMainLoop( );

    This is the infinite loop of the window also it

    takes into account the directives andcommands to the window such as any key

    press from the user

  • 7/30/2019 COMP-GRAPH.ppt

    40/101

    CREATING DOTs

    #include void nokta(void){

    glClear(GL_COLOR_BUFFER_BIT);

    glColor3f(0.0,0.0,1.0);

    glPointSize(4.0);

    glBegin(GL_POINTS);

    glVertex2f(0.5,0.4);

    glVertex2f(-0.5,0.4);

    glEND( );

    glFlush( );}

  • 7/30/2019 COMP-GRAPH.ppt

    41/101

    int main(int argc,char** argv) {

    glutInit(&argc,argv);

    glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);

    glutInitWindowPosition(0,0);

    glutInitWindowSize(800,800);

    glutCreateWindow(dot example");

    glClearColor(1.0,1.0,1.0,1.0);

    glutDisplayFunc(nokta);

    glutMainLoop();

    return 0;}

  • 7/30/2019 COMP-GRAPH.ppt

    42/101

  • 7/30/2019 COMP-GRAPH.ppt

    43/101

    glColor3f(R,G,B);

    Color adjustment for dot or surface.

    glPointSize(1.0);

    Size adjustmet for the dot.

    glBegin(GL_POINTS);

    Starts GL_POINTS directive

  • 7/30/2019 COMP-GRAPH.ppt

    44/101

    glVertex2f(x,y);

    Gives vertex coordinates i.e. x=0.5, y=0.4

    glEnd( );

    Shows the end of the drawing

  • 7/30/2019 COMP-GRAPH.ppt

    45/101

    #include"gl/glut.hvoid gosterim(void){

    glClear(GL_COLOR_BUFFER_BIT);

    glColor3f(0.0,0.0,1.0);glLineWidth(4.0);

    glBegin(GL_LINES);

    glVertex2f(0.5,0.4);

    glVertex2f(-0.5,0.4);

    glEnd();

    glFlush();}

    Line drawing

  • 7/30/2019 COMP-GRAPH.ppt

    46/101

    int main(int argc,char ** argv){

    glutInit(&argc,argv);

    glutInitDisplayMode(GLUT_SINGLE |

    GLUT_RGB);

    glutInitWindowPosition(0,0);

    glutInitWindowSize(400,400);glutCreateWindow("yeni");

    glClearColor(1.0,1.0,1.0,1.0);

    glShadeModel(GL_FLAT);glutDisplayFunc(gosterim);

    glutMainLoop();

    return 0;}

  • 7/30/2019 COMP-GRAPH.ppt

    47/101

    glLineWidth(4.0);

    Adjusts width of the line between two points

    Default line width is 1.0.

    GL_LINES directive is used to draw line

    between two points

  • 7/30/2019 COMP-GRAPH.ppt

    48/101

    Dashed line drawing

    #include"gl/glut.hvoid gosterim(void){

    glClear(GL_COLOR_BUFFER_BIT);

    glColor3f(0.0,0.0,1.0);glEnable(GL_LINE_STIPPLE);

    glLineStipple(1, 0xFF);

    glBegin(GL_LINES);

    glVertex2f(0.5,0.4);

    glVertex2f(-0.5,0.4);

    glEnd();

  • 7/30/2019 COMP-GRAPH.ppt

    49/101

    glFlush();}

    int main(int argc, ** argv){

    glutInit(&argc,arg);

    glutInitDisplayMode(GLUT_SINGLE |

    GLUT_RGB);

    glutInitWindowPosition(0,0);

    glutInitWindowSize(400,400);

  • 7/30/2019 COMP-GRAPH.ppt

    50/101

    glutCreateWindow("yeni");

    glClearColor(1.0,1.0,1.0,1.0);

    glShadeModel(GL_FLAT);

    glutDisplayFunc(gosterim);

    glutMainLoop();

    return 0;

    }

  • 7/30/2019 COMP-GRAPH.ppt

    51/101

  • 7/30/2019 COMP-GRAPH.ppt

    52/101

    In this application it is used for enable the

    dashed line drawing,

    GL_LINE_STIPPLE represents dashed

    drawing type,

    glLineStipple(1,0xFF); used to adjust dashed

    line types. First parameter is multiplier term,

  • 7/30/2019 COMP-GRAPH.ppt

    53/101

    Second one is a binary design parameter, each

    zero represents a colorless part of line where 1

    represents drawn part.

    After design selection it is time to define the

    coordinates between glBegin ( ) and glEnd ( ).

  • 7/30/2019 COMP-GRAPH.ppt

    54/101

    Question

    What will happen if we use

    glLineStipple(5,0xaa) ?

  • 7/30/2019 COMP-GRAPH.ppt

    55/101

    Coordinate System

    #include"gl/glut.h"

    void koordinat(void)

    {

    glColor3f(0.0,0.0,1.0);

    glBegin(GL_LINES);

    glVertex2f(0.0,-1.0);

    glVertex2f(0.0,1.0);

  • 7/30/2019 COMP-GRAPH.ppt

    56/101

    glVertex2f(1.0,0.0);

    glVertex2f(-1.0,0.0);glEnd();

    }

    void gosterim(void){ glClear(GL_COLOR_BUFFER_BIT);

    koordinat();

    glFlush();

    }

  • 7/30/2019 COMP-GRAPH.ppt

    57/101

    int main(int argc,char ** argv)

    {

    glutInit(&argc,argv);

    glutInitDisplayMode(GLUT_SINGLE |

    GLUT_RGB);

    glutInitWindowPosition(0,0);

    glutInitWindowSize(400,400);

    glutCreateWindow("yeni");glClearColor(1.0,1.0,1.0,1.0);

    glShadeModel(GL_FLAT);

  • 7/30/2019 COMP-GRAPH.ppt

    58/101

    glutDisplayFunc(gosterim);

    glutMainLoop();

    return 0;

    }

  • 7/30/2019 COMP-GRAPH.ppt

    59/101

    Question

    Write an OpenGL program to draw dashed

    line from (-0.5,0.4) to (0.5,0.4) on the

    coordinate system drawn by solid lines.

  • 7/30/2019 COMP-GRAPH.ppt

    60/101

    Answer

    #include"gl/glut.h

    void kesikcizgi(void)

    {

    glColor3f(1.0,0.0,0.0);

    glEnable(GL_LINE_STIPPLE);

    glLineStipple(1 , 0xff);

  • 7/30/2019 COMP-GRAPH.ppt

    61/101

    glBegin(GL_LINES);

    glVertex2f(0.5,0.4);

    glVertex2f(-0.5,0.4);

    glEnd();

    glDisable(GL_LINE_STIPPLE);

    }

  • 7/30/2019 COMP-GRAPH.ppt

    62/101

    void koordinat(void)

    {glColor3f(0.0,0.0,1.0);

    glBegin(GL_LINES);

    glVertex2f(0.0,-1.0);glVertex2f(0.0,1.0);

    glVertex2f(1.0,0.0);

    glVertex2f(-1.0,0.0);

    glEnd();

    }

  • 7/30/2019 COMP-GRAPH.ppt

    63/101

    void gosterim(void)

    {

    glClear(GL_COLOR_BUFFER_BIT);

    koordinat();

    kesikcizgi();

    glFlush();

    }

  • 7/30/2019 COMP-GRAPH.ppt

    64/101

    int main(int argc,char ** argv){

    glutInit(&argc,argv);

    glutInitDisplayMode(GLUT_SINGLE |GLUT_RGB);

    glutInitWindowPosition(0,0);

    glutInitWindowSize(400,400);

    glutCreateWindow("yeni");

  • 7/30/2019 COMP-GRAPH.ppt

    65/101

    glClearColor(1.0,1.0,1.0,1.0);

    glShadeModel(GL_FLAT);

    glutDisplayFunc(gosterim);

    glutMainLoop();

    return 0;

    }

  • 7/30/2019 COMP-GRAPH.ppt

    66/101

    Polygons

    Default values for the polygons have filled

    front and back surfaces.

    Filling is done with selected colours. If we would like to have a not filled

    drawing, following command must be used:

    glPolygonMode(glenum surface, glenummod);

  • 7/30/2019 COMP-GRAPH.ppt

    67/101

    First parameter may have;

    GL_FRONT, GL_BACK,

    GL_FRONT_AND_BACK

    Second parameter may be;

    GL_POINT

    GL_LINE

    GL_FILL

  • 7/30/2019 COMP-GRAPH.ppt

    68/101

    Drawing a Triangle

    #include"gl/glut.h"

    void ucgen(void)

    {

    glColor3f(0.0,1.0,1.0);

    glBegin(GL_TRIANGLES);

    glVertex2f(-0.4,-0.4);

    glVertex2f(0.4,-0.4);

  • 7/30/2019 COMP-GRAPH.ppt

    69/101

    glVertex2f(0.0,0.4);

    glEnd();}

    void koordinat(void)

    {

    glColor3f(0.0,0.0,1.0);

    glBegin(GL_LINES);

    glVertex2f(0.0,-1.0);

  • 7/30/2019 COMP-GRAPH.ppt

    70/101

    glVertex2f(0.0,1.0);

    glVertex2f(1.0,0.0);

    glVertex2f(-1.0,0.0);

    glEnd();

    }

  • 7/30/2019 COMP-GRAPH.ppt

    71/101

    void gosterim(void)

    {

    glClear(GL_COLOR_BUFFER_BIT);

    ucgen();

    koordinat();

    glFlush();

    }

  • 7/30/2019 COMP-GRAPH.ppt

    72/101

    int main(int argc,char ** argv)

    {glutInit(&argc,argv);

    glutInitDisplayMode(GLUT_SINGLE |

    GLUT_RGB);

    glutInitWindowPosition(0,0);

    glutInitWindowSize(400,400);

    glutCreateWindow("yeni");

    glClearColor(1.0,1.0,1.0,1.0);

  • 7/30/2019 COMP-GRAPH.ppt

    73/101

    glShadeModel(GL_FLAT);

    glutDisplayFunc(gosterim);

    glutMainLoop();

    return 0;

    }

  • 7/30/2019 COMP-GRAPH.ppt

    74/101

    Question

    If the following command line addition takes

    place to subroutine called as ucgen ( ) as sown

    below;void ucgen (void)

    glPolygonMode(GL_FRONT,GL_LINE);

    What will happen?

  • 7/30/2019 COMP-GRAPH.ppt

    75/101

    Drawing a Rectangle

    #include gl/glut.h

    void dortgen(void)

    { glPolygonMode(GL_FRONT ,GL_LINE);

    glColor3f(0.0,1.0,1.0);

    glBegin(GL_QUADS);

    glVertex2f(-0.4,-0.4);

  • 7/30/2019 COMP-GRAPH.ppt

    76/101

    glVertex2f(-0.4,0.4);

    glVertex2f(0.4,0.4);

    glVertex2f(0.4,-0.4);

    glEnd();

    }

  • 7/30/2019 COMP-GRAPH.ppt

    77/101

    void koordinat(void)

    {

    glColor3f(0.0,0.0,1.0);

    glBegin(GL_LINES);

    glVertex2f(0.0,-1.0);glVertex2f(0.0,1.0);

    glVertex2f(1.0,0.0);

    glVertex2f(-1.0,0.0);

    glEnd();

    }

  • 7/30/2019 COMP-GRAPH.ppt

    78/101

    void gosterim(void)

    {

    glClear(GL_COLOR_BUFFER_BIT);

    dortgen();

    koordinat();

    glFlush();

    }

  • 7/30/2019 COMP-GRAPH.ppt

    79/101

    int main(int argc,char ** argv)

    {

    glutInit(&argc,argv);

    glutInitDisplayMode(GLUT_SINGLE |

    GLUT_RGB);

    glutInitWindowPosition(0,0);

    glutInitWindowSize(200,200);

  • 7/30/2019 COMP-GRAPH.ppt

    80/101

    glutCreateWindow("drtgen");glClearColor(1.0,1.0,1.0,1.0);

    glShadeModel(GL_FLAT);

    glFrontFace(GL_CW);glutDisplayFunc(gosterim);

    glutMainLoop();

    return 0;

    }

  • 7/30/2019 COMP-GRAPH.ppt

    81/101

    GL_QUADS directive completes the

    rectangle.

    Sequence of vertex coordinate is important to

    have a correct rectangle.

  • 7/30/2019 COMP-GRAPH.ppt

    82/101

    If we add

    glPolygonMode(GL_BACK, GL_LINE)

    Then a frame view with transparant inner fillwill be obtained.

    This situation is directly resulted from the

    drawing sequence given by the program.

  • 7/30/2019 COMP-GRAPH.ppt

    83/101

    If drawing is done in counter clock wise

    direction then front of the shape drawn is

    assumed.

    In counter clock wise direction the drawn

    figure will be the back of the shape.

  • 7/30/2019 COMP-GRAPH.ppt

    84/101

    Adjustment of this situation can be done by

    changing

    glFrontFace(type)

    if type is selected as GL_CCW then counter

    clock wise will be front,

    if type is selected as GL_CW then clock wise

    direction will be front.

  • 7/30/2019 COMP-GRAPH.ppt

    85/101

    Another method for drawing a rectangle is to

    use command:

    glRectf(-x1, -y1, x2, y2);x1 and x2 are coordinates of width,

    y1 and y2 are coordinates of length.

  • 7/30/2019 COMP-GRAPH.ppt

    86/101

    #include gl/glut.h

    void koordinat(void)

    {

    glColor3f(0.0,0.0,1.0);

    glBegin(GL_LINES);

    glVertex2f(0.0,-1.0);

    glVertex2f(0.0,1.0);

  • 7/30/2019 COMP-GRAPH.ppt

    87/101

    glVertex2f(1.0,0.0);

    glVertex2f(-1.0,0.0);

    glEnd();

    }

    void dikdortgen(void){

    glColor3f(0.0,0.5,0.8);

    glRectf(-0.5,-0.4,0.5,0.4);

    }

  • 7/30/2019 COMP-GRAPH.ppt

    88/101

  • 7/30/2019 COMP-GRAPH.ppt

    89/101

    int main(int argc,char ** argv)

    {

    glutInit(&argc,argv);

    glutInitDisplayMode(GLUT_SINGLE |

    GLUT_RGB);

    glutInitWindowPosition(0,0);

    glutInitWindowSize(400,400);glutCreateWindow("yeni");

  • 7/30/2019 COMP-GRAPH.ppt

    90/101

    glClearColor(1.0,1.0,1.0,1.0);

    glShadeModel(GL_FLAT);

    glutDisplayFunc(gosterim);

    glutMainLoop();

    return 0;

    }

  • 7/30/2019 COMP-GRAPH.ppt

    91/101

    Drawing a Circle

    Coordinates of a point on a circle are

    X= R * cos and Y = R * sin

    Where is in Radian scale.

    Radian = (2 * * Degree ) / 360

  • 7/30/2019 COMP-GRAPH.ppt

    92/101

    #include"gl/glut.h"

    #include"math.h"

    void gosterim(void)

    { double der=0;

    int a=0;

    glClear(GL_COLOR_BUFFER_BIT);

    glColor3f(0.0,0.0,1.0);

  • 7/30/2019 COMP-GRAPH.ppt

    93/101

    glBegin(GL_POLYGON);

    for(a=0;a

  • 7/30/2019 COMP-GRAPH.ppt

    94/101

    int main(int argc,char ** argv){

    glutInit(&argc,argv);

    glutInitDisplayMode(GLUT_SINGLE |GLUT_RGB);

    glutInitWindowPosition(0,0);

    glutInitWindowSize(400,400);glutCreateWindow("ember");

  • 7/30/2019 COMP-GRAPH.ppt

    95/101

    glClearColor(1.0,1.0,1.0,1.0);

    glShadeModel(GL_FLAT);

    glPolygonMode(GL_FRONT,GL_FILL);

    glutDisplayFunc(gosterim);

    glutMainLoop();

    return 0;

    }

  • 7/30/2019 COMP-GRAPH.ppt

    96/101

    GL_LINE_LOOP makes connection among

    points. No filling is contained by this

    command.If a filling effect is required

    glBegin(GL_POLYGON)

    can be written.Then a filled circle will be obtained.

  • 7/30/2019 COMP-GRAPH.ppt

    97/101

    Question

    If we write following GL program what kind

    of output will be seen?

  • 7/30/2019 COMP-GRAPH.ppt

    98/101

    #include"gl/glut.h"#include"math.h

    void gosterim(void)

    { double der=0;int a=0;

    glClear(GL_COLOR_BUFFER_BIT);

    glColor3f(0.0,0.0,1.0);

    glBegin(GL_POINTS);

  • 7/30/2019 COMP-GRAPH.ppt

    99/101

    for(a=0;a

  • 7/30/2019 COMP-GRAPH.ppt

    100/101

    int main(int argc,char ** argv){

    glutInit(&argc,argv);

    glutInitDisplayMode(GLUT_SINGLE |GLUT_RGB);

    glutInitWindowPosition(0,0);

    glutInitWindowSize(200,200);glutCreateWindow("altgen");

  • 7/30/2019 COMP-GRAPH.ppt

    101/101

    glClearColor(1.0,1.0,1.0,1.0);

    glShadeModel(GL_FLAT);

    glPolygonMode(GL_FRONT,GL_FILL);

    glutDisplayFunc(gosterim);

    glutMainLoop();

    return 0;

    }