//----------------------------------------------------------------------------//
CEGuiOpenGLBaseApplication::CEGuiOpenGLBaseApplication()
{
    initGLFW();
    setGLFWWindowCreationHints();
    createGLFWWindow();
    setGLFWAppConfiguration();

    d_renderer = &CEGUI::OpenGLRenderer::create();
}
Example #2
0
Application::Application(const std::string& arg0) :
    photonVer_(0,0,2),  // this is the current version
    displayWidth_(0), displayHeight_(0), viewportWidth_(0), viewportHeight_(0),
    clearFlags_(GL_COLOR_BUFFER_BIT),
    mouseX_(0), mouseY_(0),
    active_(false), timerPaused_(false), unpauseOnActive_(false),
    lastPause_(0), pausedTime_(0), elapsedTime_(0), lastUpdate_(0),
    fixedTimeStep_(0), maxTimeStep_(0), timeAccumulator_(0), frameTimes_(0),
    quit_(true)
{
    util::VersionInfo physfsReq(1,0,0); // requires PhysFS 1.0.0
    util::ensureVersion("PhysFS", initPhysFS(arg0), physfsReq);
    
    util::VersionInfo glfwReq(2,4,2);   // requires GLFW 2.4.2
    util::ensureVersion("GLFW", initGLFW(), glfwReq);
}
Example #3
0
    bool Root::init(bool fullscr, int w, int h)
    {
        LOG_INFO("loading root");

        windowWidth = w;
        windowHeight = h;
        fullscreen = fullscr;

        if(!initGLFW()) return false;
        if(!initGLEW()) return false;

        // set GL stuff
        glEnable(GL_DEPTH_TEST);
        glEnable(GL_CULL_FACE);

        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

        //Call these in the right order: Models need Textures
        TextureManager::shared().initialize();
		//MaterialManager::shared().initialize();
        ModelManager::shared().initialize();

        overlay = new Overlay();
        if(!overlay->init()) return false;

        Interface* interf = new Interface;
        if(!interf->init())
        {
          LOG_INFO("Could not initialize interface");
          return false;
        }
        addFrameListener(interf);

        Console* console = new Console;
        if(!console->init()) 
        {
          LOG_INFO("Could not initialize console");
          return false;
        }
        addFrameListener(console);
        addInputListener(console);
        LOG_INFO("Root initialized");

        return true;
    }
