void DrawGLUtils::DrawCircle(const xlColor &color, double cx, double cy, double r, int ctransparency, int etransparency) { if (ctransparency) { double t = 100.0 - ctransparency; t *= 2.56; ctransparency = t; glColor4ub(color.Red(), color.Green(),color.Blue(), ctransparency); } else { glColor3ub(color.Red(), color.Green(),color.Blue()); } int num_segments = r / 2; if (num_segments < 16) { num_segments = 16; } float theta = 2 * 3.1415926 / float(num_segments); float tangetial_factor = tanf(theta);//calculate the tangential factor float radial_factor = cosf(theta);//calculate the radial factor float x = r;//we start at angle = 0 float y = 0; glBegin(GL_TRIANGLE_FAN); glVertex2f(cx, cy); //center vertex if (etransparency) { double t = 100.0 - etransparency; t *= 2.56; etransparency = t; glColor4ub(color.Red(), color.Green(),color.Blue(), etransparency); } else { glColor3ub(color.Red(), color.Green(),color.Blue()); } for(int ii = 0; ii < num_segments; ii++) { glVertex2f(x + cx, y + cy);//output vertex //calculate the tangential vector //remember, the radial vector is (x, y) //to get the tangential vector we flip those coordinates and negate one of them float tx = -y; float ty = x; //add the tangential vector x += tx * tangetial_factor; y += ty * tangetial_factor; //correct using the radial factor x *= radial_factor; y *= radial_factor; } glVertex2f(x + cx, y + cy);//output vertex glEnd(); }
void DrawGLUtils::DrawHBlendedRectangle(const xlColor &left, const xlColor &right, int x1, int y1,int x2, int y2) { glColor3ub(left.Red(), left.Green(), left.Blue()); glBegin(GL_QUADS); glVertex2f(x1, y1); glVertex2f(x1, y2); glColor3ub(right.Red(), right.Green(),right.Blue()); glVertex2f(x2, y2); glVertex2f(x2, y1); glEnd(); }
void DrawGLUtils::DrawPoint(const xlColor &color, double x, double y) { glColor3ub(color.Red(), color.Green(),color.Blue()); glBegin(GL_POINTS); glVertex2f(x, y); glEnd(); }
void DrawGLUtils::DrawLine(const xlColor &color, wxByte alpha,int x1, int y1, int x2, int y2, float width) { glLineWidth(width); glColor4ub(color.Red(), color.Green(),color.Blue(),alpha); glBegin(GL_LINES); glVertex2i(x1, y1); glVertex2i(x2, y2); glEnd(); }
void add(double x, double y, const xlColor &c) { resize(curCount + 1); vertices[curCount * 2] = x; vertices[curCount * 2 + 1] = y; colors[curCount*4] = c.Red(); colors[curCount*4 + 1] = c.Green(); colors[curCount*4 + 2] = c.Blue(); colors[curCount*4 + 3] = c.Alpha(); curCount++; }
void DrawGLUtils::DrawFillRectangle(const xlColor &color, wxByte alpha, int x, int y,int width, int height) { glColor4ub(color.Red(), color.Green(),color.Blue(),alpha); //glColor3ub(color.Red(), color.Green(),color.Blue()); glBegin(GL_QUADS); glVertex2f(x, y); glVertex2f(x+width, y); glVertex2f(x+width, y+height); glVertex2f(x, y+height); glEnd(); }
void DrawGLUtils::DrawCircleUnfilled(const xlColor &color, double cx, double cy, double r, float width ) { static const double inc = PI / 12; static const double max = 2 * PI; glLineWidth(width); glColor3ub(color.Red(), color.Green(),color.Blue()); glBegin(GL_LINE_LOOP); for(double d = 0; d < max; d += inc) { glVertex2f(cos(d) * r + cx, sin(d) * r + cy); } glEnd(); }
void RenderBuffer::SetTempPixel(int x, int y, const xlColor & color, int alpha) { xlColor c(color.Red(), color.Green(), color.Blue(), alpha); SetTempPixel(x, y, c); }
void RenderBuffer::Get2ColorAlphaBlend(const xlColor& c1, const xlColor& c2, float ratio, xlColor &color) { color.Set(ChannelBlend(c1.Red(),c2.Red(),ratio), ChannelBlend(c1.Green(),c2.Green(),ratio), ChannelBlend(c1.Blue(),c2.Blue(),ratio)); }
void RenderBuffer::Get2ColorBlend(xlColor& color, xlColor color2, float ratio) { color.Set(ChannelBlend(color.Red(), color2.Red(), ratio), ChannelBlend(color.Green(), color2.Green(), ratio), ChannelBlend(color.Blue(), color2.Blue(), ratio)); }
void DrawGLUtils::DrawRectangle(const xlColor &color, bool dashed, int x1, int y1, int x2, int y2) { glColor3ub(color.Red(), color.Green(),color.Blue()); if (!dashed) { glBegin(GL_LINES); glVertex2f(x1, y1); glVertex2f(x2, y1); glVertex2f(x2, y1); glVertex2f(x2, y2 - 0.4f); glVertex2f(x2, y2 - 0.4f); glVertex2f(x1, y2 - 0.4f); glVertex2f(x1, y1); glVertex2f(x1, y2); glEnd(); } else { glBegin(GL_POINTS); // Line 1 int xs = x1<x2?x1:x2; int xf = x1>x2?x1:x2; for(int x=xs;x<=xf;x++) { if(x%8<4) { glVertex2f(x, y1); } } // Line 2 int ys = y1<y2?y1:y2; int yf = y1>y2?y1:y2; for(int y=ys;y<=yf;y++) { if(y%8<4) { glVertex2f(x2,y); } } // Line 3 xs = x1<x2?x1:x2; xf = x1>x2?x1:x2; for(int x=xs;x<=xf;x++) { if(x%8<4) { glVertex2f(x, y2); } } // Line 4 ys = y1<y2?y1:y2; yf = y1>y2?y1:y2; for(int y=ys;y<=yf;y++) { if(y%8<4) { glVertex2f(x1,y); } } glEnd(); } }
xlColor PixelBufferClass::mixColors(const wxCoord &x, const wxCoord &y, const xlColor &fg, const xlColor &c1, int layer) { static const int n = 0; //increase to change the curve of the crossfade xlColor c0 = fg; HSVValue hsv0; HSVValue hsv1; bool handlesAlpha = MixTypeHandlesAlpha(layers[layer]->mixType); if (!handlesAlpha && layers[layer]->fadeFactor != 1.0) { //need to fade the first here as we're not mixing anything hsv0 = c0.asHSV(); hsv0.value *= layers[layer]->fadeFactor; c0 = hsv0; } float svthresh = layers[layer]->effectMixThreshold; if (layers[layer]->effectMixVaries) { //vary mix threshold gradually during effect interval -DJ layers[layer]->effectMixThreshold = layers[layer]->buffer.GetEffectTimeIntervalPosition(); } if (layers[layer]->effectMixThreshold < 0) { layers[layer]->effectMixThreshold = 0; } xlColor c; double emt, emtNot; switch (layers[layer]->mixType) { case Mix_Normal: c0.alpha = c0.alpha * layers[layer]->fadeFactor * (1.0 - layers[layer]->effectMixThreshold); c = c0.AlphaBlend(c1); break; case Mix_Effect1: case Mix_Effect2: { if (!layers[layer]->effectMixVaries) { emt = layers[layer]->effectMixThreshold; if ((emt > 0.000001) && (emt < 0.99999)) { emtNot = 1-layers[layer]->effectMixThreshold; //make cross-fade linear emt = cos((M_PI/4)*(pow(2*emt-1,2*n+1)+1)); emtNot = cos((M_PI/4)*(pow(2*emtNot-1,2*n+1)+1)); } else { emtNot = layers[layer]->effectMixThreshold; emt = 1 - layers[layer]->effectMixThreshold; } } else { emt = layers[layer]->effectMixThreshold; emtNot = 1-layers[layer]->effectMixThreshold; } xlColor c2(c1); if (layers[layer]->mixType == Mix_Effect2) { c0.Set(c0.Red()*(emtNot),c0.Green()*(emtNot), c0.Blue()*(emtNot)); c2.Set(c1.Red()*(emt),c1.Green()*(emt), c1.Blue()*(emt)); } else { c0.Set(c0.Red()*(emt),c0.Green()*(emt), c0.Blue()*(emt)); c2.Set(c1.Red()*(emtNot),c1.Green()*(emtNot), c1.Blue()*(emtNot)); } c.Set(c0.Red()+c2.Red(), c0.Green()+c2.Green(), c0.Blue()+c2.Blue()); break; } case Mix_Mask1: // first masks second hsv0 = c0.asHSV(); if (hsv0.value <= layers[layer]->effectMixThreshold) { // only if effect 1 is black c=c1; // then show the color of effect 2 } else { c.Set(0, 0, 0); } break; case Mix_Mask2: // second masks first hsv1 = c1.asHSV(); if (hsv1.value <= layers[layer]->effectMixThreshold) { c=c0; } else { c.Set(0, 0, 0); } break; case Mix_Unmask1: // first unmasks second c0.toHSV(hsv0); c1.toHSV(hsv1); if (hsv0.value > layers[layer]->effectMixThreshold) { // if effect 1 is non black hsv1.value = hsv0.value; c = hsv1; } else { c.Set(0, 0, 0); } break; case Mix_Unmask2: // second unmasks first c0.toHSV(hsv0); c1.toHSV(hsv1); if (hsv1.value > layers[layer]->effectMixThreshold) { // if effect 2 is non black hsv0.value = hsv1.value; c = hsv0; } else { c.Set(0, 0, 0); } break; case Mix_Shadow_1on2: // Effect 1 shadows onto effect 2 c0.toHSV(hsv0); c1.toHSV(hsv1); // if (hsv0.value > effectMixThreshold[layer]) { // if effect 1 is non black // to shadow we will shift the hue on the primary layer using the hue and brightness from the // other layer if(hsv0.value>0.0) hsv1.hue = hsv1.hue + (hsv0.value*(hsv1.hue-hsv0.hue))/5.0; // hsv1.value = hsv0.value; //hsv1.saturation = hsv0.saturation; c = hsv1; // } break; case Mix_Shadow_2on1: // Effect 2 shadows onto effect 1 c0.toHSV(hsv0); c1.toHSV(hsv1); //if (hsv1.value > effectMixThreshold[layer]) { // if effect 1 is non black if(hsv1.value>0.0) hsv0.hue = hsv0.hue + (hsv1.value*(hsv0.hue-hsv1.hue))/2.0; //hsv0.value = hsv1.value; //hsv0.saturation = hsv1.saturation; c = hsv0; // } break; case Mix_Layered: c1.toHSV(hsv1); if (hsv1.value <= layers[layer]->effectMixThreshold) { c=c0; } else { c=c1; } break; case Mix_Average: // only average when both colors are non-black if (c0 == xlBLACK) { c=c1; } else if (c1 == xlBLACK) { c=c0; } else { c.Set( (c0.Red()+c1.Red())/2, (c0.Green()+c1.Green())/2, (c0.Blue()+c1.Blue())/2 ); } break; case Mix_BottomTop: c= y < layers[layer]->BufferHt/2 ? c0 : c1; break; case Mix_LeftRight: c= x < layers[layer]->BufferWi/2 ? c0 : c1; break; case Mix_1_reveals_2: c0.toHSV(hsv0); c = hsv0.value > layers[layer]->effectMixThreshold ? c0 : c1; // if effect 1 is non black break; case Mix_2_reveals_1: c1.toHSV(hsv1); c = hsv1.value > layers[layer]->effectMixThreshold ? c1 : c0; // if effect 2 is non black break; } if (layers[layer]->effectMixVaries) { layers[layer]->effectMixThreshold = svthresh; //put it back afterwards in case next row didn't change it } return c; }