Exemple #1
0
void Day41App::setup()
{
    mCam.lookAt(vec3(0,0,5), vec3(0., 1.5, 0.));
    mCam.setPerspective(45.f, getWindowAspectRatio(), 1.f, 1000.f);

    auto img = loadImage(loadAsset("box.png"));
    auto img1 = loadImage(loadAsset("box_spec.png"));
    mDiffuseMap = gl::Texture2d::create(img);
    mSpecularMap = gl::Texture2d::create(img1);
    mDiffuseMap->bind(0);
    mSpecularMap->bind(1);


    lightPos = vec3(0.f);

    theta = 0.0;

    setupGlsl();

    mCamUi = CameraUi(&mCam, getWindow());

    auto cube = geom::Cube();

    mBatch = gl::Batch::create(cube, mGlsl);

    auto sphere = geom::Sphere();
    auto scale = geom::Scale(0.1f,0.1f,0.1f);
    auto shader = gl::ShaderDef().color();
    auto rotate = geom::Rotate(angleAxis(2.1f, vec3(1.0,0.,0.f)));
    mLight = gl::Batch::create(sphere >> scale >> rotate, gl::getStockShader(shader));

    gl::enableDepthRead();
    gl::enableDepthWrite();
}
Exemple #2
0
void Day62App::loadImage()
{
    auto pic = cinder::loadImage(loadAsset("window.png"));
    gl::Texture2d::Format fmt;
    
    //SET THE INTERNAL FORMAT TO RGBA SO THAT WE CAN TEST THE ALPHA VALUE IN THE FRAG SHADER
    fmt.internalFormat(GL_RGBA);
    fmt.wrap(GL_CLAMP_TO_EDGE);
    //    fmt.wrapS(GL_REPEAT);
    //    fmt.wrapT(GL_REPEAT);
    //    fmt.setMinFilter(GL_LINEAR_MIPMAP_LINEAR);
    //    fmt.setMagFilter(GL_LINEAR);
    
    mTex = gl::Texture2d::create(pic, fmt);
    
    mTex->bind();
}
Exemple #3
0
void Day8App::setup()
{
    mCam.lookAt(vec3(3,2,3), vec3(0));
    
    auto img = loadImage(loadAsset("texture.jpg"));
    
    setFrameRate(60);
    
    mTex = gl::Texture2d::create(img);
    mTex->bind(0);
    
    /*  THIS SHADER PROGRAM IS FOR MULTIPLYING THE TEXTURE BY THE COLOUR
     
    mGlsl = gl::GlslProg::create( gl::GlslProg::Format().
                                 vertex(    CI_GLSL(150,
                                                    uniform mat4    ciModelViewProjection;
                                                    in vec4         ciPosition;
                                                    in vec2         ciTexCoord0; //THIS COMES FROM CINDER AUTOMATICALLY FROM geom::Attrib::TEX_COORD_0
                                                    out vec2        TexCoord0; //SEND IT TO THE FRAG SHADER
                                                    
                                                    void main(void)
                                                    {
                                                        gl_Position = ciModelViewProjection * ciPosition;
                                                        TexCoord0 = ciTexCoord0;
                                                    })).
                                 
                                 fragment(  CI_GLSL(150,
                                                    uniform vec4        uColor;
                                                    uniform sampler2D   uTex0;
                                                    
                                                    in vec2             TexCoord0;
                                                    out vec4            oColor;
                                                    
                                                    void main(void)
                                                    {
                                                        oColor = texture(uTex0, TexCoord0) * uColor;
                                                    })
                                          ));
    
    
    */
    
    mGlsl = gl::GlslProg::create( gl::GlslProg::Format().
                                 vertex( CI_GLSL(150,
                                                 
                                                 uniform mat4   ciModelViewProjection;
                                                 uniform vec2   uRes;
                                                 in vec4        ciPosition;
                                                 in vec2        ciTexCoord0;
                                                 out vec2       TexCoord0;
                                                 uniform float  uAngle; //VARIABLE FROM THE CPU FOR MODULATING THE SINE WAVE
                                                 
                                                 /*
                                                 float offset(vec2 uv)
                                                 {
                                                     //return (sin(uv.x * 15.0) +
                                                     //        cos(uv.y * 7.0f +uv.x * 13.0f )) * 0.1f;
                                                     vec4 pos = ciPosition;
                                                     float z = sin(uAng
                                                     return cos(sqrt( uv.x * uv.x + uv.y * uv.y));
                                                     
                                                   
                                                 }
                                                 */
                                                 
                                                 void main(void)
                                                 {
                                                     vec4 pos       = ciPosition;
                                                     pos.y          = sin(uAngle * sqrt(pow(pos.x,2) + pow(pos.z,2))) / 5.;
                                                     gl_Position    = ciModelViewProjection * pos;
                                                     TexCoord0      = ciTexCoord0;
                                                 }