void setup(){


    mesh.fromFileOBJ( "common_resources/turret.obj" );
    mesh.polygonsToTriangles();
    mesh.tris2normals(true);
    object1 = new GLObject( );
    object1->nVert    = mesh.points.size();
    //object1->nInd     = mesh.triangles.size();

    //object1->setIndexes( 16, (int*)&mesh.triangles[0] );
    object1->setIndexes( mesh.triangles.size()*3, (int*)&mesh.triangles[0] );
    printf( "nVert %i nInd %i \n", object1->nVert, object1->nInd);
    object1->buffs[0].setup(0,3,GL_FALSE,(double*)&(mesh.points [0]), object1->nVert, 'v'); // vertexes
    object1->buffs[1].setup(1,3,GL_FALSE,(double*)&(mesh.normals[0]), object1->nVert, 'n'); // normals
    //object1->indexes .setup(2,3,GL_FALSE,(void*  )&(mesh.triangles[0]), 'i'); // indexes
    //object1->index_cbuff = (GLuint *)&mesh.triangles[0];
    //object1->nVert = 5;


    /*
    object1 = new GLObject( );
    object1->nVert    = nVert;
    object1->buffs[0].setup(0,3,GL_FALSE,vertexes,'v'); // vertexes
    object1->buffs[1].setup(1,3,GL_FALSE,vertexes,'c'); // colors
    object1->init();
    */

    object1->init();

    if ( render_type == 0      ){
        // --- vertex const color
        shader1=new Shader();
        shader1->init( "shaders/basicColor3D_vert.c", "shaders/basicColor3D_frag.c" );
        glUseProgram(shader1->shaderprogram);
    }else if ( render_type == 1 ){
        // --- shading
        shader1=new Shader();
        shader1->init( "shaders/basicShading3D_vert.c", "shaders/basicShading3D_frag.c" );
        glUseProgram(shader1->shaderprogram);
    };
	//mesh.fromFileOBJ("common_resources/turret.obj");

	qCamera.setOne();
}
void setup(){

    if ( render_type == 0      ){
        // --- vertex const color
        shader1=new Shader();
        shader1->init( "shaders/basicColor3D_vert.c", "shaders/basicColor3D_frag.c" );
    }else if ( render_type == 1 ){
        // --- shading
        shader1=new Shader();
        shader1->init( "shaders/basicShading3D_vert.c", "shaders/basicShading3D_frag.c" );
        glUseProgram(shader1->shaderprogram);
    };
	//mesh.fromFileOBJ("common_resources/turret.obj");

    int nVert = countVerts( Solids::Icosahedron_nfaces, Solids::Icosahedron_ngons );
    GLfloat * verts   = new GLfloat[nVert*3];
    GLfloat * normals = new GLfloat[nVert*3];
    hardFace( Solids::Icosahedron_nfaces, Solids::Icosahedron_ngons, Solids::Icosahedron_faces, Solids::Icosahedron_verts, verts, normals );

    object1 = new GLObject( );
    object1->nVert    = nVert;
    object1->buffs[0].setup(0,3,GL_FALSE,verts,  'v'); // vertexes
    object1->buffs[1].setup(1,3,GL_FALSE,normals,'n'); // normals
    object1->init();

        // shading
    if ( render_type == 1 ){
        uloc = glGetUniformLocation( shader1->shaderprogram, "cam_pos"       ); glUniform3fv      (uloc, 1, cam_pos      );
        uloc = glGetUniformLocation( shader1->shaderprogram, "light_pos"     ); glUniform3fv      (uloc, 1, light_pos     );
        uloc = glGetUniformLocation( shader1->shaderprogram, "lightColor"    ); glUniform3fv      (uloc, 1, lightColor    );
        uloc = glGetUniformLocation( shader1->shaderprogram, "diffuseColor"  ); glUniform3fv      (uloc, 1, diffuseColor  );
        uloc = glGetUniformLocation( shader1->shaderprogram, "ambientColor"  ); glUniform3fv      (uloc, 1, ambientColor  );
        uloc = glGetUniformLocation( shader1->shaderprogram, "specularColor" ); glUniform3fv      (uloc, 1, specularColor );
    };

    ninstancs = 100; // 30 ms/frame
    //ninstancs = 10000; // 30 ms/frame
    instance_points = new GLfloat[3*ninstancs];
    for (int i=0; i<ninstancs; i++){
        int i3 = 3*i;
        instance_points[i3+0] = randf(-15.0,15.0);
        instance_points[i3+1] = randf(-15.0,15.0);
        instance_points[i3+2] = randf(-60.0,-1000.0);
    }

    // ------------- Terrain
	shader2=new Shader();
	if  ( terrain_mode ){
        if(RayTerrain){ shader2->init( "shaders/terrain_vert.c",  "shaders/terrain_frag.c"  );   }
        else          { shader2->init( "shaders/terrain_vert2.c", "shaders/terrain_frag2.c" );   }
    }else {
        shader2->init( "shaders/plain_vert.c", "shaders/texture_frag.c" );
    };

    // ------------- texture
    const int imgW = 256;
    const int imgH = 256;
    unsigned int imgData [imgW*imgH];
    Vec2d pos,rot,dpos;
    rot.fromAngle( 45454*0.1 );
    for( int iy=0; iy<imgH; iy++ ){
        for( int ix=0; ix<imgW; ix++ ){
            /*
            float r = sin(ix*0.16);
            float g = sin(iy*-0.31);
            float b = sin((ix+iy)*0.1);
            r*=g*b; g=r; b=r;
            r+=1.0f; g+=1.0f; b+=1.0f;
            */
            //8, 2.0, 1.0,  0.5, 0.8, 45454, {100.0,100.0}
            //int n, double scale,  double hscale,  double fdown, double strength, int seed, const Vec2d& pos0
            pos.set(ix*5,iy*5);
            Noise::warpNoise3R( pos, rot, 0.4, 0.4, 6, dpos );
            float r = 1-(dpos.x * dpos.y)*2+0.5;
            //float r = 0.3*sin(ix*0.1)*cos(iy*0.1) + 0.2*cos(ix*0.3)*sin(iy*0.3); r+=0.5;
            float g=r; float b=r;
            imgData[ iy*imgW + ix ] =  ((int)(255*r) <<16) | ((int)(255*g)<<8) | ((int)(255*b));
        }
    }
    glGenTextures  (0, &textureID);    // Create one OpenGL texture
    glBindTexture  (GL_TEXTURE_2D, textureID); // "Bind" the newly created texture : all future texture functions will modify this texture
    glTexImage2D   (GL_TEXTURE_2D, 0,GL_RGBA, imgW, imgH, 0, GL_RGBA, GL_UNSIGNED_BYTE, imgData);   // Give the image to OpenGL
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

    if( RayTerrain ){
        object2 = new GLObject( );
        object2->draw_mode = GL_TRIANGLE_STRIP;
        object2->nVert   = 4;
        object2->buffs[0].setup(0,2,GL_FALSE,&QUAD_verts[0],'v');
        object2->init();
    }else{
        float * strip = new GLfloat[Ter_nquads*2*2];
        for(int i=0; i<Ter_nquads; i++){
            int i4 = i<<2;
            float x  = i*Ter_dx-0.5;
            strip[i4  ]=x;          strip[i4+1]=0.0f;
            strip[i4+2]=x*Ter_fsc;  strip[i4+3]=Ter_dz;
        }
        object2 = new GLObject();
        object2->draw_mode = GL_TRIANGLE_STRIP;
        object2->nVert     = Ter_nquads*2;
        object2->buffs[0].setup(0,2,GL_FALSE,strip,'v');
        object2->init();
    }

	qCamera.setOne();


	delay = 1;
}