Thanks,
The issue is solved. Now i have going through another one while using ofxUbo to develop a small app.
Please check the following snippet:
struct BlobSettings
{
ofVec4f InnerColor;
ofVec4f OuterColor;
float RadiusInner;
float RadiusOuter;
};
Then i declare a class as follows:
class ofApp : public ofBaseApp
{
public:
void setup();
void update();
void draw();
void keyPressed(int key);
void keyReleased(int key);
void mouseMoved(int x, int y );
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void windowResized(int w, int h);
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);
private:
ofxUboShader shader;
ofVbo vbo;
BlobSettings blob;
};
Now lets take a look inside the class definition.
void ofApp::setup()
{
//load the shaders
//load the programmable shaders
if(ofIsGLProgrammableRenderer())
{
shader.load("shaders/uniformblock");
}
else
{
std::cout << "Programmable Shading is not supported. " << std::endl;
exit();
}
//position data
float positionData[] =
{
-0.8f, -0.8f, 0.0f,1.0f,
0.8f, -0.8f, 0.0f,1.0f,
0.8f, 0.8f, 0.0f,1.0f,
-0.8f, -0.8f, 0.0f,1.0f,
0.8f, 0.8f, 0.0f,1.0f,
-0.8f, 0.8f, 0.0f,1.0f
};
float tcData[] =
{
0.0f, 0.0f,
1.0f, 0.0f,
1.0f, 1.0f,
0.0f, 0.0f,
1.0f, 1.0f,
0.0f, 1.0f
};
//set the vertex and texture data for the vertex buffer object
vbo.setVertexData(&positionData[0],6,24,GL_STATIC_DRAW);
vbo.setTexCoordData(&tcData[0],12,GL_STATIC_DRAW);
//pull out the current renderer
ofPtr<ofBaseRenderer> renderer = ofGetCurrentRenderer();
//set the blend mode with the current renderer
renderer->setBlendMode(OF_BLENDMODE_ALPHA);
//print the layouts for the uniform buffer
shader.printLayout("BlobSettings");
//setup the blob value
blob.InnerColor = ofVec4f(0.0f,0.0f,0.0f,0.0f);
blob.OuterColor = ofVec4f(1.0f,1.0f,0.75f,1.0f);
blob.RadiusInner = 0.25f;
blob.RadiusOuter = 0.45f;
}
At last the draw function:
void ofApp::draw()
{
shader.begin();
shader.setUniformBuffer("BlobSettings", blob);
//just draw the blob
vbo.draw(GL_TRIANGLES,0,6);
shader.end();
}
I am having blank screen - probably one of the most common problem anyone encounter when start with something based on OpenGL. Now let get inside the shader:
#version 430 core
in vec4 position;
in vec2 texcoord;
uniform mat4 modelViewProjectionMatrix;
out vec2 TexCoord;
void main()
{
TexCoord = texcoord;
gl_Position = modelViewProjectionMatrix * position;
}
And the fragment shader:
#version 430 core
in vec2 TexCoord;
out vec4 outputColor;
uniform BlobSettings
{
vec4 InnerColor;
vec4 OuterColor;
float RadiusInner;
float RadiusOuter;
};
void main()
{
float dx = TexCoord.x - 0.5;
float dy = TexCoord.y - 0.5;
float dist = sqrt(dx * dx + dy * dy);
outputColor =
mix( InnerColor, OuterColor,
smoothstep( RadiusInner, RadiusOuter, dist )
);
}
What am i missing folks? Some hint will help me to debug this type of issue.
Thanks