示例#1
0
文件: engine.c 项目: Envielox/engine
int main(int argc, char **argv)
{
    glfwSetErrorCallback(error_callback);

    /* Initialize the library */
    if (!glfwInit()){
        fprintf(stderr, "Initialization failed.\n");
        return 1;
    }

    /* Create a windowed mode window and its OpenGL context */
    window = glfwCreateWindow(width, height, "Hello World", NULL, NULL);
    if (!window) {
        glfwTerminate();
        fprintf(stderr, "Error creating window.\n");
        return 1;
    }

    /* Make the window's context current */
    glfwMakeContextCurrent(window);
    glfwSetInputMode(window, GLFW_STICKY_MOUSE_BUTTONS, 1);
    glfwSetKeyCallback(window, key_callback);
    glfwSetMouseButtonCallback(window, mouse_button_callback);
    glfwSetCursorPosCallback(window, cursor_pos_callback);

    //**************************** generowanie przykładowych piksli
    hs_init(&argc, &argv);
    initOctTree();
    hs_exit();
    float *piksele = malloc(height*width*3*sizeof(*piksele));

    printf("sizeof(OctTreeNode)=%d\n", (int)sizeof(OctTreeNode));

    //****************************

    init_cl();
    turnCamera(0.f,0.f,0.f); // Calculates initial camera direction
    fflush(stderr);

    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(window))
    {
        /* Render here */
        for (int i = 0; i < height * width * 3; i++)
            piksele[i] = 0.0;

        clock_t start = clock();
        captureOctTree(camera_pos, camera_target, up, width, height, piksele);
        clock_t end = clock();

        // show render time in window title
        char title[16];
        snprintf(title, 16, "%d ms", (int)((end - start) / (CLOCKS_PER_SEC / 1000)));
        glfwSetWindowTitle(window, title);

        /* Swap front and back buffers */
        glfwSwapBuffers(window);

        /* Poll for and process events */
        glfwPollEvents();
    }

    if (num_platforms > 0) {
        clReleaseMemObject(mainOctCL);
        clReleaseMemObject(image);
        clReleaseKernel(kernel);
        clReleaseCommandQueue(queue);
    }
    glfwDestroyWindow(window);

    glfwTerminate();
    return 0;
}
示例#2
0
文件: window.c 项目: notetau/glfw
GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height,
                                     const char* title,
                                     GLFWmonitor* monitor,
                                     GLFWwindow* share)
{
    _GLFWfbconfig fbconfig;
    _GLFWctxconfig ctxconfig;
    _GLFWwndconfig wndconfig;
    _GLFWwindow* window;
    _GLFWwindow* previous;

    _GLFW_REQUIRE_INIT_OR_RETURN(NULL);

    if (width <= 0 || height <= 0)
    {
        _glfwInputError(GLFW_INVALID_VALUE, "Invalid window size");
        return NULL;
    }

    fbconfig  = _glfw.hints.framebuffer;
    ctxconfig = _glfw.hints.context;
    wndconfig = _glfw.hints.window;

    wndconfig.width   = width;
    wndconfig.height  = height;
    wndconfig.title   = title;
    wndconfig.monitor = (_GLFWmonitor*) monitor;
    ctxconfig.share   = (_GLFWwindow*) share;

    if (wndconfig.monitor)
    {
        wndconfig.resizable = GLFW_TRUE;
        wndconfig.visible   = GLFW_TRUE;
        wndconfig.focused   = GLFW_TRUE;
    }

    // Check the OpenGL bits of the window config
    if (!_glfwIsValidContextConfig(&ctxconfig))
        return NULL;

    window = calloc(1, sizeof(_GLFWwindow));
    window->next = _glfw.windowListHead;
    _glfw.windowListHead = window;

    window->videoMode.width       = width;
    window->videoMode.height      = height;
    window->videoMode.redBits     = fbconfig.redBits;
    window->videoMode.greenBits   = fbconfig.greenBits;
    window->videoMode.blueBits    = fbconfig.blueBits;
    window->videoMode.refreshRate = _glfw.hints.refreshRate;

    window->monitor     = wndconfig.monitor;
    window->resizable   = wndconfig.resizable;
    window->decorated   = wndconfig.decorated;
    window->autoIconify = wndconfig.autoIconify;
    window->floating    = wndconfig.floating;
    window->cursorMode  = GLFW_CURSOR_NORMAL;

    // Save the currently current context so it can be restored later
    previous = _glfwPlatformGetCurrentContext();

    // Open the actual window and create its context
    if (!_glfwPlatformCreateWindow(window, &wndconfig, &ctxconfig, &fbconfig))
    {
        glfwDestroyWindow((GLFWwindow*) window);
        _glfwPlatformMakeContextCurrent(previous);
        return NULL;
    }

    _glfwPlatformMakeContextCurrent(window);

    // Retrieve the actual (as opposed to requested) context attributes
    if (!_glfwRefreshContextAttribs(&ctxconfig))
    {
        glfwDestroyWindow((GLFWwindow*) window);
        _glfwPlatformMakeContextCurrent(previous);
        return NULL;
    }

    // Verify the context against the requested parameters
    if (!_glfwIsValidContext(&ctxconfig))
    {
        glfwDestroyWindow((GLFWwindow*) window);
        _glfwPlatformMakeContextCurrent(previous);
        return NULL;
    }

    // Clearing the front buffer to black to avoid garbage pixels left over
    // from previous uses of our bit of VRAM
    window->Clear(GL_COLOR_BUFFER_BIT);
    _glfwPlatformSwapBuffers(window);

    // Restore the previously current context (or NULL)
    _glfwPlatformMakeContextCurrent(previous);

    if (wndconfig.monitor)
    {
        int width, height;
        _glfwPlatformGetWindowSize(window, &width, &height);

        window->cursorPosX = width / 2;
        window->cursorPosY = height / 2;

        _glfwPlatformSetCursorPos(window, window->cursorPosX, window->cursorPosY);
    }
    else
    {
        if (wndconfig.visible)
        {
            if (wndconfig.focused)
                _glfwPlatformShowWindow(window);
            else
                _glfwPlatformUnhideWindow(window);
        }
    }

    return (GLFWwindow*) window;
}
示例#3
0
GLFWDisplay::~GLFWDisplay() {
	glfwDestroyWindow(window);
	glfwTerminate();
}
示例#4
0
int main(void)
{
    chdir(getenv("HOME"));
    std::srand(std::time(NULL));

    // In JavaScript, this would be "var window;"
    GLFWwindow* window; // This creates a variable to store the GLFW window

    glfwSetErrorCallback(error_callback); // Gives GLFW a function to call when there's an error.

    if (!glfwInit()) // Allows GLFW to do some initial setup and initialization.
        exit(EXIT_FAILURE); // If initialization fails, we can't continue with the program.

    // ODE initialization
    dInitODE();
    gODEWorld = dWorldCreate();
    gODESpace = dHashSpaceCreate(0);
    dWorldSetGravity(gODEWorld, 0, 0, -0.98);
    dWorldSetCFM(gODEWorld, 1e-5);
    dCreatePlane(gODESpace, 0, 0, 1, 0); // create the base plane
    gODEContactGroup = dJointGroupCreate (0);
    
    static dBodyID playBody = dBodyCreate (gODEWorld);
    static dGeomID playGeom = dCreateSphere (gODESpace, 4);
    dGeomSetBody (playGeom, playBody);
    
    

    dMass* mass2;
    mass2 = new dMass;
    dMassSetBox(mass2, 1, 1, 1, 1);
    dBodySetMass(playBody, mass2);

    static dBodyID sphereBody = dBodyCreate (gODEWorld);
    static dGeomID sphereGeom  = dCreateSphere(gODESpace, 1);
    
    dGeomSetBody (sphereGeom, sphereBody);

    dMass mass3;
    dMassSetSphere(&mass3, 2, 1);
    dBodySetMass(sphereBody, &mass3);

    // Builds a new GLFW window and saves the result in the variable above.
    // If there's an error here, window will be set to 0.
    // 640x480 is the initial size, and "Simple example" is the name of the window.
    window = glfwCreateWindow(640, 480, "Simple example", NULL, NULL);

    // If window == 0, this will be true, and we've hit an error.
    if (!window /*same as saying `window == 0`*/)
    {
        glfwTerminate(); // This is the opposite of glfwInit, and allows GLFW to close up shop.
        exit(EXIT_FAILURE); // This kills the application.
    }

    glfwMakeContextCurrent(window); // Tells GLFW which window is going to be drawn to.
    glfwSwapInterval(1); // Tells GLFW how often the window should be redrawn.

    // key_callback is the function that GLFW should call when the user hits
    // a key on the keyboard. So we give that function to GLFW with this routine.
    glfwSetKeyCallback(window, key_callback);
    glfwSetCursorPosCallback(window, cursor_pos_callback);
    glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
    
    // Set some OpenGL gODEWorld options.
    glEnable(GL_CULL_FACE);
    glEnable(GL_DEPTH_TEST);
    glCullFace(GL_BACK);

    //comment this out to go to normal colors
    glEnable(GL_TEXTURE_2D);

    gTextureSteel.load();
    gTexture.load();
    gTextureWood.load();
    gTextureLeaves.load();
    gTextureRoad.load();
    gTextureRoadY.load();
    gTextureWhite.load();
    gTextureBall.load();
    gTextureClear.load();
    gTextureCerealbox.load();
    gTextureCerealboxNutFacts.load();
    gTextureCerealboxBlank.load();
    
    cubeD_D myCube;
    myCube.setTexture(gTextureBall);
    myCube.SetLocation(-10, 0, 20);
    myCube.density=0.5;
    myCube.SetSize(0.5, 0.5, 0.5);
    
    cubeD_D myCube1;
    myCube1.setTexture(gTextureWhite);
    myCube1.SetLocation(5, 1, 49);
    myCube1.density=6;
    myCube1.SetSize(2, 2, 2);    
    
    BGcubeD_D BGCube1;
    BGCube1.BGsetTexture(gTextureRoad);
    BGCube1.BGSetLocation(4, 5, 7);
    BGCube1.BGSetSize(20, 1, 14);
    
    BGcubeD_D BGCube2;
    BGCube2.BGsetTexture(gTextureRoad);
    BGCube2.BGSetLocation(14.5, 14.5, 7);
    BGCube2.BGSetSize(1, 20, 14);
    
    BGcubeD_D BGCube3;
    BGCube3.BGsetTexture(gTextureRoad);
    BGCube3.BGSetLocation(-6.5, 14.5, 7);
    BGCube3.BGSetSize(1, 20, 14);
    
    BGcubeD_D BGCube4;
    BGCube4.BGsetTexture(gTextureRoad);
    BGCube4.BGSetLocation(4, 24, 7);
    BGCube4.BGSetSize(20, 1, 14);
    
    BGcubeD_D Road1;
    Road1.BGsetTexture(gTextureRoad);
    Road1.BGSetLocation(0, 0, 0.1);
    Road1.BGSetSize(1000, 8, 0.5);
    
    cubeD_D myCube3;
    myCube3.setTexture(gTextureRoadY);
    myCube3.SetLocation(4, 0, 89);
    myCube3.density=2;
    myCube1.SetSize(4, 4, 4);
    
    

    cubeD_D BouncyBlock;
    BouncyBlock.setTexture(gTextureSteel);
    BouncyBlock.SetLocation(0, 3, 40);
    BouncyBlock.r_m=255;
    BouncyBlock.g_m=0;
    BouncyBlock.b_m=0;
    dBodyAddForce(BouncyBlock.boxBody_m, 5, 5, 0);
    myCube1.SetSize(7, 7, 7);
    
    cubeD_D cerealbox;
    cerealbox.tex4=gTextureCerealbox;
    cerealbox.tex3=gTextureCerealboxNutFacts;
    cerealbox.tex2=gTextureCerealboxNutFacts;
    cerealbox.tex1=gTextureCerealboxBlank;
    cerealbox.tex5=gTextureCerealboxBlank;
    cerealbox.tex6=gTextureCerealboxBlank;
    cerealbox.SetLocation(4, -20, 1);
    cerealbox.density=1;
    cerealbox.SetSize(2, 1, 2.5);
    
    cubeD_D freezerBack;
    freezerBack.setTexture(gTextureWhite);
    freezerBack.SetLocation(20, 30, 2.5);
    freezerBack.SetSize(10,1,5);
    

    dBodySetPosition(sphereBody,0,0,50);

    static const float simulation_start_k = glfwGetTime();
    static const float real_min_per_game_day_k = 24; // CHANGE ONLY HERE TO AFFECT DAY/NIGHT SPEED
    static const float real_sec_per_game_day_k = real_min_per_game_day_k * 60;
    static const float real_sec_per_game_hrs_k = real_sec_per_game_day_k / 24;
    static const float real_sec_per_game_min_k = real_sec_per_game_hrs_k / 60;
    static const float game_min_per_real_sec_k = 1 / real_sec_per_game_min_k;
    static const float min_per_day_k = 24 * 60;

    //look position
    camRotateX=-90;

    // This is the main processing loop that draws the spinning rectangle.
    while (!glfwWindowShouldClose(window)) // this will loop until the window should close.
    {
        
        float elapsed_real_sec = glfwGetTime() - simulation_start_k;
        float elapsed_game_min = game_min_per_real_sec_k * elapsed_real_sec;
        float elapsed_game_hrs = elapsed_game_min / 60;
        float percent_of_day = (static_cast<int>(elapsed_game_min) % static_cast<int>(min_per_day_k)) / min_per_day_k;
        float sky_cycle = std::sin(percent_of_day * M_PI);
        float sky = 0 * (1-sky_cycle) + 0.9803921569 * sky_cycle;
        // int game_hrs_mil = static_cast<int>(elapsed_game_hrs) % 24; // military hours

// Set to #if 1 to enable displaying the time
#if 0
        std::cout.width(2);
        std::cout.fill('0');
        std::cout << game_hrs_mil << ":";
        std::cout.width(2);
        std::cout << (static_cast<int>(elapsed_game_min)%60) << '\n';
#endif

        // Simulate the physics engine
        // find collisions and add contact joints
        dSpaceCollide (gODESpace, 0, &ODEContactCallback);
        // step the simulation
        dWorldQuickStep (gODEWorld, 0.1);  
        // remove all contact joints
        dJointGroupEmpty (gODEContactGroup);

        // These are variable declarations.
        int width, height; // these variables store the dimensions of the window

        glfwGetFramebufferSize(window, &width, &height); // Get the height and width of the window from GLFW.
        float ratio = width / (float) height; // compute the aspect ratio of the window, which we need below.

        glViewport(0, 0, width, height); // This tells OpenGL how big the window is,
        glClearColor(0.5294117648+sky-0.9803921569, 0.8078431373+sky-0.9803921569, sky, 0);                              // and OpenGL goes off and creates a space
                                         // for drawing.
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // This asks OpenGL to wipe clean the drawing space.
                                      // The default color is black. If you want it to be
                                      // another color, you have to call glClearColor with
                                      // the new color values before making this call.

        /*
            These operations tell OpenGL how to convert the 3D world we are about
            to create into a 2D image that can be displayed on the computer screen.
        */
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(60, ratio, 1, 1000);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();

        glRotatef(camRotateX, 1.f, 0.f, 0.f);
        glRotatef(camRotateY, 0.f, 0.f, 1.f);
        const dReal* pos = dBodyGetPosition(playBody);

        if(MoveForward){
            
            //dBodySetPosition (playBody, camX-2,camY+2.5,camZ);
            //camX -= std::sin(DegreesToRads(camRotateY))*0.1;
            //camY -= std::cos(DegreesToRads(camRotateY))*0.1;
            dBodySetForce(playBody, std::sin(DegreesToRads(camRotateY))*1, std::cos(DegreesToRads(camRotateY))*1, 0);
            
            
            
        }
        if(MoveRight){
            //camY += std::cos(DegreesToRads(camRotateY-90))*0.1;
            //camX += std::sin(DegreesToRads(camRotateY-90))*0.1;
            dBodySetForce(playBody, -std::sin(DegreesToRads(camRotateY-90))*1, -std::cos(DegreesToRads(camRotateY-90))*1, 0);
        }
        if(MoveLeft){
            //camY += std::cos(DegreesToRads(camRotateY+90))*0.1;
            //camX += std::sin(DegreesToRads(camRotateY+90))*0.1;
            dBodySetForce(playBody, -std::sin(DegreesToRads(camRotateY+90))*1, -std::cos(DegreesToRads(camRotateY+90))*1, 0);
        }
        if(MoveBackward){
            //camY += std::cos(DegreesToRads(camRotateY))*0.1;
            //camX += std::sin(DegreesToRads(camRotateY))*0.1;
            dBodySetForce(playBody, -std::sin(DegreesToRads(camRotateY))*1, -std::cos(DegreesToRads(camRotateY))*1, 0);
        }
        
        
        if(MoveUp){
            //camZ += DecreaseClimbRate;
            //DecreaseClimbRate-=0.0077;
            camZ=pos[2]-1;
            dBodySetForce(playBody, 0,0,2);
        }
        if(MoveDown){
            //camZ += DecreaseClimbRate;
            //DecreaseClimbRate-=0.0077;
            camZ=pos[2]-1;
            dBodySetForce(playBody, 0,0,-2);
        }
        if(Sprint && CarSprint){
            camY += std::cos(DegreesToRads(camRotateY))*-0.55;
            camX += std::sin(DegreesToRads(camRotateY))*-0.55;
        }
        if(CarSprint){
            camY -= std::cos(DegreesToRads(camRotateY))*1;
            camX -= std::sin(DegreesToRads(camRotateY))*1;
        }
        if(Zoom){
            camY -= std::cos(DegreesToRads(camRotateY))*50.5;
            camX -= std::sin(DegreesToRads(camRotateY))*50.5;
        }
        
        if(MoveUp==true){
            camZ=pos[2]-1;
            
            
        }
        
        if(MoveUp==false && MoveDown==false){
            camZ=pos[2]-1;
            
            
            
            
        }
        const dReal* speedSAVE = dBodyGetLinearVel(playBody);
        //std::cout << "X=" << speedSAVE[1] << '\n';
        
        
        
        
        
        if(MoveForward==false && MoveBackward==false && MoveLeft==false && MoveRight==false){
            //dBodyGetLinearVel(cubeD_D().boxBody_m);
            
            
           
            
            //speedy = -std::cos(DegreesToRads(camRotateY))*1
            if(speedSAVE[0]>0.2){
                dBodySetForce(playBody, -2.5, 0, 0);
            }
            if(speedSAVE[0]<-0.2){
                dBodySetForce(playBody, 2.5 , 0, 0);
            }
            
            if(speedSAVE[1]>0.2){
                dBodySetForce(playBody, 0, -2.5, 0);
            }
            if(speedSAVE[1]<-0.2){
                dBodySetForce(playBody, 0, 2.5, 0);
            }
           
            
            
            //dBodySetPosition (playBody, camX,camY,camZ);
            
        }
        
        /*if(MoveLeft==false){
            //dBodyGetLinearVel(cubeD_D().boxBody_m);
            
            
            
            
            //speedy = -std::cos(DegreesToRads(camRotateY))*4
            if(speedSAVE[1]<0.2){
                dBodySetForce(playBody, 0, -std::cos(DegreesToRads(camRotateY))*4, 0);
            }
            if(speedSAVE[1]>-0.2){
                dBodySetForce(playBody, 0, -std::cos(DegreesToRads(camRotateY))*4, 0);
            }
            
            
            
           
            
        }*/
        //dBodySetPosition (playBody, -camX-2,-camY+2.5,camZ+1);
        
        if(camZ<=0){
            camZ += 0.1;
            
            DecreaseClimbRate=0.2;
            MoveUp=false;
        }
        if(camX>=1){
            fall=true;
        }
        else{fall=false;}
        if(MouseOut==true){
            glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
        }
        if(MouseOut==false){
            glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
        }
        if(MouseOut==true){
            glfwSetCursorPosCallback(window, 0);
        }
        if(MouseOut==false){
            glfwSetCursorPosCallback(window, cursor_pos_callback);
        }

        glTranslatef(camX+2, camY-2.5, -camZ-2);

        gTexture.activate();
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
        
        glBegin(GL_QUADS); // All OpenGL drawing begins with a glBegin.
            glColor3f(1, 1, 1);
            glTexCoord2f(0, 0); glVertex3f(-450, -450, 0);
            glTexCoord2f(450, 0); glVertex3f(450, -450 ,0);
            glTexCoord2f(450, 450); glVertex3f(450, 450, 0);
            glTexCoord2f(0, 450); glVertex3f(-450, 450, 0);
        glEnd(); // All OpenGL drawing ends with a glEnd.

        //If you would like to make a custom make change this to true v
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        camX=-pos[0]-2;
        camY=-pos[1]+2.5;
        
        /*glPushMatrix();
        orient_body_in_opengl(playBody);
        gTextureBall.activate();
        GLUquadricObj*quad2=gluNewQuadric();
        gluQuadricTexture( quad2, GL_TRUE);
        gluSphere(quad2, 0.5, 15, 15);
        gluDeleteQuadric(quad2);
        glPopMatrix();*/

        // Position and draw the sphere
        glPushMatrix();
            orient_body_in_opengl(sphereBody);
            gTextureBall.activate();
            GLUquadricObj*quad=gluNewQuadric();
            gluQuadricTexture( quad, GL_TRUE);
            gluSphere(quad, 0.5, 15, 15);
            gluDeleteQuadric(quad);
        glPopMatrix();

        myCube.draw();
        myCube1.draw();
        
        BGCube1.BGdraw();
        BGCube2.BGdraw();
        BGCube3.BGdraw();
        BGCube4.BGdraw();
        
        //dBodyDisable(myCube2.boxBody_m);

        myCube3.draw();
        BouncyBlock.draw();
        
        Road1.BGdraw();
        cerealbox.draw();
        
        freezerBack.draw();
        
        
        
        
        
        /*const dReal* pos = dBodyGetPosition(BouncyBlock.boxBody_m);
        camX=-pos[0]-2;
        camY=-pos[1]+2.5;
        camZ=pos[2];*/
        //dBodySetPosition (playBody, camX-2,camY+2.5,camZ);
        
        
        camX=-pos[0]-2;
        camY=-pos[1]+2.5;
        
        
        dBodySetPosition (playBody, pos[0],pos[1],camZ+1);
        
        //std::cout << "X=" << camX << '\n';
        //std::cout << "Y=" << camY << '\n';
        //std::cout << "Z=" << camZ << '\n';
        
        
        
        
        
        //dMatrix3* R;
        
        

        //dBodySetRotation(playBody, *R);
        //dBodySetForce(playBody, 0, 0, 0);
        // SwapBuffers causes the background drawing to get slapped onto the
        // display for the user to see.
        glfwSwapBuffers(window);

        // This lets GLFW monitor event queues like keyboard and mouse events.
        // It's at this time GLFW will call your callbacks to let you handle
        // the events any way you would like.
        glfwPollEvents();
    } // end of the while loop - do it all again!

    // At this point the window should be destroyed. This is the opposite routine
    // for glfwCreateWindow.
    glfwDestroyWindow(window);

    // ODE teardown
    dJointGroupDestroy (gODEContactGroup);
    dSpaceDestroy (gODESpace);
    dWorldDestroy (gODEWorld);
    dCloseODE();

    // This is the opposite of glfwInit - do some final cleanup before quitting.
    glfwTerminate();

    // Quit the program.
    exit(EXIT_SUCCESS);
}
示例#5
0
文件: main.cpp 项目: nyaxt/dmix
 ~GLFWWin() { glfwDestroyWindow(m_impl); }
