Exemple #1
0
void init() {

	// Set up initial position for eye,up and amount
	// As well as booleans 

	eye = eyeinit; 
	up = upinit; 
	amount = 5;
	useGlu = true;

	glEnable(GL_DEPTH_TEST);

	// The lighting is enabled using the same framework as in mytest 3 
	// Except that we use two point lights
	// For now, lights and materials are set in display.  Will move to init 
	// later, per update lights

	vertexshader = initshaders(GL_VERTEX_SHADER,"shaders/light.vert.glsl");
	fragmentshader = initshaders(GL_FRAGMENT_SHADER,"shaders/light.frag.glsl");
	shaderprogram = initprogram(vertexshader,fragmentshader); 
	islight = glGetUniformLocation(shaderprogram,"islight");        
	light0posn = glGetUniformLocation(shaderprogram,"light0posn");       
	light0color = glGetUniformLocation(shaderprogram,"light0color");       
	light1posn = glGetUniformLocation(shaderprogram,"light1posn");       
	light1color = glGetUniformLocation(shaderprogram,"light1color");       
	ambient = glGetUniformLocation(shaderprogram,"ambient");       
	diffuse = glGetUniformLocation(shaderprogram,"diffuse");       
	specular = glGetUniformLocation(shaderprogram,"specular");       
	shininess = glGetUniformLocation(shaderprogram,"shininess");       
}
void init (void)
{
    /* select clearing color 	*/
    glClearColor (0.0, 0.0, 0.0, 0.0);

    /* initialize viewing values  */
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    // Think about this.  Why is the up vector not normalized?
    glMatrixMode(GL_MODELVIEW) ;
    glLoadIdentity() ;
    gluLookAt(0,-eyeloc,eyeloc,0,0,0,0,1,1) ;


    // Initialize the shaders

    // vertexshader = initshaders(GL_VERTEX_SHADER, "shaders/tex.vert") ;
    // fragmentshader = initshaders(GL_FRAGMENT_SHADER, "shaders/tex.frag") ;

    vertexshader = initshaders(GL_VERTEX_SHADER, "shaders/light.vert.glsl") ;
    fragmentshader = initshaders(GL_FRAGMENT_SHADER, "shaders/light.frag.glsl") ;
    GLuint program = glCreateProgram() ;
    shaderprogram = initprogram(vertexshader, fragmentshader) ;
    GLint linked;
    glGetProgramiv(shaderprogram, GL_LINK_STATUS, &linked) ;

    // * NEW * Set up the shader parameter mappings properly for lighting.
    islight = glGetUniformLocation(shaderprogram,"islight") ;
    light0dirn = glGetUniformLocation(shaderprogram,"light0dirn") ;
    light0color = glGetUniformLocation(shaderprogram,"light0color") ;
    light1posn = glGetUniformLocation(shaderprogram,"light1posn") ;
    light1color = glGetUniformLocation(shaderprogram,"light1color") ;
    ambient = glGetUniformLocation(shaderprogram,"ambient") ;
    diffuse = glGetUniformLocation(shaderprogram,"diffuse") ;
    specular = glGetUniformLocation(shaderprogram,"specular") ;
    shininess = glGetUniformLocation(shaderprogram,"shininess") ;

    // Set up the Geometry for the scene.
    // From OpenGL book pages 103-109

    glGenBuffers(numperobj*numobjects+ncolors+1, buffers) ; // 1 for texcoords
    initcolorscube() ;

    // Initialize texture
    // inittexture("wood.ppm", fragmentprogram) ;
    inittexture("wood.ppm", shaderprogram) ;

    // Initialize objects

    initobject(FLOOR, (GLfloat *) floorverts, sizeof(floorverts), (GLfloat *) floorcol, sizeof (floorcol), (GLubyte *) floorinds, sizeof (floorinds), GL_POLYGON) ;
    //       initobject(CUBE, (GLfloat *) cubeverts, sizeof(cubeverts), (GLfloat *) cubecol, sizeof (cubecol), (GLubyte *) cubeinds, sizeof (cubeinds), GL_QUADS) ;
    initobjectnocol(CUBE, (GLfloat *) cubeverts, sizeof(cubeverts), (GLubyte *) cubeinds, sizeof (cubeinds), GL_QUADS) ;

    // Enable the depth test
    glEnable(GL_DEPTH_TEST) ;
    glDepthFunc (GL_LESS) ; // The default option
}
	shaders_t loadShaders(const char * vert_path, const char * frag_path, const char * geom_path) {
		GLuint f, v, g = 0;

		v = initshaders( GL_VERTEX_SHADER, vert_path );
        f = initshaders( GL_FRAGMENT_SHADER, frag_path );
        if( geom_path )
            g = initshaders( GL_GEOMETRY_SHADER, geom_path );

        shaders_t out; out.vertex = v; out.fragment = f; out.geometry = g;

		return out;
	}
