Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

Output different with and without (simple) shader

$
0
0

@Einh06 wrote:

Hello oF'ers!

There is something I am not understanding quite yet regarding the shader behavior in piece of code.

ofApp::draw()
    ofSetColor(255, 255);
    ofTranslate(ofGetWidth() / 2, ofGetHeight() / 2);
    ofScale(700, 700);

    //I know this is ugly, but I'm just hacking thing together right now
char *VertexShaderSource = "#version 330 core layout (location = 0) in vec3 position; void main(){ gl_Position = vec4(position, 1.0); }";
char *FragmentShaderSource = "#version 330 core out vec4 color; void main(){ color = vec4(1.0, 1.0, 1.0, 1.0);}";

ofShader ShaderProgram;
ShaderProgram.setupShaderFromSource(GL_VERTEX_SHADER, VertexShaderSource);
ShaderProgram.setupShaderFromSource(GL_FRAGMENT_SHADER, FragmentShaderSource);
ShaderProgram.linkProgram();
#define USE_SHADER 1 //just a switch for helping me

#if USE_SHADER
    ShaderProgram.begin();
#endif
    ofVbo vbo;
    vbo.setVertexData((float*)VerticesBuffer, 3, VerticesCount, GL_STATIC_DRAW, 0);
    vbo.setIndexData(IndexesBuffer, IndexesCount, GL_STATIC_DRAW);
    vbo.drawElements(GL_TRIANGLES, IndexesCount);
#if USE_SHADER
    ShaderProgram.end();
#endif
}

Both the Vertex and the Fragment shader are fairly simple, no transformation going on regarding position and the color is set to white.
I get the vertices and indexes from model, and is rendered correctly.

My current understanding of how things work, I would expect the same output whether or not I am using the shader.

(Since I'm new I can post only one image, so I will explained with the best of my abilities how this output looks like)
The output WHITOUT the shader is a simple teapot (classic) upside down but with the proportion correctly respected.

And here is the output WITH the shader enabled:

As you might see, the teapot is NOT upside down, and a little flattened (as if I scaled it on Y axis).

My current hypothesis is that somehow there are some transformation happening that I am not aware of, which confuses me.

Thank you for you time!

Posts: 5

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 4929