コード例 #1
0
ファイル: lab3-3.c プロジェクト: noraply/TSBK07labbar
void init(void)
{
    glEnable(GL_TEXTURE_2D);
    walls = LoadModelPlus("windmill/windmill-walls.obj");
    wings = LoadModelPlus("windmill/blade.obj");
    roof = LoadModelPlus("windmill/windmill-roof.obj");
    balcony = LoadModelPlus("windmill/windmill-balcony.obj");
    skybox = LoadModelPlus("skybox.obj");

    LoadTGATextureSimple("grass.tga", &ground_tex);
    LoadTGATextureSimple("SkyBox512.tga", &skybox_tex);

    glActiveTexture(GL_TEXTURE0); // Activate ground texture
    glBindTexture(GL_TEXTURE_2D, ground_tex);

    glActiveTexture(GL_TEXTURE1);
    glBindTexture(GL_TEXTURE_2D, skybox_tex);

    if(walls == NULL || wings == NULL ) {
        fprintf(stderr, "Failed to load object\n");
    }
    cam_pos.x = 0.0;
    cam_pos.y = 0.0;
    cam_pos.z = 0.0;

    lookAt_pos.x = 0;
    lookAt_pos.y = 0;
    lookAt_pos.z = -30.0;

    dumpInfo();

    // GL inits
    glClearColor(0.7,0.2,0.5,1.0);
    glEnable(GL_DEPTH_TEST);

    printError("GL inits");

    // Load and compile shader
    program = loadShaders("lab3-3.vert", "lab3-3.frag");
    printError("init shader");

    glUniformMatrix4fv(glGetUniformLocation(program, "projectionMatrix"), 1, GL_TRUE, projectionMatrix);




    printError("init arrays");
}
コード例 #2
0
ファイル: lab3-3.c プロジェクト: jonatanolofsson/tsbk07
void init_skybox(void)
{
    programs[SKYBOX_PROGRAM] = loadShaders("skybox.vert", "skybox.frag");
    printError("init skybox0");
    skybox = LoadModelPlus("skybox.obj", programs[SKYBOX_PROGRAM], "inPosition", "inNormal", "inTexCoord");
    printError("init skybox1");
    LoadTGATextureSimple("SkyBox512.tga", &billboards[SKYBOX_TEXTURE]);
    printError("init skybox2");
}
コード例 #3
0
ファイル: objectHandler.c プロジェクト: GustavHager/ProjektP
objectData loadObject(char *modelFilename){
    Model *m = LoadModelPlus(modelFilename);

    objectData d;
    d.m = m;
    d.x = d.y = d.z = d.dx = d.dy = d.dz = 0;
    d.texture0 = d.texture1 = 0;
    T(0,0,0,&d.rotationMatrix);

    return d;
}
コード例 #4
0
ファイル: lab3-2.c プロジェクト: Grulfen/tsbk07
void init(void)
{
	dumpInfo();

        mill = LoadModelPlus( "windmill/windmill-walls.obj");
        blade = LoadModelPlus( "windmill/blade.obj");
        balcony = LoadModelPlus( "windmill/windmill-balcony.obj");
        roof = LoadModelPlus( "windmill/windmill-roof.obj");

	// GL inits
	glClearColor(0.0,0.3,0.3,0);
        glEnable(GL_DEPTH_TEST);
	printError("GL inits");

	// Load and compile shader
	program = loadShaders("lab3-2.vert", "lab3-2.frag");
	printError("init shader");

        glUniformMatrix4fv(glGetUniformLocation(program, "projectionMatrix"), 1, GL_TRUE, projectionMatrix);

        // Load texture
        //LoadTGATextureSimple("bilskissred.tga", &myBilTex);

	printError("init arrays");

        // Init up vector
        up.x = 0;
        up.y = 1;
        up.z = 0;

        cam_pos.x = 0;
        cam_pos.y = 5;
        cam_pos.z = 0;

        obj_pos.x = 0;
        obj_pos.y = 5;
        obj_pos.z = -30;

        initKeymapManager();
}
コード例 #5
0
void ManageChasersAndEvaders::loadEvaderModels()
{
  char *modelPath = "../objects/evader/crow/crow%d.obj";
  for(int i = 1; i < 42; i++)
    {
      char file[80]; // Arbitrary length, the string just has to fit
      sprintf(file, modelPath, i);
      
      Model* m = LoadModelPlus(file);
      evaderModels.push_back(m);
    }

}
コード例 #6
0
ファイル: lab3-2.c プロジェクト: Seanberite/CG
void init(void)
{	
	 
  	walls = LoadModelPlus("windmill-walls.obj");
	blade =  LoadModelPlus("blade.obj");
	roof = LoadModelPlus("windmill-roof.obj");


  LoadTGATextureSimple("maskros512.tga", &myTex);
  LoadTGATextureSimple("dirt.tga", &myTex2);


	// Reference to shader program
	dumpInfo();
	// GL inits
	glClearColor(0.4,0.2,0.0,0);
	glEnable(GL_DEPTH_TEST);
	printError("GL inits");

	// Load and compile shader
	program = loadShaders("lab3-2.vert", "lab3-2.frag");
	printError("init shader");
	
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, myTex);
	glActiveTexture(GL_TEXTURE1);
	glBindTexture(GL_TEXTURE_2D, myTex2);
	glUniform1i(glGetUniformLocation(program, "texUnit"), 0); // Texture unit 0
	glUniform1i(glGetUniformLocation(program, "texUnit2"), 1); // Texture unit 1
	glUniformMatrix4fv(glGetUniformLocation(program, "projectionMatrix"), 1, GL_TRUE, projectionMatrix);
   
       
	// End of upload of geometry

		
	printError("init arrays");

}
コード例 #7
0
ファイル: lab3-3.c プロジェクト: jonatanolofsson/tsbk07
void init_windmill(windmill_t* w, int n)
{
    programs[WINDMILL_PROGRAM] = loadShaders("lab3-3.vert", "lab3-3.frag");

    LoadTGATextureSimple("wood.tga", &billboards[WOOD_TEXTURE]);
    LoadTGATextureSimple("brick.tga", &billboards[BRICK_TEXTURE]);
    LoadTGATextureSimple("brick-crack.tga", &billboards[BRICK_CRACK_TEXTURE]);

    w->bladeangle = 0;
    w->windmill[WALLS] = LoadModelPlus("windmill/windmill-walls.obj", programs[WINDMILL_PROGRAM], "inPosition", "inNormal", "inTexCoord");
    w->windmill[BALCONY] = LoadModelPlus("windmill/windmill-balcony.obj", programs[WINDMILL_PROGRAM], "inPosition", "inNormal", "inTexCoord");
    w->windmill[ROOF] = LoadModelPlus("windmill/windmill-roof.obj", programs[WINDMILL_PROGRAM], "inPosition", "inNormal", "inTexCoord");

    T(0.05,9.15,4.5,work[1]);
    Ry(-M_PI_2,work[0]);
    Mult(work[0], work[1], w->bladecenterMatrix);

    {
        int i = 0;
        for(i = 0; i < 4; ++i) {
            T(0,0,0,w->bladeMDLMatrix[i]);
            Ry(100*M_PI/180,work[0]);
            Mult(work[0], w->bladeMDLMatrix[i], work[1]);
            Rz(M_PI_2*i,work[0]);
            Mult(work[0], work[1], w->bladeMDLMatrix[i]);
            w->blades[i] = LoadModelPlus("windmill/blade.obj", programs[WINDMILL_PROGRAM], "inPosition", "inNormal", "inTexCoord");
        }
    }

    T((MILL_RADIUS + MILL_RADIUS/(n+1.0))*cos(2*M_PI/(double)NUMBER_OF_WINDMILLS*n),0,(MILL_RADIUS + MILL_RADIUS/(n+1.0))*sin(2*M_PI/(double)NUMBER_OF_WINDMILLS*n),work[0]);
    double scale = 10*MILL_SCALE/(n+10.0);
    S(scale, scale, scale, work[1]);
    Mult(work[0], work[1], w->windmillMDLMatrix[WINDMILL_BASE]);
    T(0,0,0,w->windmillMDLMatrix[WALLS]);
    T(0,0,0,w->windmillMDLMatrix[BALCONY]);
    T(0,0,0,w->windmillMDLMatrix[ROOF]);
	printError("init windmill");
}
コード例 #8
0
ファイル: lab4-4.c プロジェクト: Seanberite/CG
void init(void)
{

	p = SetVector(20, 20, 0);
	l = SetVector(0,0,-1);
	v = SetVector(0,1,0);

	// GL inits
	glClearColor(0.2,0.2,0.5,0);
	glEnable(GL_DEPTH_TEST);
	glDisable(GL_CULL_FACE);
	printError("GL inits");

	projectionMatrix = frustum(-0.1, 0.1, -0.1, 0.1, 0.2, 50.0);

	// Load and compile shader
	program = loadShaders("terrain4.vert", "terrain4.frag");
	glUseProgram(program);
	printError("init shader");
	
	glUniformMatrix4fv(glGetUniformLocation(program, "projMatrix"), 1, GL_TRUE, projectionMatrix.m);

	LoadTGATextureSimple("maskros512.tga", &tex1);
	LoadTGATextureSimple("dirt.tga", &tex2);


	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, tex1);
	glUniform1i(glGetUniformLocation(program, "texUnit0"), 0); // Texture unit 0
	glActiveTexture(GL_TEXTURE1);
	glBindTexture(GL_TEXTURE_2D, tex2);
	glUniform1i(glGetUniformLocation(program, "texUnit1"), 1);

