/* OpenGL erabiltzen duen programatxoa */ /* konpilatzeko gcc -lGL -lGLU -lglut agindua erabili behar da. */ #include #include #include static float LOCAL_Red = 0.0f; static void marraztu(void) { glClear( GL_COLOR_BUFFER_BIT ); glColor3f( 0.0f, 0.0f, 0.0f ); glBegin( GL_POLYGON ); glVertex3f( -0.3f, -0.3f, 0.0f ); glVertex3f( 0.3f, -0.3f, 0.0f ); glVertex3f( 0.3f, 0.3f, 0.0f ); glVertex3f( -0.3f, 0.3f, 0.0f ); glEnd(); // Set state values that define properties that // will be assigned to future primitives glColor3f( LOCAL_Red, 1-LOCAL_Red, LOCAL_Red ); glLineWidth( 10.0f ); glBegin( GL_LINES ); glVertex3f( -0.8f, -0.8f, 0.0f ); glVertex3f( 0.8f, 0.8f, 0.0f ); glEnd(); glFlush(); } // This function will be called whenever the user pushes one key static void teklatua (unsigned char key, int x, int y) { switch(key) { case 'r': if ( LOCAL_Red > 0.01f ) LOCAL_Red -= 0.1f; printf ("red : "); break; case 'R': if ( LOCAL_Red < 1.0f ) LOCAL_Red += 0.1f; printf ("red : "); break; case 27: // exit( 0 ); break; default: printf("%d %c\n", key, key ); } printf ("(R = %f) (G = %f) (B = %f) \n", LOCAL_Red, 1-LOCAL_Red, LOCAL_Red ); // The screen must be drawn to show the new values glutPostRedisplay(); } int main(int argc, char** argv) { printf("OpenGL erabiltzen duen programatxoa: r eta R teklen bidez kolorea aldatzen da\n"); glutInit(&argc,argv); glutInitDisplayMode ( GLUT_RGB ); glutInitWindowSize ( 500, 500 ); glutInitWindowPosition ( 100, 100 ); glutCreateWindow( "OpenGL leihoa" ); glutDisplayFunc( marraztu ); glutKeyboardFunc( teklatua ); glClearColor( 0.0f, 0.0f, 0.7f, 1.0f ); glutMainLoop(); return 0; }