Quantcast
Channel: bugs, errors - openFrameworks
Viewing all articles
Browse latest Browse all 636

Textures upside down

$
0
0

Hi,

Running into a weeeeird issue: when I pass a texture into a shader, it gets flipped upside down.

Example code:

// ofApp.h
#pragma once

#include "ofMain.h"

class ofApp : public ofBaseApp{
	public:
		void setup();
		void update();
		void draw();
        
    private:
        ofImage m_testImage;
        ofShader m_shader;
};


// ofApp.cpp
ofApp::setup(){
    m_testImage.load("/home/kf/droid/camera/Camera/IMG_20221113_114350.jpg");
    m_testImage.resize(w, h);
    m_shader.load("shader/testImage");
}

ofApp::draw(){
    m_shader.begin();
    m_shader.setUniformTexture("tex0", m_testImage.getTexture(), 1);
    m_testImage.draw(0, 0);
    m_shader.end();
}

Shader files:

// testImage.vert
#version 330

uniform mat4 modelViewProjectionMatrix;

in vec4 position;
in vec2 texcoord;

out vec2 texCoordVarying;

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

// testImage.frag
#version 330

out vec4 outputColor;
uniform sampler2DRect tex0;

void main(){

    outputColor = texture( tex0, gl_FragCoord.xy);

}

and finally, the main.cpp file:

#include "ofMain.h"
#include "ofApp.h"

//========================================================================
int main( ){

	//Use ofGLFWWindowSettings for more options like multi-monitor fullscreen
	ofGLWindowSettings settings;
	settings.setSize(1024, 768);
    settings.setGLVersion(3, 2);
	settings.windowMode = OF_FULLSCREEN; //can also be OF_FULLSCREEN

	auto window = ofCreateWindow(settings);

	ofRunApp(window, make_shared<ofApp>());
	ofRunMainLoop();

}

I don’t see any reason why this should cause a vertically flipped image…?

System: Arch Linux, of: of_v20221009_linux64gcc6_release

10 posts - 5 participants

Read full topic


Viewing all articles
Browse latest Browse all 636

Trending Articles