diff options
| author | Comment <tim@gray.(none)> | 2013-01-16 14:41:27 +0000 |
|---|---|---|
| committer | Comment <tim@gray.(none)> | 2013-01-16 14:41:27 +0000 |
| commit | e775f024476943beacc433c39b6b1003f7ba0d86 (patch) | |
| tree | 5a26b90a0a11574e3cbd3aa7cead9b55a6289bc6 /liveengineUnmapped/src/layers.cpp | |
| parent | 2b3eaa8dd74c373e7c82a414014c469fe415b66e (diff) | |
frame engine with alpha channel and blending
Diffstat (limited to 'liveengineUnmapped/src/layers.cpp')
| -rwxr-xr-x | liveengineUnmapped/src/layers.cpp | 151 |
1 files changed, 131 insertions, 20 deletions
diff --git a/liveengineUnmapped/src/layers.cpp b/liveengineUnmapped/src/layers.cpp index 4ac0c59..36f9b14 100755 --- a/liveengineUnmapped/src/layers.cpp +++ b/liveengineUnmapped/src/layers.cpp @@ -63,7 +63,7 @@ void svglayer::draw(float a,unsigned char* controllers,int cx,int cy,bool transp getCentre(cx,cy);
//draw layers grouped by controllers
float layerspercontroller=((float)svg.getNumPath())/6.0f;
-
+
for (int i=0;i<6;i++) {
for (int j=(int)(i*layerspercontroller);j<(int)((i+1)*layerspercontroller);j++) {
svg.getPathAt(j).setFillColor(fills[i]*a*controllers[i]);
@@ -78,38 +78,149 @@ void svglayer::draw(float a,unsigned char* controllers,int cx,int cy,bool transp svglayer::~svglayer()
{
//dtor
-}
-
+} + +//------------------------------------------------------------------------ imglayer::imglayer() { - //img.setUseTexture(false); + //sprite.setUseTexture(false); }
-imglayer::imglayer(string _f)
-{
- load(_f);
+imglayer::imglayer(string _filename,int _frames,int _start,float _rate,int n, int e){
+ load(_filename,_frames,_start,_rate,n,e);
}
-void imglayer::load(string _f){
- bool success=img.loadImage(_f);
- printf("%s\n",success?"loaded":"not loaded");
+void imglayer::load(string _filename,int _frames,int _start,float _rate,int n, int e){ + startNote=n; + endNote=e;
+ sprite.load(_filename,_frames,_start);
+ sprite.setFrameRate(_rate);
}
-/* -WTF is going on with the image drawing - - -*/
+
void imglayer::draw(float a,int cx,int cy,float colShift) { - //if (img.isAllocated()) if (!img.isUsingTexture()) img.setUseTexture(true); //has to be done from the main thread? still doesn't work
- img.draw(0,0,ofGetWidth(),ofGetHeight()); - printf("drawing %f\n",ofGetElapsedTimef());
+ //if (sprite.isAllocated()) if (!sprite.isUsingTexture()) sprite.setUseTexture(true); //has to be done from the main thread? still doesn't work
+ sprite.update();
+ int x,y,w,h;
+ if ((((float)cx)/cy)<(((float)sprite.getWidth())/sprite.getHeight())){
+ x=0;
+ w=cx;
+ h=((float)cx)*(((float)sprite.getHeight())/sprite.getWidth());
+ y=(cy-h)/2;
+ }
+ else {
+ y=0;
+ h=cy;
+ w=((float)cy)*(((float)sprite.getWidth())/sprite.getHeight());
+ x=(cx-w)/2;
+ }
+ ofEnableAlphaBlending(); + sprite.draw(x,y,w,h);
+ ofDisableAlphaBlending();
} void imglayer::draw(float a,unsigned char* controllers,int cx,int cy,bool transparentBlack=false,float colShift=0.0f) { imglayer::draw(a,cx,cy,colShift);
-} +}
+
+void imglayer::setNote(int note)
+{ + //is called rerpeatedly no startNote,endNote + //printf("note %i (%i - %i)\n",note,startNote,endNote);
+ if ((startNote<=note)&&(endNote>=note)) {
+ if (!sprite.getIsPlaying()) {
+
+ sprite.play();
+
+ } + //printf("triggered frame %i of %i\n",(int)(((((float)note-startNote)/((float)endNote-startNote)))*sprite.getTotalFrames()),sprite.getTotalFrames());
+ sprite.setCurrentFrame((int)(((((float)note-startNote)/((float)endNote-startNote)))*sprite.getTotalFrames()));
+ //printf("movie %i (%i - %i) frame: %i\n",note,startNote,endNote,(int)(((((float)note-startNote)/((float)endNote-startNote)))*mov.getTotalNumFrames()));
+ }
+ else {
+ if (sprite.getIsPlaying()) {
+ sprite.stop();
+ }
+ }
+
+}; imglayer::~imglayer()
{
- //img.setUseTexture(false); //free texture
+ //sprite.setUseTexture(false); //free texture
+} +//------------------------------------------------------------------------ +videolayer::videolayer() { + //sprite.setUseTexture(false); +}
+videolayer::videolayer(string _f,int n,int e,float s)
+{ + startNote=n; + endNote=e;
+ speed=s;
+ load(_f);
+}
+
+void videolayer::load(string _f){
+ name=_f;
+ mov.setPixelFormat(OF_PIXELS_BGRA);
+ mov.setUseTexture(false);
+ bool success=mov.loadMovie(_f);
+ if (success) {
+ mov.stop();
+ }
+ printf("%s %s %i bpp\n",success?"loaded":"not loaded",_f.c_str(),success?mov.getPixelsRef().getBytesPerPixel():0);
+}
+
+void videolayer::draw(float a,int cx,int cy,float colShift) { + if (mov.isPlaying()) { + mov.update();
+ //unsigned char *pix=mov.getPixels();
+ //for (int i=0;i<mov.getWidth()*mov.getHeight()*4;i+=4) pix[i+3]=(pix[i]>>2)+(pix[i+1]>>1)+(pix[i+2]>>2);
+ int x,y,w,h;
+ if ((((float)cx)/cy)<(((float)mov.getWidth())/mov.getHeight())){
+ x=0;
+ w=cx;
+ h=((float)cx)*(((float)mov.getHeight())/mov.getWidth());
+ y=(cy-h)/2;
+ }
+ else {
+ y=0;
+ h=cy;
+ w=((float)cy)*(((float)mov.getWidth())/mov.getHeight());
+ x=(cx-w)/2;
+ }
+ ofEnableAlphaBlending();
+ mov.draw(x,y,w,h);
+ ofDisableAlphaBlending(); + }
+} + +void videolayer::draw(float a,unsigned char* controllers,int cx,int cy,bool transparentBlack=false,float colShift=0.0f) { + draw(a,cx,cy,colShift);
+} + +void videolayer::setNote(int note) +{
+ + if ((startNote<=note)&&(endNote>=note)) { + if (!mov.isPlaying()) {
+ //printf("starting movie!\n");
+ mov.setUseTexture(true);
+ mov.play();
+ mov.setSpeed(speed);
+ } + mov.setFrame((int)(((((float)note-startNote)/((float)endNote-startNote)))*mov.getTotalNumFrames()));
+ //printf("movie %i (%i - %i) frame: %i\n",note,startNote,endNote,(int)(((((float)note-startNote)/((float)endNote-startNote)))*mov.getTotalNumFrames())); + } + else { + if (mov.isPlaying()) { + mov.stop(); + } + } + +}; +
+
+videolayer::~videolayer()
+{
}
|
