Quantcast
Channel: openFrameworks - Latest posts
Viewing all articles
Browse latest Browse all 40524

Problem with OpenGL ES or Shaders working on Raspberry Pi

$
0
0

Hello,
Thanks for all the info. I just got started trying to run shaders on my Pi2 as well. I've had varied results running examples with shaders. The ofxOMXPlayer shader example works perfectly. I'm having trouble running my own program though. With the code below I am still getting an error that my shader couldn't be loaded and therefore could not begin().

Here is my shader.frag file

#ifdef GL_ES
precision mediump float;
#endif
    
    uniform float u_time;
    uniform vec2 u_mouse;
    uniform vec2 u_resolution;
    

vec4 r(float time, float c)
{
    vec2 pos = ((gl_FragCoord.xy - u_resolution.xy * 0.5) / u_resolution.y) * 2$
    vec2 p = vec2(cos(time * 1.0) * cos(time * 1.52), sin(time * 1.1) + sin(tim$


    return vec4(pow(0.75, 15.0 * distance(pos,p))) * sin(c);

}

void main()
{
   vec4 color = vec4(0.9, 0.9, 1.10, 1.0);

    for ( float c = 0.0; c < 75.0; c += 0.50) {

        color *= (1.0 + r(u_time * 0.15 + c, c)) / 1.0;
    }

    gl_FragColor = color;
}

Here is my ofApp.cpp file

#include "ofApp.h"

//--------------------------------------------------------------
void ofApp::setup(){
    
    //  Load and compile the shader
    //
    shader.load("","shader.frag");
    ofSetCircleResolution(60);
    ofBackground(ofColor::whiteSmoke);
    

}

//--------------------------------------------------------------
void ofApp::update(){
    
}

//--------------------------------------------------------------
void ofApp::draw(){
    
    // Replace the pipeline with our shader
    shader.begin();
    
    // Send uniforms
    shader.setUniform1f("u_time", ofGetElapsedTimef());
    shader.setUniform2f("u_mouse", mouseX, mouseY);
    shader.setUniform2f("u_resolution", ofGetWidth(), ofGetHeight());
    for ( int i = 0; i < 4; i++ ) {
        for ( int j = 0; j < 4; j ++) {
        
    ofCircle(ofGetWidth() * .20 + i * 200, ofGetHeight() * .10 + j * 200 , 75);
    
        }
    }
    shader.end();
    
    //cout << "This is MouseX: " << mouseX << endl;
    //cout << "This is MouseY: " << mouseY << endl;
    
    ofSetColor(0);
    ofDrawBitmapString(ofToString(ofGetFrameRate()), 50, 50);

}

//--------------------------------------------------------------
void ofApp::keyPressed(int key){
    
    //  Reload everytime you press a key
    //
    shader.load("","shader.frag");
}

Here is my ofApp.h file

#pragma once

#include "ofMain.h"

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);
    
    ofShader shader;

};

This is my main.cpp

#include "ofMain.h"
#include "ofApp.h"
#ifdef TARGET_OPENGLES
#include "ofGLProgrammableRenderer.h"
#endif
//========================================================================
int main( ){

	ofSetLogLevel(OF_LOG_VERBOSE);
	#ifdef TARGET_OPENGLES
	ofSetCurrentRenderer(ofPtr<ofBaseRenderer>(new ofGLProgrammableRenderer()));
	#endif
	ofSetupOpenGL(1280,720, OF_WINDOW);			// <-------- setup the GL context

	// this kicks off the running of my app
	// can be OF_WINDOW or OF_FULLSCREEN
	// pass in width and height too:
	ofRunApp( new ofApp());

}

Viewing all articles
Browse latest Browse all 40524

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>