示例#6
0
//
// デストラクタ
//
Window::~Window()
{
  glfwDestroyWindow(window);
}
示例#7
0
文件: app.cpp 项目: Aidonis/OpenGL201
void App::Shutdown() {
    Gizmos::destroy();
    glfwDestroyWindow(window);
    glfwTerminate();
}
示例#8
0
int main(int argc, char * argv[]) try
{
    rs::log_to_console(rs::log_severity::warn);
    //rs::log_to_file(rs::log_severity::debug, "librealsense.log");

    rs::context ctx;
    if(ctx.get_device_count() == 0) throw std::runtime_error("No device detected. Is it plugged in?");
    rs::device & dev = *ctx.get_device(0);

    dev.enable_stream(rs::stream::depth, rs::preset::best_quality);
    dev.enable_stream(rs::stream::color, rs::preset::best_quality);
    try { dev.enable_stream(rs::stream::infrared2, rs::preset::best_quality); } catch(...) {}
    dev.start();

    // Open a GLFW window
    glfwInit();
    std::ostringstream ss; ss << "CPP Image Alignment Example (" << dev.get_name() << ")";
    GLFWwindow * win = glfwCreateWindow(dev.is_stream_enabled(rs::stream::infrared2) ? 1920 : 1280, 960, ss.str().c_str(), 0, 0);
    glfwMakeContextCurrent(win);

    while (!glfwWindowShouldClose(win))
    {
        // Wait for new images
        glfwPollEvents();
        dev.wait_for_frames();

        // Clear the framebuffer
        int w,h;
        glfwGetFramebufferSize(win, &w, &h);
        glViewport(0, 0, w, h);
        glClear(GL_COLOR_BUFFER_BIT);

        // Draw the images        
        glPushMatrix();
        glfwGetWindowSize(win, &w, &h);
        glOrtho(0, w, h, 0, -1, +1);
        int s = w / (dev.is_stream_enabled(rs::stream::infrared2) ? 3 : 2);
        buffers[0].show(dev, rs::stream::color, 0, 0, s, h-h/2);
        buffers[1].show(dev, rs::stream::color_aligned_to_depth, s, 0, s, h-h/2);
        buffers[2].show(dev, rs::stream::depth_aligned_to_color, 0, h/2, s, h-h/2);
        buffers[3].show(dev, rs::stream::depth, s, h/2, s, h-h/2);
        if(dev.is_stream_enabled(rs::stream::infrared2))
        {
            buffers[4].show(dev, rs::stream::infrared2_aligned_to_depth, 2*s, 0, s, h-h/2);
            buffers[5].show(dev, rs::stream::depth_aligned_to_infrared2, 2*s, h/2, s, h-h/2);
        }
        glPopMatrix();
        glfwSwapBuffers(win);
    }

    glfwDestroyWindow(win);
    glfwTerminate();
    return EXIT_SUCCESS;
}
catch(const rs::error & e)
{
    std::cerr << "RealSense error calling " << e.get_failed_function() << "(" << e.get_failed_args() << "):\n    " << e.what() << std::endl;
    return EXIT_FAILURE;
}
catch(const std::exception & e)
{
    std::cerr << e.what() << std::endl;
    return EXIT_FAILURE;
}
示例#9
0
int main()
{
    GLFWwindow *window;
    char *userptr = "userptr";

    glfwSetErrorCallback(errorcb);
    assert(glfwInit() == GL_TRUE);
    assert(!strcmp(glfwGetVersionString(), "3.2.1 JS WebGL Emscripten"));
    assert(glfwGetCurrentContext() == NULL);

    {
        int major, minor, rev;
        glfwGetVersion(&major, &minor, &rev);
        assert(major == 3);
        assert(minor == 2);
        assert(rev == 1);
    }

    {
        int count, x, y, w, h;
        GLFWmonitor **monitors = glfwGetMonitors(&count);
        assert(count == 1);
        for (int i = 0; i < count; ++i) {
            assert(monitors[i] != NULL);
        }

        assert(glfwGetPrimaryMonitor() != NULL);
        glfwGetMonitorPos(monitors[0], &x, &y);
        glfwGetMonitorPhysicalSize(monitors[0], &w, &h);
        assert(glfwGetMonitorName(monitors[0]) != NULL);
        glfwSetMonitorCallback(monitcb);

        // XXX: not implemented
        // assert(glfwGetVideoModes(monitors[0], &count) != NULL);
        // assert(glfwGetVideoMode(monitors[0]) != NULL);
        // glfwSetGamma(monitors[0], 1.0f);
        // assert(glfwGetGammaRamp(monitors[0]) != NULL);
        // glfwSetGammaRamp(monitors[0], ramp);
    }

    {
        int x, y, w, h;
        glfwDefaultWindowHints();
        glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);

        window = glfwCreateWindow(640, 480, "glfw3.c", NULL, NULL);
        assert(window != NULL);

        glfwSetWindowPosCallback(window, wposicb);
        glfwSetWindowSizeCallback(window, wsizecb);
        glfwSetWindowCloseCallback(window, wcloscb);
        glfwSetWindowRefreshCallback(window, wrfrscb);
        glfwSetWindowFocusCallback(window, wfocucb);
        glfwSetWindowIconifyCallback(window, wiconcb);
        glfwSetFramebufferSizeCallback(window, wfsizcb);

        assert(glfwWindowShouldClose(window) == 0);
        glfwSetWindowShouldClose(window, 1);
        assert(glfwWindowShouldClose(window) == 1);

        glfwSetWindowTitle(window, "test");
        glfwSetWindowTitle(window, "glfw3.c");

        // XXX: not implemented
        // glfwSetWindowPos(window, 1, 1);

        glfwGetWindowPos(window, &x, &y); // stub
        glfwGetWindowSize(window, &w, &h);
        assert(w == 640 && h == 480);

        glfwSetWindowSize(window, 1, 1);
        glfwGetWindowSize(window, &w, &h);
        assert(w == 1 && h == 1);

        glfwSetWindowSize(window, 640, 480);
        glfwGetFramebufferSize(window, &w, &h);

        // XXX: not implemented
        // glfwIconifyWindow(window);
        // glfwRestoreWindow(window);
        // glfwShowWindow(window);
        // glfwHideWindow(window);

        assert(glfwGetWindowMonitor(window) == NULL);
        glfwDestroyWindow(window);

        window = glfwCreateWindow(640, 480, "glfw3.c", glfwGetPrimaryMonitor(), NULL);
        assert(window != NULL);
        assert(glfwGetWindowMonitor(window) == glfwGetPrimaryMonitor());
        glfwDestroyWindow(window);

        window = glfwCreateWindow(640, 480, "glfw3.c", NULL, NULL);
        assert(window != NULL);

        assert(glfwGetWindowAttrib(window, GLFW_CLIENT_API) == GLFW_OPENGL_ES_API);

        assert(glfwGetWindowUserPointer(window) == NULL);
        glfwSetWindowUserPointer(window, userptr);
        assert(glfwGetWindowUserPointer(window) == userptr);
    }

    {
        double x, y;

        glfwSetKeyCallback(window, wkeypcb);
        glfwSetCharCallback(window, wcharcb);
        glfwSetMouseButtonCallback(window, wmbutcb);
        glfwSetCursorPosCallback(window, wcurpcb);
        glfwSetCursorEnterCallback(window, wcurecb);
        glfwSetScrollCallback(window, wscrocb);

        // XXX: stub, events come immediatly
        // glfwPollEvents();
        // glfwWaitEvents();

        assert(glfwGetInputMode(window, GLFW_CURSOR) == GLFW_CURSOR_NORMAL);

        // XXX: not implemented
        // glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);

        glfwGetKey(window, GLFW_KEY_A);
        glfwGetMouseButton(window, 0);
        glfwGetCursorPos(window, &x, &y);

        // XXX: not implemented
        // glfwSetCursorPos(window, 0, 0);
    }

    {
        // XXX: not implemented
        // glfwJoystickPresent(joy);
        // glfwGetJoystickAxes(joy, &count);
        // glfwGetJoystickButtons(joy, &count);
        // glfwGetJoystickName(joy);
    }

    {
        // XXX: not implemented
        // glfwSetClipboardString(window, "string");
        // glfwGetClipboardString(window);
    }

    {
        glfwGetTime();
        glfwSetTime(0);
    }

    {
        glfwMakeContextCurrent(window); // stub
        assert(glfwGetCurrentContext() == window);
        glfwSwapBuffers(window); // stub
        glfwSwapInterval(0); // stub
    }

    {
        assert(glfwExtensionSupported("nonexistant") == 0);
        assert(glfwGetProcAddress("nonexistant") == NULL);
    }

    glfwTerminate();

