Example #1
0
void initOpenGL() {
    // Initialize GLEW on Windows, to make sure that OpenGL 2.0 is loaded
#ifdef FRAMEWORK_USE_GLEW
    GLuint error = glewInit();
    if (GLEW_OK != error) {
        std::cerr << glewGetErrorString(error) << std::endl;
        exit(-1);
    }
    if (!GLEW_VERSION_2_0 || !GL_EXT_framebuffer_object) {
        std::cerr << "This program requires OpenGL 2.0 and FBOs" << std::endl;
        exit(-1);
    }
#endif

    // This initializes OpenGL with some common defaults.  More info here:
    // http://www.sfml-dev.org/tutorials/1.6/window-opengl.php
    glClearDepth(1.0f);
    //glClearColor(0.529f, 0.808f, 0.980f, 1.0f);//sky blue
	//glClearColor(0.529f, 0.808f, 0.980f, 1.0f);//sky blue
	glClearColor(0.15f, 0.15f, 0.15f, 1.0f);//sky blue
    glEnable(GL_DEPTH_TEST);

	GL_CHECK(glEnable(GL_TEXTURE_2D));
    glViewport(0, 0, window.GetWidth(), window.GetHeight());
}
Example #2
0
void setMatrices(const aiScene * scene) {
    // Set up the projection and model-view matrices
    GLfloat aspectRatio = (GLfloat)window.GetWidth()/window.GetHeight();
    GLfloat nearClip = 0.1f;
    GLfloat farClip = 500.0f;
    GLfloat fieldOfView = 45.0f; // Degrees
    
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(fieldOfView, aspectRatio, nearClip, farClip);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(current_location.x, current_location.y, current_location.z, 
              current_location.x + current_forward.x,
              current_location.y + current_forward.y,
              current_location.z + current_forward.z, 0.0f, 1.0f, 0.0f);
    
    setupLights();
        
    // Pass in our view matrix for cubemapping purposes 
    // note: this may not be the best place to actually pass it to the shader...
    int shaderNum = 1;
    GLfloat* vMatrix = new GLfloat[16];
    glGetFloatv(GL_MODELVIEW_MATRIX, vMatrix);
    
//    // Ugly, ugly, UGLY!
//    aiMatrix4x4 invertMe = aiMatrix4x4(vMatrix[0], vMatrix[1], vMatrix[2], vMatrix[3], vMatrix[4], vMatrix[5], vMatrix[6], vMatrix[7], vMatrix[8], vMatrix[9], vMatrix[10], vMatrix[11], vMatrix[12], vMatrix[13], vMatrix[14], vMatrix[15]);
//    aiMatrix4x4 inverted = invertMe.Inverse();
//    GLfloat* vInvMatrix = new GLfloat{ inverted.a1, inverted.a2, inverted.a3, inverted.a4, inverted.b1, inverted.b2, inverted.b3, inverted.b4, inverted.c1, inverted.c2, inverted.c3, inverted.c4};
    
    GLint vM = glGetUniformLocation(shaders[shaderNum]->programID(), "viewMatrix");
    glUniformMatrix4fv(vM,1,true,vMatrix);
    
    applyMatrixTransform(scene->mRootNode);
}
Example #3
0
void renderFrame() {
    glUseProgram(_mainShader.programID());
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0f, _window.GetWidth()/_window.GetHeight(), 0.1f, 500);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    _camera.setViewTransform();
    /*
    glBegin(GL_TRIANGLES);
    glVertex2f(0.0f, 0.0f);
    glVertex2f(1.0f, 0.0f);
    glVertex2f(1.0f, 1.0f);
    glEnd();*/
    for (int i =0; i < _scene._VBOs.size(); i++) {
        Scene::VBO vbo = _scene._VBOs.at(i);
        glBindBuffer(GL_ARRAY_BUFFER, vbo.position);
        glVertexAttribPointer(_mainShader.getAttribLocationOf("positionIn"), 3, GL_FLOAT, GL_FALSE, sizeof(aiVector3D), 0);
        glBindBuffer(GL_ARRAY_BUFFER, vbo.texcoord);
        glVertexAttribPointer(_mainShader.getAttribLocationOf("texcoordIn"), 2, GL_FLOAT, GL_FALSE, sizeof(aiVector3D), 0);
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.indices);
        glDrawElements(GL_TRIANGLES, vbo.numIndices, GL_UNSIGNED_INT, 0);
    }
}
Example #4
0
void setMatrices()
{
    // Set up the projection and model-view matrices
    GLfloat aspectRatio = (GLfloat)window.GetWidth()/window.GetHeight();
    GLfloat nearClip = 0.1f;
    GLfloat farClip = 500.0f;
    GLfloat fieldOfView = 45.0f; // Degrees

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(fieldOfView, aspectRatio, nearClip, farClip);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(0.0, 0.0, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f);

    glPushMatrix(); // set the light in the scene correctly
    transNode(cathedralScene, cathedralScene->mRootNode);
    GLfloat light0_position[] = { 0, 30, 0, 0 };
    glLightfv( GL_LIGHT0, GL_POSITION, light0_position );
    GLfloat light1_position[] = { 0, 11, 0, 0.0 };
    glLightfv( GL_LIGHT1, GL_POSITION, light1_position );
    glPopMatrix();

    glRotatef(rad_to_deg(pitch), 1.0, 0.0, 0.0);
    glRotatef(rad_to_deg(yaw), 0.0, 1.0, 0.0);
    glTranslatef(position.x, position.y, position.z);

    // We store the modelview matrix here, but it's actually the view matrix because we haven't done any model transforms yet
//    static double viewMatrix[16];
    GLfloat *viewMatrix = new GLfloat[16];
    glGetFloatv(GL_MODELVIEW_MATRIX, viewMatrix);
    GLint inverseViewMatrixUniform = glGetUniformLocation(envMapShader->programID(), "inverseViewMatrix");
    glUniformMatrix4fv(inverseViewMatrixUniform, 1, true, viewMatrix);
    delete [] viewMatrix;
}
Example #5
0
void init(int argc, const char **argv)
{
	assert(glewInit() == GLEW_OK);
	assert(GLEW_VERSION_2_0 || GL_EXT_framebuffer_object);
	glClearDepth(1.0f);
    glClearColor(0.15f, 0.15f, 0.15f, 1.0f);
    glEnable(GL_DEPTH_TEST);
    glViewport(0, 0, window.GetWidth(), window.GetHeight());
}
Example #6
0
void setPerspective()
{

	mat4 r;
	switch (fflag) {
		case 'a':
		case 'q': dir = rot(-ROT_SPEED * bank * abs(bank) / 50 / 50, dir); 
				  if (bank < MAX_BANK) {
				      r = glm::rotate(mstack.top(), BANK_SPEED, glm::vec3(0.0f, 0.0f, 1.0f));
				      mstack.pop();
				      mstack.push(r);
				      bank += BANK_SPEED ;
				  }
				  break;
		case 'd':
		case 'e': 
				  dir = rot(-ROT_SPEED * bank * abs(bank) / 50 / 50, dir);
				  if (bank > -MAX_BANK) {
					  r = glm::rotate(mstack.top(), -BANK_SPEED, glm::vec3(0.0f, 0.0f, 1.0f));
					  mstack.pop();
					  mstack.push(r);
				      bank -= BANK_SPEED;
			      }
				  break;
		default:
				  if (speed_multiplier > 0.2 && fflag == 's') speed_multiplier -= 0.01;
		          if (speed_multiplier < 4.0 && fflag == 'w') speed_multiplier += 0.01;

				  if (bank < BANK_SPEED && bank > -BANK_SPEED) {
					  r = glm::rotate(mstack.top(), -bank, glm::vec3(0.0f, 0.0f, 1.0f));
					  bank = 0;
				  }
				  else {
					  dir = rot(-ROT_SPEED * bank * abs(bank) / 50 / 50, dir);
					  r = glm::rotate(mstack.top(), -bank * BANK_SPEED / 40, glm::vec3(0.0f, 0.0f, 1.0f));
					  bank += -bank * BANK_SPEED / 40;
				  }
				  mstack.pop();
				  mstack.push(r);
				  break;
	}
	
	if (move)
		eye += vec2(dir.x * PLANE_SPEED, dir.y * PLANE_SPEED);
	


	g_projection = glm::perspective(45.0f, 
						(GLfloat)window.GetWidth()/window.GetHeight(), 0.1f, 175.0f);
	g_modelview = glm::lookAt(vec3(eye.x, 5, eye.y), vec3(eye.x+dir.x, 4.7, eye.y+dir.y), vec3(0, 1, 0));
	
}
Example #7
0
void initOpenGL() {
    // Initialize GLEW on Windows, to make sure that OpenGL 2.0 is loaded
#ifdef FRAMEWORK_USE_GLEW
    GLint error = glewInit();
    if (GLEW_OK != error) {
        std::cerr << glewGetErrorString(error) << std::endl;
        exit(-1);
    }
    if (!GLEW_VERSION_2_0 || !GL_EXT_framebuffer_object) {
        std::cerr << "This program requires OpenGL 2.0 and FBOs" << std::endl;
        exit(-1);
    }
#endif

    // This initializes OpenGL with some common defaults.  More info here:
    // http://www.sfml-dev.org/tutorials/1.6/window-opengl.php
    glClearDepth(1.0f);
    glClearColor(0.15f, 0.15f, 0.15f, 1.0f);
    glEnable(GL_DEPTH_TEST);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
    glViewport(0, 0, window.GetWidth(), window.GetHeight());

    position = aiVector3D(35.0, -20.0, 0.0);
    yaw = M_PI * 3 / 2.0;
    pitch = -M_PI / 7;

    GLfloat light0_position[] = { 0.0, 30.0, 0.0, 0.0 };
    GLfloat light0_ambient[] = { 245/2550.0, 222/2550.0, 179/2550.0, 1 };
    GLfloat light0_diffuse[] = { 245/255.0, 232/255.0, 199/255.0, 1 };
    GLfloat light0_specular[] = { 0.7, 0.7, 0.7, 1 };
    GLfloat shininess = 90;
    glLightfv(GL_LIGHT0, GL_POSITION, light0_position);
    glLightfv( GL_LIGHT0, GL_AMBIENT, light0_ambient );
    glLightfv( GL_LIGHT0, GL_DIFFUSE, light0_diffuse );
    glLightfv( GL_LIGHT0, GL_SPECULAR, light0_specular );
    glLightfv( GL_LIGHT0, GL_SHININESS, &shininess );
    glEnable(GL_LIGHT0);

    GLfloat light1_position[] = { 0, 11, 0, 0.0 };
    GLfloat light1_diffuse[] = { 145/2550.0, 222/2550.0, 149/2550.0, 1 };
    GLfloat light1_specular[] = { 0.1, 0.1, 0.1, 1 };
    glLightfv( GL_LIGHT1, GL_POSITION, light1_position );
    glLightfv( GL_LIGHT1, GL_DIFFUSE, light1_diffuse );
    glLightfv( GL_LIGHT1, GL_SPECULAR, light1_specular );
    glEnable(GL_LIGHT1);

    depthRenderTarget = new DepthRenderTarget(RENDER_WIDTH * SHADOW_MAP_RATIO, RENDER_HEIGHT * SHADOW_MAP_RATIO);
}
Example #8
0
void createView() {
  // Set up the projection and model-view matrices
  GLfloat aspectRatio = (GLfloat) window.GetWidth() / window.GetHeight();
  GLfloat nearClip = 0.1f;
  GLfloat farClip = 500.0f;
  GLfloat fieldOfView = 45.0f; // Degrees

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(fieldOfView, aspectRatio, nearClip, farClip);

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  gluLookAt(cameraX, cameraY, cameraZ, 0, 0, 0, 0, 1, 0);

}
Example #9
0
int main(int argc, char** argv) {

    initOpenGL();
    loadAssets();
    
    // go to a square Viewport
    glViewport(0, 0, CUBE_MAP_SIZE, CUBE_MAP_SIZE);
    generateEnvironmentMap();
    
    // go to our window Viewport
    glViewport(0, 0, window.GetWidth(), window.GetHeight());

    // Put your game loop here (i.e., render with OpenGL, update animation)
    while (window.IsOpened()) {
        handleInput();
        renderFrame();
        window.Display();
        
        updatePositions();
    }
    
    return 0;
}
Example #10
0
int main ( int argc, char **argv )
{
	// On cr�e notre fen�tre gr�ce � SFML
	Application.Create( sf::VideoMode( 800, 500, 32 ), "SFML : Bullet physics", sf::Style::Titlebar | sf::Style::Resize | sf::Style::Close);
    //Application.Create(sf::VideoMode::GetMode(0), "SFML Window", sf::Style::Fullscreen);
	// Creation d'une fen�tre plein �cran avec le meilleur mode vid�o
  	
    
    
    /// Bullet physics
	
    ///collision configuration contains default setup for memory, collision setup
	myCollisionConfiguration = new btDefaultCollisionConfiguration();
	
	///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded)
	myDispatcher = new	btCollisionDispatcher(myCollisionConfiguration);
	
	myBroadphase = new btDbvtBroadphase();
	
	///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded)
	mySequentialImpulseConstraintSolver = new btSequentialImpulseConstraintSolver;
	
	// initialisation du monde bullet
	myWorld = new btDiscreteDynamicsWorld(myDispatcher,myBroadphase,mySequentialImpulseConstraintSolver,myCollisionConfiguration);
	
	// On d�finit la gravit�, de fa�on � ce que les objets tombent vers le bas (-Y).
	myWorld->setGravity( btVector3(0,-10,0) );
	
	/// SOL ///////////////////////////////////////////
	// create a shape
	btCollisionShape* shape_sol = new btBoxShape( btVector3(100,1,100) );
	
	myTransform.setIdentity();
	myTransform.setOrigin( btVector3(0,0,0) );
	
	btVector3 localInertiaSol(0,0,0);
	
	btScalar mass = 0;
	
	// Using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
	myMotionState_Sol = new btDefaultMotionState(myTransform);
	btRigidBody::btRigidBodyConstructionInfo rbInfo_sol( mass, myMotionState_Sol, shape_sol, localInertiaSol );
	body_sol = new btRigidBody(rbInfo_sol);
	
	// Add the body to the dynamics world
	myWorld->addRigidBody(body_sol);

 
    
    
    
    // Create a clock for measuring time elapsed
    sf::Clock montre;
    //Variable pour calculer le delta de d�placement de la souris quand les clicks droit et gauche de la souris sont enfonc� pour manipuler la cam�ra
  
    // Pour d�clancher la chute d'un seul kapla quand la touche Espace est relach�e
	bool trigger = false; 
 
	unsigned int windowsWidth = Application.GetWidth();
    unsigned int windowsHeight = Application.GetHeight();
    
    
    int startPointX(0),startPointY(0);
    float deltaX(0),deltaY(0),prevDeltaX(1),prevDeltaY(1);
    int   MouseX(0);
    int   MouseY(0);
    bool show = true;
    
	//unsigned int sizeWidth = sf::Window::GetWidth();
    
    //On initialise une cam�ra qui sera plac� par d�faut par le constructeur
    Camera camcam(110,60.0,60.0);
    Cursor cursor;
bool test = false;
       
    float time;

 // pour avoir les infos clavier en temps r�el
	const sf::Input& Input = Application.GetInput();
	// Notre boucle d'affichage
	while(Application.IsOpened() )
	{
        Application.ShowMouseCursor (false);
        // r�f�rence vers l'entr�e associ�e � une fen�tre (pour r�cup�rer les donn�s clavier en temps r�el
        
        sf::Event Event;
        //Utilise les fl�che pour d�placer le Kapla qui va �tre lach�
        // Get some useless input states, just to illustrate the tutorial
        bool         LeftKeyDown     = Input.IsKeyDown(sf::Key::Left);
        bool         RightKeyDown     = Input.IsKeyDown(sf::Key::Right);
        bool         UpKeyDown     = Input.IsKeyDown(sf::Key::Up);
        bool         DownKeyDown     = Input.IsKeyDown(sf::Key::Down);
        
        bool         RightButtonDown = Input.IsMouseButtonDown(sf::Mouse::Right);
        bool         LeftButtonDown = Input.IsMouseButtonDown(sf::Mouse::Left);
        bool         Espace     = Input.IsKeyDown(sf::Key::Space);
        bool         Shift     = Input.IsKeyDown(sf::Key::LShift);
        MouseX  =   Input.GetMouseX() ;
        MouseY  =   Input.GetMouseY() ;
        
        if (LeftButtonDown) 
        {
                if (show ) 
                {
                    montre.Reset();
                    startPointY = MouseY;
                    startPointX = MouseX;
                //cout<< "start point" <<startPointX<< endl;
                    
                    show = false;
                }
                time = montre.GetElapsedTime();
            //cout<< time << endl;
           
                if (time > 0.02) 
                {
                
                    deltaX = ((MouseX-startPointX));
                
                    deltaY = ((MouseY-startPointY));
                    //show = true;
                cout<< deltaX<< endl;
                    if ((prevDeltaX != deltaX)||(prevDeltaY != deltaY)) {
                        camcam.tumble(deltaX/5,deltaY/5);
                        show = true;
                        //montre.Reset();
                        prevDeltaX = deltaX;
                        prevDeltaY = deltaY;
                        
                    }
            }
            
        }else
        {
            show = true;
            cursor.set((MouseX - windowsWidth/2), (MouseY - windowsHeight/2));
        }
        
        if (Shift) {
            test=true; 
        }else{
            test=false;
        }
        
        

        if (LeftKeyDown) {
            camcam.tumble(0.005, 0);
            LeftKeyDown = false;
        }
        if (RightKeyDown) {
            camcam.tumble(-0.005, 0);
            RightKeyDown = false;
        }
        if (UpKeyDown) {
            camcam.tumble(0, 0.005);
        }
        if (DownKeyDown) {
            camcam.tumble(0, -0.005);
        }
        //unsigned int delta =mouseT3 - mouseT1;
        //cout << delta<< endl;
        
        
        
        
        while (Application.GetEvent(Event))
        {
            
            if (Event.Type == sf::Event::Resized)
                glViewport(0, 0, Event.Size.Width, Event.Size.Height);
            // Fen�tre ferm�e
            if (Event.Type == sf::Event::Closed)
                Application.Close();
            
            // Touche 'echap' appuy�e
            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
                Application.Close();
            if ((Event.Type == sf::Event::KeyReleased) && (Event.Key.Code == sf::Key::Space)) {
                /// box ///////////////////////////////////////////
                // create a shape
                btCollisionShape* shape_kapla = new btBoxShape( btVector3(3,1,15) );
                
                myTransform.setIdentity();
                int dropX((MouseX - windowsWidth/2));
                int dropY((MouseY - windowsHeight/2));
                myTransform.setOrigin(btVector3(dropX,5,dropY));
                
                btVector3 localInertia(0,0,0);
                
                mass = 0.5f;
                
                shape_kapla->calculateLocalInertia( mass, localInertia );
                
                //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
                myMotionState = new btDefaultMotionState(myTransform);
                btRigidBody::btRigidBodyConstructionInfo myBoxRigidBodyConstructionInfo( mass,myMotionState, shape_kapla, localInertia );
                body_kapla = new btRigidBody(myBoxRigidBodyConstructionInfo);
                
                //add the body to the dynamics world
                
                myWorld->addRigidBody(body_kapla);
                trigger=true;
            }
        }

        Application.SetActive();
         
        
        

        
        //NEED convertiseur coord souris -> coord du plan visible par la cam�ra
        // le d�placement sur le plan de la fen�tre est proportionel � celui du plan de construction
        
        // dessin  le curseur
        //cursor.drawKapla(1,15,3); 
        
        
        //touche espace enfonc�e et relach�e
       if ((Espace))
        {
           
         
        }              
                                   
        if (myWorld)
		{
			myWorld->stepSimulation( 0.0001 );
		}

       
        camcam.display();
        
        cursor.drawKapla(15, 3, 1);
        // On recup�re la matrice OpenGL transform�e par Bullet qu'on appliquera � notre boite
        if (trigger)
        {
                myMotionState->m_graphicsWorldTrans.getOpenGLMatrix( matrix );
            glPushMatrix();
            glMultMatrixf( matrix );
            box(3,1,15);
            glPopMatrix();
            
        }
        
        
		box(100,1,100);
		// On a	ffiche le sol;
        if (test==true)
        {
                   }
		
		
        
		
		// swap buffers, etc
		Application.Display();
        
	}
}
Example #11
0
void initGL() {
    glClearDepth(1.0f);
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glEnable(GL_DEPTH_TEST);
    glViewport(0, 0, _window.GetWidth(), _window.GetHeight());
}
	void handleEvents()
	{
		sf::Event Event;
		while (App->GetEvent(Event))
		{
			// Close window : exit
			if (Event.Type == sf::Event::Closed)
				App->Close();
			
			// Escape key : exit
			if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
				App->Close();

			if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Space))
				board->newGame(true);
			
			// This is for grading your code. DO NOT REMOVE
			if(Event.Type == sf::Event::KeyPressed && Event.Key.Code == sf::Key::Equal)
			{
				unsigned char *dest;
				unsigned int w = App->GetWidth();
				unsigned int h = App->GetHeight();
				glPixelStorei(GL_PACK_ALIGNMENT, 1);
				dest = (unsigned char *) malloc( sizeof(unsigned char)*w*h*3);
				glReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, dest);
				
				FILE *file;
				file = fopen("_program1.ppm", "wb");
				fprintf(file, "P6\n%i %i\n%i\n", w, h, 255);
				for(int i=h-1; i>=0; i--)
					fwrite(&dest[i*w*3], sizeof(unsigned char), w*3, file);
				fclose(file);
				free(dest);
			}

			if(Event.Type == sf::Event::KeyPressed && Event.Key.Code == sf::Key::N){
				board->newGame();
			}
			//handle mouse pressed
			if(Event.Type == sf::Event::MouseButtonPressed)
			{
				if(Event.MouseButton.Button == sf::Mouse::Right) board->cancelPickup();
				if(Event.MouseButton.Button == sf::Mouse::Left) {
					int x = Event.MouseButton.X;
					int y = Event.MouseButton.Y;
					y = RESOLUTION - y;

					board->display(true);
					glFlush();
					glFinish();
				
					float clickColor[4];
					glPixelStorei(GL_PACK_ALIGNMENT, 1);
					glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
					glReadPixels(x, y, 1, 1, GL_RGBA, GL_FLOAT, clickColor);

					GLuint clickId = 0;
					clickId = clickId | ((unsigned int)(clickColor[0] * 255.0f) << 0);
					clickId = clickId | ((unsigned int)(clickColor[1] * 255.0f) << 8);
					clickId = clickId | ((unsigned int)(clickColor[2] * 255.0f) << 16);
					clickId = clickId | ((unsigned int)(clickColor[3] * 255.0f) << 24);

					
					unsigned int objectId = clickId;

					//printf("Selected: %02X %02X %02X %02X\n", (objectId >> 24) & 0xFF, (objectId >> 16) & 0xFF, (objectId >> 8) & 0xFF, objectId & 0xFF );
					if(!board->piecePlace(objectId)){
						board->piecePickUp(objectId);
					}
				}
			}
		}
	}
