• OpenGL Study Notes (2008-08-26) - [OpenGL]

    2008-08-26 | Tag:OpenGL 图形学 计算机

    版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
    http://anthonychan.blogbus.com/logs/28187215.html

    1.      An easy-forgotten problem.

    When we are applying OpenGL code,we tempt to draw something without translating the coordinate. However this isnot gonna work. Because the default view point is at (0.0, 0.0, 0.0). when youtry to draw something it starts from this point and you are not gonna to seeanything

    To make it different, redefinethe matrix mode:

     

            glMatrixMode(GL_PROJECTION);

     

    this line should be following therendering section. 

    Another way to do it is beforethe rendering section, define the model view:

     

    glMatrixMode(GL_MODELVIEW);

    glLoadIdentity();

    gluLookAt(0.0,0.0, 1.0, 0.0, 0.0, -100.0, 0.0, 1.0, 0.0);

    //just an example

     

    2.      Apiece of code making color changing

     

    int DrawGLScene(GLvoid)                                 // Here's Where We Do All The Drawing

    {

    static float r = 0.0, g = 0.0, b = 0.0;

     

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  // Clear Screen And Depth Buffer

    glLoadIdentity();                                    // Reset The Current Modelview Matrix

     

    glMatrixMode(GL_MODELVIEW);                             // Set the model view of the object

    glLoadIdentity();                                         // Reset the current matrix

    gluLookAt(0.0,0.0,5.0,

    0.0,0.0,-100.0,

    0.0,1.0,0.0);                                  // Set the view point

     

    if(delta < 0.0 || delta > 3.0)                          // In case delta is out of bound

    delta = 0.0;                                          // Reset it to zero

    else if(delta < 1.0 && delta >= 0.0)                   // To set the red component

    r = delta;

    else if(delta < 2.0 && delta >= 1.0)                    // To set the green component

    g = (delta-1.0);

    else                                                          // To set the blue component

    b = (delta-2.0);

     

    delta += 0.001;                                             // Increment the delta variable

     

    glColor3f(r, g, b);                                         // Set the color

     

    glBegin(GL_TRIANGLES);                                      // Below is the drawing of a triangle

    glVertex3f(0.0, 1.0, 0.0);

    glVertex3f(1.0, 0.0, 0.0);

    glVertex3f(-1.0, 0.0, 0.0);

    glEnd();

     

    return TRUE;                                          // Everything Went OK

    }


    收藏到:Del.icio.us




    引用地址:

    评论

  • 万华根交出来的徒弟?