Exemple #4
0
void init(const char* filename) {

	// Set up initial position for eye,up and amount
	// As well as booleans 

	eye = eyeinit; 
	up = upinit; 
	amount = 5;
	useGlu = true;

	glEnable(GL_DEPTH_TEST);

	// The lighting is enabled using the same framework as in mytest 3 
	// Except that we use two point lights
	// For now, lights and materials are set in display.  Will move to init 
	// later, per update lights

	vertexshader = initshaders(GL_VERTEX_SHADER,"shaders/light.vert.glsl");
	fragmentshader = initshaders(GL_FRAGMENT_SHADER,"shaders/light.frag.glsl");
	shaderprogram = initprogram(vertexshader,fragmentshader); 
	islight = glGetUniformLocation(shaderprogram,"islight"); 
        isdebug = glGetUniformLocation(shaderprogram, "debug");     
	light0posn = glGetUniformLocation(shaderprogram,"light0posn");       
	light0color = glGetUniformLocation(shaderprogram,"light0color");       
	light1posn = glGetUniformLocation(shaderprogram,"light1posn");       
	light1color = glGetUniformLocation(shaderprogram,"light1color");       
	ambient = glGetUniformLocation(shaderprogram,"ambient");       
	diffuse = glGetUniformLocation(shaderprogram,"diffuse");       
	specular = glGetUniformLocation(shaderprogram,"specular");       
	shininess = glGetUniformLocation(shaderprogram,"shininess");     
	
	std::cout << "Loading in file: " << filename << std::endl;
    if (!pre_simplified) {
        Mesh temp;
        temp.loadMesh(filename);
        simplify_num = temp._faces.size();
        temp.quadricSimplify(simplify_num);
    }
    
    model.loadMesh(filename);
    if (!pre_simplified) {
        model.loadEdgeCollapse("edge_collapse.txt");
        
    } else {
        model.loadEdgeCollapse(collapse_file);
    }
    slider_max = model.numOfCollapse();
    std::cout << "Done loading" << std::endl;  
}
void initGraphics() {

    glEnable(GL_TEXTURE_2D);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    eyeVector = vec3(0.0,0.0,defaultEyeZ);
    upVector = vec3(0.0,1.0,0.0);
    centerVector = vec3(0,0,0);

    initializeAnimation();
    //initialize display lists
    initCircleThingy();
    initTorus();
    initSpaceStation();
    initMouse();

    //initialize shaders
    vertexShader = initshaders(GL_VERTEX_SHADER, "vertexShader.glsl");
    fragmentShader = initshaders(GL_FRAGMENT_SHADER, "fragmentShader.glsl");
    shaderProgram = initprogram(vertexShader,fragmentShader);

//link up variables in shaders
//
    computingTeapot = glGetUniformLocation(shaderProgram,"computingTeapot");
    computingSphere = glGetUniformLocation(shaderProgram,"computingSphere");
    centerDist = glGetUniformLocation(shaderProgram, "centerDist");
    computingTorus = glGetUniformLocation(shaderProgram, "computingTorus");
    torusTransparency = glGetUniformLocation(shaderProgram, "torusTransparency");
    materialDiffuse = glGetUniformLocation(shaderProgram, "materialDiffuse");
    materialSpecular = glGetUniformLocation(shaderProgram, "materialSpecular");
    materialShininess = glGetUniformLocation(shaderProgram, "materialShininess");
    viewMatrix = glGetUniformLocation(shaderProgram, "viewMatrix");
    usingTextures = glGetUniformLocation(shaderProgram, "usingTextures");
    computingMonitor = glGetUniformLocation(shaderProgram, "computingMonitor");

    //initialize textures
    initSphereTexture(fragmentShader);

}
Exemple #6
0
void initShading() {
      eye = glm::vec3(0.0, 0.0, 5.0);   
      up = glm::vec3(0.0, 1.0, 0.0);
      amount = 5;

      glEnable(GL_DEPTH_TEST);

      vertexshader = initshaders(GL_VERTEX_SHADER, "shaders/light.vert.glsl") ;
      fragmentshader = initshaders(GL_FRAGMENT_SHADER, "shaders/light.frag.glsl") ;
      shaderprogram = initprogram(vertexshader, fragmentshader) ; 
      islight = glGetUniformLocation(shaderprogram,"islight") ;        
      light0posn = glGetUniformLocation(shaderprogram,"light0posn") ;       
      light0color = glGetUniformLocation(shaderprogram,"light0color") ;       
      light1posn = glGetUniformLocation(shaderprogram,"light1posn") ;       
      light1color = glGetUniformLocation(shaderprogram,"light1color") ;       
      ambient = glGetUniformLocation(shaderprogram,"ambient") ;       
      diffuse = glGetUniformLocation(shaderprogram,"diffuse") ;       
      specular = glGetUniformLocation(shaderprogram,"specular") ;       
      shininess = glGetUniformLocation(shaderprogram,"shininess") ;
      isSin = glGetUniformLocation(shaderprogram, "isSin");
}
Exemple #7
0
void init() {
  vertexshader = initshaders(GL_VERTEX_SHADER, "shaders/nop.vert.glsl");
  fragmentshader = initshaders(GL_FRAGMENT_SHADER, "shaders/nop.frag.glsl");
  shaderprogram = initprogram(vertexshader, fragmentshader); 
}