Esempio n. 1
0
void View::initializeGL()
{
    cout << "Using OpenGL Version " << glGetString(GL_VERSION) << endl << endl;

    glEnable(GL_TEXTURE_2D);
    createShaderPrograms();

    // All OpenGL initialization *MUST* be done during or after this
    // method. Before this method is called, there is no active OpenGL
    // context and all OpenGL calls have no effect.

    // Start a timer that will try to get 60 frames per second (the actual
    // frame rate depends on the operating system and other running programs)
    //time.start();
    //timer.start(1000 / 60);

    // Start the drawing timer
    m_timer.start(1000.0f / MAX_FPS);

    // Center the mouse, which is explained more in mouseMoveEvent() below.
    // This needs to be done here because the mouse may be initially outside
    // the fullscreen window and will not automatically receive mouse move
    // events. This occurs if there are two monitors and the mouse is on the
    // secondary monitor.
    QCursor::setPos(mapToGlobal(QPoint(width() / 2, height() / 2)));

    glClearColor(0.0f,0.0f,0.0f,0.0f);
    glEnable(GL_COLOR_MATERIAL);
    glShadeModel(GL_SMOOTH);

    // Enable depth testing, so that objects are occluded based on depth instead of drawing order
    glEnable(GL_DEPTH_TEST);
    // Setup blending
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);

    // Setup the cube map
    setupCubeMap();

    // Enable alpha
    glEnable(GL_ALPHA_TEST);

    setupScene();

    // Load the snow texture
    m_snowflakeTextures.push_back( ResourceLoader::loadTexture( ":/textures/textures/snowflake_design.png" ) );
    m_snowflakeTextures.push_back( ResourceLoader::loadTexture( ":/textures/textures/second-snowflake.png" ) );
    m_snowflakeTextures.push_back( ResourceLoader::loadTexture( ":/textures/textures/snowball-texture.png" ) );
    m_snowflakeTextures.push_back( ResourceLoader::loadTexture( ":/textures/textures/snowflake-icon.png" ) );
    m_snowflakeTextures.push_back( ResourceLoader::loadTexture( ":/textures/textures/actual-snowflake.png" ) );
    m_snowEmitter.setTextures(&m_snowflakeTextures);

    m_snowTextureId = ResourceLoader::loadTexture( ":/textures/textures/plain-surface.jpg" );

    updateCamera();

    setupLights();
    glFrontFace(GL_CCW);
    paintGL();
}
Esempio n. 2
0
// the following function was adapted from Keith Lantz
// http://www.keithlantz.net/2011/10/rendering-a-skybox-using-a-cube-map-with-opengl-and-glsl/
void setupCubeMap(GLuint& texture, SDL_Surface *xpos, SDL_Surface *xneg, SDL_Surface *ypos, SDL_Surface *yneg, SDL_Surface *zpos, SDL_Surface *zneg) {
	setupCubeMap(texture);
	glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, xpos->w, xpos->h, 0, xpos->format->BytesPerPixel == 4 ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE, xpos->pixels);
	glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, xneg->w, xneg->h, 0, xneg->format->BytesPerPixel == 4 ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE, xneg->pixels);
	glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, ypos->w, ypos->h, 0, ypos->format->BytesPerPixel == 4 ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE, ypos->pixels);
	glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, yneg->w, yneg->h, 0, yneg->format->BytesPerPixel == 4 ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE, yneg->pixels);
	glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, zpos->w, zpos->h, 0, zpos->format->BytesPerPixel == 4 ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE, zpos->pixels);
	glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, zneg->w, zneg->h, 0, zneg->format->BytesPerPixel == 4 ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE, zneg->pixels);
}
Esempio n. 3
0
void SetupCubeMap()
{
	// set up the cube map texture
	SDL_Surface *xpos = IMG_Load("media/xpos.png");
	SDL_Surface *xneg = IMG_Load("media/xneg.png");
	SDL_Surface *ypos = IMG_Load("media/ypos.png");
	SDL_Surface *yneg = IMG_Load("media/yneg.png");
	SDL_Surface *zpos = IMG_Load("media/zpos.png");
	SDL_Surface *zneg = IMG_Load("media/zneg.png");
	setupCubeMap(cubemap_texture, xpos, xneg, ypos, yneg, zpos, zneg);
	SDL_FreeSurface(xneg);	SDL_FreeSurface(xpos);
	SDL_FreeSurface(yneg);	SDL_FreeSurface(ypos);
	SDL_FreeSurface(zneg);	SDL_FreeSurface(zpos);
}
Esempio n. 4
0
//--------------------------------------------------------------
void ofApp::setup(){
    w = 960;
    h = 540;
    cubeMapTileSize = 540;
    
    ofSetWindowShape(w,h);
    ofSetFrameRate(30);
    ofDisableArbTex();
    
    //fogShader.load("FogShaderTex.vert", "FogShaderTex.frag");
    embossShader.load("base.vert", "emboss.frag");
    blurHShader.load("blurH.vert", "blur.frag");
    blurVShader.load("blurV.vert", "blur.frag");
    displaceShader.load("displace.vert", "FogShaderTex.frag");
    bumpShader.load("base.vert", "bump.frag");
    rgbShader.load("base.vert", "rgb.frag");
    glowShader.load("base.vert", "glow.frag");
    blurHShader2.load("base.vert", "blurH.frag");
    blurVShader2.load("base.vert", "blurV.frag");
    compositeShader.load("base.vert", "composite.frag");
    fxaaShader.load("base.vert", "fxaa.frag");
    finalShader.load("base.vert", "final.frag");
    
    fbPix.allocate(w, h, OF_PIXELS_RGB);
    fbTex.allocate(w, h, GL_RGB);
    
    fbPix2.allocate(w, h, OF_PIXELS_RGB);
    fbTex2.allocate(w, h, GL_RGB);
    
    ofFbo::Settings s;
    
    s.width = w;
    s.height = h;
    s.textureTarget = GL_TEXTURE_2D;
    s.useDepth = true;
    s.depthStencilInternalFormat = GL_DEPTH_COMPONENT24;
    s.depthStencilAsTexture = true;
    s.numSamples = 1;
    
    //calm.loadMovie("calm.mov");
    //angry.loadMovie("angry.mov");
    //calm.setLoopState(OF_LOOP_NORMAL);
    //angry.setLoopState(OF_LOOP_NORMAL);
    //calm.play();
    //angry.play();
    
    int numSamples = 1;
    
    embossFbo.allocate(w, h, GL_RGB, numSamples);
    embossFbo2.allocate(w, h, GL_RGB, numSamples);
    blurHFbo.allocate(w, h, GL_RGB, numSamples);
    blurVFbo.allocate(w, h, GL_RGB, numSamples);
    embossBlurHFbo.allocate(w, h, GL_RGB, numSamples);
    embossBlurVFbo.allocate(w, h, GL_RGB, numSamples);
    embossBlurHFbo2.allocate(w, h, GL_RGB, numSamples);
    embossBlurVFbo2.allocate(w, h, GL_RGB, numSamples);
    bumpFbo.allocate(w, h, GL_RGB, numSamples);
    sceneFbo.allocate(w, h, GL_RGB, numSamples);
    compositeFbo.allocate(w, h, GL_RGB, numSamples);
    glowFbo.allocate(w, h, GL_RGB, numSamples);
    blurHFbo2.allocate(w, h, GL_RGB, numSamples);
    blurVFbo2.allocate(w, h, GL_RGB, numSamples);
    fxaaFbo.allocate(w, h, GL_RGB, numSamples);
    
    pp.allocate(w, h, GL_RGB);
    
    
    save = false;
    
    ofColor *colors = new ofColor[w*h];
    
    for(int i = 0; i<w*h*3; i++){
        //colors[i] = ofRandom(255);
        int r = ofRandom(255);
        int r2 = ofRandom(255);
        fbPix[i] = r;
        fbPix2[i] = r2;
    }
    
    img.setFromPixels(fbPix);
    img2.setFromPixels(fbPix2);

    
    embossFbo.begin();
    ofClear(0);
    ofBackground(255);
    ofSetColor(255);
    //ofRect(100, 0, w-200, 500 );
    img.draw(0,0, w, h);
    embossFbo.end();
    
    embossFbo2.begin();
    ofClear(0);
    ofBackground(255);
    ofSetColor(255);
    //ofRect(100, 0, w-200, 500 );
    img2.draw(0,0, w, h);
    embossFbo2.end();
    
    cam.setFarClip(1000000000);
    
    
    
    embossFbo.readToPixels(fbPix);
    fbTex.loadData(fbPix);
    
    embossFbo2.readToPixels(fbPix2);
    fbTex2.loadData(fbPix2);
    
    //cube.set(100,100,10000, 1,1,1);
    //cube.mapTexCoords(0, 0, w, h);
    

    
    cylinder.set(500, 40000, 500, 500);
    cylinder.setCapped(false);
    cylinder.mapTexCoords(0, 0, 1, 1);
    
    sphere.set(100000, 100);
    sphere.mapTexCoords(0, 0, 1, 1);

    //fogShader.begin();
    //fogShader.setUniform1f("density", 0.5f);
    //fogShader.setUniform4f("fogColor", 1.0, 0.0, 0.0, 1.0);
    //fogShader.end();
    
    cam.setFov(90);
    
    noiseTex.load("noise.jpg");
    noiseTex.getTexture().setTextureWrap(GL_MIRRORED_REPEAT, GL_MIRRORED_REPEAT);
    sceneFbo.getTexture().setTextureWrap(GL_MIRRORED_REPEAT, GL_MIRRORED_REPEAT);
    blurHFbo.getTexture().setTextureWrap(GL_MIRRORED_REPEAT, GL_MIRRORED_REPEAT);
    blurVFbo.getTexture().setTextureWrap(GL_MIRRORED_REPEAT, GL_MIRRORED_REPEAT);
    embossFbo.getTexture().setTextureWrap(GL_MIRRORED_REPEAT, GL_MIRRORED_REPEAT);
    sceneFbo.getTexture().setTextureWrap(GL_MIRRORED_REPEAT, GL_MIRRORED_REPEAT);
    bumpFbo.getTexture().setTextureWrap(GL_MIRRORED_REPEAT, GL_MIRRORED_REPEAT);
    fbTex.setTextureWrap(GL_MIRRORED_REPEAT, GL_MIRRORED_REPEAT);
    
    //ofSetTextureWrap(GL_MIRRORED_REPEAT, GL_MIRRORED_REPEAT);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
    
    
    displaceShader.begin();
       // displaceShader.setUniformTexture("noise", noiseTex.getTexture(), 2);
    displaceShader.end();
    
    //m = plane.getMesh();
    
    recorder.setVideoBitrate("50000k");
    recorder.setVideoCodec("mpeg4");
    
    planeScale = 450;
    
    plane.set((w)*planeScale, w*2*planeScale, 1000, 1000);
    plane.mapTexCoords(0, 0, 1,1);
    
    //////////////////////
    renderCubeMap = false;
    //////////////////////
    
    if(renderCubeMap){
        setupCubeMap();
        savePix.allocate(cubeMapTileSize*4, cubeMapTileSize*3, OF_PIXELS_RGB);
        saveFbo.allocate(cubeMapTileSize*4, cubeMapTileSize*3, GL_RGB, numSamples);
        bumpFbo.allocate(cubeMapTileSize, cubeMapTileSize, GL_RGB, numSamples);
        compositeFbo.allocate(cubeMapTileSize, cubeMapTileSize, GL_RGB, numSamples);
        glowFbo.allocate(cubeMapTileSize, cubeMapTileSize, GL_RGB, numSamples);
        blurHFbo2.allocate(cubeMapTileSize, cubeMapTileSize, GL_RGB, numSamples);
        blurVFbo2.allocate(cubeMapTileSize, cubeMapTileSize, GL_RGB, numSamples);
        blurHFbo.allocate(cubeMapTileSize, cubeMapTileSize, GL_RGB, numSamples);
        blurVFbo.allocate(cubeMapTileSize, cubeMapTileSize, GL_RGB, numSamples);
        fxaaFbo.allocate(cubeMapTileSize, cubeMapTileSize, GL_RGB, numSamples);
    } else{
        savePix.allocate(w,h, OF_PIXELS_RGB);
        saveFbo.allocate(w,h, GL_RGB);
    }
    
    saveFbo.begin();
        ofClear(0);
    saveFbo.end();
    
    embossBlurHFbo.begin();
        ofClear(0);
    embossBlurHFbo.end();
    
    embossBlurVFbo.begin();
        ofClear(0);
    embossBlurVFbo.end();
    
    saveFbo.begin();
        ofClear(0);
    saveFbo.end();
    
    texDirection = 1.0;
    
    
    
    hello = 6452;
    goodBye = 7126;
    
    inc = hello;
    
    beginFrame = 6602;
    frameCounter = hello;

    endFrame = 6976;
    
    angryMix = 0;
    isAngry = 0.0;
    
    boom = 6703;
    endBoom = boom+30;
    
    wait = 0;
    
    gui = new ofxDatGui(ofxDatGuiAnchor::TOP_LEFT);
    ofRectangle bounds = ofRectangle(0, 0, ofGetWidth(), ofGetHeight());

    pad = gui->add2dPad("pad");
    colorslider = gui->addSlider("color", 0.0, 1.0);
    colorslider->setPrecision(4);
    
    fogSlider = gui->addSlider("fog", 0.0, 1.0);
    fogSlider->setPrecision(4);
    
    angryButton = gui->addSlider("angry", 0.0,1.0);
    angryButton->setPrecision(4);
    
//    fadeToBlackSlider = gui->addSlider("fade to black", 0.0,1.0);
//    fadeToBlackSlider->setPrecision(4);
//    
//    fadeInColorSlider = gui->addSlider("fade in color", 0.0,1.0);
//    fadeInColorSlider->setPrecision(4);
    
    colorMixSlider = gui->addSlider("colorMix", 0.0,1.0);
    colorMixSlider->setPrecision(4);
    
    increaseDispSlider = gui->addSlider("inc disp", 0.01, 20);
    increaseDispSlider->setPrecision(4);
    
    
    //  pad->setBounds(bounds);
    showGui = true;
    cam.disableMouseInput();
    
    ofxDatGuiLog::quiet();
}