Unwanted FBO distortion

I’m drawing a textured sphere into a FBO. I’m also rotating the scene camera around via the update() method in the main testApp class. I’ve stitched together 6 frames from the animation which shows distortion in the texture. It seems to me that the pixels from each frame are just piled on top of the last frame, as opposed to them being updated and rotating normally.

I realize the texture is a bit abstract to begin with, but hopefully you can get the picture. Here’s my code:

glowSphere.h

#ifndef _GLOWSPHERE
#define _GLOWSPHERE

#include "ofMain.h"

class glowSphere
{

public:

ofSpherePrimitive sphere;
ofShader sphereShader;
ofImage img;

glowSphere();
void update();
void draw();

private:
};

#endif

glowSphere.cpp

#include "glowSphere.h"

glowSphere::glowSphere()
{
sphereShader.load("shaders/sphereshader");

sphere.set(200, 15);
img.loadImage("glass.jpg");

sphere.mapTexCoordsFromTexture(img.getTextureReference());
}

void glowSphere::update()
{

}

void glowSphere::draw()
{
sphereShader.begin();
sphereShader.setUniformTexture("img", img.getTextureReference(), 0);

sphere.draw();

sphereShader.end();
}

testApp.h

#pragma once

#include "ofMain.h"
#include "glowSphere.h"

class testApp : public ofBaseApp{

public:

ofCamera camera;
ofLight ambLight;

float camAngle;
float camX;
float camY;
float camZ;

ofFbo blurPass01;
ofShader Xpass;

glowSphere *sphere01;

void setup();
void update();
void draw();
void exit();
};

testApp.cpp

#include "testApp.h"

//--------------------------------------------------------------
void testApp::setup()
{
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);

ofBackground(33, 33, 33);
ofSetFrameRate(30);

camera.setNearClip(0.1);
camera.setFarClip(900);
camAngle = 0;
camX = 500;
camY = 0;
camZ = 500;

ambLight.setAmbientColor(ofColor(200.0, 200.0, 200.0, 20.0));

Xpass.load("shaders/Xpass");

blurPass01.allocate(1024, 768);

blurPass01.begin();
ofClear(0, 0, 0, 0);
blurPass01.end();

sphere01 = new glowSphere();
}

//--------------------------------------------------------------
void testApp::update()
{
camAngle += 0.01f;

if (camAngle >= 360)
{
    camAngle = 0;
}

camX = 800 * sin(camAngle);
camZ = 800 * cos(camAngle);

camera.lookAt(ofVec3f(0, 0, 0));
camera.setPosition(ofVec3f(camX, camY, camZ));
}

//--------------------------------------------------------------
void testApp::draw()
{
blurPass01.begin();
ambLight.enable();
camera.begin();
sphere01->draw();
camera.end();
ambLight.disable();
blurPass01.end();

blurPass01.draw(0, 0);
}

//--------------------------------------------------------------
void testApp::exit()
{
delete sphere01;
}

Xpass.vert

// vertex shader

#version 150

uniform mat4 modelViewProjectionMatrix;
in vec4 position;
in vec2 texcoord;

out vec2 texCoordVar;

void main()
{
texCoordVar = texcoord;
gl_Position = modelViewProjectionMatrix * position;
}

Xpass.frag

// fragment shader

#version 150

in vec2 texCoordVar;

out vec4 outputColor;
uniform sampler2DRect img;

void main()
{
vec4 color;
float blurAmnt = 5.0;

color += 1.0 * texture(img, texCoordVar + vec2(blurAmnt * -4.0, 0.0));
color += 2.0 * texture(img, texCoordVar + vec2(blurAmnt * -3.0, 0.0));
color += 3.0 * texture(img, texCoordVar + vec2(blurAmnt * -2.0, 0.0));
color += 4.0 * texture(img, texCoordVar + vec2(blurAmnt * -1.0, 0.0));

color += 5.0 * texture(img, texCoordVar + vec2(blurAmnt, 0));

color += 4.0 * texture(img, texCoordVar + vec2(blurAmnt * 1.0, 0.0));
color += 3.0 * texture(img, texCoordVar + vec2(blurAmnt * 2.0, 0.0));
color += 2.0 * texture(img, texCoordVar + vec2(blurAmnt * 3.0, 0.0));
color += 1.0 * texture(img, texCoordVar + vec2(blurAmnt * 4.0, 0.0));

color /= 25.0;

outputColor = color;
}

I tried putting the camera rotation code in the draw() method, but that didn’t work. Looked through some of the examples here, but didn’t see anything that involved a moving camera. Thanks!

Ughhhhh, of course 10 seconds after I spend 20 minutes putting a post together, I think of the answer. Hopefully this can help someone else some day. I simply added the following after I draw the FBO:

blurPass01.begin();
ofClear(0, 0, 0, 0);
blurPass01.end();

So, the draw method looks like this:

blurPass01.begin();
ambLight.enable();
camera.begin();
sphere01->draw();
camera.end();
ambLight.disable();
blurPass01.end();

blurPass01.draw(0, 0);

blurPass01.begin();
ofClear(0, 0, 0, 0);
blurPass01.end();