예제 #1
0
파일: texpage.c 프로젝트: amlanpradhan/GLUT
static void
display(void) {
    glClear(GL_COLOR_BUFFER_BIT);
    loadtiles();
    if (texture) {
	drawtexture();
    } else {
	drawmesh(64,64);
	if (grid) showgrid();
    }
    glutSwapBuffers();
}
예제 #2
0
void display(void)
{
    // clear all pixels

    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) ;

    // draw white polygon (square) of unit length centered at the origin
    // Note that vertices must generally go counterclockwise
    // Change from the first program, in that I just made it white.
    // The old OpenGL code of using glBegin... glEnd no longer appears.
    // The new version uses vertex buffer objects from init.

    // Does the order of drawing matter?  What happens if I draw the ground
    // after the pillars?  I will show this in class

    glUniform1i(islight,0) ; // Turn off lighting (except on teapot, later)
    glUniform1i(istex,texturing) ;
    drawtexture(FLOOR,texNames[0]) ; // Texturing floor
    // drawobject(FLOOR) ;
    glUniform1i(istex,0) ; // Other items aren't textured


    // Now draw several cubes with different transforms, colors
    // I continue to use the deprecated push-pop and matrix mode
    // Since it is convenient (or you have to write your own stack).

    glMatrixMode(GL_MODELVIEW) ;

    // 1st pillar
    glPushMatrix() ;
    glTranslatef(-0.4,-0.4,0.0) ;
    drawcolor(CUBE, 0) ;
    glPopMatrix() ;

    // 2nd pillar
    glPushMatrix() ;
    glTranslatef(0.4,-0.4,0.0) ;
    drawcolor(CUBE, 1) ;
    glPopMatrix() ;

    // 3rd pillar
    glPushMatrix() ;
    glTranslatef(0.4,0.4,0.0) ;
    drawcolor(CUBE, 2) ;
    glPopMatrix() ;

    // 4th pillar
    glPushMatrix() ;
    glTranslatef(-0.4,0.4,0.0) ;
    drawcolor(CUBE, 3) ;
    glPopMatrix() ;

    // Draw the glut teapot
    // This is using deprecated old-style OpenGL certainly

    /* New for Demo 3; add lighting effects */
    {
        const GLfloat one[] = {1,1,1,1};
        const GLfloat medium[] = {0.5, 0.5, 0.5, 1};
        const GLfloat small[] = {0.2, 0.2, 0.2, 1};
        const GLfloat high[] = {100} ;
        const GLfloat zero[] = {0.0, 0.0, 0.0, 1.0} ;
        const GLfloat light_specular[] = {1, 1, 0, 1};
        const GLfloat light_specular1[] = {0, 0.5, 1, 1};
        const GLfloat light_direction[] = {0.5, 0, 0, 0}; // Dir light 0 in w
        const GLfloat light_position1[] = {0, -0.5, 0, 1};

        GLfloat light0[4], light1[4] ;

        // Set Light and Material properties for the teapot
        // Lights are transformed by current modelview matrix.
        // The shader can't do this globally.
        // So we need to do so manually.
        transformvec(light_direction, light0) ;
        transformvec(light_position1, light1) ;

        glUniform3fv(light0dirn, 1, light0) ;
        glUniform4fv(light0color, 1, light_specular) ;
        glUniform4fv(light1posn, 1, light1) ;
        glUniform4fv(light1color, 1, light_specular1) ;
        // glUniform4fv(light1color, 1, zero) ;

        glUniform4fv(ambient,1,small) ;
        glUniform4fv(diffuse,1,medium) ;
        glUniform4fv(specular,1,one) ;
        glUniform1fv(shininess,1,high) ;

        // Enable and Disable everything around the teapot
        // Generally, we would also need to define normals etc.
        // But glut already does this for us
        if (DEMO > 4)
            glUniform1i(islight,lighting) ; // turn on lighting only for teapot.

    }
    //  ** NEW ** Put a teapot in the middle that animates
    glColor3f(0.0,1.0,1.0) ; // Deprecated command to set the color
    glPushMatrix() ;
    //  I now transform by the teapot translation for animation
    glTranslatef(teapotloc, 0.0, 0.0) ;

    //  The following two transforms set up and center the teapot
    //  Remember that transforms right-multiply the stack

    glTranslatef(0.0,0.0,0.1) ;
    glRotatef(rotamount, 0.0, 0.0, 1.0);
    glRotatef(90.0,1.0,0.0,0.0) ;
    glutSolidTeapot(0.15) ;
    glUniform1i(islight,0) ; // turn off lighting
    glPopMatrix() ;


    // Does order of drawing matter?
    // What happens if I draw the ground after the pillars?
    // I will show this in class.

    // drawobject(FLOOR) ;

    // don't wait!
    // start processing buffered OpenGL routines


    glutSwapBuffers() ;
    glFlush ();
}