void ggControl::BaseDraw() { if (!(flags & GGFLAG_DONT_DRAW_BORDER)) { float mul = (flags & GGFLAG_DOWN) ? 0.7f : 1.0f; glBegin(GL_QUADS); glColor4f(r*0.6f*mul,g*0.6f*mul,b*0.6f*mul,a); glVertex2d(x ,y ); glColor4f(r*0.9f*mul,g*0.9f*mul,b*0.9f*mul,a); glVertex2d(x+xsize,y ); glColor4f(r*1.0f*mul,g*1.0f*mul,b*1.0f*mul,a); glVertex2d(x+xsize,y+ysize); glColor4f(r*0.7f*mul,g*0.7f*mul,b*0.7f*mul,a); glVertex2d(x ,y+ysize); glEnd(); glColor4f(1,1,1,a); glBegin(GL_LINES); glVertex2d(x ,y ); glVertex2d(x+xsize,y ); glVertex2d(x+xsize,y ); glVertex2d(x+xsize,y+ysize); glVertex2d(x+xsize,y+ysize); glVertex2d(x ,y+ysize); glVertex2d(x ,y+ysize); glVertex2d(x ,y-1 ); glEnd(); } }
/** * Fonction privée qui sert à dessiner un vecteur via OpenGL * en s'occupant au passage de la gestion du viewport. * @param v: le vecteurà dessiner. */ void OpenGLVisiteur::drawVect(const Vecteur2D&v)const{ glVertex2d(v.getX()/screenWidth,v.getY()/screenHeight); }
void tile_set_draw_tile(struct tile_set *ts, struct tile_texture *tt) { if (!tt->texture_valid) { glGenTextures( 1, &tt->texture_id ); tt->texture_valid = 1; glPixelTransferi(GL_INDEX_SHIFT, 0); glPixelTransferi(GL_INDEX_OFFSET, 0); glPixelTransferi(GL_MAP_COLOR, GL_TRUE); uint8_t *data = (uint8_t*) malloc(tt->tile->width * tt->tile->height); gridmap_decode_base(data, tt->tile->width, tt->tile->height, tt->tile->data, tt->tile->datalen); glPixelStorei (GL_UNPACK_ROW_LENGTH, tt->tile->width); glPixelStorei (GL_UNPACK_ALIGNMENT, 1); glBindTexture (GL_TEXTURE_2D, tt->texture_id); glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, tt->tile->width, tt->tile->height, 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, data); glPixelStorei (GL_UNPACK_ROW_LENGTH, 0); glPixelTransferi(GL_MAP_COLOR, GL_FALSE); glBindTexture (GL_TEXTURE_2D, 0); free(data); } glPushAttrib (GL_ENABLE_BIT); glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable (GL_DEPTH_TEST); glEnable (GL_TEXTURE_2D); if (ts->r && ts->g && ts->b && ts->a) { glPixelTransferi(GL_INDEX_SHIFT, 0); glPixelTransferi(GL_INDEX_OFFSET, 0); glPixelTransferi(GL_MAP_COLOR, GL_TRUE); glPixelMapfv(GL_PIXEL_MAP_I_TO_R, 256, ts->r); glPixelMapfv(GL_PIXEL_MAP_I_TO_G, 256, ts->g); glPixelMapfv(GL_PIXEL_MAP_I_TO_B, 256, ts->b); glPixelMapfv(GL_PIXEL_MAP_I_TO_A, 256, ts->a); } glPixelStorei (GL_UNPACK_ROW_LENGTH, tt->tile->width); glPixelStorei (GL_UNPACK_ALIGNMENT, 1); glBindTexture (GL_TEXTURE_2D, tt->texture_id); glPixelStorei (GL_UNPACK_ROW_LENGTH, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); double x0 = tt->tile->x0; double x1 = tt->tile->x0 + tt->tile->width * tt->tile->meters_per_pixel; double y0 = tt->tile->y0; double y1 = tt->tile->y0 + tt->tile->height * tt->tile->meters_per_pixel; int d = 1; glBegin (GL_QUADS); glTexCoord2i (0,0); glVertex2d (x0, y0); glTexCoord2i (0, d); glVertex2d (x0, y1); glTexCoord2i (d, d); glVertex2d (x1, y1); glTexCoord2i (d, 0); glVertex2d (x1, y0); glEnd (); glPixelTransferi(GL_MAP_COLOR, GL_FALSE); glBindTexture (GL_TEXTURE_2D, 0); glPopAttrib (); }
void RulerMark::glCommands(double units) { glDisable(GL_POLYGON_OFFSET_FILL); double half_width = width/2; double dpos = (double)pos; if(units > 25.0) { dpos *= 2.54; // position of the tenth of an inch, in mm } if(wxGetApp().GetPixelScale() < 10) { // draw a line glBegin(GL_LINES); glVertex2d(dpos, 0.0); glVertex2d(dpos, -length); glEnd(); } else { // draw triangles double p[5][3] = { {dpos, 0.0, 0.0}, {dpos - half_width, -half_width, 0.0}, {dpos - half_width, -length, 0.0}, {dpos + half_width, -length, 0.0}, {dpos + half_width, -half_width, 0.0} }; glBegin(GL_TRIANGLES); glVertex3dv(p[0]); glVertex3dv(p[1]); glVertex3dv(p[4]); glVertex3dv(p[1]); glVertex3dv(p[2]); glVertex3dv(p[4]); glVertex3dv(p[2]); glVertex3dv(p[3]); glVertex3dv(p[4]); glEnd(); } // draw text if(pos == 0) { wxString str = _T("cm"); if(units > 25.0)str = _T("inches"); glPushMatrix(); glTranslated(dpos + half_width, -length + 2.05, 0.0); glColor4ub(0, 0, 0, 255); wxGetApp().render_text(str); glPopMatrix(); } else if(pos % 10 == 0) { float text_width, text_height; wxString str = wxString::Format(_T("%d"), pos/10); if(!wxGetApp().get_text_size(str, &text_width, &text_height))return; glPushMatrix(); glTranslated(dpos - half_width - text_width, -length + 2.05, 0.0); wxGetApp().render_text(str); glPopMatrix(); } glEnable(GL_POLYGON_OFFSET_FILL); }
void View::draw_continuous_scale(char* title, bool righttext) { int i; double y0 = scale_y + scale_height; set_ortho_projection(true); glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glDisable(GL_TEXTURE_1D); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); // background const int b = 5; glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(1.0f, 1.0f, 1.0f, 0.65f); int rt = righttext ? 0 : labels_width + 8; glBegin(GL_QUADS); glVertex2d(scale_x - b - rt, y0 + 5 + b); glVertex2d(scale_x + scale_width + 8 + labels_width + b - rt, y0 + 5 + b); glVertex2d(scale_x + scale_width + 8 + labels_width + b - rt, scale_y - 5 - b); glVertex2d(scale_x - b - rt, scale_y - 5 - b); glEnd(); // palette glDisable(GL_BLEND); glColor3f(0.0f, 0.0f, 0.0f); glBegin(GL_QUADS); glVertex2d(scale_x, scale_y); glVertex2d(scale_x, scale_y + scale_height + 1); glVertex2d(scale_x + scale_width + 1, scale_y + scale_height + 1); glVertex2d(scale_x + scale_width + 1, scale_y); glEnd(); glEnable(GL_TEXTURE_1D); glBindTexture(GL_TEXTURE_1D, gl_pallete_tex_id); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); glBegin(GL_QUADS); glTexCoord1d(tex_scale + tex_shift); glVertex2d(scale_x + 1, scale_y + 1); glVertex2d(scale_x + scale_width, scale_y + 1); glTexCoord1d(tex_shift); glVertex2d(scale_x + scale_width, scale_y + scale_height); glVertex2d(scale_x + 1, scale_y + scale_height); glEnd(); // focus glDisable(GL_TEXTURE_1D); if (scale_focused) { glEnable(GL_BLEND); glColor4f(1.0f, 1.0f, 1.0f, 0.3f); glBegin(GL_QUADS); glVertex2d(scale_x + 1, scale_y + 1); glVertex2d(scale_x + scale_width, scale_y + 1); glVertex2d(scale_x + scale_width, scale_y + scale_height); glVertex2d(scale_x + 1, scale_y + scale_height); glEnd(); } // ticks glColor3f(0, 0, 0); glDisable(GL_BLEND); glDisable(GL_LINE_STIPPLE); glLineWidth(1.0); glBegin(GL_LINES); for (i = 0; i < scale_numticks; i++) { y0 = scale_y + scale_height - (double) (i+1) * scale_height / (scale_numticks+1); glVertex2d(scale_x, y0); glVertex2d(scale_x + 0.2 * scale_width + 1, y0); glVertex2d(scale_x + 0.8 * scale_width, y0); glVertex2d(scale_x + scale_width, y0); } glEnd(); // labels for (i = 0; i <= scale_numticks+1; i++) { double value = range_min + (double) i * (range_max - range_min) / (scale_numticks+1); if (fabs(value) < 1e-8) value = 0.0; char text[50]; sprintf(text, scale_fmt, value); y0 = scale_y + scale_height - (double) i * scale_height / (scale_numticks+1); if (righttext) draw_text(scale_x + scale_width + 8, y0, text); else draw_text(scale_x - 8, y0, text, 1); } }
void TextFieldWidget::Render() { //Color BackgroundColor(1.0, 1.0, 1.0); Color BackgroundColor = m_BackgroundColor; Color BorderColor(0.3, 0.3, 0.3); /*if (CheckHover(WidgetManager) && CheckActive(WidgetManager)) { } else if ((CheckHover(WidgetManager) && !CheckAnyActive(WidgetManager)) || (!CheckHover(WidgetManager) && CheckActive(WidgetManager))) { BorderColor[0] = 0.898; BorderColor[1] = 0.765; BorderColor[2] = 0.396; } else { }*/ //if (CheckHover()) // HACK if (HasTypingFocus()) { BorderColor[0] = 0.898; BorderColor[1] = 0.765; BorderColor[2] = 0.396; } /*glBegin(GL_QUADS); glVertex2d(m_Position.X(), m_Position.Y()); glVertex2d(m_Position.X(), m_Position.Y() + 30); glVertex2d(m_Position.X() + 30, m_Position.Y() + 30); glVertex2d(m_Position.X() + 30, m_Position.Y()); glEnd();*/ DrawAroundBox(GetPosition(), GetDimensions(), BackgroundColor, BorderColor); // TEST auto ContentWithInsertion = m_Content; if (!m_TypingModule.GetString().empty()) { for (auto & Pointer : GetGestureRecognizer().GetConnected()) { if (Pointer::VirtualCategory::POINTING == Pointer->GetVirtualCategory()) { Vector2n GlobalPosition(Pointer->GetPointerState().GetAxisState(0).GetPosition(), Pointer->GetPointerState().GetAxisState(1).GetPosition()); Vector2n LocalPosition(GlobalToLocal(GlobalPosition)); LocalPosition = m_TypingModule.GetInsertionPosition(LocalPosition); auto InsertionPosition = GetNearestCaretPosition(LocalPosition); ContentWithInsertion.insert(InsertionPosition, m_TypingModule.GetString()); } } } glColor3d(0, 0, 0); OpenGLStream OpenGLStream(GetPosition()); OpenGLStream << ContentWithInsertion.substr(0, std::min(m_CaretPosition, m_SelectionPosition)); Vector2n CaretPosition; // Remember caret position at selection front if (std::min(m_CaretPosition, m_SelectionPosition) == m_CaretPosition) { CaretPosition = OpenGLStream.GetCaretPosition(); } // Draw selected text as highlighted if (HasTypingFocus()) { OpenGLStream.SetBackgroundColor(Color(static_cast<uint8>(195), 212, 242)); } else { OpenGLStream.SetBackgroundColor(Color(static_cast<uint8>(212), 212, 212)); } auto SelectionLength = std::max(m_CaretPosition, m_SelectionPosition) - std::min(m_CaretPosition, m_SelectionPosition); OpenGLStream << ContentWithInsertion.substr(std::min(m_CaretPosition, m_SelectionPosition), SelectionLength); OpenGLStream.SetBackgroundColor(Color(1.0, 1.0, 1.0)); // Remember caret position at selection back if (std::max(m_CaretPosition, m_SelectionPosition) == m_CaretPosition) { CaretPosition = OpenGLStream.GetCaretPosition(); } OpenGLStream << ContentWithInsertion.substr(std::max(m_CaretPosition, m_SelectionPosition)); //if (CheckHover()) // HACK if (HasTypingFocus()) { // Draw caret //if (static_cast<int>(glfwGetTime() * 2) % 2) { glPushMatrix(); glTranslated(CaretPosition.X(), CaretPosition.Y(), 0); glColor3d(0, 0, 0); glBegin(GL_QUADS); glVertex2d(-1, 0); glVertex2d(-1, lineHeight); glVertex2d(+1, lineHeight); glVertex2d(+1, 0); glEnd(); glPopMatrix(); } } }
void cc2DLabel::drawMeOnly2D(CC_DRAW_CONTEXT& context) { if (!m_dispIn2D) return; assert(!m_points.empty()); //standard case: list names pushing bool pushName = MACRO_DrawEntityNames(context); if (pushName) glPushName(getUniqueID()); //we should already be in orthoprojective & centered omde //glOrtho(-halfW,halfW,-halfH,halfH,-maxS,maxS); int strHeight = 0; int titleHeight = 0; QString title(getName()); QStringList body; GLdouble arrowDestX=-1.0,arrowDestY=-1.0; QFont bodyFont,titleFont; if (!pushName) { /*** line from 2D point to label ***/ //compute arrow head position CCVector3 arrowDest; m_points[0].cloud->getPoint(m_points[0].index,arrowDest); for (unsigned i=1;i<m_points.size();++i) arrowDest += *m_points[i].cloud->getPointPersistentPtr(m_points[i].index); arrowDest /= (PointCoordinateType)m_points.size(); //project it in 2D screen coordinates int VP[4]; context._win->getViewportArray(VP); const double* MM = context._win->getModelViewMatd(); //viewMat const double* MP = context._win->getProjectionMatd(); //projMat GLdouble zp; gluProject(arrowDest.x,arrowDest.y,arrowDest.z,MM,MP,VP,&arrowDestX,&arrowDestY,&zp); /*** label border ***/ bodyFont = context._win->getTextDisplayFont(); //takes rendering zoom into account! titleFont = QFont(context._win->getTextDisplayFont()); //takes rendering zoom into account! titleFont.setBold(true); QFontMetrics titleFontMetrics(titleFont); QFontMetrics bodyFontMetrics(bodyFont); strHeight = bodyFontMetrics.height(); titleHeight = titleFontMetrics.height(); if (m_showFullBody) body = getLabelContent(context.dispNumberPrecision); //base box dimension int dx = 150; dx = std::max(dx,titleFontMetrics.width(title)); int dy = c_margin; //top vertical margin dy += titleHeight; //title if (!body.empty()) { dy += c_margin; //vertical margin above separator for (int j=0; j<body.size(); ++j) { dx = std::max(dx,bodyFontMetrics.width(body[j])); dy += strHeight; //body line height } dy += c_margin; //vertical margin below text } else { dy += c_margin; // vertical margin (purely for aesthetics) } dy += c_margin; // bottom vertical margin dx += c_margin*2; // horizontal margins //main rectangle m_labelROI[0]=0; m_labelROI[1]=0; m_labelROI[2]=dx; m_labelROI[3]=dy; //close button /*m_closeButtonROI[2]=dx-c_margin; m_closeButtonROI[0]=m_closeButtonROI[2]-c_buttonSize; m_closeButtonROI[3]=c_margin; m_closeButtonROI[1]=m_closeButtonROI[3]+c_buttonSize; //*/ //automatically elide the title //title = titleFontMetrics.elidedText(title,Qt::ElideRight,m_closeButtonROI[0]-2*c_margin); } int halfW = (context.glW>>1); int halfH = (context.glH>>1); //draw label rectangle int xStart = m_lastScreenPos[0] = (int)((float)context.glW * m_screenPos[0]); int yStart = m_lastScreenPos[1] = (int)((float)context.glH * (1.0f-m_screenPos[1])); //colors bool highlighted = (!pushName && isSelected()); //default background color colorType defaultBkgColor[4]; memcpy(defaultBkgColor,context.labelDefaultCol,sizeof(colorType)*3); defaultBkgColor[3] = (colorType)((float)context.labelsTransparency*(float)MAX_COLOR_COMP/100.0f); //default border color (mustn't be totally transparent!) colorType defaultBorderColor[4]; if (highlighted) memcpy(defaultBorderColor,ccColor::red,sizeof(colorType)*3); else memcpy(defaultBorderColor,context.labelDefaultCol,sizeof(colorType)*3); defaultBorderColor[3] = (colorType)((float)(50+context.labelsTransparency/2)*(float)MAX_COLOR_COMP/100.0f); glPushAttrib(GL_COLOR_BUFFER_BIT); glEnable(GL_BLEND); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glTranslatef(static_cast<GLfloat>(-halfW+xStart),static_cast<GLfloat>(-halfH+yStart),0); if (!pushName) { //compute arrow base position relatively to the label rectangle (for 0 to 8) int arrowBaseConfig = 0; int iArrowDestX = (int)arrowDestX-xStart; int iArrowDestY = (int)arrowDestY-yStart; { if (iArrowDestX < m_labelROI[0]) //left arrowBaseConfig += 0; else if (iArrowDestX > m_labelROI[2]) //Right arrowBaseConfig += 2; else //Middle arrowBaseConfig += 1; if (iArrowDestY > -m_labelROI[1]) //Top arrowBaseConfig += 0; else if (iArrowDestY < -m_labelROI[3]) //Bottom arrowBaseConfig += 6; else //Middle arrowBaseConfig += 3; } //we make the arrow base start from the nearest corner if (arrowBaseConfig != 4) //4 = label above point! { glColor4ubv(defaultBorderColor); glBegin(GL_TRIANGLE_FAN); glVertex2d(arrowDestX-xStart,arrowDestY-yStart); switch(arrowBaseConfig) { case 0: //top-left corner glVertex2i(m_labelROI[0], -m_labelROI[1]-2*c_arrowBaseSize); glVertex2i(m_labelROI[0], -m_labelROI[1]); glVertex2i(m_labelROI[0]+2*c_arrowBaseSize, -m_labelROI[1]); break; case 1: //top-middle edge glVertex2i(std::max(m_labelROI[0],iArrowDestX-c_arrowBaseSize), -m_labelROI[1]); glVertex2i(std::min(m_labelROI[2],iArrowDestX+c_arrowBaseSize), -m_labelROI[1]); break; case 2: //top-right corner glVertex2i(m_labelROI[2], -m_labelROI[1]-2*c_arrowBaseSize); glVertex2i(m_labelROI[2], -m_labelROI[1]); glVertex2i(m_labelROI[2]-2*c_arrowBaseSize, -m_labelROI[1]); break; case 3: //middle-left edge glVertex2i(m_labelROI[0], std::min(-m_labelROI[1],iArrowDestY+c_arrowBaseSize)); glVertex2i(m_labelROI[0], std::max(-m_labelROI[3],iArrowDestY-c_arrowBaseSize)); break; case 4: //middle of rectangle! break; case 5: //middle-right edge glVertex2i(m_labelROI[2], std::min(-m_labelROI[1],iArrowDestY+c_arrowBaseSize)); glVertex2i(m_labelROI[2], std::max(-m_labelROI[3],iArrowDestY-c_arrowBaseSize)); break; case 6: //bottom-left corner glVertex2i(m_labelROI[0], -m_labelROI[3]+2*c_arrowBaseSize); glVertex2i(m_labelROI[0], -m_labelROI[3]); glVertex2i(m_labelROI[0]+2*c_arrowBaseSize, -m_labelROI[3]); break; case 7: //bottom-middle edge glVertex2i(std::max(m_labelROI[0],iArrowDestX-c_arrowBaseSize), -m_labelROI[3]); glVertex2i(std::min(m_labelROI[2],iArrowDestX+c_arrowBaseSize), -m_labelROI[3]); break; case 8: //bottom-right corner glVertex2i(m_labelROI[2], -m_labelROI[3]+2*c_arrowBaseSize); glVertex2i(m_labelROI[2], -m_labelROI[3]); glVertex2i(m_labelROI[2]-2*c_arrowBaseSize, -m_labelROI[3]); break; } glEnd(); } } //main rectangle glColor4ubv(defaultBkgColor); glBegin(GL_QUADS); glVertex2i(m_labelROI[0], -m_labelROI[1]); glVertex2i(m_labelROI[0], -m_labelROI[3]); glVertex2i(m_labelROI[2], -m_labelROI[3]); glVertex2i(m_labelROI[2], -m_labelROI[1]); glEnd(); //if (highlighted) { glPushAttrib(GL_LINE_BIT); glLineWidth(3.0f); glColor4ubv(defaultBorderColor); glBegin(GL_LINE_LOOP); glVertex2i(m_labelROI[0], -m_labelROI[1]); glVertex2i(m_labelROI[0], -m_labelROI[3]); glVertex2i(m_labelROI[2], -m_labelROI[3]); glVertex2i(m_labelROI[2], -m_labelROI[1]); glEnd(); glPopAttrib(); } //draw close button /*glColor3ubv(ccColor::black); glBegin(GL_LINE_LOOP); glVertex2i(m_closeButtonROI[0],-m_closeButtonROI[1]); glVertex2i(m_closeButtonROI[0],-m_closeButtonROI[3]); glVertex2i(m_closeButtonROI[2],-m_closeButtonROI[3]); glVertex2i(m_closeButtonROI[2],-m_closeButtonROI[1]); glEnd(); glBegin(GL_LINES); glVertex2i(m_closeButtonROI[0]+2,-m_closeButtonROI[1]+2); glVertex2i(m_closeButtonROI[2]-2,-m_closeButtonROI[3]-2); glVertex2i(m_closeButtonROI[2]-2,-m_closeButtonROI[1]+2); glVertex2i(m_closeButtonROI[0]+2,-m_closeButtonROI[3]-2); glEnd(); //*/ //display text if (!pushName) { int xStartRel = c_margin; int yStartRel = -c_margin; yStartRel -= titleHeight; const colorType* defaultTextColor = (context.labelsTransparency<40 ? context.textDefaultCol : ccColor::darkBlue); context._win->displayText(title,xStart+xStartRel,yStart+yStartRel,ccGenericGLDisplay::ALIGN_DEFAULT,0,defaultTextColor,&titleFont); yStartRel -= c_margin; if (!body.empty()) { //line separation glColor4ubv(defaultBorderColor); glBegin(GL_LINES); glVertex2i(xStartRel,yStartRel); glVertex2i(xStartRel+m_labelROI[2]-m_labelROI[0]-2*c_margin,yStartRel); glEnd(); //display body yStartRel -= c_margin; for (int i=0; i<body.size(); ++i) { yStartRel -= strHeight; context._win->displayText(body[i],xStart+xStartRel,yStart+yStartRel,ccGenericGLDisplay::ALIGN_DEFAULT,0,defaultTextColor,&bodyFont); } } } glPopAttrib(); glPopMatrix(); if (pushName) glPopName(); }
void display(void) { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0, 0.0, 0.0); char name[15] = "TYLER GAJEWSKI"; for (int i = 0; i < 14; i++) { glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, name[i]); } glBegin(GL_LINES); // Start F glVertex2d(10, 10); glVertex2d(10, 20); glVertex2d(20, 20); glVertex2d(10, 20); glVertex2d(10, 15); glVertex2d(15, 15); // End F // Start R glVertex2d(30,10); glVertex2d(30,20); glVertex2d(30,20); glVertex2d(40,18); glVertex2d(40,18); glVertex2d(30,14); glVertex2d(30,14); glVertex2d(40,10); // End R glEnd(); glColor3f(0.0, 0.0, 1.0); glBegin(GL_LINES); // Start E glVertex2d(50, 10); glVertex2d(50, 20); glVertex2d(50, 20); glVertex2d(60, 20); glVertex2d(50, 15); glVertex2d(55, 15); glVertex2d(50, 10); glVertex2d(60, 10); // End E // Start D glVertex2d(70, 10); glVertex2d(70, 20); glVertex2d(70, 10); glVertex2d(80, 15); glVertex2d(70, 20); glVertex2d(80, 15); // End D glEnd(); glColor3f(0.0, 1.0, 0.0); glBegin(GL_LINES); // Start O glVertex2d(90, 10); glVertex2d(90, 20); glVertex2d(90, 10); glVertex2d(100, 10); glVertex2d(100, 20); glVertex2d(100, 10); glVertex2d(90, 20); glVertex2d(100, 20); // End O // Start N glVertex2d(110, 10); glVertex2d(110, 20); glVertex2d(110, 20); glVertex2d(120, 10); glVertex2d(120, 10); glVertex2d(120, 20); // End N glEnd(); glColor3f(1.0, 1.0, 1.0); glBegin(GL_LINES); // Start I glVertex2d(130, 10); glVertex2d(130, 20); // End I // Start A glVertex2d(140, 10); glVertex2d(145, 20); glVertex2d(145, 20); glVertex2d(150, 10); glVertex2d(142, 15); glVertex2d(148, 15); // End A glEnd(); glFlush(); }
void DrawTarget(int _x,int _y,int ttype) { glLoadIdentity(); glBindTexture(GL_TEXTURE_2D, 0); glTranslated(_x+16,_y+16,0); if(ttype==0) glRotatef(float(SDL_GetTicks())/4.0f,0,0,1); else if(ttype==1) glRotatef((float(SDL_GetTicks()+360)/4.0f),0,0,1); glBegin( GL_TRIANGLES ); if(ttype==0) { glColor4f(1,0,0,0.75f); glVertex2d( -16,-6 ); glColor4f(1,1,0,0.75f); glVertex2d( -10, 0 ); glColor4f(1,0,0,0.75f); glVertex2d( -16, 6 ); glColor4f(1,0,0,0.75f); glVertex2d( 16,-6 ); glColor4f(1,1,0,0.75f); glVertex2d( 10, 0 ); glColor4f(1,0,0,0.75f); glVertex2d( 16, 6 ); } else if(ttype==1) { glColor4f(0,1,0,0.75f); glVertex2d( -16, -6 ); glColor4f(0,0,1,0.75f); glVertex2d( -10, 0 ); glColor4f(0,1,0,0.75f); glVertex2d( -16, 6 ); glColor4f(0,1,0,0.75f); glVertex2d( 16, -6 ); glColor4f(0,0,1,0.75f); glVertex2d( 10, 0 ); glColor4f(0,1,0,0.75f); glVertex2d( 16, 6 ); } glEnd(); }
void GUITriggeredRerouter::GUITriggeredRerouterEdge::drawGL(const GUIVisualizationSettings& s) const { const SUMOReal exaggeration = s.addSize.getExaggeration(s); if (s.scale * exaggeration >= 3) { glPushName(getGlID()); const SUMOReal prob = myParent->getProbability(); if (myAmClosedEdge) { // draw closing symbol onto all lanes const RerouteInterval* const ri = myParent->getCurrentReroute(MSNet::getInstance()->getCurrentTimeStep()); if (ri != 0 && prob > 0) { // draw only if the edge is closed at this time if (std::find(ri->closed.begin(), ri->closed.end(), myEdge) != ri->closed.end()) { const size_t noLanes = myFGPositions.size(); for (size_t j = 0; j < noLanes; ++j) { Position pos = myFGPositions[j]; SUMOReal rot = myFGRotations[j]; glPushMatrix(); glTranslated(pos.x(), pos.y(), 0); glRotated(rot, 0, 0, 1); glTranslated(0, -1.5, 0); int noPoints = 9; if (s.scale > 25) { noPoints = (int)(9.0 + s.scale / 10.0); if (noPoints > 36) { noPoints = 36; } } glTranslated(0, 0, getType()); //glScaled(exaggeration, exaggeration, 1); glColor3d(0.7, 0, 0); GLHelper::drawFilledCircle((SUMOReal) 1.3, noPoints); glTranslated(0, 0, .1); glColor3d(1, 0, 0); GLHelper::drawFilledCircle((SUMOReal) 1.3, noPoints, 0, prob * 360); glTranslated(0, 0, .1); glColor3d(1, 1, 1); glRotated(-90, 0, 0, 1); glBegin(GL_TRIANGLES); glVertex2d(0 - .3, -1.); glVertex2d(0 - .3, 1.); glVertex2d(0 + .3, 1.); glVertex2d(0 + .3, -1.); glVertex2d(0 - .3, -1.); glVertex2d(0 + .3, 1.); glEnd(); glPopMatrix(); } } } } else { // draw rerouter symbol onto all lanes for (size_t i = 0; i < myFGPositions.size(); ++i) { const Position& pos = myFGPositions[i]; SUMOReal rot = myFGRotations[i]; glPushMatrix(); glTranslated(pos.x(), pos.y(), 0); glRotated(rot, 0, 0, 1); glTranslated(0, 0, getType()); glScaled(exaggeration, exaggeration, 1); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glBegin(GL_TRIANGLES); glColor3d(1, .8f, 0); // base glVertex2d(0 - 1.4, 0); glVertex2d(0 - 1.4, 6); glVertex2d(0 + 1.4, 6); glVertex2d(0 + 1.4, 0); glVertex2d(0 - 1.4, 0); glVertex2d(0 + 1.4, 6); glEnd(); glTranslated(0, 0, .1); glColor3d(0, 0, 0); pfSetPosition(0, 0); pfSetScale(3.f); SUMOReal w = pfdkGetStringWidth("U"); glRotated(180, 0, 1, 0); glTranslated(-w / 2., 2, 0); pfDrawString("U"); glTranslated(w / 2., -2, 0); std::string str = toString((int)(prob * 100)) + "%"; pfSetPosition(0, 0); pfSetScale(.7f); w = pfdkGetStringWidth(str.c_str()); glTranslated(-w / 2., 4, 0); pfDrawString(str.c_str()); glPopMatrix(); } } glPopName(); } }
void UVWidget::paintGL() { glPushAttrib( GL_ALL_ATTRIB_BITS ); glMatrixMode( GL_PROJECTION ); glPushMatrix(); glLoadIdentity(); setupViewport( width(), height() ); glMatrixMode( GL_MODELVIEW ); glPushMatrix(); glLoadIdentity(); qglClearColor( Options::bgColor() ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glDisable( GL_DEPTH_TEST ); glDepthMask( GL_FALSE ); // draw texture glPushMatrix(); glLoadIdentity(); glEnable( GL_TEXTURE_2D ); if ( aTextureBlend->isChecked() ) glEnable( GL_BLEND ); else glDisable( GL_BLEND ); if( !texfile.isEmpty() ) bindTexture( texfile ); else bindTexture( texsource ); glTranslatef( -0.5f, -0.5f, 0.0f ); glTranslatef( -1.0f, -1.0f, 0.0f ); for( int i = 0; i < 3; i++ ) { for( int j = 0; j < 3; j++ ) { if( i == 1 && j == 1 ) { glColor4f( 0.75f, 0.75f, 0.75f, 1.0f ); } else { glColor4f( 0.5f, 0.5f, 0.5f, 1.0f ); } glDrawArrays( GL_QUADS, 0, 4 ); glTranslatef( 1.0f, 0.0f, 0.0f ); } glTranslatef( -3.0f, 1.0f, 0.0f ); } glTranslatef( 1.0f, -2.0f, 0.0f ); glDisable( GL_TEXTURE_2D ); glPopMatrix(); // draw grid glPushMatrix(); glLoadIdentity(); glEnable( GL_BLEND ); glLineWidth( 0.8f ); glBegin( GL_LINES ); int glGridMinX = qRound( qMin( glViewRect[0], glViewRect[1] ) / glGridD ); int glGridMaxX = qRound( qMax( glViewRect[0], glViewRect[1] ) / glGridD ); int glGridMinY = qRound( qMin( glViewRect[2], glViewRect[3] ) / glGridD ); int glGridMaxY = qRound( qMax( glViewRect[2], glViewRect[3] ) / glGridD ); for( int i = glGridMinX; i < glGridMaxX; i++ ) { GLdouble glGridPos = glGridD * i; if( ( i % ( GRIDSEGS * GRIDSEGS ) ) == 0 ) { glLineWidth( 1.4f ); glColor4f( 1.0f, 1.0f, 1.0f, 0.4f ); } else if( zoom > ( GRIDSEGS * GRIDSEGS / 2.0 ) ) { continue; } else if( ( i % GRIDSEGS ) == 0 ) { glLineWidth( 1.2f ); glColor4f( 1.0f, 1.0f, 1.0f, 0.2f ); } else if( zoom > ( GRIDSEGS / 2.0 ) ) { continue; } else { glLineWidth( 0.8f ); glColor4f( 1.0f, 1.0f, 1.0f, 0.1f ); } glVertex2d( glGridPos, glViewRect[2] ); glVertex2d( glGridPos, glViewRect[3] ); } for( int i = glGridMinY; i < glGridMaxY; i++ ) { GLdouble glGridPos = glGridD * i; if( ( i % ( GRIDSEGS * GRIDSEGS ) ) == 0 ) { glLineWidth( 1.4f ); glColor4f( 1.0f, 1.0f, 1.0f, 0.4f ); } else if( zoom > ( GRIDSEGS * GRIDSEGS / 2.0 ) ) { continue; } else if( ( i % GRIDSEGS ) == 0 ) { glLineWidth( 1.2f ); glColor4f( 1.0f, 1.0f, 1.0f, 0.2f ); } else if( zoom > ( GRIDSEGS / 2.0 ) ) { continue; } else { glLineWidth( 0.8f ); glColor4f( 1.0f, 1.0f, 1.0f, 0.1f ); } glVertex2d( glViewRect[0], glGridPos ); glVertex2d( glViewRect[1], glGridPos ); } glEnd(); glPopMatrix(); drawTexCoords(); glDisable( GL_DEPTH_TEST ); glDepthMask( GL_FALSE ); if( ! selectRect.isNull() ) { glLoadIdentity(); glHighlightColor(); glBegin( GL_LINE_LOOP ); glVertex( mapToContents( selectRect.topLeft() ) ); glVertex( mapToContents( selectRect.topRight() ) ); glVertex( mapToContents( selectRect.bottomRight() ) ); glVertex( mapToContents( selectRect.bottomLeft() ) ); glEnd(); } if ( ! selectPoly.isEmpty() ) { glLoadIdentity(); glHighlightColor(); glBegin( GL_LINE_LOOP ); foreach ( QPoint p, selectPoly ) { glVertex( mapToContents( p ) ); }
/* draw the paddle */ int draw_paddle( ARPaddleInfo *paddleInfo, PaddleItemInfo *paddleItemInfo ) { double gl_para[16]; int i; argDrawMode3D(); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); argDraw3dCamera( 0, 0 ); argConvGlpara(paddleInfo->trans, gl_para); glMatrixMode(GL_MODELVIEW); glLoadMatrixd( gl_para ); glColor3f( 1.0, 0.0, 0.0 ); glLineWidth(4.0); glBegin(GL_LINE_LOOP); glVertex2f( -25.0, -25.0 ); glVertex2f( 25.0, -25.0 ); glVertex2f( 25.0, 25.0 ); glVertex2f( -25.0, 25.0 ); glEnd(); glColor3f( 0.0, 0.0, 1.0); glBegin(GL_LINE_LOOP); for( i = 0; i < 16; i++ ) { double x, y; x = PADDLE_RADIUS * cos(i*3.141592*2/16); y = PADDLE_RADIUS * sin(i*3.141592*2/16); glVertex2d( x, y ); } glEnd(); glBegin(GL_LINE_LOOP); glVertex2f( -7.5, 0.0 ); glVertex2f( 7.5, 0.0 ); glVertex2f( 7.5, -105.0 ); glVertex2f( -7.5, -105.0 ); glEnd(); glEnable(GL_BLEND); glBlendFunc(GL_ZERO,GL_ONE); glColor4f(1,1,1,0); glBegin(GL_POLYGON); for( i = 0; i < 16; i++ ) { double x, y; x = 40.0 * cos(i*3.141592*2/16); y = 40.0 * sin(i*3.141592*2/16); glVertex2d( x, y ); } glEnd(); glBegin(GL_POLYGON); glVertex2f( -7.5, 0.0 ); glVertex2f( 7.5, 0.0 ); glVertex2f( 7.5, -105.0 ); glVertex2f( -7.5, -105.0 ); glEnd(); glDisable(GL_BLEND); /* draw any objects on the paddle */ if( (i=paddleItemInfo->item) !=-1) { glPushMatrix(); glTranslatef( paddleItemInfo->x, paddleItemInfo->y, 10.0 ); glRotatef( paddleItemInfo->angle * 180.0/3.141592, 0.0, 0.0, 1.0 ); glColor3f(0.0,1.0,0.0); glutSolidSphere(10,10,10); // glutSolidTeapot(10.); glPopMatrix(); } glDisable(GL_DEPTH_TEST); argDrawMode2D(); return 0; }
/* Handler for window-repaint event. Call back when the window first appears and whenever the window needs to be re-painted. */ void display() { glClear(GL_COLOR_BUFFER_BIT); // Clear the color buffer with current clearing color // Define shapes enclosed within a pair of glBegin and glEnd glBegin(GL_QUADS); glColor3f(0.7f, 0.7f, 0.7f); glVertex2f(0.0f, 1.0f); glColor3f(0.5f, 0.5f, 0.5f); glVertex2f(0.0f, 0.0f); glColor3f(0.7f, 0.7f, 0.7f); glVertex2f(1.0f, 0.0f); glColor3f(0.5f, 0.5f, 0.5f); glVertex2f(1.0f, 1.0f); glEnd(); for(float i = 0.0; i < 1.0; i += 0.05){ glBegin(GL_LINES); glColor3f(0.3f, 0.3f, 0.3f); glVertex2f(0.0f, i); glVertex2f(1.0f, i); glEnd(); } for(float i = 0.0; i < 1.0; i += 0.05){ glBegin(GL_LINES); glColor3f(0.3f, 0.3f, 0.3f); glVertex2f(i, 0.0f); glVertex2f(i, 1.0f); glEnd(); } /*****************************************************************************/ /* AFISARE TRIUNGHIURI */ glBegin(GL_TRIANGLES); for(unsigned int i = 0; i < Tris.size(); i ++){ setRandomColor(); glVertex2f(Tris.at(i).at(0).getX(), Tris.at(i).at(0).getY()); glVertex2f(Tris.at(i).at(1).getX(), Tris.at(i).at(1).getY()); glVertex2f(Tris.at(i).at(2).getX(), Tris.at(i).at(2).getY()); } glEnd(); /*****************************************************************************/ /* AFISARE LINII concav concav = blue convex convex = red concav convex = yellow */ glEnable(GL_LINE_SMOOTH); glColor3dv(black); //glLineWidth(1.0); glBegin(GL_LINE_STRIP); for (unsigned int i = 0; i < Points.size(); i++){ if (i == (Points.size() - 1)){ if ((getPointType(i) == CONVEX) && (getPointType(0) == CONVEX)){ glColor3dv(red); glVertex2f(Points.at(i).getX(), Points.at(i).getY()); glVertex2f(Points.at(0).getX(), Points.at(0).getY()); } else if ((getPointType(i) == CONCAVE) && (getPointType(0) == CONCAVE)){ glColor3dv(blue); glVertex2f(Points.at(i).getX(), Points.at(i).getY()); glVertex2f(Points.at(0).getX(), Points.at(0).getY()); } else{ glColor3dv(yellow); glVertex2f(Points.at(i).getX(), Points.at(i).getY()); glVertex2f(Points.at(0).getX(), Points.at(0).getY()); } } else{ if ((getPointType(i) == CONVEX) && (getPointType(i + 1) == CONVEX)){ glColor3dv(red); glVertex2f(Points.at(i).getX(), Points.at(i).getY()); glVertex2f(Points.at(i + 1).getX(), Points.at(i + 1).getY()); } else if ((getPointType(i) == CONCAVE) && (getPointType(i + 1) == CONCAVE)){ glColor3dv(blue); glVertex2f(Points.at(i).getX(), Points.at(i).getY()); glVertex2f(Points.at(i + 1).getX(), Points.at(i + 1).getY()); } else{ glColor3dv(yellow); glVertex2f(Points.at(i).getX(), Points.at(i).getY()); glVertex2f(Points.at(i + 1).getX(), Points.at(i + 1).getY()); } } } glEnd(); /*****************************************************************************/ /* AFISARE PUNCTE convex = green concav = black */ glColor3dv(v); glPointSize(4.0); glBegin(GL_POINTS); for (unsigned int i = 0; i < Points.size(); i++){ if (getPointType(i) == CONVEX){ glColor3dv(green); glVertex2d(Points.at(i).getX(), Points.at(i).getY()); } else{ glColor3dv(black); glVertex2d(Points.at(i).getX(), Points.at(i).getY()); } } glEnd(); //glLineWidth(1.0); glFlush(); // Render now }
void CGLBase::Draw(double rot, int x,int y,int pattern) { //Rotate = Rotate + rot; //Image.x = Image.x + x; //Image.y = Image.y + y; //int ObjNum; CPoint touch; glClearColor(1.0, 1.0, 1.0, 1.0); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); //L字型になった時の描画処理 if(IsLshape) { //2枚目の下部 if(2760 < currentTouchPos.x && currentTouchPos.x < 3840 && 1010 < currentTouchPos.y) { GhostTouchPos.x = currentTouchPos.y + 2760; GhostTouchPos.y = 3840 - currentTouchPos.x; //3枚目の左 }else if(3830 <= currentTouchPos.x && currentTouchPos.x < 3910) { GhostTouchPos.x = 3840 - currentTouchPos.y; GhostTouchPos.y = currentTouchPos.x - 2760; if(1080 < GhostTouchPos.y) { Elaser.x = GhostTouchPos.x; Elaser.y = GhostTouchPos.y - 140; GhostTouchPos.y = 1079; //glColor3d(1.0,1.0,1.0); //DrawSquare(Elaser); } }else{ GhostTouchPos.x = -100; GhostTouchPos.y = -100; } } if(!IsLshape) GhostTouchPos = CPoint(-100,-100); if(m_CreateGoalFlag) DrawGoal(TargetPos[m_correct]); if(IsStandby && m_Moving == false) { if(IsLshape) { glClearColor(1.0, 1.0, 1.0, 1.0); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glPushMatrix(); glBegin(GL_QUADS); glColor3d(0.0,0.0,0.0); glVertex2d(-0.52, 0.1); glVertex2d(-0.52, -0.1); glVertex2d(-0.48, -0.1); glVertex2d(-0.48, 0.1); glEnd(); glPopMatrix(); }else{ glClearColor(1.0, 1.0, 1.0, 1.0); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glPushMatrix(); glBegin(GL_QUADS); glColor3d(0.0,0.0,0.0); glVertex2d(-0.02, 0.1); glVertex2d(-0.02, -0.1); glVertex2d( 0.02, -0.1); glVertex2d( 0.02, 0.1); glEnd(); glPopMatrix(); } //Sleep(3000); m_CreateGoalFlag = false; //IsStandby = false; IsFirstTouch = true; IsTasking = false; GhostObjectPos[m_correct] = ObjectPos[m_correct]; }else if(m_Moving == true){ glClearColor(1.0, 1.0, 1.0, 1.0); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); }else{ if(IsTaskFinish == true){ //タッチしていない状態 glColor3d(1.0,0.0,0.0); DrawSquare(ObjectPos[m_correct]); tmpObjectPos[m_correct] = ObjectPos[m_correct]; IsTaskFinish = false; //TRACE("スタート\n"); }else if(IsTasking == true && IsCorrectTouch == true) //ドラッグしている状態 { glColor3d(0.0,1.0,0.0); //if(1930 < currentTouchPos.x && currentTouchPos.y < 1080 && IsLined) // glColor3d(1.0,1.0,1.0); // if(!IsLshape) // glColor3d(1.0,1.0,1.0); DrawSquare(GhostTouchPos); //glColor3d(0.0,1.0,0.0); DrawSquare(currentTouchPos); }else if(IsTasking == false && IsCorrectTouch == true){ //手を放した状態 glColor3d(0.0,0.0,1.0); if(1930 < currentTouchPos.x && currentTouchPos.y < 1080 && IsLined) glColor3d(1.0,1.0,1.0); // if(!IsLshape) // glColor3d(1.0,1.0,1.0); DrawSquare(GhostTouchPos); glColor3d(0.0,0.0,1.0); DrawSquare(tmpObjectPos[m_correct]); }else{ //TRACE("ハズレ\n"); glColor3d(1.0,0.0,0.0); // if(!IsLshape) // glColor3d(1.0,1.0,1.0); DrawSquare(GhostTouchPos); glColor3d(1.0,0.0,0.0); DrawSquare(tmpObjectPos[m_correct]); //TRACE("(%d,%d)\n",currentTouchPos.x, currentTouchPos.y); } } if(IsLshape) { if(3830 <= currentTouchPos.x && currentTouchPos.x < 3910) { glColor3d(1.0,1.0,1.0); GhostTouchPos.y = 1080 + (currentTouchPos.x - 3980); DrawSquare(GhostTouchPos); Elaser.x = 3770; Elaser.y = currentTouchPos.y; DrawSquare(Elaser); } if(2760 < currentTouchPos.x && currentTouchPos.x < 3840 && 1010 < currentTouchPos.y) { Elaser.x = 3770; Elaser.y = 3840 - currentTouchPos.x; glColor3d(1.0,1.0,1.0); DrawSquare(Elaser); } } }
//Sprite Class Draw Function void msl::sprite::draw(const double x,const double y,const double rotation,const unsigned int frame, const double scale_x,const double scale_y, const msl::color& color,const bool smooth) const { //Bound Passed Frame unsigned int frame_bounded=std::min(_number_of_frames,frame); //Determine Frame Drawing Variables double frame_width_halfed=((_width/_number_of_frames)*scale_x)/2.0; double frame_height_halfed=(_height*scale_y)/2.0; double frame_to_draw_begin=(1.0/_number_of_frames)*frame_bounded; double frame_to_draw_end=(1.0/_number_of_frames)*(frame_bounded+1); //Enable Transparency glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); //Enable Texture glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,_texture); //Determine Texture Filter(Pixelated/Smooth) int filter=GL_NEAREST; if(smooth) filter=GL_LINEAR; //Set Texture Filters glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,filter); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,filter); //Limit Rotation double rotation_limited=rotation; while(rotation_limited>=360) rotation_limited-=360; while(rotation_limited<=0) rotation_limited+=360; //Draw Image Frame with Rotation and Alpha Value (0.001 and 0.999 are to Remove Bad Borders) glPushMatrix(); glTranslated(x,y,0); glRotated(rotation_limited+180,0,0,1); glTranslated(_origin_x*scale_x,_origin_y*scale_y,0); glBegin(GL_QUADS); glColor4d(color.r,color.g,color.b,color.a); glTexCoord2d(frame_to_draw_begin+0.001,0.999); glVertex2d(frame_width_halfed,frame_height_halfed); glTexCoord2d(frame_to_draw_end-0.001,0.999); glVertex2d(-frame_width_halfed,frame_height_halfed); glTexCoord2d(frame_to_draw_end-0.001,0.001); glVertex2d(-frame_width_halfed,-frame_height_halfed); glTexCoord2d(frame_to_draw_begin+0.001,0.001); glVertex2d(frame_width_halfed,-frame_height_halfed); glColor4f(1,1,1,1); glEnd(); glPopMatrix(); //Disable Texture glDisable(GL_TEXTURE_2D); //Disable Transparency glDisable(GL_BLEND); }
void az_draw_particle(const az_particle_t *particle, az_clock_t clock) { assert(particle->kind != AZ_PAR_NOTHING); assert(particle->age <= particle->lifetime); switch (particle->kind) { case AZ_PAR_NOTHING: AZ_ASSERT_UNREACHABLE(); case AZ_PAR_BOOM: glBegin(GL_TRIANGLE_FAN); { with_color_alpha(particle->color, 0); glVertex2d(0, 0); const double ratio = particle->age / particle->lifetime; with_color_alpha(particle->color, 1 - ratio * ratio); const double radius = particle->param1 * ratio; for (int i = 0; i <= 16; ++i) { glVertex2d(radius * cos(i * AZ_PI_EIGHTHS), radius * sin(i * AZ_PI_EIGHTHS)); } } glEnd(); break; case AZ_PAR_BEAM: { const double alpha = (particle->lifetime <= 0.0 ? 1.0 : 1.0 - particle->age / particle->lifetime); glBegin(GL_QUAD_STRIP); { with_color_alpha(particle->color, 0); glVertex2d(0, particle->param2); glVertex2d(particle->param1, particle->param2); with_color_alpha(particle->color, alpha); glVertex2d(0, 0); glVertex2d(particle->param1, 0); with_color_alpha(particle->color, 0); glVertex2d(0, -particle->param2); glVertex2d(particle->param1, -particle->param2); } glEnd(); glBegin(GL_TRIANGLE_FAN); { with_color_alpha(particle->color, alpha); glVertex2d(particle->param1, 0); with_color_alpha(particle->color, 0); for (int i = -90; i <= 90; i += 30) { glVertex2d(particle->param1 + particle->param2 * cos(AZ_DEG2RAD(i)) * 0.75, particle->param2 * sin(AZ_DEG2RAD(i))); } } glEnd(); } break; case AZ_PAR_CHARGED_BOOM: { const double factor = particle->age / particle->lifetime; const double major = sqrt(factor) * particle->param1; const double minor = (1 - factor) * particle->param2; const double alpha = 1 - factor; glBegin(GL_QUAD_STRIP); { const double outer = major + minor; for (int i = 0; i <= 360; i += 20) { with_color_alpha(particle->color, 0); glVertex2d(outer * cos(AZ_DEG2RAD(i)), outer * sin(AZ_DEG2RAD(i))); with_color_alpha(particle->color, alpha); glVertex2d(major * cos(AZ_DEG2RAD(i)), major * sin(AZ_DEG2RAD(i))); } } glEnd(); glBegin(GL_QUAD_STRIP); { const double inner = fmax(0, major - minor); const double beta = alpha * (1 - fmin(major, minor) / minor); for (int i = 0; i <= 360; i += 20) { with_color_alpha(particle->color, alpha); glVertex2d(major * cos(AZ_DEG2RAD(i)), major * sin(AZ_DEG2RAD(i))); with_color_alpha(particle->color, beta); glVertex2d(inner * cos(AZ_DEG2RAD(i)), inner * sin(AZ_DEG2RAD(i))); } } glEnd(); } break; case AZ_PAR_EMBER: glBegin(GL_TRIANGLE_FAN); { with_color_alpha(particle->color, 1); glVertex2f(0, 0); with_color_alpha(particle->color, 0); const double radius = particle->param1 * (1.0 - particle->age / particle->lifetime); for (int i = 0; i <= 360; i += 30) { glVertex2d(radius * cos(AZ_DEG2RAD(i)), radius * sin(AZ_DEG2RAD(i))); } } glEnd(); break; case AZ_PAR_EXPLOSION: glBegin(GL_QUAD_STRIP); { const double tt = 1.0 - particle->age / particle->lifetime; const double inner_alpha = tt * tt; const double outer_alpha = tt; const double inner_radius = particle->param1 * (1.0 - tt * tt * tt); const double outer_radius = particle->param1; for (int i = 0; i <= 360; i += 6) { const double c = cos(AZ_DEG2RAD(i)), s = sin(AZ_DEG2RAD(i)); with_color_alpha(particle->color, inner_alpha); glVertex2d(inner_radius * c, inner_radius * s); with_color_alpha(particle->color, outer_alpha); glVertex2d(outer_radius * c, outer_radius * s); } } glEnd(); break; case AZ_PAR_FIRE_BOOM: { const int i_step = 10; const double liveness = 1.0 - particle->age / particle->lifetime; const double x_radius = particle->param1; const double y_radius = particle->param1 * liveness; for (int i = 0; i < 180; i += i_step) { glBegin(GL_TRIANGLE_STRIP); { const int limit = 180 * liveness; for (int j = 0; j < limit; j += 20) { glColor4f(1.0, 0.75 * j / limit, 0.0, 0.35 + 0.25 * sin(AZ_DEG2RAD(i)) * sin(AZ_DEG2RAD(j)) - 0.35 * j / limit); const double x = x_radius * cos(AZ_DEG2RAD(j)); glVertex2d(x, y_radius * cos(AZ_DEG2RAD(i)) * sin(AZ_DEG2RAD(j))); glVertex2d(x, y_radius * cos(AZ_DEG2RAD(i + i_step)) * sin(AZ_DEG2RAD(j))); } glVertex2d(x_radius * cos(AZ_DEG2RAD(limit)), y_radius * cos(AZ_DEG2RAD(i + i_step/2)) * sin(AZ_DEG2RAD(limit))); } glEnd(); } } break; case AZ_PAR_ICE_BOOM: { const double t0 = particle->age / particle->lifetime; const double t1 = 1.0 - t0; glBegin(GL_TRIANGLE_FAN); { with_color_alpha(particle->color, 0); glVertex2f(0, 0); with_color_alpha(particle->color, t1 * t1 * t1); for (int i = 0; i <= 360; i += 6) { glVertex2d(particle->param1 * cos(AZ_DEG2RAD(i)), particle->param1 * sin(AZ_DEG2RAD(i))); } } glEnd(); glPushMatrix(); { const double rx = 0.65 * particle->param1; const double ry = sqrt(3.0) * rx / 3.0; const double cx = fmin(1, 4 * t0) * rx; for (int i = 0; i < 6; ++i) { glBegin(GL_TRIANGLE_FAN); { with_color_alpha(particle->color, t1); glVertex2d(cx, 0); with_color_alpha(particle->color, t1 * t1); glVertex2d(cx + rx, 0); glVertex2d(cx, ry); glVertex2d(cx - rx, 0); glVertex2d(cx, -ry); glVertex2d(cx + rx, 0); } glEnd(); glRotatef(60, 0, 0, 1); } } glPopMatrix(); } break; case AZ_PAR_LIGHTNING_BOLT: if (particle->age >= particle->param2) { const int num_steps = az_imax(2, round(particle->param1 / 10.0)); const double step = particle->param1 / num_steps; az_random_seed_t seed = { clock / 5, 194821.0 * particle->angle }; az_vector_t prev = {0, 0}; for (int i = 1; i <= num_steps; ++i) { const az_vector_t next = (i == num_steps ? (az_vector_t){particle->param1, 0} : (az_vector_t){3.0 * az_rand_sdouble(&seed) + i * step, 10.0 * az_rand_sdouble(&seed)}); const az_vector_t side = az_vwithlen(az_vrot90ccw(az_vsub(next, prev)), 4); glBegin(GL_TRIANGLE_STRIP); { with_color_alpha(particle->color, 0); az_gl_vertex(az_vadd(prev, side)); az_gl_vertex(az_vadd(next, side)); glColor4f(1, 1, 1, 0.5); az_gl_vertex(prev); az_gl_vertex(next); with_color_alpha(particle->color, 0); az_gl_vertex(az_vsub(prev, side)); az_gl_vertex(az_vsub(next, side)); } glEnd(); prev = next; } draw_bolt_glowball(particle->color, particle->param1, clock); } draw_bolt_glowball(particle->color, 0, clock); break; case AZ_PAR_OTH_FRAGMENT: glRotated(particle->age * AZ_RAD2DEG(particle->param2), 0, 0, 1); glBegin(GL_TRIANGLES); { const double radius = (particle->param1 >= 0.0 ? particle->param1 * (1.0 - particle->age / particle->lifetime) : -particle->param1 * (particle->age / particle->lifetime)); const az_color_t color = particle->color; for (int i = 0; i < 3; ++i) { const az_clock_t clk = clock + 2 * i; glColor4ub((az_clock_mod(6, 1, clk) < 3 ? color.r : color.r / 4), (az_clock_mod(6, 1, clk + 2) < 3 ? color.g : color.g / 4), (az_clock_mod(6, 1, clk + 4) < 3 ? color.b : color.b / 4), color.a); glVertex2d(radius * cos(AZ_DEG2RAD(i * 120)), radius * sin(AZ_DEG2RAD(i * 120))); } } glEnd(); break; case AZ_PAR_NPS_PORTAL: { const double progress = particle->age / particle->lifetime; const double scale = 1 - 2 * fabs(progress - 0.5); const double tscale = fmax(0, 1 - pow(2.25 * progress - 1.25, 2)); // Tendrils: for (int i = 0; i < 10; ++i) { const double theta = AZ_DEG2RAD(i * 36); const az_vector_t tip = az_vadd(az_vpolar(1.1 * particle->param1 * tscale, theta), az_vpolar(15 * tscale, particle->age * AZ_DEG2RAD(180) * ((i % 3) + 1))); const az_vector_t ctrl1 = az_vadd(az_vpolar(0.8 * particle->param1 * tscale, theta), az_vpolar(10 * sin(particle->age * AZ_DEG2RAD(400)), theta + AZ_HALF_PI)); const az_vector_t ctrl2 = az_vadd(az_vpolar(0.4 * particle->param1 * tscale, theta), az_vpolar(10 * cos(particle->age * AZ_DEG2RAD(400)), theta + AZ_HALF_PI)); az_draw_oth_tendril(AZ_VZERO, ctrl1, ctrl2, tip, 5 * tscale, 1.0f, clock); } // Portal: glBegin(GL_TRIANGLE_FAN); { const GLfloat r = (az_clock_mod(6, 1, clock) < 3 ? 1.0f : 0.25f); const GLfloat g = (az_clock_mod(6, 1, clock + 2) < 3 ? 1.0f : 0.25f); const GLfloat b = (az_clock_mod(6, 1, clock + 4) < 3 ? 1.0f : 0.75f); glColor4f(r, g, b, 1.0f); glVertex2f(0, 0); glColor4f(r, g, b, 0.15f); const double radius = particle->param1 * scale; for (int i = 0; i <= 360; i += 10) { glVertex2d(radius * cos(AZ_DEG2RAD(i)), radius * sin(AZ_DEG2RAD(i))); } } glEnd(); } break; case AZ_PAR_ROCK: glScaled(particle->param1, particle->param1, 1); glRotated(particle->age * AZ_RAD2DEG(particle->param2), 0, 0, 1); glBegin(GL_TRIANGLE_FAN); { const double progress = particle->age / particle->lifetime; const az_color_t black = {0, 0, 0, 255}; az_gl_color(az_transition_color(particle->color, black, progress)); glVertex2f(0, 0); az_gl_color(az_transition_color(particle->color, black, 0.7 + 0.3 * progress)); glVertex2f(4, 0); glVertex2f(1, 4); glVertex2f(-1, 5); glVertex2f(-2, 0); glVertex2f(-1, -2); glVertex2f(1, -3); glVertex2f(4, 0); } glEnd(); break; case AZ_PAR_SHARD: glScaled(particle->param1, particle->param1, 1); glRotated(particle->age * AZ_RAD2DEG(particle->param2), 0, 0, 1); glBegin(GL_TRIANGLES); { az_color_t color = particle->color; const double alpha = 1.0 - particle->age / particle->lifetime; with_color_alpha(color, alpha); glVertex2f(2, 3); color.r *= 0.6; color.g *= 0.6; color.b *= 0.6; with_color_alpha(color, alpha); glVertex2f(-2, 4); color.r *= 0.6; color.g *= 0.6; color.b *= 0.6; with_color_alpha(color, alpha); glVertex2f(0, -4); } glEnd(); break; case AZ_PAR_SPARK: glBegin(GL_TRIANGLE_FAN); { glColor4f(1, 1, 1, 0.8); glVertex2f(0, 0); with_color_alpha(particle->color, 0); const double radius = particle->param1 * (1.0 - particle->age / particle->lifetime); const double theta_offset = particle->param2 * particle->age; for (int i = 0; i <= 360; i += 45) { const double rho = (i % 2 ? 1.0 : 0.5) * radius; const double theta = AZ_DEG2RAD(i) + theta_offset; glVertex2d(rho * cos(theta), rho * sin(theta)); } } glEnd(); break; case AZ_PAR_SPLOOSH: glBegin(GL_TRIANGLE_FAN); { with_color_alpha(particle->color, 1); glVertex2f(0, 0); with_color_alpha(particle->color, 0); const GLfloat height = particle->param1 * sin(AZ_PI * particle->age / particle->lifetime); const GLfloat semiwidth = particle->param2; glVertex2f(0, semiwidth); glVertex2f(0.3f * height, 0.5f * semiwidth); glVertex2f(height, 0); glVertex2f(0.3f * height, -0.5f * semiwidth); glVertex2f(0, -semiwidth); glVertex2f(-0.05f * height, 0); glVertex2f(0, semiwidth); } glEnd(); break; case AZ_PAR_TRAIL: { const double scale = 1.0 - particle->age / particle->lifetime; const double alpha = scale * scale * scale; const double semiwidth = alpha * particle->param2; glBegin(GL_TRIANGLE_STRIP); { with_color_alpha(particle->color, 0); glVertex2d(0, semiwidth); glVertex2d(particle->param1, semiwidth); with_color_alpha(particle->color, alpha); glVertex2d(0, 0); glVertex2d(particle->param1, 0); with_color_alpha(particle->color, 0); glVertex2d(0, -semiwidth); glVertex2d(particle->param1, -semiwidth); } glEnd(); } break; } }
void Laser::Draw() { if (state) { //TODO: set up shade model in game engine when possible //glShadeModel(GL_SMOOTH); /* double dirX = direction.x * WINDOW_DIAG; double dirY = direction.y * WINDOW_DIAG; double widX = direction.y * width; double widY = -direction.x * width; glBegin(GL_QUADS); glColor3ubv(color.arr()); glVertex2d(position.x + widX, position.y + widY); glVertex2d(position.x + widX + dirX, position.y + widY + dirY); glColor3ubv(gWhite.arr()); glVertex2d(position.x + dirX, position.y + dirY); glVertex2d(position.x, position.y); glVertex2d(position.x + dirX, position.y + dirY); glVertex2d(position.x, position.y); glColor3ubv(color.arr()); glVertex2d(position.x - widX, position.y - widY); glVertex2d(position.x - widX + dirX, position.y - widY + dirY); glEnd(); */ glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE); glColor3ubv(color.arr()); texture.Draw(position + direction * WINDOW_DIAG / 2, direction, 2 * (int)width, WINDOW_DIAG); glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE); /* Electricity effect, consists of random poly lines */ glColor3ub(250, 250, 255); glBegin(GL_LINE_STRIP); double randX = 0.0, randY = 0.0; Vector2 temp(position); Vector2 point; Vector2 perpendicular(direction.y, -direction.x); /* generate electricity until reaches edge of screen */ while (temp.x > 0 && temp.x < WINDOW_WID && temp.y > 0 && temp.y < WINDOW_HEI) { randX = rand()%(2*(int)width+8) - width - 4; randY = rand() % 80; point = temp + perpendicular * randX; glVertex2d(point.x, point.y); temp += direction * randY; /* random break */ if (rand()%5 == 0) { glEnd(); glBegin(GL_LINE_STRIP); } } glEnd(); } }
void gpuPictoString::update(){ float w = testApp::getW(); float h = testApp::getH(); if(bNeedUpdateCharPos){ charPosList = calcCharPos(); bNeedUpdateCharPos = false; } int total = gpuPicto::totalPicto; int totalPix = textureRes*textureRes; // manual mipmap // *** should check icon size resizeIcon(h); int iconSize = prm.iconSize * h; iconSize*=0.5; if(iconSize<1){ iconSize=1; } // // nomad // bool bNomad = true; if(bNomad){ if(total>0 && ofRandom(1.0)>0.95){ if(gpchars.size()>2){ int charIndexA = (int)ofRandom(2, gpchars.size()-2); int charIndexB = charIndexA + (int)ofRandom(-2, 2); if(charIndexA!=charIndexB){ int numPictoA = gpchars[charIndexA]->numPicto; int numPictoB = gpchars[charIndexB]->numPicto; int firstIdA = gpchars[charIndexA]->firstIndex; int firstIdB = gpchars[charIndexB]->firstIndex; int indexA = ofRandom(firstIdA, numPictoA-1); int indexB = ofRandom(firstIdB, numPictoB-1); float attractOnA = springPrmData[indexA*4+3]; float attractOnB = springPrmData[indexB*4+3]; if(attractOnA<0 && attractOnB<0){ float Ax = finalTargetPosData[indexA*3 + 0]; float Ay = finalTargetPosData[indexA*3 + 1]; finalTargetPosData[indexA*3 + 0] = finalTargetPosData[indexB*3 + 0]; finalTargetPosData[indexA*3 + 1] = finalTargetPosData[indexB*3 + 1]; finalTargetPosData[indexB*3 + 0] = Ax; finalTargetPosData[indexB*3 + 1] = Ay; finalTargetTex.loadData(finalTargetPosData, textureRes, textureRes, GL_RGB); } } } } } { // offset = attractor::getPos(); const ofVec2f& attr = attractor::getPos(); float K = 20; float maxSpeed = 0.05; ofVec2f dir = attr - offset; ofVec2f acc = K * 0.000167 * dir; offsetVel += acc; offsetVel.limit(maxSpeed); offset += offsetVel; ofVec2f dirf = attr - offset; if(dirf.length() > 0.1){ offset += dirf - dirf.normalized() * 0.1; } } // // check pictoChar // bool shouldUpdateSpringTexture = false; GPICTO_STR_ITR itr = gpchars.begin(); int particleMax = textureRes*textureRes; for(; itr!=gpchars.end(); itr++){ if((*itr)->spreadCheck()){ shouldUpdateSpringTexture = true; int index = (*itr)->firstIndex; int numPicto = (*itr)->numPicto; if(index<=particleMax){ for(int i=0; i<numPicto; i++){ springPrmData[index*4 + 3] = -1; // attractOn index++; if(index>particleMax){ index = 0; } } } } } if(clearCheck()){ clearAll(); bNeedUpdateCharPos = true; } if(testApp::bAutoPlay) shouldStartNextCheck(); if(shouldUpdateSpringTexture){ springPrmTex.loadData(springPrmData, textureRes, textureRes, GL_RGBA); } // // make random tex // // if(ofGetFrameNum()%3 == 0){ for(int index=0; index<total; index++){ randomData[index*3 + 0] = ofRandom(1.0); randomData[index*3 + 1] = ofRandom(1.0); randomData[index*3 + 2] = ofRandom(1.0); // randomData[index*4 + 3] = ofRandom(1.0); } randomTex.loadData(randomData, textureRes, textureRes, GL_RGB); // } // // 1. calc vel // velPingPong.dst->begin();{ ofClear(0); updateVel.begin();{ updateVel.setUniformTexture("backbuffer", velPingPong.src->getTextureReference(), 0); updateVel.setUniformTexture("posData", posPingPong.src->getTextureReference(), 1); updateVel.setUniformTexture("springData", springPrmTex, 2); updateVel.setUniformTexture("randomData", randomTex, 3); updateVel.setUniformTexture("targetData", finalTargetTex, 4); updateVel.setUniform1i("resolution", (int)textureRes); updateVel.setUniform2f("screen", (float)width, (float)height); updateVel.setUniform2f("offset", (float)offset.x, (float)offset.y); updateVel.setUniform2f("pastOffset", (float)pastOffset.x, (float)pastOffset.y); updateVel.setUniform1f("timestep", (float)timeStep); updateVel.setUniform1f("ACCEL",(float) prm.accel ); updateVel.setUniform1f("SPEED",(float) prm.speed); updateVel.setUniform1f("VIBRATION",(float) prm.vibration ); // draw the source velocity texture to be updated velPingPong.src->draw(0, 0); }updateVel.end(); }velPingPong.dst->end(); velPingPong.swap(); // // 2. calc pos // posPingPong.dst->begin();{ ofClear(0); updatePos.begin();{ updatePos.setUniformTexture("prevPosData", posPingPong.src->getTextureReference(), 0); // Previus position updatePos.setUniformTexture("velData", velPingPong.src->getTextureReference(), 1); // Velocity updatePos.setUniformTexture("springData", springPrmTex, 2); updatePos.setUniform1f("timestep",(float) timeStep ); // updatePos.setUniform2f("offset", (float)offset.x, (float)offset.y); // updatePos.setUniform2f("pastOffset", (float)pastOffset.x, (float)pastOffset.y); posPingPong.src->draw(0, 0); }updatePos.end(); }posPingPong.dst->end(); posPingPong.swap(); // // 3. render // renderFBO.begin(); ofClear(testApp::getBackgroundColor()); // ofClear(0); //ofClear(0, 0, 0, 0); updateRender.begin(); updateRender.setUniformTexture("posTex", posPingPong.dst->getTextureReference(), 0); updateRender.setUniformTexture("sparkTex", img->getTextureReference() , 1); updateRender.setUniformTexture("iconPrmTex", iconPrmTex, 2); updateRender.setUniformTexture("springData", springPrmTex, 3); updateRender.setUniform1i("resolution", (float)textureRes); updateRender.setUniform2f("screen", (float)testApp::getW(), (float)testApp::getH()); updateRender.setUniform1i("size", (int)iconSize); updateRender.setUniform1f("imgWidth", imgSize); updateRender.setUniform1f("imgHeight", imgSize); // updateRender.setUniform2f("offset", (float)offset.x, (float)offset.y); ofPushStyle(); //ofEnableBlendMode( OF_BLENDMODE_ADD ); ofEnableBlendMode( OF_BLENDMODE_ALPHA); ofEnableAlphaBlending(); ofEnableSmoothing(); ofSetColor(255); glBegin( GL_POINTS ); int count = 0; for(int y = 0; y < textureRes; y++){ for(int x = 0; x < textureRes; x++){ if(count >= total) break; count++; glVertex2d(x,y); glTexCoord2i(x, y); } if(count >= total) break; } ofDisableBlendMode(); glEnd(); updateRender.end(); if(testApp::getDebugDraw()){ { // Attractor const ofVec2f& attr = attractor::getPos(); ofFill(); ofSetColor(255, 55, 0); ofRect(attr.x*w, attr.y*h, 10, 10); ofFill(); ofSetColor(5, 255, 0); ofRect(pastOffset.x*w, pastOffset.y*h, 10, 10); ofFill(); ofSetColor(0, 5, 220); ofRect(offset.x*w, offset.y*h, 10, 10); } { // + line if(testApp::bWallMapMouseAdjust){ ofSetColor(0, 255, 0); }else{ ofSetColor(255, 0, 0); } glBegin(GL_LINES); glVertex3f(w/2, 0, 0); glVertex3f(w/2, h, 0); glVertex3f(0, h/2, 0); glVertex3f(w, h/2, 0); glVertex3f(1, 1, 0); glVertex3f(w-1, 1, 0); glVertex3f(1, h-1, 0); glVertex3f(w-1, h-1, 0); glVertex3f(1, 1, 0); glVertex3f(1, h-1, 0); glVertex3f(w-1, 1, 0); glVertex3f(w-1, h-1, 0); glVertex3f(1, 1, 0); glVertex3f(w-1, h-1, 0); glVertex3f(w-1, 1, 0); glVertex3f(1, h-1, 0); glEnd(); } } if(testApp::bShowInfo){ ofPushMatrix();{ ofTranslate(0,0); ofSetColor(ofColor(255,255,255)-testApp::bg); ofFill(); ofRect(0, 0, w, 30); ofSetColor(testApp::bg); int y = 23; ofDrawBitmapString("fps: " + ofToString(ofGetFrameRate()),20,y); ofDrawBitmapString("picto num: " + ofToString(gpuPicto::totalPicto), 200, y); ofDrawBitmapString("Frame num: " + ofToString(ofGetFrameNum()), 400, y); }ofPopMatrix(); } renderFBO.end(); ofPopStyle(); pastOffset = offset; }
void GNECrossing::drawGL(const GUIVisualizationSettings& s) const { // only draw if option drawCrossingsAndWalkingareas is enabled and size of shape is greather than 0 and zoom is close enough if (s.drawCrossingsAndWalkingareas && (myShapeRotations.size() > 0) && (myShapeLengths.size() > 0) && (s.scale > 3.0)) { auto crossing = myParentJunction->getNBNode()->getCrossing(myCrossingEdges); if (s.editMode != GNE_NMODE_TLS) { // push first draw matrix glPushMatrix(); // push name glPushName(getGlID()); // must draw on top of junction glTranslated(0, 0, GLO_JUNCTION + 0.1); // set color depending of selection and priority if (drawUsingSelectColor()) { glColor3d(0.118, 0.565, 1.000); } else if (!crossing->valid) { glColor3d(1.0, 0.1, 0.1); } else if (crossing->priority) { glColor3d(0.9, 0.9, 0.9); } else { glColor3d(0.1, 0.1, 0.1); } // traslate to front glTranslated(0, 0, .2); // set default values double length = 0.5; double spacing = 1.0; double halfWidth = crossing->width * 0.5; // push second draw matrix glPushMatrix(); // draw on top of of the white area between the rails glTranslated(0, 0, 0.1); for (int i = 0; i < (int)myShape.size() - 1; ++i) { // push three draw matrix glPushMatrix(); // translate and rotate glTranslated(myShape[i].x(), myShape[i].y(), 0.0); glRotated(myShapeRotations[i], 0, 0, 1); // draw crossing depending if isn't being drawn for selecting if (!s.drawForSelecting) { for (double t = 0; t < myShapeLengths[i]; t += spacing) { glBegin(GL_QUADS); glVertex2d(-halfWidth, -t); glVertex2d(-halfWidth, -t - length); glVertex2d(halfWidth, -t - length); glVertex2d(halfWidth, -t); glEnd(); } } else { // only draw a single rectangle if it's being drawn only for selecting glBegin(GL_QUADS); glVertex2d(-halfWidth, 0); glVertex2d(-halfWidth, -myShapeLengths.back()); glVertex2d(halfWidth, -myShapeLengths.back()); glVertex2d(halfWidth, 0); glEnd(); } // pop three draw matrix glPopMatrix(); } // XXX draw junction index / tls index // pop second draw matrix glPopMatrix(); // traslate to back glTranslated(0, 0, -.2); // pop name glPopName(); // pop draw matrix glPopMatrix(); } // link indices must be drawn in all edit modes if isn't being drawn for selecting if (s.drawLinkTLIndex.show && !s.drawForSelecting) { drawTLSLinkNo(s); } // check if dotted contour has to be drawn if (!s.drawForSelecting && (myNet->getViewNet()->getDottedAC() == this)) { GLHelper::drawShapeDottedContour(getType(), myShape, crossing->width * 0.5); } } }
void View::draw_discrete_scale(int numboxes, const char* boxnames[], const float boxcolors[][3]) { set_ortho_projection(true); glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glDisable(GL_TEXTURE_1D); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); // background const int b = 5; glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(1.0f, 1.0f, 1.0f, 0.65f); glBegin(GL_QUADS); glVertex2d(scale_x - b, scale_y - b); glVertex2d(scale_x - b, scale_y + scale_height + b+1); glVertex2d(scale_x + scale_width + b+1, scale_y + scale_height + b+1); glVertex2d(scale_x + scale_width + b+1, scale_y - b); glEnd(); // boxes glDisable(GL_BLEND); int y = scale_y; for (int i = 0; i < numboxes; i++) { glColor3f(0.0, 0.0, 0.0); glBegin(GL_QUADS); glVertex2d(scale_x, y); glVertex2d(scale_x, y + scale_box_height + 1); glVertex2d(scale_x + scale_width + 1, y + scale_box_height + 1); glVertex2d(scale_x + scale_width + 1, y); glEnd(); const float* color = boxcolors[numboxes-1-i]; float bcolor[3] = { color[0], color[1], color[2] }; if (scale_focused) { bcolor[0] = color[0]*0.7f + 1.0f*0.3f; bcolor[1] = color[1]*0.7f + 1.0f*0.3f; bcolor[2] = color[2]*0.7f + 1.0f*0.3f; } glColor3f(bcolor[0], bcolor[1], bcolor[2]); glBegin(GL_QUADS); glVertex2d(scale_x+1, y+1); glVertex2d(scale_x+1, y + scale_box_height); glVertex2d(scale_x + scale_width, y + scale_box_height); glVertex2d(scale_x + scale_width, y+1); glEnd(); if ((color[0] + color[1] + color[2]) / 3 > 0.5) glColor3f(0, 0, 0); else glColor3f(1, 1, 1); int a = scale_x + scale_width/2; int b = y + scale_box_height/2; draw_text(a, b, boxnames[numboxes-1-i], 0); draw_text(a+1, b, boxnames[numboxes-1-i], 0); y += scale_box_height + scale_box_skip; } }
/* CTextureCanvas::drawTextureBorder * Draws a black border around the texture *******************************************************************/ void CTextureCanvas::drawTextureBorder() { // Draw the texture border double ext = 0.11; glLineWidth(2.0f); OpenGL::setColour(COL_BLACK); glBegin(GL_LINE_LOOP); glVertex2d(-ext, -ext); glVertex2d(-ext, texture->getHeight()+ext); glVertex2d(texture->getWidth()+ext, texture->getHeight()+ext); glVertex2d(texture->getWidth()+ext, -ext); glEnd(); glLineWidth(1.0f); // Draw vertical ticks int y = 0; glColor4f(0.0f, 0.0f, 0.0f, 0.6f); while (y <= texture->getHeight()) { glBegin(GL_LINES); glVertex2i(-4, y); glVertex2i(0, y); glVertex2i(texture->getWidth(), y); glVertex2i(texture->getWidth() + 4, y); glEnd(); y += 8; } // Draw horizontal ticks int x = 0; while (x <= texture->getWidth()) { glBegin(GL_LINES); glVertex2i(x, -4); glVertex2i(x, 0); glVertex2i(x, texture->getHeight()); glVertex2i(x, texture->getHeight() + 4); glEnd(); x += 8; } // Draw grid if (show_grid) { // Draw inverted grid lines glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); // Vertical y = 8; while (y <= texture->getHeight() - 8) { glBegin(GL_LINES); glVertex2i(0, y); glVertex2i(texture->getWidth(), y); glEnd(); y += 8; } // Horizontal x = 8; while (x <= texture->getWidth() - 8) { glBegin(GL_LINES); glVertex2i(x, 0); glVertex2i(x, texture->getHeight()); glEnd(); x += 8; } // Darken grid lines glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(0.0f, 0.0f, 0.0f, 0.5f); // Vertical y = 8; while (y <= texture->getHeight() - 8) { glBegin(GL_LINES); glVertex2i(0, y); glVertex2i(texture->getWidth(), y); glEnd(); y += 8; } // Horizontal x = 8; while (x <= texture->getWidth() - 8) { glBegin(GL_LINES); glVertex2i(x, 0); glVertex2i(x, texture->getHeight()); glEnd(); x += 8; } } }
void ConsoleWindow::drawUILayer() { glLineWidth ( 3.0 ); // _contentWindow.outlineRounded(0.05); // _cubeWindow.outlineRounded(0.05); Audicle* audi = Audicle::instance(); double glomod = fabs( -1.0 + 2.0 * ( m_time * 0.6 - floor(m_time * 0.6 ) ) ); double xdiv = 0.5 * ( _cubeWindow.right() + _contentWindow.left() ) ; glBegin(GL_LINES); glColor4d ( 0.2,0.2, 0.2, 1.0 ); glVertex2d ( xdiv, _cubeWindow.top() - _marginSize ); glVertex2d ( xdiv, _cubeWindow.bottom() + _marginSize ); glEnd(); _sizeBox.outlineRounded(); glLineWidth(1.5); _curLabel.draw( 0.75 ); _curDisplay.draw( 0.75 ); if ( _active ) { _prevLabel.draw( 0.75 ); _prevDisplay.draw( 0.75 ); } static char buffer[256]; double time = the()->shreduler()->now_system; int sr = Digitalio::sampling_rate(); //m_sampling_rate; int samp = (int) time; int sec = samp / sr; int min = ( sec / 60 ) ; int hr = ( min / 60 ) ; int day = ( hr / 24 ); samp = samp % sr; sec = sec % 60; min = min % 60; hr = hr % 24; if ( day ) sprintf(buffer, "%dd:%02d:%02d:%02d.%05d", day, hr, min, sec, samp ); else if ( hr ) sprintf(buffer, "%02d:%02d:%02d.%05d", hr, min, sec, samp ); else if ( min ) sprintf(buffer, "%02d:%02d.%05d", min, sec, samp ); else if ( sec ) sprintf(buffer, "%02d.%05d", sec, samp ); else sprintf(buffer, "%05d", samp ); _timeDisplay.setLabel( buffer ) ; _timeDisplay.fitLabel( 1 ); _timeDisplay.setw( _timeDisplay.w() * 0.70 ); _timeDisplay.filledRounded( 0.03 ); _timeDisplay.drawLabel( 0.75, 1 ); _timeDisplay.outlineRounded( 0.03 ); glPushName( _timeLabel.id() ); Color4D tdark = Color4D( 0.6, 0.9, 0.6, 1.0 ); Color4D tglow = tdark.interp( _timeLabel.col(), glomod * 1.2 ); tglow[3] = 1.0; _timeLabel.setCol( tglow ); glBegin( GL_POLYGON ); _timeLabel.roundVerts( ); glEnd( ); _timeLabel.drawLeadedLabel( 0.75, 0.15 ); _timeLabel.outlineRounded( ); glPopName(); if ( _active ) { glLineWidth( 3.0 ); glPushMatrix(); double cubh = _cubeSides[0].h(); glTranslated ( _cubeWindow.center()[0] - cubh * 3.5 , _cubeWindow.center()[1] + cubh * 1.5, 0 ); if ( _cube_swapping ) { double w = ( m_time - _cube_swap_start ) / _cube_swap_span ; if ( w > 1.0 ) { _cube_swapping = false ; for ( int i = 0 ; i < 6 ; i++ ) _swapPos[i] = _cubeSides[i].pos(); } else if ( w > 0 ) { for ( int i = 0; i < 6 ; i++ ) { glPushMatrix(); glPushName( _cubeSides[i].id() ); Point2D animp = _swapPos[i].interp ( _cubeSides[i].pos() , w ); glTranslated( animp[0] - _cubeSides[i].pos()[0], \ animp[1] - _cubeSides[i].pos()[1], 0 ); _cubeSides[i].drawQuad( 0.75 ); glPopName(); glPopMatrix(); } } } if ( !_cube_swapping ) { for ( int i = 0 ; i < 6; i++ ) { glPushName( _cubeSides[i].id() ); _cubeSides[i].drawQuad( 0.75 ); glPopName(); } } t_CKUINT cur = audi->look_here(); Point2D _cube_spot( cubh * 6.0 , -cubh * 1.5 ); glPushMatrix(); glTranslated ( _cube_spot[0], _cube_spot[1], 0 ); glScaled ( 1.5, 1.5, 1.5 ); glRotatef ( -30, 1.0, 0.0, 0.0 ); glRotatef ( 30, 0.0, 1.0 ,0.0 ); glPushMatrix(); glTranslated( 0, 0, -0.5 * cubh ); glTranslated(-_cubeSides[cur].center()[0], -_cubeSides[cur].center()[1], 0.0 ); glPushName( _cubeSides[cur].id() ); Color4D dark = _cubeSides[cur].col().scale(0.75); Color4D glow = dark.interp( _cubeSides[cur].col(), glomod * 1.1 ); glow[3] = 1.0; _cubeSides[cur].setCol( glow ); glBegin( GL_QUADS); _cubeSides[cur].quadVerts( ); glEnd( ); _cubeSides[cur].drawLabel( 0.75 ); _cubeSides[cur].outlineQuad( ); // _cubeSides[cur].drawQuad( 0.75 ); glPopName(); glPopMatrix(); glPushMatrix(); glRotatef ( 90, 1.0 , 0, 0 ); t_CKUINT up = audi->look_from( cur, Audicle::UP ) ; glTranslated( 0, 0, -0.5 * cubh ); glTranslated(-_cubeSides[up].center()[0], -_cubeSides[up].center()[1], 0.0 ); glPushName( _cubeSides[up].id() ); _cubeSides[up].drawQuad( 0.75 ); glPopName(); glPopMatrix(); glPushMatrix(); glRotatef ( -90, 0.0 , 1.0 , 0 ); t_CKUINT rt = audi->look_from( cur, Audicle::RIGHT ); glTranslated( 0, 0, -0.5 * cubh ); glTranslated(-_cubeSides[rt].center()[0], -_cubeSides[rt].center()[1], 0.0 ); glPushName( _cubeSides[rt].id() ); _cubeSides[rt].drawQuad( 0.75 ); glPopName(); glPopMatrix(); glPopMatrix(); glPopMatrix(); } }
bool OglUBitMapMC(int x, int y,grsBitmap *bm,int c) { GLint curFunc; GLdouble xo,yo,xf,yf; GLdouble u1,u2,v1,v2; r_ubitmapc++; x+=grdCurCanv->cvBitmap.bmProps.x; y+=grdCurCanv->cvBitmap.bmProps.y; xo=x/(double)last_width; xf=(bm->bmProps.w+x)/(double)last_width; yo=1.0-y/(double)last_height; yf=1.0-(bm->bmProps.h+y)/(double)last_height; glActiveTextureARB(GL_TEXTURE0); OglBindBmTex(bm); OglTexWrap(bm->glTexture,GL_CLAMP); glEnable(GL_TEXTURE_2D); glGetIntegerv (GL_DEPTH_FUNC, &curFunc); glDepthFunc(GL_ALWAYS); glEnable (GL_ALPHA_TEST); glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); if (bm->bmProps.x==0) { u1=0; if (bm->bmProps.w==bm->glTexture->w) u2=bm->glTexture->u; else u2=(bm->bmProps.w+bm->bmProps.x)/(double)bm->glTexture->tw; } else { u1=bm->bmProps.x/(double)bm->glTexture->tw; u2=(bm->bmProps.w+bm->bmProps.x)/(double)bm->glTexture->tw; } if (bm->bmProps.y==0) { v1=0; if (bm->bmProps.h==bm->glTexture->h) v2=bm->glTexture->v; else v2=(bm->bmProps.h+bm->bmProps.y)/(double)bm->glTexture->th; } else{ v1=bm->bmProps.y/(double)bm->glTexture->th; v2=(bm->bmProps.h+bm->bmProps.y)/(double)bm->glTexture->th; } glBegin(GL_QUADS); if (c < 0) glColor3d (1.0,1.0,1.0); else glColor3d (CPAL2Tr (bmP->bmPalette, c), CPAL2Tg (bmP->bmPalette, c), CPAL2Tb (bmP->bmPalette, c)); glTexCoord2f (u1, v1); glVertex2d (xo, yo); glTexCoord2f (u2, v1); glVertex2d (xf, yo); glTexCoord2f (u2, v2); glVertex2d (xf, yf); glTexCoord2f (u1, v2); glVertex2d (xo, yf); glEnd(); glDepthFunc(curFunc); glDisable (GL_ALPHA_TEST); glDisable (GL_BLEND); glActiveTextureARB(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D,0); glDisable(GL_TEXTURE_2D); return 0; }