openframeworks / openframeworks/openFrameworks
gl_FragCoord is upside down inside FBO
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 10.4k
- Forks
- 2.6k
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 9
Description
FBOs are rendered upside down compared to not using an FBO, which means anything based gl_FragCoord (which is not affected by any model or view matrix transformations) gets rendered upside down.
so if you do this:
#version 120
uniform float height;
void main() {
float y = gl_FragCoord.y / height;
gl_FragColor = vec4(vec3(y), 1.);
}
#include "ofMain.h"
class ofApp : public ofBaseApp {
public:
ofShader shader;
void setup() {
shader.setup("", "shader.fs");
}
void draw() {
shader.begin();
shader.setUniform1f("height", ofGetHeight());
ofDrawRectangle(0, 0, ofGetWidth(), ofGetHeight());
shader.end();
}
};
int main() {
ofSetupOpenGL(1280, 720, OF_WINDOW);
ofRunApp(new ofApp());
}
you get black at top and white at bottom.
and then you stick everything inside an FBO:
...
void draw() {
ofFbo fbo;
fbo.allocate(ofGetWidth(), ofGetHeight());
fbo.begin();
shader.begin();
shader.setUniform1f("height", ofGetHeight());
ofDrawRectangle(0, 0, ofGetWidth(), ofGetHeight());
shader.end();
fbo.end();
fbo.draw(0, 0);
}
};
...
you get white at top and black at bottom.
not sure if there's anything we can do about this, but i wanted to at least have an issue for it in case someone else runs into it.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the shader.fs example and the ofApp::draw path, focusing on the ofShader and ofFbo calls shown in the report. Reproduce the comparison between direct drawing and FBO drawing, then trace the relevant FBO and coordinate-handling entry points; done means gl_FragCoord-based output has consistent orientation in both cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100