#ifdef REPORT_RESULT
    REPORT_RESULT(1);
#endif
    return 0;
}
示例#10
0
文件: main.cpp 项目: flair2005/VCTGI
int main() 
{
	// init GLFW and GLEW
	glfwInit();
	CVK::useOpenGL33CoreProfile();
	GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "Normal Mapping", 0, 0);
	glfwSetWindowPos(window, 100, 50);
	glfwMakeContextCurrent(window);
	glewInit();
	glfwSetWindowSizeCallback(window, resizeCallback);
	glfwSetCharCallback(window, charCallback);

	// setup camera
	camera.setCenter(glm::vec3( 0.0f, 0.0f, 0.0f));
	camera.setRadius(5);
	camera.setNearFar(1.0f, 10.0f);
	CVK::State::getInstance()->setCamera(&camera);

	// setup light
	CVK::Light plight(glm::vec4(0.0f, 1.0, 10.0f, 1.0f), grey, glm::vec3( 0, 0, 0), 1.0f, 0.0f);
	CVK::State::getInstance()->addLight(&plight);

	// setup scene
	CVK::Node* node = new CVK::Node("Cube");
	// create and set teapot geometrie
	CVK::Cube* cube = new CVK::Cube(); 
	node->setGeometry(cube);
	// define material with diffuse color and normal texture
	CVK::Material matTex((char*)RESOURCES_PATH "/normalmapping/diffusemap.png", glm::vec3( 0.5f, 0.5f, 0.5f), glm::vec3( 0.3f, 0.3f, 0.3f), 120.0f);
	matTex.setTexture(CVK::NORMAL_TEXTURE, (char*)RESOURCES_PATH "/normalmapping/normalmap.png");
	CVK::Material matRed(glm::vec3(1.0,0.0,0.0), glm::vec3(1.0,1.0,1.0), 120.0f);
	useColorTexture = false;

	// phong shader
	const char *shadernames0[2] = {SHADERS_PATH "/NormalMapping/Phong.vert", SHADERS_PATH "/NormalMapping/Phong.frag"};
 	CVK::ShaderPhong phongShader = CVK::ShaderPhong( VERTEX_SHADER_BIT|FRAGMENT_SHADER_BIT, shadernames0);
 	//define Scene uniforms (ambient and fog)
	CVK::State::getInstance()->updateSceneSettings(glm::vec3(0.3,0.3,0.3), 0, glm::vec3(1.0,1.0,1.0), 1, 10, 1);
	// normal mapping shader
	const char *shadernames1[2] = {SHADERS_PATH "/NormalMapping/NormalMapping.vert", SHADERS_PATH "/NormalMapping/NormalMapping.frag"};
	ShaderNormalMapping normalMappingShader = ShaderNormalMapping( VERTEX_SHADER_BIT|FRAGMENT_SHADER_BIT, shadernames1);
	//use normal mapping shader
	useNormalMappingShader = false;

	// print infos
	std::cout << "Key s: " << "swap shader" << std::endl;
	std::cout << "Key m: " << "swap material" << std::endl;

	glClearColor(1.0, 1.0, 1.0, 0.0);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_BLEND);         
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);  

	while( !glfwWindowShouldClose(window))
	{
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		
		// set active shader
		if(useNormalMappingShader)
			CVK::State::getInstance()->setShader(&normalMappingShader);
		else
			CVK::State::getInstance()->setShader(&phongShader);

		// set material
		if(useColorTexture)
			node->setMaterial(&matTex);
		else
			node->setMaterial(&matRed);
		
		// update camera
		camera.update(window);
		// update view, projection matrix, light uniforms
		CVK::State::getInstance()->getShader()->update();
		// render scene
		node->render();

		glfwSwapBuffers( window);
		glfwPollEvents();
	}
	glfwDestroyWindow(window);
	glfwTerminate();

	// clean up
	delete cube;
	delete node;

	return 0;
}
示例#11
0
GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height,
                                     const char* title,
                                     GLFWmonitor* monitor,
                                     GLFWwindow* share)
{
    _GLFWfbconfig fbconfig;
    _GLFWwndconfig wndconfig;
    _GLFWwindow* window;
    _GLFWwindow* previous;

    _GLFW_REQUIRE_INIT_OR_RETURN(NULL);

    if (width <= 0 || height <= 0)
    {
        _glfwInputError(GLFW_INVALID_VALUE, "Invalid window size");
        return GL_FALSE;
    }

    // Set up desired framebuffer config
    fbconfig.redBits        = Max(_glfw.hints.redBits, 0);
    fbconfig.greenBits      = Max(_glfw.hints.greenBits, 0);
    fbconfig.blueBits       = Max(_glfw.hints.blueBits, 0);
    fbconfig.alphaBits      = Max(_glfw.hints.alphaBits, 0);
    fbconfig.depthBits      = Max(_glfw.hints.depthBits, 0);
    fbconfig.stencilBits    = Max(_glfw.hints.stencilBits, 0);
    fbconfig.accumRedBits   = Max(_glfw.hints.accumRedBits, 0);
    fbconfig.accumGreenBits = Max(_glfw.hints.accumGreenBits, 0);
    fbconfig.accumBlueBits  = Max(_glfw.hints.accumBlueBits, 0);
    fbconfig.accumAlphaBits = Max(_glfw.hints.accumAlphaBits, 0);
    fbconfig.auxBuffers     = Max(_glfw.hints.auxBuffers, 0);
    fbconfig.stereo         = _glfw.hints.stereo ? GL_TRUE : GL_FALSE;
    fbconfig.samples        = Max(_glfw.hints.samples, 0);
    fbconfig.sRGB           = _glfw.hints.sRGB ? GL_TRUE : GL_FALSE;

    // Set up desired window config
    wndconfig.width         = width;
    wndconfig.height        = height;
    wndconfig.title         = title;
    wndconfig.resizable     = _glfw.hints.resizable ? GL_TRUE : GL_FALSE;
    wndconfig.visible       = _glfw.hints.visible ? GL_TRUE : GL_FALSE;
    wndconfig.decorated     = _glfw.hints.decorated ? GL_TRUE : GL_FALSE;
    wndconfig.clientAPI     = _glfw.hints.clientAPI;
    wndconfig.glMajor       = _glfw.hints.glMajor;
    wndconfig.glMinor       = _glfw.hints.glMinor;
    wndconfig.glForward     = _glfw.hints.glForward ? GL_TRUE : GL_FALSE;
    wndconfig.glDebug       = _glfw.hints.glDebug ? GL_TRUE : GL_FALSE;
    wndconfig.glProfile     = _glfw.hints.glProfile;
    wndconfig.glRobustness  = _glfw.hints.glRobustness;
    wndconfig.monitor       = (_GLFWmonitor*) monitor;
    wndconfig.share         = (_GLFWwindow*) share;

    // Check the OpenGL bits of the window config
    if (!_glfwIsValidContextConfig(&wndconfig))
        return GL_FALSE;

    window = (_GLFWwindow*) calloc(1, sizeof(_GLFWwindow));
    window->next = _glfw.windowListHead;
    _glfw.windowListHead = window;

    if (wndconfig.monitor)
    {
        wndconfig.resizable = GL_TRUE;
        wndconfig.visible   = GL_TRUE;

        // Set up desired video mode
        window->videoMode.width       = width;
        window->videoMode.height      = height;
        window->videoMode.redBits     = Max(_glfw.hints.redBits, 0);
        window->videoMode.greenBits   = Max(_glfw.hints.greenBits, 0);
        window->videoMode.blueBits    = Max(_glfw.hints.blueBits, 0);
        window->videoMode.refreshRate = Max(_glfw.hints.refreshRate, 0);
    }

    window->monitor     = wndconfig.monitor;
    window->resizable   = wndconfig.resizable;
    window->decorated   = wndconfig.decorated;
    window->cursorMode  = GLFW_CURSOR_NORMAL;

    // Save the currently current context so it can be restored later
    previous = (_GLFWwindow*) glfwGetCurrentContext();

    // Open the actual window and create its context
    if (!_glfwPlatformCreateWindow(window, &wndconfig, &fbconfig))
    {
        glfwDestroyWindow((GLFWwindow*) window);
        glfwMakeContextCurrent((GLFWwindow*) previous);
        return GL_FALSE;
    }

    glfwMakeContextCurrent((GLFWwindow*) window);

    // Retrieve the actual (as opposed to requested) context attributes
    if (!_glfwRefreshContextAttribs())
    {
        glfwDestroyWindow((GLFWwindow*) window);
        glfwMakeContextCurrent((GLFWwindow*) previous);
        return GL_FALSE;
    }

    // Verify the context against the requested parameters
    if (!_glfwIsValidContext(&wndconfig))
    {
        glfwDestroyWindow((GLFWwindow*) window);
        glfwMakeContextCurrent((GLFWwindow*) previous);
        return GL_FALSE;
    }

    // Clearing the front buffer to black to avoid garbage pixels left over
    // from previous uses of our bit of VRAM
    glClear(GL_COLOR_BUFFER_BIT);
    _glfwPlatformSwapBuffers(window);

    // Restore the previously current context (or NULL)
    glfwMakeContextCurrent((GLFWwindow*) previous);

    if (wndconfig.monitor == NULL && wndconfig.visible)
        glfwShowWindow((GLFWwindow*) window);

    return (GLFWwindow*) window;
}
示例#12
0
void OpenClRayTracer::initialize() {
	OpenClContexts openClContexts;
	

#ifndef RUN_ON_CPU
	openClContexts.initializeInteropGpu();
	cl::Device device = openClContexts.getGpuDevice(0);
	this->context = openClContexts.getGpuContext(0);
#else
	openClContexts.initializeCpu();
	cl::Device device = openClContexts.getCpuDevice(0);
	this->context = openClContexts.getCpuContext(0);
#endif
	


	cl::Program::Sources sources;

	std::string vertexShaderSource = readFileToString("kernels/vertexShader.cl");
	std::string aabbSource = readFileToString("kernels/aabb.cl");
	std::string rayTracerSource = readFileToString("kernels/oldKernels/rayTracer.cl");
	std::string rayTracerKernelSource = readFileToString("kernels/oldKernels/rayTracerMain.cl");
	std::string debugSource = readFileToString("kernels/debug.cl");
#ifdef ADVANCED_RENDERER
	std::string perspectiveRayGeneratorSource = readFileToString("kernels/newKernels/1_perspectiveRayGenerator.cl");
	std::string rayGeneratorSource = readFileToString("kernels/newKernels/2A_rayGenerator.cl");
	std::string rayTraceAdvancedSource = readFileToString("kernels/newKernels/2B_rayTracer.cl");
	std::string treeTraverserSource = readFileToString("kernels/newKernels/3_treeTraverser.cl");
	std::string colorToPixelSource = readFileToString("kernels/newKernels/4_colorToPixel.cl");
#endif



	sources.push_back({ vertexShaderSource.c_str(), vertexShaderSource.length() });
	sources.push_back({ aabbSource.c_str(), aabbSource.length() });
	//sources.push_back({ rayTracerSource.c_str(), rayTracerSource.length() });
	sources.push_back({ rayTracerKernelSource.c_str(), rayTracerKernelSource.length() });
	sources.push_back({ debugSource.c_str(), debugSource.length() });
#ifdef ADVANCED_RENDERER
	sources.push_back({ perspectiveRayGeneratorSource.c_str(), perspectiveRayGeneratorSource.length() });
	sources.push_back({ rayTraceAdvancedSource.c_str(), rayTraceAdvancedSource.length() });
	sources.push_back({ rayGeneratorSource.c_str(), rayGeneratorSource.length() });
	sources.push_back({ treeTraverserSource.c_str(), treeTraverserSource.length() });
	sources.push_back({ colorToPixelSource.c_str(), colorToPixelSource.length() });
#endif

	writeSourcesToFile(sources, "kernels/output/allKernels.cl");

	cl::Program program(context, sources);



	std::cout << "---------------- Compilation status ----------------" << std::endl;
	std::string compileMessage;
	char programPathBuffer[256];
	getcwd(programPathBuffer, 256);
	std::string programPath = programPathBuffer;
	std::string stuff = device.getInfo<CL_DEVICE_OPENCL_C_VERSION>();
	std::string supported_extensions = device.getInfo<CL_DEVICE_EXTENSIONS>();
	std::cout << supported_extensions << std::endl;


	std::cout << "Path: \"" << programPath << "\"" << std::endl;







	// KOLLA PÅ						-CL-STD=CL2.0












#ifdef ADVANCED_RENDERER
	std::string extraOptions = "-cl-std=CL2.2 "/*-s \"" + programPath + "kernels/newKernels/3_treeTraverser.cl\" "*/;
#else
	std::string extraOptions = "";// "-cl-std=CL2.0";// "-cl-std=c++";// "-cl-std=CL2.0";// "-cl-unsafe-math-optimizations -cl-fast-relaxed-math";
#endif
	std::string compilerFlags = /*-O0 -g*/" -I " + programPath + " " + extraOptions;
	std::cout << compilerFlags << std::endl;
	try {
		std::cout << "Build started..." << std::endl;
		program.build({ device }, compilerFlags.c_str());
	}catch(cl::Error e){
		glfwDestroyWindow(renderer.getWindow());
		std::cout << "Prepping error message..." << std::endl;
		compileMessage = program.getBuildInfo<CL_PROGRAM_BUILD_LOG>(device);
		std::cout << "Failed to compile with status " << e.err() << ": " << compileMessage << std::endl;
		system("pause");
		exit(1);
	}
	
	compileMessage = program.getBuildInfo<CL_PROGRAM_BUILD_LOG>(device);
	std::cout << compileMessage << std::endl;
	
	cl_int status = CL_SUCCESS;
	
	queue = cl::CommandQueue(context, device, NULL, &status);

	vertexShaderKernel = cl::Kernel(program, "vertexShader", &status);
	aabbKernel = cl::Kernel(program, "aabb", &status);
	rayTraceKernel = cl::Kernel(program, "rayTracer", &status);
	debugKernel = cl::Kernel(program, "debug", &status);


#ifdef ADVANCED_RENDERER
	perspectiveRayGeneratorKernel = cl::Kernel(program, "perspectiveRayGenerator", &status);
	rayTraceAdvancedKernel = cl::Kernel(program, "rayTraceAdvanced", &status);
	rayGeneratorKernel = cl::Kernel(program, "rayGenerator", &status);
	treeTraverserKernel = cl::Kernel(program, "treeTraverser", &status);
	colorToPixelKernel = cl::Kernel(program, "colorToPixel", &status);
#endif
if (status != CL_SUCCESS) {
	std::cout << "Failed to create kernels" << std::endl;
	exit(1);
}

#ifndef RUN_ON_CPU
resultImages[0] = cl::ImageGL(context, CL_MEM_WRITE_ONLY, GL_TEXTURE_2D, 0, openGlTextureID, &status);
if (status != CL_SUCCESS) {
	std::cout << "Failed to create OpenCL image from OpenGL texture" << std::endl;
	exit(1);
}
#else
resultImages[0] = cl::Buffer(context, CL_MEM_WRITE_ONLY, sizeof(float4) * width * height);
if (status != CL_SUCCESS) {
	std::cout << "Failed to create OpenCL image from OpenGL texture" << std::endl;
	exit(1);
}
#endif // !RUN_ON_CPU


}
示例#13
0
int main(int argc, char* argv[])
{
	glfwSetErrorCallback(error_callback);
	if (!glfwInit()) return 1;
	glfwWindowHint(GLFW_RED_BITS, 8);
	glfwWindowHint(GLFW_GREEN_BITS, 8);
	glfwWindowHint(GLFW_BLUE_BITS, 8);
	glfwWindowHint(GLFW_ALPHA_BITS, 8);
	glfwWindowHint(GLFW_DEPTH_BITS, 32);
	glfwWindowHint(GLFW_STENCIL_BITS, GLFW_DONT_CARE);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
	glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
	glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
	glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
	glfwWindowHint(GLFW_SAMPLES, 4);
	GLFWwindow *window = glfwCreateWindow(1024, 768, "Lightmapping Example", NULL, NULL);
	if (!window) return 1;
	glfwMakeContextCurrent(window);
	gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
	glfwSwapInterval(1);

	scene_t scene = {0};
	if (!initScene(&scene))
	{
		fprintf(stderr, "Could not initialize scene.\n");
		return 1;
	}

	printf("Ambient Occlusion Baking Example.\n");
	printf("Use your mouse and the W, A, S, D, E, Q keys to navigate.\n");
	printf("Press SPACE to start baking one light bounce!\n");
	printf("This will take a few seconds and bake a lightmap illuminated by:\n");
	printf("1. The mesh itself (initially black)\n");
	printf("2. A white sky (1.0f, 1.0f, 1.0f)\n");

	while (!glfwWindowShouldClose(window))
	{
		glfwPollEvents();
		if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS)
			bake(&scene);

		int w, h;
		glfwGetFramebufferSize(window, &w, &h);
		glViewport(0, 0, w, h);

		// camera for glfw window
		float view[16], projection[16];
		fpsCameraViewMatrix(window, view);
		perspectiveMatrix(projection, 45.0f, (float)w / (float)h, 0.01f, 100.0f);
		
		// draw to screen with a blueish sky
		glClearColor(0.6f, 0.8f, 1.0f, 1.0f);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		drawScene(&scene, view, projection);

		glfwSwapBuffers(window);
	}

	destroyScene(&scene);
	glfwDestroyWindow(window);
	glfwTerminate();
	return 0;
}
示例#14
0
Window::~Window()
{
	mouse.release();
	glfwDestroyWindow(window);
}
void Application::Run()
{
	loaddone = false;

	m_timer.startTimer();    // Start timer to calculate how long it takes to render this frame
	while (!b_quitProgram)
	{
		m_dElapsedTime = m_timer.getElapsedTime();
		m_dAccumulatedTime_ThreadOne += m_dElapsedTime;
		m_dAccumulatedTime_ThreadTwo += m_dElapsedTime;

		if (m_dAccumulatedTime_ThreadOne > 0.016)
		{
			if (!loaddone)
			{
				loaddone = true;
				m_dAccumulatedTime_ThreadOne = 0.0;
			}
			//S_MANAGER->Update(m_dAccumulatedTime_ThreadOne);
			S_MANAGER->Update(m_dElapsedTime);
			m_dAccumulatedTime_ThreadOne = 0.0;
		}
		if (m_dAccumulatedTime_ThreadTwo > 0.03)
		{
			//Update
			m_dAccumulatedTime_ThreadTwo = 0.0;
		}

		S_MANAGER->Render();

		//Swap buffers
		glfwSwapBuffers(m_window);
		//Get and organize events, like keyboard and mouse input, window resizing, etc...
		glfwPollEvents();

		if (frameLimiter)
		{
			m_timer.waitUntil(frameTime);       // Frame rate limiter. Limits each frame to a specified time in ms.
		}

		// Quits program if window is closed or esc is pressed

		/*if (IsKeyPressed(VK_ESCAPE))
		{
		b_quitProgram = true;
		}*/


		if (togglefullscreen || IsKeyPressed(VK_F11))
		{
			if (!FULL_SCREEN)
			{
				S_MANAGER->getCurScene()->Exit();
				S_MANAGER->getCurScene()->CleanShaders();

				FULL_SCREEN = true;
				glfwDestroyWindow(m_window);
				const GLFWvidmode *win_data = glfwGetVideoMode(glfwGetPrimaryMonitor());
				i_WINDOW_WIDTH = win_data->width;
				i_WINDOW_HEIGHT = win_data->height;
				glfwWindowHint(GLFW_DECORATED, GL_FALSE);
				m_window = glfwCreateWindow(win_data->width, win_data->height, WIN_NAME, NULL, NULL);
				glfwMakeContextCurrent(m_window);

				S_MANAGER->getCurScene()->InitShaders();
				S_MANAGER->getCurScene()->Init();
			}
			else
			{
				S_MANAGER->getCurScene()->Exit();
				S_MANAGER->getCurScene()->CleanShaders();

				FULL_SCREEN = false;
				i_WINDOW_WIDTH = initWidth;
				i_WINDOW_HEIGHT = initHeight;
				glfwDestroyWindow(m_window);
				glfwWindowHint(GLFW_DECORATED, GL_TRUE);
				m_window = glfwCreateWindow(i_WINDOW_WIDTH, i_WINDOW_HEIGHT, WIN_NAME, NULL, NULL);
				glfwMakeContextCurrent(m_window);

				S_MANAGER->getCurScene()->InitShaders();
				S_MANAGER->getCurScene()->Init();
			}
			togglefullscreen = false;
		}
	}

	S_MANAGER->destroy();
}
示例#16
0
int main(int argc, char *argv[]){
	GLenum glResult;
	GLFWwindow *pWindow = NULL;
	GLuint program,linked;
	
	if(!glfwInit()){
		return 0;
	}
	
	pWindow = glfwCreateWindow(640, 480, "Triangle", NULL, NULL);

	glfwMakeContextCurrent(pWindow);

	glResult = glewInit();
	if(glResult != GLEW_OK){
		printf("Error: %s\n", glewGetErrorString(glResult));
		return 0;
	}

	printf("VENDOR=%s\n", glGetString(GL_VENDOR));
	printf("GPU=%s\n", glGetString(GL_RENDERER));
	printf("OpenGL=%s\n", glGetString(GL_VERSION));
	printf("GLSL=%s\n", glGetString(GL_SHADING_LANGUAGE_VERSION));
	
	s_vertexShader = glCreateShader(GL_VERTEX_SHADER);
	printf("s_vertexShader = %d\n", s_vertexShader);

	readShaderCompile(s_vertexShader, "triangle.vert");

	program = glCreateProgram();
	if(program == 0){
		printf("Failed to create program\n");
		goto error_destroy_window;
	}

	glAttachShader(program, s_vertexShader);
	glLinkProgram(program);
	glGetProgramiv(program, GL_LINK_STATUS, &linked);

	if(linked == GL_FALSE){
		char *pInfoLog;
		GLsizei size,len;
		printf("failed to link shader\n");
		glGetProgramiv( program, GL_INFO_LOG_LENGTH, &size );
		if ( size > 0 ) 
		{
			pInfoLog = (char *)malloc(size);
			glGetProgramInfoLog( program, size, &len, pInfoLog );
			printf("%s\n",pInfoLog);
			free(pInfoLog);
		}	
	}
	
	while(!glfwWindowShouldClose(pWindow)){
		glClear(GL_COLOR_BUFFER_BIT);

		glUseProgram(program);
		glBegin(GL_TRIANGLES);
		glColor3d(1.0, 0.0, 0.0);
		glVertex2d(0.9*cos(0.0), 0.9*sin(0.0));
		glColor3d(0.0, 1.0, 0.0);
		glVertex2d(0.9*cos(2.0*M_PI/3.0), 0.9*sin(2.0*M_PI/3.0));
		glColor3d(0.0, 0.0, 1.0);
		glVertex2d(0.9*cos(2.0*M_PI*2.0/3.0), 0.9*sin(2.0*M_PI*2.0/3.0));
		glEnd();
		glUseProgram(0);
		glFlush();
		glfwSwapBuffers(pWindow);
		glfwPollEvents();
	}

	glDeleteProgram(program);
	
 error_destroy_window:
	glfwDestroyWindow(pWindow);

	glDeleteShader(s_vertexShader);
	
 error_exit:	
	glfwTerminate();
	return 0;
}
示例#17
0
void SimpleApp::SimpleCleanUp()
{
	glfwDestroyWindow(glfwWindow);
	glfwTerminate();
}
示例#18
0
int main(void)
{
    GLFWwindow* window;

    glfwSetErrorCallback(error_callback);

    if (!glfwInit())
        exit(EXIT_FAILURE);

    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
	glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
	glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
	glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
	
	window = glfwCreateWindow(640, 480, "Simple example", NULL, NULL);
    if (!window)
    {
        glfwTerminate();
        exit(EXIT_FAILURE);
    }

    glfwMakeContextCurrent(window);

    glfwSetKeyCallback(window, key_callback);

    // Initialize GLEW
    glewExperimental = GL_TRUE;
    glewInit();
	
	// Create Vertex Array Object
    GLuint vao;
    glGenVertexArrays(1, &vao);
    glBindVertexArray(vao);

    // Create a Vertex Buffer Object and copy the vertex data to it
    GLuint vbo;
    glGenBuffers(1, &vbo);

    GLfloat vertices[] = {
    //  Position   Color             Texcoords
        -0.5f,  0.5f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, // Top-left
         0.5f,  0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, // Top-right
         0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, // Bottom-right
        -0.5f, -0.5f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f  // Bottom-left
    };

    glBindBuffer(GL_ARRAY_BUFFER, vbo);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

    // Create an element array
    GLuint ebo;
    glGenBuffers(1, &ebo);

    GLuint elements[] = {
        0, 1, 2,
        2, 3, 0
    };

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(elements), elements, GL_STATIC_DRAW);
    
	GLint result = GL_FALSE;
	
	GLchar*   vertexSource;
    GLchar*   fragmentSource;

    // Create and compile the vertex shader
    loadShaderSource("./resources/shaders/transformations/vertexShader.vert", vertexSource);
    GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
    glShaderSource(vertexShader, 1, (const GLchar**)&vertexSource, NULL);
    glCompileShader(vertexShader);
    
    // Check Vertex Shader
    glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &result);
    if (result != GL_TRUE) {
    	std::cout<<"Failed to load vertex shader"<<std::endl;
    }
    
    unloadShaderSource(vertexSource);

    // Create and compile the fragment shader
	loadShaderSource("./resources/shaders/transformations/fragmentShader.frag", fragmentSource);
    GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
    glShaderSource(fragmentShader, 1, (const GLchar**)&fragmentSource, NULL);
    glCompileShader(fragmentShader);
    
    // Check Fragment Shader
    glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &result);
    if (result != GL_TRUE) {
    	std::cout<<"Failed to load fragment shader"<<std::endl;
    }
    
    unloadShaderSource(vertexSource);

    // Link the vertex and fragment shader into a shader program
    GLuint shaderProgram = glCreateProgram();
    glAttachShader(shaderProgram, vertexShader);
    glAttachShader(shaderProgram, fragmentShader);
    glBindFragDataLocation(shaderProgram, 0, "outColor");
    glLinkProgram(shaderProgram);
    glUseProgram(shaderProgram);

    // Specify the layout of the vertex data
    GLint posAttrib = glGetAttribLocation(shaderProgram, "position");
    glEnableVertexAttribArray(posAttrib);
    glVertexAttribPointer(posAttrib, 2, GL_FLOAT, GL_FALSE, 7 * sizeof(GLfloat), 0);

    GLint colAttrib = glGetAttribLocation(shaderProgram, "color");
    glEnableVertexAttribArray(colAttrib);
    glVertexAttribPointer(colAttrib, 3, GL_FLOAT, GL_FALSE, 7 * sizeof(GLfloat), (void*)(2 * sizeof(GLfloat)));

    GLint texAttrib = glGetAttribLocation(shaderProgram, "texcoord");
    glEnableVertexAttribArray(texAttrib);
    glVertexAttribPointer(texAttrib, 2, GL_FLOAT, GL_FALSE, 7 * sizeof(GLfloat), (void*)(5 * sizeof(GLfloat)));

    // Load textures
    GLuint textures[2];
    glGenTextures(2, textures);
    
    int width, height;
    unsigned char* image;

    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, textures[0]);
        image = SOIL_load_image("./resources/textures/kitty.png", &width, &height, 0, SOIL_LOAD_RGB);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
        SOIL_free_image_data(image);
    glUniform1i(glGetUniformLocation(shaderProgram, "texKitten"), 0);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    glActiveTexture(GL_TEXTURE1);
    glBindTexture(GL_TEXTURE_2D, textures[1]);
        image = SOIL_load_image("./resources/textures/puppy.png", &width, &height, 0, SOIL_LOAD_RGB);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
        SOIL_free_image_data(image);
    glUniform1i(glGetUniformLocation(shaderProgram, "texPuppy"), 1);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    GLint uniModel = glGetUniformLocation(shaderProgram, "model");
    
    // Set up projection
    glm::mat4 view = glm::lookAt(
        glm::vec3(1.2f, 1.2f, 1.2f),
        glm::vec3(0.0f, 0.0f, 0.0f),
        glm::vec3(0.0f, 0.0f, 1.0f)
    );
    GLint uniView = glGetUniformLocation(shaderProgram, "view");
    glUniformMatrix4fv(uniView, 1, GL_FALSE, glm::value_ptr(view));

    glm::mat4 proj = glm::perspective(45.0f, 800.0f / 600.0f, 1.0f, 10.0f);
    GLint uniProj = glGetUniformLocation(shaderProgram, "proj");
    glUniformMatrix4fv(uniProj, 1, GL_FALSE, glm::value_ptr(proj));   

    while (!glfwWindowShouldClose(window))
    {
    	
    	// Clear the screen to black
        glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT);

        // Calculate transformation
        glm::mat4 model;
        model = glm::rotate(
            model,
            (GLfloat)clock() / (GLfloat)CLOCKS_PER_SEC * 180.0f,
            glm::vec3(0.0f, 0.0f, 1.0f)
        );
        glUniformMatrix4fv(uniModel, 1, GL_FALSE, glm::value_ptr(model));
        
        // Draw a rectangle from the 2 triangles using 6 indices
        glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
    
        glfwSwapBuffers(window);
        glfwPollEvents();
    }

    glDeleteTextures(2, textures);

    glDeleteProgram(shaderProgram);
    glDeleteShader(fragmentShader);
    glDeleteShader(vertexShader);

    glDeleteBuffers(1, &ebo);
    glDeleteBuffers(1, &vbo);

    glDeleteVertexArrays(1, &vao);

    glfwDestroyWindow(window);

    glfwTerminate();
    exit(EXIT_SUCCESS);
}
示例#19
0
int main()
{
	GLFWwindow* window = nullptr;
	if(!init(window))
	{
		system("pause");
		exit(0);
	}

	glClearColor(0.0, 0.0, 0.0, 0.0);

	//set up audio engine
	SoundSystemClass sounds;

	GLSLProgram shaders;
	//load shaders, compile and link	
	shaders.compileShaderFromFile("triangle.v.glsl", VERTEX);
	shaders.compileShaderFromFile("triangle.f.glsl", FRAGMENT);
	shaders.link();
	shaders.use();

	Screen* currentScreen;

	MainMenuScreen *mms = new MainMenuScreen(&sounds, &shaders);
	currentScreen = mms;
	
	//Text t(glm::vec3(0, 0, 0), glm::vec4(1.0, 0.0, 0.0, 1.0), 40, 40, "arial_0.png", "arial.fnt");

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	
	//create projection matrix
	glm::mat4 projectionMatrix = glm::ortho(0.0f, 800.0f, 0.0f, 600.0f);
	double lastTime = glfwGetTime(), currentTime;

	while(!glfwWindowShouldClose(window) && currentScreen != nullptr)
	{
		//calculate delta time
		currentTime = glfwGetTime();
		double deltaTime = currentTime - lastTime;

		//draw
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		
		currentScreen->Draw();

		glfwSwapBuffers(window);
		
		//update
		Screen* next = currentScreen->Update(deltaTime);
		//if returned screen is null, pop current screen
		if(next != currentScreen)
		{
			delete currentScreen;
			currentScreen = next;
		}
		//else continue with current top of stack

		
		glfwPollEvents();
		lastTime = currentTime;
	}

	glfwDestroyWindow(window);
	glfwTerminate();
	return 0;
}
示例#20
0
GLFWView::~GLFWView() {
    glfwDestroyWindow(window);
    glfwTerminate();
}
示例#21
0
/* ------------------------------------------------------------------ main - */
int main( int argc, char **argv )
{
    GLFWwindow* window;

    glfwSetErrorCallback( error_callback );

    if (!glfwInit( ))
    {
        exit( EXIT_FAILURE );
    }

    glfwWindowHint( GLFW_VISIBLE, GL_TRUE );
    glfwWindowHint( GLFW_RESIZABLE, GL_FALSE );

    window = glfwCreateWindow( 1, 1, argv[0], NULL, NULL );

    if (!window)
    {
        glfwTerminate( );
        exit( EXIT_FAILURE );
    }

    glfwMakeContextCurrent( window );
    glfwSwapInterval( 1 );

    glfwSetFramebufferSizeCallback( window, reshape );
    glfwSetWindowRefreshCallback( window, display );
    glfwSetKeyCallback( window, keyboard );

#ifndef __APPLE__
    glewExperimental = GL_TRUE;
    GLenum err = glewInit();
    if (GLEW_OK != err)
    {
        /* Problem: glewInit failed, something is seriously wrong. */
        fprintf( stderr, "Error: %s\n", glewGetErrorString(err) );
        exit( EXIT_FAILURE );
    }
    fprintf( stderr, "Using GLEW %s\n", glewGetString(GLEW_VERSION) );
#endif

    buffer = text_buffer_new( LCD_FILTERING_OFF );
    vec4 black = {{0.0, 0.0, 0.0, 1.0}};
    vec4 none  = {{1.0, 1.0, 1.0, 0.0}};

    markup_t markup;
    markup.family  = "fonts/VeraMono.ttf",
    markup.size    = 15.0;
    markup.bold    = 0;
    markup.italic  = 0;
    markup.rise    = 0.0;
    markup.spacing = 0.0;
    markup.gamma   = 1.0;
    markup.foreground_color    = black;
    markup.background_color    = none;
    markup.underline           = 0;
    markup.underline_color     = black;
    markup.overline            = 0;
    markup.overline_color      = black;
    markup.strikethrough       = 0;
    markup.strikethrough_color = black;
    markup.font = 0;

    vec2 pen = {{10.0, 480.0}};
    FILE *file = fopen ( "data/256colors.txt", "r" );
    if ( file != NULL )
    {
        wchar_t line[1024];
        while( fgetws ( line, sizeof(line), file ) != NULL )
        {
            print( buffer, &pen, line, &markup );
        }
        fclose ( file );
    }

    mat4_set_identity( &projection );
    mat4_set_identity( &model );
    mat4_set_identity( &view );

    glfwSetWindowSize( window, 800, 500 );
    glfwShowWindow( window );

    while(!glfwWindowShouldClose( window ))
    {
        display( window );
        glfwPollEvents( );
    }

    glfwDestroyWindow( window );
    glfwTerminate( );

    return 0;
}
示例#22
0
int main(int argc, const char * argv[]) {
    
    // Initialize glfw
    if (!glfwInit()){
        std::cerr << "Failed to initialize glfw" << std::endl;
        exit(EXIT_FAILURE);
    }
    
    // Set the error callback for glfw
    glfwSetErrorCallback(error_callback);
    
    // Set window settings
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    
    glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
    
    GLFWwindow *window = glfwCreateWindow(800,600, "OpenGL Renderer", NULL, NULL);
    
    if (!window) {
        std::cerr << "Could not create glfw window!" << std::endl;
        glfwTerminate();
        exit(EXIT_FAILURE);
    }
    glfwMakeContextCurrent(window);
    glfwSwapInterval(1);
    
    glfwSetKeyCallback(window, key_callback);
    glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
    
    int width, height;
    glfwGetFramebufferSize(window, &width, &height);
    glViewport(0, 0, width, height);
    float ratio = width / (float) height;
    
    Camera cam(glm::vec3(0,0,-2));
    cam.setProjMatrix(ratio);
    
    DefaultMaterial m(glm::vec3(.2f,.2f,.9f));
    
    MeshObject cube;
    cube.setMaterial(&m);
    
    SceneNode cubeNode(&cube);
    cubeNode.setTransform(glm::scale(glm::mat4(), glm::vec3(2)));
    
    double lastFrameTime = glfwGetTime();
    double xpos, ypos;
    
    while (!glfwWindowShouldClose(window)) {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
        
        double currentFrameTime = glfwGetTime();
        
        double delta = currentFrameTime - lastFrameTime;
        
        lastFrameTime = currentFrameTime;
        
        cam.translate(glm::vec3(delta * camXSpeed, delta * camYSpeed, delta * camZSpeed));
        
        glfwGetCursorPos(window, &xpos, &ypos);
        
        // Cursor rotation is currently broken.
        //cam.rotateFromCursor(2*xpos/width - 1, 2*ypos/height - 1);
        
        cubeNode.render(window, cam.getViewMatrix(), cam.getProjMatrix());
        
        glfwSwapBuffers(window);
        glfwPollEvents();
    }
    
    glfwDestroyWindow(window);
    glfwTerminate();
    return 0;
}
示例#23
0
文件: window.c 项目: hanxi/glfw
GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height,
                                     const char* title,
                                     GLFWmonitor* monitor,
                                     GLFWwindow* share)
{
    _GLFWfbconfig fbconfig;
    _GLFWctxconfig ctxconfig;
    _GLFWwndconfig wndconfig;
    _GLFWwindow* window;

    assert(title != NULL);
    assert(width >= 0);
    assert(height >= 0);

    _GLFW_REQUIRE_INIT_OR_RETURN(NULL);

    if (width <= 0 || height <= 0)
    {
        _glfwInputError(GLFW_INVALID_VALUE,
                        "Invalid window size %ix%i",
                        width, height);

        return NULL;
    }

    fbconfig  = _glfw.hints.framebuffer;
    ctxconfig = _glfw.hints.context;
    wndconfig = _glfw.hints.window;

    wndconfig.width   = width;
    wndconfig.height  = height;
    wndconfig.title   = title;
    ctxconfig.share   = (_GLFWwindow*) share;

    if (!_glfwIsValidContextConfig(&ctxconfig))
        return NULL;

    window = calloc(1, sizeof(_GLFWwindow));
    window->next = _glfw.windowListHead;
    _glfw.windowListHead = window;

    window->videoMode.width       = width;
    window->videoMode.height      = height;
    window->videoMode.redBits     = fbconfig.redBits;
    window->videoMode.greenBits   = fbconfig.greenBits;
    window->videoMode.blueBits    = fbconfig.blueBits;
    window->videoMode.refreshRate = _glfw.hints.refreshRate;

    window->monitor     = (_GLFWmonitor*) monitor;
    window->resizable   = wndconfig.resizable;
    window->decorated   = wndconfig.decorated;
    window->autoIconify = wndconfig.autoIconify;
    window->floating    = wndconfig.floating;
    window->focusOnShow = wndconfig.focusOnShow;
    window->cursorMode  = GLFW_CURSOR_NORMAL;

    window->minwidth    = GLFW_DONT_CARE;
    window->minheight   = GLFW_DONT_CARE;
    window->maxwidth    = GLFW_DONT_CARE;
    window->maxheight   = GLFW_DONT_CARE;
    window->numer       = GLFW_DONT_CARE;
    window->denom       = GLFW_DONT_CARE;

    // Open the actual window and create its context
    if (!_glfwPlatformCreateWindow(window, &wndconfig, &ctxconfig, &fbconfig))
    {
        glfwDestroyWindow((GLFWwindow*) window);
        return NULL;
    }

    if (ctxconfig.client != GLFW_NO_API)
    {
        if (!_glfwRefreshContextAttribs(window, &ctxconfig))
        {
            glfwDestroyWindow((GLFWwindow*) window);
            return NULL;
        }
    }

    if (window->monitor)
    {
        if (wndconfig.centerCursor)
            _glfwCenterCursorInContentArea(window);
    }
    else
    {
        if (wndconfig.visible)
        {
            _glfwPlatformShowWindow(window);
            if (wndconfig.focused)
                _glfwPlatformFocusWindow(window);
        }
    }

    return (GLFWwindow*) window;
}
示例#24
0
ControlState::~ControlState()
{
    glfwDestroyWindow(window);
}
int main(void)
{
    GLFWwindow* window;
    glfwSetErrorCallback(error_callback);
    if (!glfwInit())
        exit(EXIT_FAILURE);

    window = glfwCreateWindow(640, 480, "Simple example", NULL, NULL);
    if (!window)
    {
        glfwTerminate();
        exit(EXIT_FAILURE);
    }

    glfwMakeContextCurrent(window);
    glfwSwapInterval(1);
    glfwSetKeyCallback(window, key_callback);

    while (!glfwWindowShouldClose(window))
    {
        float ratio;
        int width, height;
        glfwGetFramebufferSize(window, &width, &height);
        ratio = width / (float) height;
        glViewport(0, 0, width, height);
        glClear(GL_COLOR_BUFFER_BIT);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(-ratio, ratio, -1.f, 1.f, 1.f, -1.f);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        // glRotatef((float) glfwGetTime() * 50.f, 0.f, 0.f, 1.f);
        glBegin(GL_TRIANGLES); // segitiga kiri bawah
        glColor3f(1.f, 0.f, 0.f);
        glVertex3f(-0.8f, -0.6f, 0.f);
        glVertex3f(0.f, -0.6f, 0.f);
        glVertex3f(-0.4f, 0.f, 0.f);
        glEnd();

        glBegin(GL_TRIANGLES); // segitiga kanan bawah
        glColor3f(0.f, 1.f, 0.f);
        glVertex3f(0.f, -0.6f, 0.f);
        glVertex3f(0.8f, -0.6f, 0.f);
        glVertex3f(0.4f, 0.f, 0.f);
        glEnd();

        glBegin(GL_TRIANGLES); // segitiga atas
        glColor3f(0.f, 0.f, 1.f);
        glVertex3f(-0.4f, 0.f, 0.f);
        glVertex3f(0.4f, 0.f, 0.f);
        glVertex3f(0.f, 0.6f, 0.f);
        glEnd();

        glfwSwapBuffers(window);
        glfwPollEvents();
    }
    glfwDestroyWindow(window);
    glfwTerminate();
    exit(EXIT_SUCCESS);
    
}
示例#26
0
文件: trees.cpp 项目: selony/Trees
int main(void) {
	unsigned int stage = grow_tree_stage;
	
	glfwSetErrorCallback(error_callback);
	if (!glfwInit()) {
	    exit(EXIT_FAILURE);		
	};

#ifdef __APPLE__
			syslog(LOG_NOTICE, "Starting trees");
#else
			// need to implement for other platforms...
#endif
		
	// make sure we're using OpenGL 3
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
	glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
	glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
		
	GLFWwindow* window = glfwCreateWindow(1024, 768, "Test tree logic", NULL, NULL);
	if (window) {
		glfwMakeContextCurrent(window);
		
		// init GLEW
		glewExperimental=true;
		GLenum err = glewInit();
		if (err != GLEW_OK) {
#ifdef __APPLE__
			syslog(LOG_ALERT, "Error: %s", glewGetErrorString(err));
#else
			// need to implement for other platforms...
#endif
		} else {
#ifdef __APPLE__
			syslog(LOG_NOTICE, "Using GLEW %s", glewGetString(GLEW_VERSION));
#else
			// need to implement for other platforms...
#endif
		};
		
		glfwSetKeyCallback(window, key_callback);
		glfwSetScrollCallback(window, scroll_callback);

		// our new tree
		treelogic * tree = new treelogic();
	
		// add just one branch to start of with, you could build the start of a tree here manually
		tree->growBranch(0, vec3(0.0, 10.0, 0.0));
	
		// and generate our attraction points, as a sample I've staged the points to get larger concentrations of points nearer to the center
		tree->generateAttractionPoints(800, 75.0, 50.0, 1.5, 50.0);
		tree->generateAttractionPoints(300, 90.0, 75.0, 1.5, 60.0, false);
		tree->generateAttractionPoints(50, 100.0, 90.0, 1.5, 70.0, false);

		// and an example with very few attraction points:
//		tree->generateAttractionPoints(50, 100.0, 40.0, 2.0, 50.0, false);
		
		tree->initShaders();
		
		while (!glfwWindowShouldClose(window)) {
	        int width, height;

			// get our width and height, may have been resized
	        glfwGetFramebufferSize(window, &width, &height);
			
			// clear our viewport
	        glViewport(0, 0, width, height);
			glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

			// setup our projection matrix
			mat4 projection;
	        float ratio = width / (float) height;
			projection.perspective(45, ratio, 1.0, 10000.0);
			tree->setProjection(projection);

			// note, with just an identity matrix our "camera" is at 0.0 ,0.0 ,0.0 looking straight ahead (looking towards 0.0 ,0.0 , -1.0)..
			// but we do adjust our view
			mat4 view;			
			view += vec3(0.0f, -100.0f, -distance);
			view.rotate(rotate, 0.f, 1.f, 0.f);
			tree->setView(view);
			
			// we leave our model alone for now...
			
			// and render
			tree->setWireframe(wireframe);
			tree->render();
			
			if ((stage == grow_tree_stage) && !paused) {
				// This is just for testing, if we were generating for real we would call this until it returns false in our initialisation... 
				if (!tree->doIteration(100.0, 1.0, 10.0, vec3(0.1, 0.2, 0.0))) {
					stage = grow_roots_stage;
					
					// we also add a small point cloud for our roots to grow next
//					tree->generateAttractionPoints(150, 50.0, 20.0, 0.2, -3.0, false);					
				};
			} else if ((stage == grow_roots_stage) && !paused) {
				if (!tree->doIteration(30.0, 2.0, 10.0, vec3(0.0, 0.0, 0.0))) {
					stage = optimise_tree_stage;
					paused = true;
				};
			} else if ((stage == optimise_tree_stage) && !paused) {
				tree->optimiseNodes();
				stage = build_mesh_stage;
				paused = true;
			} else if ((stage == build_mesh_stage) && !paused) {
				tree->setMinRadius(0.4f);
				tree->setRadiusFactor(0.0005f);
				tree->createModel();
				stage = add_leaves_stage;
				paused = true;
			};
						
			glfwSwapBuffers(window);
			glfwPollEvents();
		};
	
		glfwDestroyWindow(window);	

		delete tree;
	};	
	
	glfwTerminate();
};
示例#27
0
 Context::~Context() noexcept {
   glfwDestroyWindow(m_window);
 }