// Load terrain data
	
	LoadTGATextureData("fft-terrain.tga", &ttex);
	tm = GenerateTerrain(&ttex);
	TextureData *texturePointer = &ttex;
	texWidth = texturePointer->width;
	printError("init terrain");
// Load objects
sphere = LoadModelPlus("groundsphere.obj");

}
コード例 #9
0
ManageChasersAndEvaders::ManageChasersAndEvaders(GLuint* phongShader, char *modelPathEvader, char *imagePathEvader, char *modelPathChaser, char *imagePathChaser, Camera cam)
{
  shader = phongShader;

  glUseProgram(*shader);

  //________________Evader________________
  glActiveTexture(GL_TEXTURE8);
  glGenTextures(1, &evaderTexture);
  glBindTexture(GL_TEXTURE_2D, evaderTexture);
  LoadTGATextureSimple(imagePathEvader, &evaderTexture);
  
  glUniform1i(glGetUniformLocation(*shader, "evaderTexture"), 8); // Texture unit 8

  //________________Chaser________________
  glActiveTexture(GL_TEXTURE9);
  glGenTextures(1, &chaserTexture);
  glBindTexture(GL_TEXTURE_2D, chaserTexture);
  LoadTGATextureSimple(imagePathChaser, &chaserTexture);
 
  glUniform1i(glGetUniformLocation(*shader, "chaserTexture"), 9); // Texture unit 9

  loadEvaderModels();
  chaserModel = LoadModelPlus(modelPathChaser);

  // 350 boids is to much in one flock, ca 200 possible. // Can maybe be increased by threading
  Evader* evaders = new Evader(cam.position + vec3(25,25,25), 200, 0, cam.position); 
  Evader* evaders2 = new Evader(cam.position + vec3(30,30,50), 100, 1, cam.position);
  Evader* evaders3 = new Evader(cam.position + vec3(-30,30,-50), 100, 2, cam.position);
  Evader* evaders4 = new Evader(cam.position + vec3(-70,30,70), 150, 3, cam.position);

  flocks.push_back(evaders);
  flocks.push_back(evaders2);
  flocks.push_back(evaders3);
  flocks.push_back(evaders4);

  chasers = new Chaser(cam.position + vec3(300,100,300), 3, cam.position);

  prevTime = 0.0;
  modelIndex = 0;
}
コード例 #10
0
ファイル: lab4-1.c プロジェクト: 3born/TSBK07
void init(void)
{
  forward = SetVector(1,1,1);
  // GL inits
  glClearColor(0.2,0.2,0.5,0);
  glEnable(GL_DEPTH_TEST);
  glDisable(GL_CULL_FACE);
  printError("GL inits");

  projectionMatrix = frustum(-0.1, 0.1, -0.1, 0.1, 0.2, 500.0);

  // Load and compile shader
  program = loadShaders("terrain.vert", "terrain.frag");
  glUseProgram(program);
  printError("init shader");
	
  glUniformMatrix4fv(glGetUniformLocation(program, "projMatrix"), 1, GL_TRUE, projectionMatrix.m);
  glActiveTexture(GL_TEXTURE0);	
  glUniform1i(glGetUniformLocation(program, "tex"), 0); // Texture unit 0
  LoadTGATextureSimple("grass.tga", &tex1);

  //  glActiveTexture(GL_TEXTURE1);	
  //glUniform1i(glGetUniformLocation(program, "tex"),1); // Texture unit 0
  //  LoadTGATextureSimple("dirt.tga", &tex2);

	
  // Load terrain data
	
  LoadTGATextureData("fft-terrain.tga", &ttex);
  tm = GenerateTerrain(&ttex);
  printError("init terrain");

  //
  bunny= LoadModelPlus("bunnyplus.obj");

}
コード例 #11
0
ファイル: lab3-2.c プロジェクト: LordStraider/TSBK07
void init(void) {
	/* GL inits*/
	glClearColor(0.2,0.2,0.5,0);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);
	glCullFace(GL_TRUE);
	glActiveTexture(GL_TEXTURE0);
	printError("GL inits");

	xModify = 0.0;
	zModify = 0.0;
	xValue = 0.0;
	zValue = -2.0;
	yLookAt = 0.0;
	xLookAt = 0.0;

	/* Load and compile shader*/
	program = loadShaders("lab3-1.vert", "lab3-1.frag");
	glUseProgram(program);
	printError("init shader");
	/* Upload geometry to the GPU:*/

	bunny = LoadModelPlus("bunnyplus.obj");
    cow = LoadModelPlus("cow.obj");
    windmillBalcony = LoadModelPlus("windmill-balcony.obj");
    windmillRoof = LoadModelPlus("windmill-roof.obj");
    windmillWalls = LoadModelPlus("windmill-walls.obj");
    blade = LoadModelPlus("blade.obj");

	LoadTGATextureSimple("maskros512.tga", &myTex);

	glBindTexture(GL_TEXTURE_2D, myTex);
	glUniform1i(glGetUniformLocation(program, "texUnit"), 0); // Texture unit 0

 	/* End of upload of geometry*/
	glUniformMatrix4fv(glGetUniformLocation(program, "projMatrix"), 1, GL_TRUE, projMatrix);


	printError("init arrays");
}
コード例 #12
0
ファイル: lab3-4.c プロジェクト: LordStraider/TSBK07
void init(void) {
    /* GL inits*/
    glClearColor(0.2,0.2,0.5,0);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);
    glCullFace(GL_TRUE);
    glActiveTexture(GL_TEXTURE0);
    printError("GL inits");

    gravity = -0.18;
    xModify = 0.0;
    yModify = 0.55;
    zModify = 0.0;
    xValue = 0.0;
    yValue = 0.5;
    zValue = 16.0;
    rotate = M_PI / 2;
    angle = 0.0;
    camPos = M_PI / 2;
    menuPressed = false;
    yCamPos = 2.0;


    /* Load and compile shader*/
    program = loadShaders("lab3-1.vert", "lab3-1.frag");
    programShade = loadShaders("Shade.vert", "Shade.frag");
    programMultitex = loadShaders("multitex.vert", "multitex.frag");
    glUseProgram(program);
    printError("init shader");
    /* Upload geometry to the GPU:*/

    windmillBalcony = LoadModelPlus("windmill-balcony.obj");
    windmillRoof = LoadModelPlus("windmill-roof.obj");
    windmillWalls = LoadModelPlus("windmill-walls.obj");
    blade = LoadModelPlus("blade.obj");
    skyBox = LoadModelPlus("skybox.obj");
    ground = LoadModelPlus("cubeplus.obj");
    bunny = LoadModelPlus("bunnyplus.obj");

    LoadTGATextureSimple("grass.tga", &groundTex);
    LoadTGATextureSimple("maskros512.tga", &bunnyTex);
    LoadTGATextureSimple("skyBox512.tga", &skyBoxTex);

    glUniform1i(glGetUniformLocation(program, "texUnit"), 0); // Texture unit 0
    glUniform1i(glGetUniformLocation(programMultitex, "texUnit"), 1); // Texture unit 1
    glUniform1i(glGetUniformLocation(programMultitex, "texUnit2"), 2); // Texture unit 2

    /* End of upload of geometry*/
    glUniformMatrix4fv(glGetUniformLocation(program, "projMatrix"), 1, GL_TRUE, projMatrix);
    glUseProgram(programShade);
    glUniformMatrix4fv(glGetUniformLocation(programShade, "projMatrix"), 1, GL_TRUE, projMatrix);



    glUniform3fv(glGetUniformLocation(programShade, "lightSourcesDirPosArr"), 4, &lightSourcesDirectionsPositions[0].x);
    glUniform3fv(glGetUniformLocation(programShade, "lightSourcesColorArr"), 4, &lightSourcesColorsArr[0].x);
    glUniform1fv(glGetUniformLocation(programShade, "specularExponent"), 4, specularExponent);
    glUniform1iv(glGetUniformLocation(programShade, "isDirectional"), 4, isDirectional);



    glUseProgram(programMultitex);
    glUniformMatrix4fv(glGetUniformLocation(programMultitex, "projMatrix"), 1, GL_TRUE, projMatrix);

    printError("init arrays");
}
コード例 #13
0
ファイル: main.cpp プロジェクト: PONT-MAX/TSBK07
void init(void)
{
    
    printf("i1 \n");
    sfMakeRasterFont();
    
    sphere = LoadModelPlus("./OBJ/groundsphere.obj");
    
    camera = lookAt(0.0,2.0,-8.0,
                    0.0,0.0,0.0,
                    0.0,1.0,0.0);
    srand (time(NULL));
    
    skytot = T(0.0,0.0,0.0);
    lavatot = Mult(T(0,-1, 0), S(20, 0, 20));
    
    // GL inits
    glClearColor(0.2,0.2,0.5,0);
    glEnable(GL_DEPTH_TEST);
    glDisable(GL_CULL_FACE);
    printError("GL inits");
    
    projectionMatrix = frustum(-0.1, 0.1, -0.1, 0.1, 0.2, 100.0);
    
    printf("i2 \n");
    // Load and compile shader
    program = loadShaders("./Shader/terrain.vert", "./Shader/terrain.frag");
    skyprogram = loadShaders("./Shader/sky.vert", "./Shader/sky.frag");
    glUseProgram(program);
    printError("init shader");
    
    glUniformMatrix4fv(glGetUniformLocation(program, "projMatrix"), 1, GL_TRUE, projectionMatrix.m);
    glUniform1i(glGetUniformLocation(program, "tex"), 0); // Texture unit 0
    LoadTGATextureSimple("./TGA/lavaroad.tga", &tex1);
    LoadTGATextureSimple("./TGA/conc.tga", &tex2);
    

    printf("i3 \n");
    // Load terrain data
    InitTerrain();
    
    LoadTGATextureData("./TGA/fft-terrain.tga", &ttex);
    printError("init terrain");
    
    //Body
    LoadTGATextureSimple("./TGA/tex_01_lfy_weapon1out.tga", &tex_head);
    LoadTGATextureSimple("./TGA/red.tga", &tex_body);
    
    LegR = LoadModelPlus("./OBJ/LegR.obj");//Load Right Leg
    LegL = LoadModelPlus("./OBJ/LegL.obj");//Load Left Leg
    Body = LoadModelPlus("./OBJ/groundsphere.obj"); //Load Body & head
    ArmR = LoadModelPlus("./OBJ/armr.obj");//Load Right Arm
    ArmL = LoadModelPlus("./OBJ/arml.obj");//Load Right Arm
    printf("i4 \n");
    //boost & Obst
    LoadTGATextureSimple("./TGA/red.tga", &startex);
    LoadTGATextureSimple("./TGA/speed.tga", &speedtex);
    LoadTGATextureSimple("./TGA/imortal.tga", &imortaltex);
    //LoadTGATextureSimple("./TGA/spike.tga", &gatetex);
    LoadTGATextureSimple("./TGA/dirt.tga", &gatetex); //NY ANDREAS

    Star = LoadModelPlus("./OBJ/groundsphere.obj");//extra points
    SpeedObj = LoadModelPlus("./OBJ/groundsphere.obj");//speed
    Imortal = LoadModelPlus("./OBJ/groundsphere.obj");//speed

    //Gate = LoadModelPlus("./OBJ/spike.obj");//gate
    Gate = LoadModelPlus("./OBJ/gatecube.obj");//gate //NY ANDREREAS

    
    
    // Lava Ground
    Lava = LoadModelPlus("./OBJ/ground.obj");//load ground aka lava
    LoadTGATextureSimple("./TGA/lava.tga", &lavatex); //load the lava texture
    
    //Sky
    skybox = LoadModelPlus("./OBJ/cubeplus.obj");//Load skybox
    glUseProgram(skyprogram);
    glUniformMatrix4fv(glGetUniformLocation(skyprogram, "projMatrix"), 1, GL_TRUE, projectionMatrix.m);
    LoadTGATextureSimple("./TGA/skybox2.tga", &skytex); 	// Texture unit 1
    glUseProgram(program);
    
}
コード例 #14
0
ファイル: lab3-4.c プロジェクト: hansfilipelo/TSBK07
void init(void)
{
  // vertex buffer object, used for uploading the geometry

  dumpInfo(); // Dump driver info to stdout

  glutPassiveMotionFunc(&handle_mouse_helper); // set up mouse movement.
  #ifdef __APPLE__
  glutHideCursor();
  #endif

  // Load Model
  mill = LoadModelPlus("models/windmill/windmill-walls.obj");
  wing = LoadModelPlus("models/windmill/blade.obj");
  roof = LoadModelPlus("models/windmill/windmill-roof.obj");
  balcony = LoadModelPlus("models/windmill/windmill-balcony.obj");
  ground = LoadModelPlus("models/ground.obj");
  skybox = LoadModelPlus("models/skybox.obj");
  teapot = LoadModelPlus("models/teapot.obj");

  // GL inits
  glClearColor(1,1,1,0);
  //glClearColor(0.2,0.2,0.5,0); // Color in buffer upon clear buffer
  glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
  glEnable(GL_DEPTH_TEST);
  printError("GL inits");

  // ------------------------------------
  // Load and compile shader
  char* vertex_shader = malloc(MAX_FILE_SIZE);
  char* fragment_shader = malloc(MAX_FILE_SIZE);
  // Initialize to empty string
  vertex_shader[0] = '\0';
  fragment_shader[0] = '\0';

  // Append correct filename to shaders
  char* this_file = __FILE__;
  /* File ends with .c, 2 chars needs to be
  removed when appending to shaders which ends with .shader-stage */
  strncat(vertex_shader, this_file, strlen(this_file)-2);
  strncat(fragment_shader, this_file, strlen(this_file)-2);
  // Append name of shader-stage
  strcat(vertex_shader,".vert");
  strcat(fragment_shader,".frag");

  program = loadShaders(vertex_shader, fragment_shader); // These are the programs that run on GPU
  ground_shaders = loadShaders("src/lab3-4-ground.vert", "src/lab3-4-ground.frag");
  skybox_shaders = loadShaders("src/lab3-4-skybox.vert", "src/lab3-4-skybox.frag");
  printError("init shader");

  // --------------------------------------

  glUseProgram(program);
  glUniformMatrix4fv(glGetUniformLocation(program, "projectionMatrix"), 1, GL_TRUE, projectionMatrix);
  // Translations for windmill
  trans_mill = T(0,-5,-30);
  trans_teapot = T(-20,-5, -20);
  trans_roof = T(0, -4, -30);
  trans_balcony = T(0, -5, -30);
  glUniformMatrix4fv(glGetUniformLocation(program, "transformMatrix"), 1, GL_TRUE,  trans_mill.m);
  trans_wings = T(0,0,-26);
  trans_wings_up = T(4.6, 4.2, -4);
  // Upload light
  glUniform3fv(glGetUniformLocation(program, "lightSourcesDirPosArr"), 4, &lightSourcesDirectionsPositions[0].x);
  glUniform3fv(glGetUniformLocation(program, "lightSourcesColorArr"), 4, &lightSourcesColorsArr[0].x);
  glUniform1fv(glGetUniformLocation(program, "specularExponent"), 4, specularExponent);
  glUniform1iv(glGetUniformLocation(program, "isDirectional"), 4, isDirectional);

  // Upload stuff for ground
  glUseProgram(ground_shaders);
  glUniformMatrix4fv(glGetUniformLocation(ground_shaders, "projectionMatrix"), 1, GL_TRUE, projectionMatrix);

  glActiveTexture(GL_TEXTURE0);
  LoadTGATextureSimple("models/grass.tga", &ground_tex); // 5c
  int gr_scler_scalar = 10;
  mat4 temp_scaler = {
    1*gr_scler_scalar, 0, 0, 0,
    0, 1*gr_scler_scalar, 0, 0,
    0, 0, 1*gr_scler_scalar, 0,
    0, 0, 0, 1
  };
  mat4 ground_scaler = Mult(T(0, -5.4, 0), temp_scaler);
  glUniformMatrix4fv(glGetUniformLocation(ground_shaders, "transformMatrix"), 1, GL_TRUE, ground_scaler.m);

  // Upload stuff for skybox
  glUseProgram(skybox_shaders);
  glUniformMatrix4fv(glGetUniformLocation(skybox_shaders, "projectionMatrix"), 1, GL_TRUE, projectionMatrix);
  glActiveTexture(GL_TEXTURE0);
  LoadTGATextureSimple("models/SkyBox512.tga", &skybox_tex); // 5c
  skybox_transform = IdentityMatrix();



  printError("init arrays");

}
コード例 #15
0
void init(void)
{
	dumpInfo();  // shader info

	// GL inits
	glClearColor(0.1, 0.1, 0.3, 0);
	glClearDepth(1.0);

	glEnable(GL_TEXTURE_2D);
	glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);


    // Load shader
    shader = loadShaders("shaders/projekt.vert", "shaders/projekt.frag");
    phongshader = loadShaders("shaders/phong.vert", "shaders/phong.frag");
    passShader = loadShaders("shaders/plaintextureshader.vert", "shaders/plaintextureshader.frag");
    joinshader = loadShaders("shaders/joinshader.vert", "shaders/joinshader.frag");
    lightShader = loadShaders("shaders/illuminati.vert", "shaders/illuminati.frag");
    cameraDepthShader = loadShaders("shaders/cameraDepth.vert", "shaders/cameraDepth.frag");
    lightDepthShader = loadShaders("shaders/lightDepth.vert", "shaders/lightDepth.frag");
    thickness = loadShaders("shaders/thickness.vert", "shaders/thickness.frag");

    //shadow shaders

    projTexShaderId = loadShaders("shaders/depth1V.vert", "shaders/depth1F.frag");
    projTexShaderId2 = loadShaders("shaders/depth2V.vert", "shaders/depth2F.frag");
    projTexMapUniform = glGetUniformLocation(projTexShaderId,"textureUnit");
    plainShaderId = loadShaders("shaders/plain.vert", "shaders/plain.frag");


    // Init FBOs
	fbo_phong = initFBO(W, H, 0);
	//fbo2 = initFBO(W, H, 0);
    fbo_depth = initFBO2(W,H, 0, 1);
    fbo_depth2 = initFBO2(W,H, 0, 1);
	fbo3 = initFBO(W, H, 0);
    fbo_sub = initFBO(W,H,0);
    fbo_lightDepth = initFBO(W,H,0);


    squareModel = LoadDataToModel(
            square, NULL, squareTexCoord, NULL,
            squareIndices, 4, 6);

    cam = SetVector(0, 0, 0.01);
    point = SetVector(0, 0, -10);
    axis = SetVector(0, 1, 0);


	// load the model
    bunny = LoadModelPlus("objects/bunny2/bunny_unwrap_noextras_blender.obj");
    LoadTGATextureSimple("textures/badBunny.tga", &thicknessBunny);
    modelMatrix = Mult( modelMatrix, ArbRotate(axis, -0.6));
    statue = LoadModelPlus("good_objects/statue_unwrapped_blender.obj");
    LoadTGATextureSimple("textures/statue.tga", &thicknessStatue);

    box = LoadModelPlus("good_objects/box_standard_blender.obj");
    LoadTGATextureSimple("textures/box.tga", &thicknessBox);

    box_bulge = LoadModelPlus("good_objects/box_bulge.obj");
    box_valley = LoadModelPlus("good_objects/box_valley.obj");
    box_stretched = LoadModelPlus("good_objects/box_stretched.obj");

    // load the scenemodels
    bottom = LoadModelPlus("objects/bottom.obj");
    side1 = LoadModelPlus("objects/side1.obj");
    side2 = LoadModelPlus("objects/side2.obj");

    // load sphere
    sphere = LoadModelPlus("objects/sphere.obj");
    printf("%d vertices\n", sphere->numVertices);
    printf("%d indices\n", sphere->numIndices);

    //Light stuff
    lightPosition = SetVector(-5.0,5.0,-4.0);
    sphereModelMatrix = Mult(T(lightPosition.x, lightPosition.y, lightPosition.z), sphereModelMatrix);
    lightColor = SetVector(1.0,1.0,1.0);

    //Colors
    bunnyColor = SetVector(1.0,0.4,1.0);
    sceneColor = SetVector(0.2,0.2,0.7);

    glutTimerFunc(5, &OnTimer, 0);

    moveValue = 0.002;
    moveX = moveValue;

	zprInit(&viewMatrix, cam, point);


    //modelMatrix = Mult( T(0.0, -2.4,0.0),modelMatrix);

}
コード例 #16
0
ファイル: Starter.cpp プロジェクト: hento581/OProject2
void init(void)
{

	GLenum err = glewInit();
	//glutReshapeWindow(screenX,screenY);
	glutFullScreen();
	glutSetCursor(GLUT_CURSOR_NONE);

	// GL inits
	glClearColor(0.2,0.2,0.5,0);
	glEnable(GL_DEPTH_TEST); 
	glEnable(GL_CULL_FACE);
	glAlphaFunc(GL_GREATER, 0.0f);
	
	printError("GL inits");

	projectionMatrix = frustum(left,right, bottom, top, near, far);

	for(int i = 0; i<256; i++)
	{
		for(int j = 0; j<256; j++)
		{
			randXZ->xz[i][j].x=-9999.0;
			randXZ->xz[i][j].z=-9999.0;
		}
	}

	// Load and compile shaders
	program = loadShaders("terrain.vert", "terrain.frag");
	billBoardProgram = loadShaders("billBoardShader.vert", "billBoardShader.frag");
	skyProgram = loadShaders("skyShader.vert", "skyShader.frag");
	glUseProgram(program);
	printError("init shader");
	
	glUniformMatrix4fv(glGetUniformLocation(program, "projMatrix"), 1, GL_TRUE, projectionMatrix.m);

	//Load textures for terrain
	glUniform1i(glGetUniformLocation(program, "tex1"), 0);
	LoadTGATextureSimple("mygrass.tga", &tex1);
	LoadTGATextureSimple("newterrain.tga", &tex2);
	LoadTGATextureSimple("ok1.tga", &tex3);
	LoadTGATextureSimple("water0hk.tga", &tex4);
	
// Load terrain data and init player and world	
	LoadTGATexture("ownterrain.tga", &ttex);
	world = new World(&ttex);
	player = new Player(p,l,world);
	tm = world->GenerateTerrain();

	//There shouldn't be trees in the water
	for(int i=0; i<254; i++)
	{
		for(int j=0; j<254; j++)
		{
			if(world->findHeight(i,j) < 0.5)
			{
				
				posIsTree[i][j]=false;
			}
			else
			{
				posIsTree[i][j]=true;
			}
		}
	}

	//Load models and textures
	glUseProgram(billBoardProgram);
	glUniformMatrix4fv(glGetUniformLocation(billBoardProgram, "projMatrix"), 1, GL_TRUE, projectionMatrix.m);
	bill = billboardModel();
	map = mapModel();
	punsh = punshModel();
	compass = compassModel();
	control = controlModel();

	LoadTGATextureSimple("tree.tga", &treeTex);
	LoadTGATextureSimple("control.tga", &controlTex);
	LoadTGATextureSimple("compass.tga", &compassTex);
	LoadTGATextureSimple("mapcourse.tga", &mapTex);
	LoadTGATextureSimple("punsh.tga", &punshTex);
	LoadTGATextureSimple("goal.tga", &goalTex);

	//Load skybox
	glUseProgram(skyProgram);
	glUniformMatrix4fv(glGetUniformLocation(skyProgram, "projMatrix"), 1, GL_TRUE, projectionMatrix.m);
	sky = LoadModelPlus("skybox.obj");
	LoadTGATextureSimple("SkyBox512.tga", &skyTex);

	printError("init terrain");

	
}
コード例 #17
0
ファイル: lab2-3.c プロジェクト: hansfilipelo/TSBK07
void init(void)
{
  // vertex buffer object, used for uploading the geometry

  dumpInfo(); // Dump driver info to stdout

  // Load Model
  m = LoadModelPlus("bunnyplus.obj");

  // GL inits
  glClearColor(1,1,1,0);
  //glClearColor(0.2,0.2,0.5,0); // Color in buffer upon clear buffer
  glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
  glEnable(GL_DEPTH_TEST);
  printError("GL inits");

  // Load and compile shader
  program = loadShaders("lab2-3.vert", "lab2-3.frag"); // These are the programs that run on GPU
  printError("init shader");

  // Upload geometry to the GPU:
  glGenVertexArrays(1, &bunnyVertexArrayObjID);
  glGenBuffers(1, &bunnyVertexBufferObjID);
  glGenBuffers(1, &bunnyIndexBufferObjID);
  glGenBuffers(1, &bunnyNormalBufferObjID);
  printError("glGenBuffers");

  glBindVertexArray(bunnyVertexArrayObjID);

  // Lab2
  //--------------
  glGenBuffers(1, &bunnyTexCoordBufferObjID);

  if (m->texCoordArray != NULL)
  {
    // Load model and its texture mapping coordinates
    glBindBuffer(GL_ARRAY_BUFFER, bunnyTexCoordBufferObjID);
    glBufferData(GL_ARRAY_BUFFER, m->numVertices*2*sizeof(GLfloat), m->texCoordArray, GL_STATIC_DRAW);
    glVertexAttribPointer(glGetAttribLocation(program, "inTexCoord"), 2, GL_FLOAT, GL_FALSE, 0, 0);
    glEnableVertexAttribArray(glGetAttribLocation(program, "inTexCoord"));
  }

  // Load texture into uniform in fragment shader
  glUniform1i(glGetUniformLocation(program, "tex"), 0); // Create texture unit
  LoadTGATextureSimple("grass.tga", &tex); // Load texture to texture unit
  glBindTexture(GL_TEXTURE_2D, tex); // Bind texture unit
  glActiveTexture(GL_TEXTURE0); // Activate texture unit 0 (in case we have multiple textures, this is nessecary)

  // Create a texture unit

  // -----------------

  // VBO for vertex data
  glBindBuffer(GL_ARRAY_BUFFER, bunnyVertexBufferObjID);
  glBufferData(GL_ARRAY_BUFFER, m->numVertices*3*sizeof(GLfloat), m->vertexArray, GL_STATIC_DRAW);
  glVertexAttribPointer(glGetAttribLocation(program, "in_Position"), 3, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(glGetAttribLocation(program, "in_Position"));

  // VBO for normal data
  glBindBuffer(GL_ARRAY_BUFFER, bunnyNormalBufferObjID);
  glBufferData(GL_ARRAY_BUFFER, m->numVertices*3*sizeof(GLfloat), m->normalArray, GL_STATIC_DRAW);
  glVertexAttribPointer(glGetAttribLocation(program, "in_Normal"), 3, GL_FLOAT, GL_FALSE, 0, 0);
  glEnableVertexAttribArray(glGetAttribLocation(program, "in_Normal"));

  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bunnyIndexBufferObjID);
  glBufferData(GL_ELEMENT_ARRAY_BUFFER, m->numIndices*sizeof(GLuint), m->indexArray, GL_STATIC_DRAW);

  // --------------------------------------

  glUniformMatrix4fv(glGetUniformLocation(program, "projectionMatrix"), 1, GL_TRUE, projectionMatrix);

  printError("init arrays");
}
コード例 #18
0
ファイル: lab3-4.c プロジェクト: Nicsi918/Labs
void init(void)
{	
	GLuint myTex;
	// Reference to shader program
	
	unsigned int vertexBufferObjID;

	dumpInfo();

	// GL inits
	glClearColor(0.1,0.2,1.0,0);
	glEnable(GL_DEPTH_TEST);
	printError("GL inits");
	
	m = LoadModelPlus("windmill/windmill-balcony.obj");	
	m2 = LoadModelPlus("windmill/windmill-walls.obj");
	m3 = LoadModelPlus("windmill/windmill-roof.obj");
	blade = LoadModelPlus("windmill/blade.obj");
	skybox = LoadModelPlus("skybox.obj");
	
	int i;
	int j;
	for(j = 0; j < nrOfMills; j++)
	{
		for(i = 0; i  < nrOfMills; i++)
		{
			windmills[j*nrOfMills + i].pos = SetVector(i * -25, 0, -25*j + i * -25);
		}
	}
	
	p = SetVector(35.0f, 10.0f, 0.0f);
   l = SetVector(0.0, 10.0, 0.0);
   v = SetVector(0, 1.0, 0);

	// Load and compile shader
	program = loadShaders("lab3-4.vert", "lab3-4.frag");
	terrainProgram = loadShaders("lab3-3.vert", "lab3-3.frag");
	skyboxProgram = loadShaders("lab3-3-skybox.vert", "lab3-3-skybox.frag");
	
	LoadTGATextureSimple("SkyBox512.tga", &skyboxTex);
	glUseProgram(skyboxProgram);
	glBindTexture(GL_TEXTURE_2D, skyboxTex);
	printf("TExture object : %d", skyboxTex);
	 glUniform1i(glGetUniformLocation(skyboxProgram, "texUnit"), 0); // Texture unit 0

	printError("init shader");
	printf("-3 : %d\n", terrainProgram);
	printf("-2 : %d\n", program);
	
	
	glGenVertexArrays(1, &vertexArrayObjID);
	glBindVertexArray(vertexArrayObjID);
	// Allocate Vertex Buffer Objects
	glGenBuffers(1, &vertexBufferObjID);
	
	// VBO for vertex data
	glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObjID);
	
	glBufferData(GL_ARRAY_BUFFER, 6*3*sizeof(GLfloat), terrain, GL_STATIC_DRAW);
	
	glUseProgram(terrainProgram);
	glVertexAttribPointer(glGetAttribLocation(terrainProgram, "in_Position"), 3, GL_FLOAT, GL_FALSE, 0, 0); 
	glEnableVertexAttribArray(glGetAttribLocation(terrainProgram, "in_Position"));
	
	glUseProgram(program);
	glUniform3fv(glGetUniformLocation(program, "lightSourcesDirPosArr"), 4, &lightSourcesDirectionsPositions[0].x);
	glUniform3fv(glGetUniformLocation(program, "lightSourcesColorArr"), 4, &lightSourcesColorsArr[0].x);
	glUniform1fv(glGetUniformLocation(program, "specularExponent"), 4, specularExponent);
	glUniform1iv(glGetUniformLocation(program, "isDirectional"), 4, isDirectional);
	
	printError("init arrays");
}