Example #13
0
void loadAssets()
{
	loadParticles();
	loadPlane();

	pstack.push(glm::perspective(45.0f, 
					(GLfloat)window.GetWidth()/window.GetHeight(), 0.1f, 175.0f));
	
	mstack.push(glm::lookAt(vec3(0, 2.7, 7), vec3(0, 2.4, 6), vec3(0, 1, 0)));
	
	// Load terrain shader
	if (!g_program.compileShaderFromFile(
			ROOT_PATH_RELATIVE SHADER_DIR "terrain-vert.glsl", 
			GLSLShader::VERTEX)) {
		fprintf(stderr, "%s\n", g_program.log().c_str());
		exit(1);
	}

	if (!g_program.compileShaderFromFile(
			ROOT_PATH_RELATIVE SHADER_DIR "terrain-frag.glsl", 
			GLSLShader::FRAGMENT)) {
		fprintf(stderr, "%s\n", g_program.log().c_str());
		exit(1);
	}

	if (!g_program.compileShaderFromFile(
			ROOT_PATH_RELATIVE SHADER_DIR "terrain-tc.glsl", 
			GLSLShader::TESS_CONTROL)) {
		fprintf(stderr, "%s\n", g_program.log().c_str());
		exit(1);
	}

	if (!g_program.compileShaderFromFile(
			ROOT_PATH_RELATIVE SHADER_DIR "terrain-te.glsl", 
			GLSLShader::TESS_EVALUATION)) {
		fprintf(stderr, "%s\n", g_program.log().c_str());
		exit(1);
	}

	if (!g_program.link()) {
		fprintf(stderr, "%s\n", g_program.log().c_str());
		exit(1);
	}

	// Load plane shader
	if (!d_program.compileShaderFromFile(
			ROOT_PATH_RELATIVE SHADER_DIR "default-vert.glsl", 
			GLSLShader::VERTEX)) {
		fprintf(stderr, "%s\n", d_program.log().c_str());
		exit(1);
	}

	if (!d_program.compileShaderFromFile(
			ROOT_PATH_RELATIVE SHADER_DIR "default-frag.glsl", 
			GLSLShader::FRAGMENT)) {
		fprintf(stderr, "%s\n", d_program.log().c_str());
		exit(1);
	}

	const char *outputNames[] = { "Position" };
	glTransformFeedbackVaryings(d_program.getHandle(), 1, outputNames, GL_SEPARATE_ATTRIBS);

	if (!d_program.link()) {
		fprintf(stderr, "%s\n", d_program.log().c_str());
		exit(1);
	}

	
	g_program.use();
	g_program.setUniform("Viewport", viewport);
	
	g_program.setUniform("MinTessLevel", 1.0f);
	g_program.setUniform("MaxTessLevel", max_tess);
	//g_program.setUniform("MaxTessLevel", 20.0f);

	g_program.setUniform("NearClip", 0.1f);
	g_program.setUniform("FarClip", 175.0f);
	g_program.setUniform("NearFog", 10.0f);
	g_program.setUniform("FarFog", 125.0f);

	g_program.setUniform("Light0.position", vec3(L0POSITION));
	g_program.setUniform("Light0.La", vec3(L0AMBIENT));
	g_program.setUniform("Light0.Ld", vec3(L0DIFFUSE));


	GLuint terrainmap = SOIL_load_OGL_texture (
							ROOT_PATH_RELATIVE TEXTURE_DIR "heightmap-vlarge.png",
							SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_LOAD_L );
	GLuint watermap = SOIL_load_OGL_texture (
							ROOT_PATH_RELATIVE TEXTURE_DIR "watermap.jpg",
							SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_LOAD_L );
	GLuint ttex1 = SOIL_load_OGL_texture (
							ROOT_PATH_RELATIVE TEXTURE_DIR "grass.jpg",
							SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_LOAD_L );
	GLuint ttex2 = SOIL_load_OGL_texture (
							ROOT_PATH_RELATIVE TEXTURE_DIR "stonesnow.jpg",
							SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_LOAD_L );
	GLuint ttex3 = SOIL_load_OGL_texture (
							ROOT_PATH_RELATIVE TEXTURE_DIR "water.jpg",
							SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_LOAD_L );
	GLuint ttex4 = SOIL_load_OGL_texture (
							ROOT_PATH_RELATIVE TEXTURE_DIR "foam.jpg",
							SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_LOAD_L );
	GLuint nmap1 = SOIL_load_OGL_texture (
							ROOT_PATH_RELATIVE TEXTURE_DIR "normalmap-vlarge.png",
							SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_LOAD_L );
	GLuint nmap2 = SOIL_load_OGL_texture (
							ROOT_PATH_RELATIVE TEXTURE_DIR "watermap_NRM.jpg",
							SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_LOAD_L );
	GLuint omap1 = SOIL_load_OGL_texture (
							ROOT_PATH_RELATIVE TEXTURE_DIR "occmap-vlarge.jpg",
							SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_LOAD_L );
	omap2 = SOIL_load_OGL_texture (
							ROOT_PATH_RELATIVE TEXTURE_DIR "watermap_OCC.jpg",
							SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_LOAD_L );
	plane = SOIL_load_OGL_texture (
							ROOT_PATH_RELATIVE TEXTURE_DIR "F16_diffusemap2.tga",
							SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_LOAD_L );

	
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, terrainmap);
	g_program.setUniform("TerrainMap", 0);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

	glActiveTexture(GL_TEXTURE1);
	glBindTexture(GL_TEXTURE_2D, watermap);
	g_program.setUniform("WaterMap", 1);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

	glActiveTexture(GL_TEXTURE2);
	glBindTexture(GL_TEXTURE_2D, ttex1);
	g_program.setUniform("TTex1", 2);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

	glActiveTexture(GL_TEXTURE3);
	glBindTexture(GL_TEXTURE_2D, ttex2);
	g_program.setUniform("TTex2", 3);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

	glActiveTexture(GL_TEXTURE4);
	glBindTexture(GL_TEXTURE_2D, ttex3);
	g_program.setUniform("TTex3", 4);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

	glActiveTexture(GL_TEXTURE5);
	glBindTexture(GL_TEXTURE_2D, ttex4);
	g_program.setUniform("TTex4", 5);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

	glActiveTexture(GL_TEXTURE6);
	glBindTexture(GL_TEXTURE_2D, nmap1);
	g_program.setUniform("NMap1", 6);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

	glActiveTexture(GL_TEXTURE7);
	glBindTexture(GL_TEXTURE_2D, nmap2);
	g_program.setUniform("NMap2", 7);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

	glActiveTexture(GL_TEXTURE8);
	glBindTexture(GL_TEXTURE_2D, omap1);
	g_program.setUniform("OMap1", 8);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

	glActiveTexture(GL_TEXTURE9);
	glBindTexture(GL_TEXTURE_2D, omap2);
	g_program.setUniform("OMap2", 9);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

	
	d_program.use();

	plv = glGetSubroutineIndex(d_program.getHandle(), GL_VERTEX_SHADER, "RenderPlane");
	plf = glGetSubroutineIndex(d_program.getHandle(), GL_FRAGMENT_SHADER, "RenderPlane");
	pav = glGetSubroutineIndex(d_program.getHandle(), GL_VERTEX_SHADER, "RenderParticles");
	paf = glGetSubroutineIndex(d_program.getHandle(), GL_FRAGMENT_SHADER, "RenderParticles");


	glActiveTexture(GL_TEXTURE9);
	glBindTexture(GL_TEXTURE_2D, plane);
	d_program.setUniform("PlaneTex", 9);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

	d_program.setUniform("Light0.position", vec3(L0POSITION));
	d_program.setUniform("Light0.La", vec3(L0AMBIENT));
	d_program.setUniform("Light0.Ld", vec3(L0DIFFUSE));

	loadLand(156, 100);
}
Example #14
0
void generateCubeMap()
{
    glViewport(0, 0, CUBE_MAP_SIZE, CUBE_MAP_SIZE);

    glUseProgram(phongShader->programID());
    GLint drawShadows = glGetUniformLocation(phongShader->programID(), "drawShadows");
    glUniform1i(drawShadows, 0);

    glGenTextures(1, &cubeMapTextureID);
    glBindTexture(GL_TEXTURE_CUBE_MAP, cubeMapTextureID);
    glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
    for (uint face = 0; face < 6; face++) {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        // Set up the projection and model-view matrices
        GLfloat aspectRatio = 1.0f;
        GLfloat nearClip = 0.1f;
        GLfloat farClip = 500.0f;
        GLfloat fieldOfView = 90.0f; // Degrees

        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(fieldOfView, aspectRatio, nearClip, farClip);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        switch (face) {
        case 0:
            /// positive x
            gluLookAt(0.0f, 2.0f, 0.0f,
                      1.0f, 2.0f, 0.0f,
                      0.0f, 1.0f, 0.0f);
            break;
        case 1:
            // negative x
            gluLookAt(0.0f, 2.0f, 0.0f,
                      -1.0f, 2.0f, 0.0f,
                      0.0f, 1.0f, 0.0f);
            break;
        case 2:
            // positive y
            gluLookAt(0.0f, 2.0f, 0.0f,
                      0.0f, 3.0f, 0.0f,
                      0.0f, 0.0f, -1.0f);
            break;
        case 3:
            // negative y
            gluLookAt(0.0f, 2.0f, 0.0f,
                      0.0f, 1.0f, 0.0f,
                      0.0f, 0.0f, 1.0f);
            break;
        case 4:
            // positive z
            gluLookAt(0.0f, 2.0f, 0.0f,
                      0.0f, 2.0f, 1.0f,
                      0.0f, 1.0f, 0.0f);
            break;
        case 5:
            // negative z
            gluLookAt(0.0f, 2.0f, 0.0f,
                      0.0f, 2.0f, -1.0f,
                      0.0f, 1.0f, 0.0f);
            break;
        default:
            break;
        }



        // TODO: WHY SO DARK CUBEMAP
        glPushMatrix(); // set the light in the scene correctly

        transNode(cathedralScene, cathedralScene->mRootNode);  // TODO: STILL NEED TO FIGURE OUT WHY I DO THIS

        GLfloat light0_position[] = { 0, 30, 0, 0 };
        glLightfv( GL_LIGHT0, GL_POSITION, light0_position );

        GLfloat light1_position[] = { 0, 11, 0, 0.0 };
        glLightfv( GL_LIGHT1, GL_POSITION, light1_position );

        glPopMatrix();


        renderNode(phongShader, cathedralScene, cathedralScene->mRootNode, false);

        // Copy the back buffer into the current face of the cube map
        glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_RGBA,
                     CUBE_MAP_SIZE, CUBE_MAP_SIZE, 0, GL_RGBA, GL_FLOAT, NULL);
        glCopyTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, 0, 0, 0, 0, CUBE_MAP_SIZE, CUBE_MAP_SIZE);
    }

    glUniform1i(drawShadows, 1);
    glViewport(0, 0, window.GetWidth(), window.GetHeight());
}