bool init(int argc, char *argv[]){

    setDataDir(argc, argv);
    initGLFW();
    ogle::initGLEW();
    bool found_extensions = checkExtensions();
    if (!found_extensions)
        return false;
    
    ogle::Debug::init();

    initGLSettings();

    createParticles();

    createBufferObject();

    return true;
}
Example #5
0
bool initFrameworks()
{
    if( !initGLFW() )
    {
	std::cout << "Failed to init GLFW!" << std::endl;
	return false;
    }

    // init GLEW
    glewExperimental = GL_TRUE;
    if( glewInit() != GLEW_OK )
    {
	std::cout << "Failed to init GLEW!" << std::endl;
	return false;
    }

    // set viewport
    glViewport( 0, 0, WIN_WIDTH, WIN_HEIGHT );

    return true;
}
int main(){
	gWidth = 1024;
	gHeight = 600;

	if (!initGLFW() || !initUserInterface())
		return EXIT_FAILURE;

	if (!initialize())
		exit(EXIT_FAILURE);

	gpScene = new CScene();

	gpCamera = new CCamera();

	gpScene->loadObjects();

	reshape(gpWindow, gWidth, gHeight);
	
	mainLoop();

	destroy();
	return EXIT_SUCCESS;
}
int main(int argc, char* argv[]) {
  // initialization and window creation
  initGLFW();
  GLFWwindow* window = createWindow(800, 600, "Learn OpenGL");
  glfwSetKeyCallback(window, glfwKeyCallback);
  if (window == nullptr) return -1;
  glfwMakeContextCurrent(window);
  if (initGLEW() != GLEW_OK) return -1;
  
  glViewport(0, 0, 800, 600);
  
  // game loop
  while (!glfwWindowShouldClose(window)) {
    glfwPollEvents();

    glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);

    glfwSwapBuffers(window);
  }
  
  glfwTerminate();
  return 0;
}
Example #8
0
int main( void )
{
	initGLFW();
	initWindow();
	initGLEW();
	initKeyboard();
	
	// Dark blue background
	glClearColor(0.0f, 0.0f, 0.4f, 0.0f);

	int size = 5;
	float* map = generateHeightMap(size);
	printf("generated map\n" );
	std::vector<glm::vec3> terrain;
	mapHeightsToPoints(terrain, map, size);
	printf("mapped to points\n");
	// GLuint* indices = generateIndices(terrain, size);

	uint terrainVertexAmount = size* size * 3;
	uint indiceAmount = 3 * (1 << size);

	for(int i = 0; i < terrain.size(); ++i){
		printf("[%f, %f, %f]\n", terrain[i].x, terrain[i].y, terrain[i].z);
	}

	printf("vertices %d\n", terrainVertexAmount);

	GLuint VertexArrayID = newVertexArray();

	// Create and compile our GLSL program from the shaders
	GLuint programID = LoadShaders( "SimpleVertexShader.vertexshader", "SimpleFragmentShader.fragmentshader" );
	printf("loaded\n");
	initMatrices(programID);

	
	GLuint vertexbuffer = newVertexBuffer(terrainVertexAmount, &terrain);
	
	double lastTime = glfwGetTime();
 	int nbFrames = 0;
 	printf("loop\n");


 	initDepth();
	do{

		// Clear the screen
		glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		// Use our shader
		glUseProgram(programID);
		
		// TODO
		// recalculateMatrices();

		// Send our transformation to the currently bound shader, 
		// in the "MVP" uniform
		glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]);

		// 1rst attribute buffer : vertices
		bindVertexBuffer(vertexbuffer);

		// Draw the triangle !
		glDrawArrays(GL_TRIANGLE_FAN, 0, terrainVertexAmount); // 3 indices starting at 0 -> 1 triangle

		glDisableVertexAttribArray(0);

		// Swap buffers
		glfwSwapBuffers(window);
		glfwPollEvents();


		// measureTime(lastTime, &nbFrames);

	} // Check if the ESC key was pressed or the window was closed
	while( glfwGetKey(window, GLFW_KEY_ESCAPE ) != GLFW_PRESS &&
		   glfwWindowShouldClose(window) == 0 );

	// Cleanup VBO
	glDeleteBuffers(1, &vertexbuffer);
	glDeleteVertexArrays(1, &VertexArrayID);
	glDeleteProgram(programID);

	// Close OpenGL window and terminate GLFW
	glfwTerminate();
	// normal** ns = generateNormals(map, size);
	return 0;
}
Example #9
0
int main (int argc, char** argv)
{

int lives=3;

  int width = 1400;
  int height = 715;
  int numBlocks;

  points=10;
  /*float v[][6] = {
    2.5, -8.6, 3, 0.5,0,1,
    4, -7, 1, 4,0,1,
    5.5, -8.6, 3, 0.5,0,1,
    2.5, -5.5, 2, 1,1,1,
    4, -5.5, 2, 1,1,1,

    5.5, -5.5, 2, 1,1,1,
    4, -9.5, 2.5, 1.5, 2,2,
    4, -10.5, 1, 4, 0, 3,
    9, -9, 4, 4, 0, 3
  };*/


  GLFWwindow* window = initGLFW(width, height);

 initGL (window, width, height);
 float tm=glfwGetTime();
  elements e;
  while (glfwGetTime()-tm<=5 and mode==0)
  {
    e.menu();
    glfwSwapBuffers(window);
    glfwPollEvents();
  //  cout<<mode;  
  }

if(mode==0)
  mode=1;

if(mode==1){
  numBlocks= 12;
  groundLevel=-15;
}

dummy d1(0-2,12);

dummy d2(4-2,12);

dummy d3(8-2,12);
float v1[][6] = {
    2, -9.5-3, 3, 0.5,0,3,
    5, -9-3, 4, 0.5,0,3,

    8, -8.5-3, 5, 0.5,0,3,
    11, -8-3, 6, 0.5,0,3,
    
    2, -8-3, 1, 2,0,1,
    5, -7.0-3, 1, 2,0,1,
    
    8, -6.0-3, 1, 2,0,1,
    11, -5-3, 1, 2,0,1,
    
    2, -7-3, 1, 1,0,2,
    5, -6.0-3, 1, 1,0,2,
    
    8, -5.0, 1, 1,0,2,
    11, -4, 1, 1,0,2,
    
   // 2, -8+6, 1, 2,0,1,
    //5, -7+6, 1, 2,0,1,
    
   // 2,-8+9,1,1,0,2,
    //5, -7+9, 1, 1,0,2
};

if(mode==2)
{
  numBlocks=14;
  groundLevel=-15;
  
}


    float v2[][6] = {
    //0,-14.5,5,3,0,3,//hill
    //0,-11,1,1,1,4,//ball
    //7.5,groundLevel+4*2,1,5,0,1,
    2+4, -9.5-3, 3, 0.5,0,3,
    5+4, -9-3, 4, 0.5,0,3,
    8+4, -8.5-3, 5, 0.5,0,3,
    11+4, -8-3, 6, 0.5,0,3,
    
    2+4, -8-3, 1, 2,0,1,
    5+4, -7.0-3, 1, 2,0,1,
    
    8+4, -6.0-3, 1, 2,0,1,
    11+4, -5-3, 1, 2,0,1,

    2+4, -7-3, 1, 1,0,2,
    5+4, -6.0-3, 1, 1,0,2,
    
    2+4, -7-3, 1, 1,0,2,
    5+4, -6.0-3, 1, 1,0,2,
    
      
    8+4, -5.0, 1, 1,0,2,
    11+4, -4, 1, 1,0,2
   
};




 
  double last_update_time = glfwGetTime(), current_time;
  canon c;
  bird b(c.x-2, c.y-2);

  speedy speedo;
  vector<block> arr;

  for(int i=0; i<numBlocks;++i){
    if(mode==1){
    block a(v1[i][0], v1[i][1], v1[i][2], v1[i][3], v1[i][4], v1[i][5]);
   arr.push_back(a);
 }
    
    if(mode==2){
    block a(v2[i][0], v2[i][1], v2[i][2], v2[i][3], v2[i][4], v2[i][5]);
    arr.push_back(a);
  }

  }
  e.modeupdate();

  arr[1].fire(scale*2);
  while (!glfwWindowShouldClose(window) or glfwGetTime()-tm>=0.08 ) {

    // OpenGL Draw commands

  tm=glfwGetTime(); 


    e.draw();

    if(shoot == 1) {
      b.fire(boost, rectangle_rotation);
      shoot = 0;
    }

     c.draw();
     b.draw();
    

    for(int i=0; i<numBlocks;++i){
      bool flag=false;
     // if(i==1)
    //  cout<<i<<" "<<arr[i].vy<<" "<<arr[i].fall<<endl;
      for(int j=0; j<numBlocks;++j) {
        //if(i==1 and j==4)
        //cout<<arr[i].checkBelow(arr[j])<<" "<<;
        if(arr[i].checkBelow(arr[j])==true and i!=j){
          flag=true;
          
           //cout<<i<<" "<<j<<endl;

          //  if(arr[j].t==2 && arr[i].t==1) arr[j].lives--;
        }
        else if(arr[i].checkBelow(arr[j])==false and i!=j)
            {
                         }

      }
      if(flag==false)
        arr[i].fall=1;
      else arr[i].fall = 0,arr[i].vy=0;
      if(i==0)
        arr[i].fall = 0,arr[i].vy=0;
      arr[i].draw();
        

    }

    for(int i=4; i<numBlocks;++i) {
      for(int j=0; j<numBlocks;++j) {
        if(arr[i].checkCollision(arr[j]) && i!=j) {
         if(arr[j].type==1 && arr[i].type==4)
          arr[i].vx = arr[j].vx = (arr[i].vx+arr[j].vx)/2;

         if(arr[j].type==4&& arr[i].type==1)
          arr[i].vx = arr[j].vx = (arr[i].vx+arr[j].vx)/2;
          if(arr[j].type==1 && arr[i].type==1) {
          arr[i].vx = arr[j].vx = (arr[i].vx+arr[j].vx)/2;
         // arr[i].vy = arr[j].vy = (arr[i].vy+arr[j].vy)/2;
        }
   //     else if(arr[j].type == 3) {
          //cout<<"hi"<<endl;
    //      arr[i].vx = -coeff*arr[i].vx;
     // }
    }
    }
  }


    int hit,diff;

    for(int i=0; i<numBlocks;++i) {
      if(b.checkCollision(arr[i].x, arr[i].y, arr[i].h, arr[i].w, arr[i].alive))
      {
        if(arr[i].type == 2) {
          points+=10;
          arr[i].alive = false;
        }
        if(arr[i].type == 1 or arr[i].type==4) {
          arr[i].fire(scale*2);
        }
        if(arr[i].type==3)
          lives--;
        break;
      }
    }

    /*if(arr[i].t==2) {

      arr[i].lives=0;
      points+=arr[i].score;

      }*/
    /*  hit=arr[i].getLayer();
    //arr[i].fire(1);
    for(int j=0; j<numBlocks;++j){
    diff=(arr[j].getLayer()-hit);
    if(diff==0)
    arr[j].fire(scale*1.0);
    else if (diff==1) 
    arr[j].fire(scale*0.5);
    else if (diff==2) 
    arr[j].fire(scale*0.2);
    }
    break;  */
      //cout<<c.x<<" "<<c.y<<" "<<b.x<<" "<<b.y<<endl;  


    speedo.draw();

    if(lives==0)
      break;
    if(lives==1)
      d1.draw();
    if(lives==2){
      d1.draw();
      d2.draw();
    }
    if(lives==3){
    d1.draw();
    d2.draw();
    d3.draw();  
    }

    // Swap Frame Buffer in double buffering
    glfwSwapBuffers(window);

    // Poll for Keyboard and mouse events
    glfwPollEvents();

    // Control based on time (Time based transformation like 5 degrees rotation every 0.5s)
    current_time = glfwGetTime(); // Time in seconds
    if ((current_time - last_update_time) >= 0.5) { // atleast 0.5s elapsed since last frame
      // do something every 0.5 seconds ..
      last_update_time = current_time;
    }


  }
  cout<<"Score="<<points<<endl;;
    
  glfwTerminate();
  exit(EXIT_SUCCESS);
}
Example #10
0
void WindowManager::init()
{
	initGLFW();
	initGLEW();
	setGlStates();
}
Example #11
0
int main(void){
    initGLFW();
    initOpenGL();

    mcs = createFloppyThing();

    cam = new Camera(window, mcs);
    matrices = new MatrixHandler(cam);
    
    // Create and compile the shader
    programID = LoadShaders( "../../data/shaders/simple.vert", "../../data/shaders/simple.frag" );
    
    textureID = loadBMP_custom("../../data/textures/empty.bmp");
    faces_textureID = loadBMP_custom("../../data/textures/empty1.bmp");
    waffle_textureID = loadBMP_custom("../../data/textures/waffle.bmp");
    cloth1_textureID = loadBMP_custom("../../data/textures/cloth1.bmp");
    cloth2_textureID = loadBMP_custom("../../data/textures/cloth2.bmp");
    cloth3_textureID = loadBMP_custom("../../data/textures/cloth3.bmp");
    cloth4_textureID = loadBMP_custom("../../data/textures/cloth4.bmp");
    cloth5_textureID = loadBMP_custom("../../data/textures/cloth5.bmp");
    slime_textureID = loadBMP_custom("../../data/textures/slime3.bmp");
    floor2_textureID = loadBMP_custom("../../data/textures/floor2.bmp");
    floor3_textureID = loadBMP_custom("../../data/textures/floor3.bmp");
    die_textureID = loadBMP_custom("../../data/textures/die.bmp");
    induction_textureID = loadBMP_custom("../../data/textures/induction.bmp");
    tiling_textureID = loadBMP_custom("../../data/textures/tiling.bmp");
    wall1_textureID = loadBMP_custom("../../data/textures/wall1.bmp");
    wall2_textureID = loadBMP_custom("../../data/textures/wall2.bmp");
    wall3_textureID = loadBMP_custom("../../data/textures/wall3.bmp");

    
    // INIT SIMULATION 
    int simulations_per_frame = 12;
    float dt = 1.0f/(60.0f*simulations_per_frame);

    std::vector<float> w;
    w.push_back(1.0f);
    w.push_back(3.0f);
    w.push_back(3.0f);
    w.push_back(1.0f);

    RungeKutta rk4(w);
    EulerExplicit ee;
    NumericalMethod * nm = &ee; //Make use of polymorphism

    float current_time = glfwGetTime();;
    int FPS = 0;

    //OpenGL_Drawer //od;
    ////od.add(mcs);
    
    ground_material = new Material;
    object_material = new Material;
    object_material->wetness = 0.1f;

    
    drawable_mcs = new OpenGL_drawable(mcs, *object_material, programID, cloth1_textureID);
    for (int i=0; i<mcs->collisionPlanes.size(); ++i) {
        drawable_planes.push_back(new OpenGL_drawable(&mcs->collisionPlanes[i], *ground_material, programID, floor3_textureID));
    }
    
    int frame = 0;
    
    std::cout << "�" << std::endl;
    
    while (!glfwWindowShouldClose(window)){

        // Moving one mass 
        //double x_mouse, y_mouse;
        //glfwGetCursorPos(window, &x_mouse, &y_mouse);
        //glm::vec2 pos2d = glm::vec2(float(x_mouse-0.5*width)*2*scale/height, -float(y_mouse-0.5*height)*2*scale/height);
        //mcs->setAvgPosition(glm::vec3(pos2d[0],pos2d[1],-50));
        //mcs->vertices.positions[0] = glm::vec3(pos2d[0],pos2d[1],-50);
        //mcs->particles.velocities[0] = glm::vec3(0);
        if(!pause){
            for (int i = 0; i < simulations_per_frame; ++i){   
                nm->update(*mcs,dt);
            }
        }
        else{
            for (int i = 0; i < simulations_per_frame; ++i){
                if(forward) nm->update(*mcs,dt/10.0f);
                if(backward) nm->update(*mcs,-dt/10.0f);
            }
        }
        mcs->updateVertexPositions();
        mcs->updateNormals();

        // DRAW
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glfwGetFramebufferSize(window, &width, &height);
        //od.ratio = width / (float) height;
        //if(!od.draw()) break;
        
        drawable_mcs->updateRuntimeBuffers(mcs, matrices);
        
        
        /*
        for (int i=0; i<mcs->collisionPlanes.size(); ++i) {
            drawable_planes[i].draw();
        }
         */
        
        //drawable_plane->draw();
        for (int i=0; i<mcs->collisionPlanes.size(); ++i) {
            drawable_planes[i]->draw();
        }
        drawable_mcs->draw();

        //Swap draw buffers
        glfwSwapBuffers(window);
        glfwPollEvents();

        // Print FPS
        ++FPS;
        ++frame;
        if((glfwGetTime() - current_time) > 1){
            std::string title = "Elastic materials, ";
            std::ostringstream ss;
            ss << FPS;
            std::string s(ss.str());
            title.append(s);
            title.append(" FPS");
            glfwSetWindowTitle (window,  title.c_str());
            FPS = 0;
            current_time = glfwGetTime();
        }
    }
    delete mcs;
    delete cam;
    delete drawable_mcs;
    for (int i = 0; i<drawable_planes.size(); ++i) {
        delete drawable_planes[i];
    }
    cleanUpGLFW();
}