示例#28
0
int main (int argc, char *argv[])	// MAIN
{
    FILE *f;
    int i=0;

    if (argc!=3)
    {
      print_usage();
      exit(0);
    }
    coo_file=argv[1];
    data_file=argv[2];

    load_chr_font("DRFT.CHR");

    for (i=0;i<86400;i++)
    {
		coord[i][0]=0.0f;
		coord[i][1]=0.0f;
		coord[i][2]=0.0f;
		data[i][0] = 0.0f;
		data[i][1] = 0.0f;
		selected[i]=-1;
	}

    f = fopen(coo_file,"rt");
    if (f == NULL)
    {
		printf("Error opening file %s\n",coo_file);
		exit(0);
	}
	i = 0;
	while (!feof(f))
	{
		int snum;
		float n;
		float e;
		float h;
		fscanf(f,"%d\t%f\t%f\t%f\n",&snum,&n,&e,&h);
		coord[snum][0] = n;
		coord[snum][1] = e;
		coord[snum][2] = h;
		if (i == 0)
		{
			max_coo_x = n;
			max_coo_y = e;
			max_coo_h = h;
			min_coo_x = n;
			min_coo_y = e;
			min_coo_h = h;
			i = 1;
		}
		else
		{
			if (max_coo_x < n) max_coo_x = n;
			if (max_coo_y < e) max_coo_y = e;
			if (max_coo_h < h) max_coo_h = h;
			if (min_coo_x > n) min_coo_x = n;
			if (min_coo_y > e) min_coo_y = e;
			if (min_coo_h > h) min_coo_h = h;
		}
		selected[snum] = 1;
	}
	fclose(f);
	coo_w = max_coo_x - min_coo_x;
	coo_h = max_coo_y - min_coo_y;
	coo_a = max_coo_h - min_coo_h;

	f = fopen(data_file,"rt");
	if (f == NULL)
	{
		printf("Error opening file %s\n",data_file);
		exit(0);
	}
	i = 0;
	int j = 0;
	while (!feof(f))
	{
		fscanf(f,"%f\t%f\n",&data[i][0],&data[i][1]);
		if (i>=14400) if (selected[i-14400]>=0)
		{
			if (j==0)
			{
				max_data[0]=data[0][0];
				max_data[1]=data[0][1];
				min_data[0]=data[0][0];
				min_data[1]=data[0][1];
				j = 1;
			}
			else
			{
				if (max_data[0]<data[i][0]) max_data[0]=data[i][0];
				if (max_data[1]<data[i][1]) max_data[1]=data[i][1];
				if (min_data[0]>data[i][0]) min_data[0]=data[i][0];
				if (min_data[1]>data[i][1]) min_data[1]=data[i][1];
			}
		}
		i++;
	}
	fclose(f);
	data_w[0] = max_data[0]-min_data[0];
	data_w[1] = max_data[1]-min_data[1];

    if (!glfwInit())
        exit(EXIT_FAILURE);
    current_vmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
    screen_width = current_vmode->width;
    screen_height = current_vmode->height;
    arat = (float)screen_width / (float)screen_height;
    px = 2.0F / screen_width;
    py = 2.0F / screen_height;
    window = glfwCreateWindow(screen_width, screen_height, "PROFB", glfwGetPrimaryMonitor(), NULL);
    if (!window)
    {
        glfwTerminate();
        exit(EXIT_FAILURE);
    }

    glfwMakeContextCurrent(window);
    glfwSetKeyCallback(window, key_callback);
    glfwSetMouseButtonCallback(window, mousepress);
    glfwSetCursorPosCallback(window, mousemove);
    glfwSetScrollCallback(window, mouseweelscroll);

    glClearColor(1.0,1.0,1.0,0);
    glEnable(GL_LINE_SMOOTH);
    glEnable(GL_POINT_SMOOTH);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    while (!glfwWindowShouldClose(window))
    {
        glfwPollEvents();
        if (Redisplay==1)
        {
            Draw();
            Redisplay=0;
        }
    }
    glfwDestroyWindow(window);
    glfwTerminate();

	return 0;
}
示例#29
0
文件: main.cpp 项目: MarcelBock/GeKo
int main()
{
    glfwInit();

    Window testWindow(50, 50, WINDOW_WIDTH, WINDOW_HEIGHT, "Deferred Shading");
    glfwMakeContextCurrent(testWindow.getWindow());
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);


    // You have to set a camera name
    cam.setName("PilotviewCam");
    cam.setPosition(glm::vec4(0.0, 0.5, 3.0, 1.0));
    cam.setNearFar(0.01f, 100.0f);

    iH.setAllInputMaps(cam);
    iH.changeActiveInputMap("Pilotview");

    //Callback
    glfwSetKeyCallback(testWindow.getWindow(), key_callback);

    glewInit();

    //our shader
    VertexShader vsGBuffer(loadShaderSource(SHADERS_PATH + std::string("/GBuffer/GBuffer.vert")));
    FragmentShader fsGBuffer(loadShaderSource(SHADERS_PATH + std::string("/GBuffer/GBuffer.frag")));
    ShaderProgram shaderGBuffer(vsGBuffer, fsGBuffer);

    //load shader here
    VertexShader vsDsLighting(loadShaderSource(SHADERS_PATH + std::string("/DeferredShading/dsLighting.vert")));
    FragmentShader fsDsLighting(loadShaderSource(SHADERS_PATH + std::string("/DeferredShading/dsLighting.frag")));
    ShaderProgram shaderDsLightingShader(vsDsLighting, fsDsLighting);

    VertexShader vsDsCompositing(loadShaderSource(SHADERS_PATH + std::string("/DeferredShading/dsFinalCompositing.vert")));
    FragmentShader fsDsCompositing(loadShaderSource(SHADERS_PATH + std::string("/DeferredShading/dsFinalCompositing.frag")));
    ShaderProgram shaderDsCompositingShader(vsDsCompositing, fsDsCompositing);

    VertexShader vsSfq(loadShaderSource(SHADERS_PATH + std::string("/ScreenFillingQuad/ScreenFillingQuad.vert")));
    FragmentShader fsSfq(loadShaderSource(SHADERS_PATH + std::string("/ScreenFillingQuad/ScreenFillingQuad.frag")));
    ShaderProgram shaderSFQ(vsSfq, fsSfq);

    //our renderer
    OpenGL3Context context;
    Renderer renderer(context);

    FBO fboGBuffer(WINDOW_WIDTH, WINDOW_HEIGHT, 3, true, false);
    FBO fboDeferredShading(WINDOW_WIDTH, WINDOW_HEIGHT, 3, true, false);
    FBO fboCompositing(WINDOW_WIDTH, WINDOW_HEIGHT, 3, false, false);

    //our object
    Cube cube;

    Teapot teapot;

    Rect plane;
    Rect screenFillingQuad;
    screenFillingQuad.loadBufferData();

    //our textures
    Texture bricks((char*)RESOURCES_PATH "/bricks_diffuse.png");
    Texture bricks_normal((char*)RESOURCES_PATH "/bricks_normal.png");
    Texture bricks_height((char*)RESOURCES_PATH "/bricks_height.png");

    Texture chrome((char*)RESOURCES_PATH "/chrome.jpg");
    Texture cvLogo((char*)RESOURCES_PATH "/cv_logo.bmp");

    //Scene creation
    Level testLevel("testLevel");
    Scene testScene("testScene");
    testLevel.addScene(&testScene);
    testLevel.changeScene("testScene");

    //Add Camera to scenegraph
    testScene.getScenegraph()->addCamera(&cam);
    testScene.getScenegraph()->getCamera("PilotviewCam");
    testScene.getScenegraph()->setActiveCamera("PilotviewCam");

    Rect rect;

    Node cube1("cube1");
    cube1.addGeometry(&cube);
    cube1.addTexture(&bricks);
    cube1.addNormalMap(&bricks_normal);
    cube1.addHeightMap(&bricks_height);
    cube1.setModelMatrix(glm::translate(cube1.getModelMatrix(), glm::vec3(-1.0, 0.5, -0.5)));
    cube1.setModelMatrix(glm::scale(cube1.getModelMatrix(), glm::vec3(0.7, 0.7, 0.7)));

    Node cube2("cube2");
    cube2.addGeometry(&cube);
    cube2.addTexture(&bricks);
    cube2.addNormalMap(&bricks_normal);
    cube2.setModelMatrix(glm::translate(cube2.getModelMatrix(), glm::vec3(-1, 0.5, 0.5)));
    cube2.setModelMatrix(glm::scale(cube2.getModelMatrix(), glm::vec3(0.7, 0.7, 0.7)));

    Node cube3("cube3");
    cube3.addGeometry(&cube);
    cube3.addTexture(&bricks);
    cube3.setModelMatrix(glm::translate(cube3.getModelMatrix(), glm::vec3(0, 0.5, -0.5)));
    cube3.setModelMatrix(glm::scale(cube3.getModelMatrix(), glm::vec3(0.7, 0.7, 0.7)));

    Node cube4("cube4");
    cube4.addGeometry(&cube);
    cube4.addTexture(&bricks);
    cube4.addNormalMap(&bricks_normal);
    cube4.addHeightMap(&bricks_height,0.07,0.1,true);
    cube4.setModelMatrix(glm::translate(cube4.getModelMatrix(), glm::vec3(0, 0.5, 0.5)));
    cube4.setModelMatrix(glm::scale(cube4.getModelMatrix(), glm::vec3(0.7, 0.7, 0.7)));

    Node wallNode1("wall1");
    wallNode1.addGeometry(&plane);
    wallNode1.addTexture(&cvLogo);
    wallNode1.setModelMatrix(glm::translate(wallNode1.getModelMatrix(), glm::vec3(0.0, 0.1, 0.2)));
    wallNode1.setModelMatrix(glm::rotate(wallNode1.getModelMatrix(), 90.0f, glm::vec3(1.0, 0.0, 0.0)));
    wallNode1.setModelMatrix(glm::scale(wallNode1.getModelMatrix(), glm::vec3(10.5, 10.5, 10.5)));


    Node teaNode("teaNode");
    teaNode.addGeometry(&teapot);
    teaNode.addTexture(&chrome);
    teaNode.setModelMatrix(glm::translate(teaNode.getModelMatrix(), glm::vec3(0.2, 0.4, 0.7)));
    teaNode.setModelMatrix(glm::scale(teaNode.getModelMatrix(), glm::vec3(0.5, 0.5, 0.5)));


    //Creating a scenegraph
    testScene.getScenegraph()->getRootNode()->addChildrenNode(&wallNode1);
    testScene.getScenegraph()->getRootNode()->addChildrenNode(&cube1);
    testScene.getScenegraph()->getRootNode()->addChildrenNode(&cube2);
    testScene.getScenegraph()->getRootNode()->addChildrenNode(&cube3);
    testScene.getScenegraph()->getRootNode()->addChildrenNode(&cube4);
    //testScene.getScenegraph()->getRootNode()->addChildrenNode(&teaNode);

    double startTime = glfwGetTime();
    //Renderloop

    //create Light spheres for DS
    Node lights = Node("Root");
    Sphere lightSphere = Sphere();

    for (int i = -4; i < 4; i++)
        for (int j = -4; j < 4; j++)
        {
            Node *newLight = new Node(std::string("Node_"+std::to_string(i)+std::to_string(j)));
            newLight->addGeometry(&lightSphere);
            newLight->setModelMatrix(glm::translate(glm::mat4(1.0f), glm::vec3(i*1.5, 1.0f, j*1.5)));
            //newLight.setModelMatrix(glm::translate(glm::mat4(1.0f), glm::vec3(0, 1, 1.0f)));
            newLight->setModelMatrix(glm::scale(newLight->getModelMatrix(), glm::vec3(2.0, 2.0, 2.0)));
            lights.addChildrenNode(newLight);
        }

    int outputFPS = 0;

    while (!glfwWindowShouldClose(testWindow.getWindow()))
    {
        // You have to compute the delta time

        float deltaTime = glfwGetTime() - startTime;
        cam.setSensitivity(deltaTime);

        //if (!(outputFPS % 20))
        //std::cout << "FPS: " << static_cast<int>(1 / (glfwGetTime() - startTime)) << std::endl;

        std::cout << "FPS: " << static_cast<double>(glfwGetTime() - startTime) * 100 << std::endl;


        outputFPS++;
        startTime = glfwGetTime();

        //update Model Matrix
        lights.setModelMatrix(glm::rotate(lights.getModelMatrix(), 10.0f * deltaTime, glm::vec3(0.0, 1.0, 0.0)));


        fboGBuffer.bind();
        glClearColor(0, 0, 0, 0);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        shaderGBuffer.bind();
        shaderGBuffer.sendMat4("viewMatrix", cam.getViewMatrix());
        shaderGBuffer.sendMat4("projectionMatrix", cam.getProjectionMatrix());

        testScene.render(shaderGBuffer);


        shaderGBuffer.unbind();
        fboGBuffer.unbind();

        //DEFERRED SHADING TEIL============================

        fboDeferredShading.bind();

        glCullFace(GL_FRONT);
        glEnable(GL_CULL_FACE);
        glDisable(GL_DEPTH_TEST);
        glEnable(GL_BLEND);
        glBlendFunc(GL_ONE, GL_ONE);
        glClearColor(0, 0, 0, 0);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        shaderDsLightingShader.bind();

        shaderDsLightingShader.sendMat4("viewMatrix", cam.getViewMatrix());
        shaderDsLightingShader.sendMat4("projectionMatrix", cam.getProjectionMatrix());

        shaderDsLightingShader.sendSampler2D("positionMap", fboGBuffer.getColorTexture(0),0);
        shaderDsLightingShader.sendSampler2D("normalMap", fboGBuffer.getColorTexture(1),1);

        shaderDsLightingShader.sendInt("windowWidth", testWindow.getWidth());
        shaderDsLightingShader.sendInt("windowHeight", testWindow.getHeight());

        shaderDsLightingShader.sendVec3("lightColor", glm::fvec3(0.7f,0.7f,0.4f));

        lights.render(shaderDsLightingShader);

        glDisable(GL_CULL_FACE);
        glEnable(GL_DEPTH_TEST);
        glDisable(GL_BLEND);
        glClearColor(1.0, 1.0, 1.0, 0.0);
        shaderDsLightingShader.unbind();
        fboDeferredShading.unbind();

        //COMPOSITING TEIL ===============================
        fboCompositing.bind();
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        shaderDsCompositingShader.bind();

        shaderDsCompositingShader.sendSampler2D("colorMap", fboGBuffer.getColorTexture(2),0);
        shaderDsCompositingShader.sendSampler2D("lightMap", fboDeferredShading.getColorTexture(2),1);

        screenFillingQuad.renderGeometry();

        shaderDsCompositingShader.unbind();
        fboCompositing.unbind();

        //================================================

        //ScreenFillingQuad Render Pass
        shaderSFQ.bind();
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        if (glfwGetKey(testWindow.getWindow(), GLFW_KEY_F1))
            shaderSFQ.sendSampler2D("fboTexture", fboDeferredShading.getColorTexture(2));
        else
            shaderSFQ.sendSampler2D("fboTexture", fboCompositing.getColorTexture(2));

        screenFillingQuad.renderGeometry();
        shaderSFQ.unbind();


        glfwSwapBuffers(testWindow.getWindow());
        glfwPollEvents();
    }

    glfwDestroyWindow(testWindow.getWindow());
    glfwTerminate();

    return 0;
}
void Application::shutdown()
{
	glfwDestroyWindow(this->m_window);
	glfwTerminate();
}