Esempio n. 1
1
static void mask_draw_curve_type(const bContext *C, MaskSpline *spline, float (*orig_points)[2], int tot_point,
                                 const bool is_feather, const bool is_smooth, const bool is_active,
                                 const unsigned char rgb_spline[4], const char draw_type)
{
	const int draw_method = (spline->flag & MASK_SPLINE_CYCLIC) ? GL_LINE_LOOP : GL_LINE_STRIP;
	const unsigned char rgb_black[4] = {0x00, 0x00, 0x00, 0xff};
//	const unsigned char rgb_white[4] = {0xff, 0xff, 0xff, 0xff};
	unsigned char rgb_tmp[4];
	SpaceClip *sc = CTX_wm_space_clip(C);
	float (*points)[2] = orig_points;

	if (sc) {
		int undistort = sc->clip && sc->user.render_flag & MCLIP_PROXY_RENDER_UNDISTORT;

		if (undistort) {
			int i;

			points = MEM_callocN(2 * tot_point * sizeof(float), "undistorthed mask curve");

			for (i = 0; i < tot_point; i++) {
				mask_point_undistort_pos(sc, points[i], orig_points[i]);
			}
		}
	}

	glEnableClientState(GL_VERTEX_ARRAY);
	glVertexPointer(2, GL_FLOAT, 0, points);

	switch (draw_type) {

		case MASK_DT_OUTLINE:
			glLineWidth(3);

			mask_color_active_tint(rgb_tmp, rgb_black, is_active);
			glColor4ubv(rgb_tmp);

			glDrawArrays(draw_method, 0, tot_point);

			glLineWidth(1);
			mask_color_active_tint(rgb_tmp, rgb_spline, is_active);
			glColor4ubv(rgb_tmp);
			glDrawArrays(draw_method, 0, tot_point);

			break;

		case MASK_DT_DASH:
		default:
			glEnable(GL_LINE_STIPPLE);

#ifdef USE_XOR
			glEnable(GL_COLOR_LOGIC_OP);
			glLogicOp(GL_OR);
#endif
			mask_color_active_tint(rgb_tmp, rgb_spline, is_active);
			glColor4ubv(rgb_tmp);
			glLineStipple(3, 0xaaaa);
			glEnableClientState(GL_VERTEX_ARRAY);
			glVertexPointer(2, GL_FLOAT, 0, points);
			glDrawArrays(draw_method, 0, tot_point);

#ifdef USE_XOR
			glDisable(GL_COLOR_LOGIC_OP);
#endif
			mask_color_active_tint(rgb_tmp, rgb_black, is_active);
			glColor4ubv(rgb_tmp);
			glLineStipple(3, 0x5555);
			glDrawArrays(draw_method, 0, tot_point);

			glDisable(GL_LINE_STIPPLE);
			break;


		case MASK_DT_BLACK:
		case MASK_DT_WHITE:
			if (draw_type == MASK_DT_BLACK) { rgb_tmp[0] = rgb_tmp[1] = rgb_tmp[2] = 0;   }
			else                            { rgb_tmp[0] = rgb_tmp[1] = rgb_tmp[2] = 255; }
			/* alpha values seem too low but gl draws many points that compensate for it */
			if (is_feather) { rgb_tmp[3] = 64; }
			else            { rgb_tmp[3] = 128; }

			if (is_feather) {
				rgb_tmp[0] = (unsigned char)(((short)rgb_tmp[0] + (short)rgb_spline[0]) / 2);
				rgb_tmp[1] = (unsigned char)(((short)rgb_tmp[1] + (short)rgb_spline[1]) / 2);
				rgb_tmp[2] = (unsigned char)(((short)rgb_tmp[2] + (short)rgb_spline[2]) / 2);
			}

			if (is_smooth == FALSE && is_feather) {
				glEnable(GL_BLEND);
				glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
			}

			mask_color_active_tint(rgb_tmp, rgb_tmp, is_active);
			glColor4ubv(rgb_tmp);

			glEnableClientState(GL_VERTEX_ARRAY);
			glVertexPointer(2, GL_FLOAT, 0, points);
			glDrawArrays(draw_method, 0, tot_point);

			if (is_smooth == FALSE && is_feather) {
				glDisable(GL_BLEND);
			}

			break;
	}

	glDisableClientState(GL_VERTEX_ARRAY);

	if (points != orig_points)
		MEM_freeN(points);
}
Esempio n. 2
0
// Overwrite base class update
//----------------------------------------------------------------------------------------------------------------------
void ArmMuscledViz::update()
{
  // Let simple viz do its rendering first
  //ArmViz::update();
  
  glPushAttrib(GL_LIGHTING);
  glDisable(GL_LIGHTING);  
  glDisable(GL_DEPTH_TEST);  
  
  // Get shoulder and elbow TMs and other useful data
  const float shdAngle = m_arm->getJointAngle(JT_shoulder);
  const float elbAngle = m_arm->getJointAngle(JT_elbow);
  
  const ci::Vec3f elbPos = Vec3f(m_arm->getElbowPos());
  //const ci::Vec3f effPos = Vec3f(m_arm->getEffectorPos());
  const ci::Vec3f shdPos = Vec3f(0,0,0);
  
  const double elbRad = m_arm->getJointRadius(JT_elbow);
  const double shdRad = m_arm->getJointRadius(JT_shoulder);   

  ci::Matrix44f elbLimTM;
  elbLimTM.setToIdentity();
  elbLimTM.rotate(Vec3f(0.0f, 0.0f, 1.0f), shdAngle); 
  elbLimTM.setTranslate(elbPos);    
  
  ci::Matrix44f elbTM = elbLimTM;
  elbTM.rotate(Vec3f(0,0,1), elbAngle);
  
  ci::Matrix44f shdTM;
  shdTM.setToIdentity();
  shdTM.rotate(Vec3f(0.0f, 0.0f, 1.0f), shdAngle); 
  shdTM.setTranslate(shdPos);      

  // Overall position and orientation
  glPushMatrix();
  glMultMatrixf(*m_pTM);   
  glLineWidth(1.0);
  glColor3f(0,0,0);
  
  // Desired kinematic state
  if(m_drawDesiredState)
  {
    Pos p1, p2;    
    double desElbAngle = m_arm->getDesiredJointAngle(JT_elbow); 
    double desShdAngle = m_arm->getDesiredJointAngle(JT_shoulder); 
    m_arm->forwardKinematics(desElbAngle, desShdAngle, p1, p2);
    
    Vec3f desShdPos(0,0,0);
    Vec3f desElbPos(p1);
    Vec3f desEffPos(p2);
    ci::gl::color(m_colors.desired);
    // Draw bones
    glEnable(GL_LINE_STIPPLE);
    glLineStipple(2, 0xAAAA);
    ci::gl::drawLine(desShdPos, desElbPos);
    ci::gl::drawLine(desElbPos, desEffPos);
    glDisable(GL_LINE_STIPPLE);
    
    // Points indicating joints
    glPointSize(4.0);
    glBegin(GL_POINTS);
    glVertex3f(desShdPos.x, desShdPos.y, 0.0);
    glVertex3f(desElbPos.x, desElbPos.y, 0.0);
    glVertex3f(desEffPos.x, desEffPos.y, 0.0);
    glEnd();
  }    
  
  // Draw elbow joint and bone
  glPushMatrix();
  glMultMatrixf(elbTM);
  // bone triangle
  ci::gl::color(m_colors.boneFill);
  ci::Vec3f lt = -elbRad * ci::Vec3f(0,1,0);
  ci::Vec3f rt = elbRad * ci::Vec3f(0,1,0);
  ci::Vec3f bt = m_arm->getLength(JT_elbow) * ci::Vec3f(1,0,0);
  drawTriangle(rt, lt, bt);
  ci::gl::color(m_colors.boneOutline);
  drawTriangle(rt, lt, bt, GL_LINE);
  ci::gl::drawLine(ci::Vec2f(&bt.x), elbRad * ci::Vec2f(1,0));
  // joint disk
  ci::gl::color(m_colors.jointFill);
  ci::gl::drawSolidCircle(ci::Vec2f(0,0), elbRad, 32);
  ci::gl::color(m_colors.jointOutline);
  ci::gl::drawStrokedCircle(ci::Vec2f(0,0), elbRad, 32);

  glPopMatrix();
  
  // Draw elbow limits
  glPushMatrix();
  glMultMatrixf(elbLimTM);
  float limMin = radiansToDegrees(m_arm->getJointLimitLower(JT_elbow));
  float limMax = radiansToDegrees(m_arm->getJointLimitUpper(JT_elbow));
  ci::gl::color(m_colors.limitsFill);
  drawPartialDisk(elbRad, elbRad + 0.01, 16, 1, 90 - limMin, -(limMax - limMin));
  glPopMatrix();
  
  // Draw shoulder joint and bone
  glColor3f(0,0,0);  
  glPushMatrix();
  glMultMatrixf(shdTM);
  // bone triangle
  lt = -shdRad * ci::Vec3f(0,1,0);
  rt = shdRad * ci::Vec3f(0,1,0);
  bt = m_arm->getLength(JT_shoulder) * ci::Vec3f(1,0,0);  
  ci::gl::color(m_colors.boneFill);
  drawTriangle(rt, lt, bt);
  ci::gl::color(m_colors.boneOutline);
  drawTriangle(rt, lt, bt, GL_LINE);
  ci::gl::drawLine(m_arm->getLength(JT_shoulder) * ci::Vec2f(1,0), shdRad * ci::Vec2f(1,0));
  // joint disk
  ci::gl::color(m_colors.jointFill);
  ci::gl::drawSolidCircle(ci::Vec2f(0,0), shdRad, 32);
  ci::gl::color(m_colors.jointOutline);
  ci::gl::drawStrokedCircle(ci::Vec2f(0,0), shdRad, 32);
  glPopMatrix();
  
  // Draw shoulder limits
  limMin = m_arm->getJointLimitLower(JT_shoulder) * RAD_TO_DEG;
  limMax = m_arm->getJointLimitUpper(JT_shoulder) * RAD_TO_DEG;  
  ci::gl::color(m_colors.limitsFill);
  drawPartialDisk(shdRad, shdRad + 0.01, 16, 1, 90 - limMin, -(limMax - limMin));
  glLineWidth(1.0);    
  
  // Trajectory  
  if(m_drawOverlays)
  {
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);
    const std::deque<Pos>& effTrajectory = m_arm->getTrajectory();
    int numPoints =  effTrajectory.size();  
    float lineVerts[numPoints*2];
    float colors[numPoints*4];
    glVertexPointer(2, GL_FLOAT, 0, lineVerts); // 2d positions
    glColorPointer(4, GL_FLOAT, 0, colors);     // 4d colors
    
    for(size_t i = 0; i < numPoints; i++)
    {
      lineVerts[i*2 + 0] = effTrajectory[i].x;
      lineVerts[i*2 + 1] = effTrajectory[i].y;
      float a = 0.5 * (float)i / (float)numPoints;
      
      colors[i*4 + 0] = m_colors.trajectory[0];
      colors[i*4 + 1] = m_colors.trajectory[1];
      colors[i*4 + 2] = m_colors.trajectory[2];
      colors[i*4 + 3] = a;
    }
    glLineWidth(2.0);
    glDrawArrays( GL_LINE_STRIP, 0, numPoints);
    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_COLOR_ARRAY);
    glLineWidth(1.0);  
  }
  
  // Draw muscles
  for(size_t i = 0; i < m_arm->getNumMuscles(); ++i)
  {
    Muscle* muscle = m_arm->getMuscle(i);
    double act = muscle->getActivation();
    
    // Muscle line width dependent on activation
    float lineWidth = act * 32.0;
    glLineWidth(lineWidth);

    // Muscle colour dependent on length
    float l = muscle->getNormalisedLength() - 1;
    l = clamp(l, -1.0f, 1.0f);

    ci::ColorA col = m_colors.midMuscle;
    if(l >= 0)
    {
      col += (m_colors.longMuscle - m_colors.midMuscle) * l;
    }
    else
    {
      col -= (m_colors.shortMuscle - m_colors.midMuscle) * l;
    }    
    ci::gl::color(col);
    
    // Draw origin and insertion points
    Vec3f origin = Vec3f(muscle->getOriginWorld());
    Vec3f insertion = Vec3f(muscle->getInsertionWorld());    
    glPointSize(4.0);
    glBegin(GL_POINTS);
    glVertex3f(origin.x, origin.y, 0);
    glVertex3f(insertion.x, insertion.y, 0);
    glEnd();
    
    if(muscle->isMonoArticulate())
    {
      MuscleMonoWrap* m = ((MuscleMonoWrap*)muscle);        
      if(!m->m_muscleWraps)
      {
        //ci::Vec2f dir = m->getInsertionWorld() - m->getOriginWorld();
        //dir.normalize();
        // Only hold in the non-wrapping case. Otherwise we need to do a proper projection (dot product).
        //ci::Vec2f closestPoint = m->getOriginWorld() + dir * m->m_originCapsuleDist;
        //ci::Vec2f maVec = closestPoint - m_arm->getElbowPos();
        //float ma = maVec.length();
        //const bool muscleWraps = ma < r && m_arm->getJointAngle(JT_elbow) < PI_OVER_TWO;
        //ci::gl::drawLine(ci::Vec3f(closestPoint), ci::Vec3f(m_arm->getElbowPos())); 
        ci::gl::drawLine(origin, insertion); 
        // Indicate optimal length
        //ci::Vec3f l0Pos = origin + m->getOptimalLength() * (insertion - origin).normalized();
        //drawPoint(l0Pos, 4.0);
      }    
      else
      {
        // Upstream segment
        ci::Vec2f pathDir = (m->m_joint == JT_elbow) ? m_arm->getElbowPos() : ci::Vec2f(1, 0);
        float rotDir = m->m_isFlexor ? 1.0 : -1.0;
        pathDir.rotate(rotDir * (PI_OVER_TWO - m->m_originCapsuleAngle));
        pathDir.normalize();
        ci::Vec2f pathEnd = m->getOriginWorld() + (pathDir * m->m_originCapsuleDist);
        ci::gl::drawLine(origin, ci::Vec3f(pathEnd));
        
        // Downstream segment
        pathDir = (m->m_joint == JT_elbow) ? (m_arm->getElbowPos() - m_arm->getEffectorPos()) : ( -m_arm->getElbowPos());
        pathDir.rotate(-rotDir * (PI_OVER_TWO - m->m_insertCapsuleAngle));
        pathDir.normalize();
        pathEnd = m->getInsertionWorld() + (pathDir * m->m_insertCapsuleDist);
        ci::gl::drawLine(insertion, ci::Vec3f(pathEnd));     
      }
    } // is mono
    else 
    {
      glPushAttrib (GL_LINE_BIT);
      glEnable(GL_LINE_STIPPLE);
      glLineStipple (1, 0xAAAA);
      MuscleBiWrap* m = ((MuscleBiWrap*)muscle);
      if (m->wrapsElbow() && m->wrapsShoulder())
      {
        //glColor3f(0,0,1);
        // Upstream segment: always shoulder
        ci::Vec2f pathDir = ci::Vec2f(1, 0);
        float rotDir = m->m_isFlexor ? 1.0 : -1.0;
        pathDir.rotate(rotDir * (PI_OVER_TWO - m->m_originCapsuleAngle));
        pathDir.normalize();
        ci::Vec2f pathEnd = m->getOriginWorld() + (pathDir * m->m_originCapsuleDist);
        ci::gl::drawLine(origin, ci::Vec3f(pathEnd));        
        // Downstream segment: always elbow.
        pathDir = m_arm->getElbowPos() - m_arm->getEffectorPos();
        pathDir.rotate(-rotDir * (PI_OVER_TWO - m->m_insertCapsuleAngle));
        pathDir.normalize();
        pathEnd = m->getInsertionWorld() + (pathDir * m->m_insertCapsuleDist);
        ci::gl::drawLine(insertion, ci::Vec3f(pathEnd));
        // Middle segment
        pathDir = m_arm->getElbowPos();
        pathDir.rotate(rotDir * m->m_gammaAngle);
        pathDir.normalize();
        pathDir = pathDir * m->m_momentArms[JT_shoulder];
        ci::Vec2f pathStart = pathDir;
        
        pathDir = m_arm->getEffectorPos() - m_arm->getElbowPos();
        pathDir.rotate(rotDir * (m->m_insertCapsuleAngle + m->getWrapAngle(JT_elbow)));
        pathDir.normalize();
        pathDir = pathDir * m_arm->getJointRadius(JT_elbow);
        pathEnd = m_arm->getElbowPos() + pathDir;      
        ci::gl::drawLine(ci::Vec3f(pathStart), ci::Vec3f(pathEnd));          
      }
      else if (m->wrapsElbow())
      {
        //glColor3f(0,1,0);
        // Downstream segment: always elbow. Upstream segment from origin to capsule
        ci::Vec2f pathDir = ci::Vec2f(m_arm->getElbowPos() - m_arm->getEffectorPos());
        float rotDir = m->m_isFlexor ? 1.0 : -1.0;
        pathDir.rotate(-rotDir * (PI_OVER_TWO - m->m_insertCapsuleAngle));
        pathDir.normalize();
        ci::Vec2f pathEnd = m->getInsertionWorld() + (pathDir * m->m_insertCapsuleDist);
        ci::gl::drawLine(insertion, ci::Vec3f(pathEnd));
        
        pathDir = m_arm->getEffectorPos() - m_arm->getElbowPos();
        pathDir.rotate(rotDir * (m->m_insertCapsuleAngle + m->getWrapAngle(JT_elbow)));
        pathDir.normalize();
        pathDir = pathDir * m_arm->getJointRadius(JT_elbow);
        pathEnd = m_arm->getElbowPos() + pathDir;
        ci::gl::drawLine(origin, ci::Vec3f(pathEnd));
      }
      else if (m->wrapsShoulder())
      {
        //glColor3f(1,0,0);
        // Upstream segment: always shoulder
        ci::Vec2f pathDir = ci::Vec2f(1, 0);
        float rotDir = m->m_isFlexor ? 1.0 : -1.0;
        pathDir.rotate(rotDir * (PI_OVER_TWO - m->m_originCapsuleAngle));
        pathDir.normalize();
        ci::Vec2f pathEnd = m->getOriginWorld() + (pathDir * m->m_originCapsuleDist);
        ci::gl::drawLine(origin, ci::Vec3f(pathEnd));
        
        //Downstream segment: from capsule to insertion
        pathDir = m_arm->getElbowPos();
        pathDir.rotate(rotDir * m->m_gammaAngle);
        pathDir.normalize();
        pathDir = pathDir * m->m_momentArms[JT_shoulder];
        ci::Vec2f pathStart = pathDir;
        ci::gl::drawLine(ci::Vec3f(pathStart), insertion);
      }
      else
      {
        // No wrap
        //glColor3f(1,1,1);
        ci::gl::drawLine(origin, insertion);          
      }
      glPopAttrib();
    }
  } // for all muscles
  
  glLineWidth(1.0);
  
  glPopMatrix();
  glEnable(GL_DEPTH_TEST);    
  
  glPopAttrib();  
}
Esempio n. 3
0
void Route::DrawGL( ViewPort &VP, OCPNRegion &region )
{
#ifdef ocpnUSE_GL
    if( m_nPoints < 1 || !m_bVisible ) return;
    
    if(m_hiliteWidth) {
        wxColour y = GetGlobalColor( _T ( "YELO1" ) );
        wxColour hilt( y.Red(), y.Green(), y.Blue(), 128 );

        wxPen HiPen( hilt, m_hiliteWidth, wxPENSTYLE_SOLID );

        ocpnDC dc;
        dc.SetPen( HiPen );
        DrawGLLines(VP, &dc);
    }
    
    /* determine color and width */
    wxColour col;

    int width = g_route_line_width;
    if( m_width != STYLE_UNDEFINED )
        width = m_width;
    if(m_bIsTrack)
        width = g_pRouteMan->GetTrackPen()->GetWidth();
    
    if( m_bRtIsActive )
    {
        col = g_pRouteMan->GetActiveRoutePen()->GetColour();
    } else if( m_bRtIsSelected ) {
        col = g_pRouteMan->GetSelectedRoutePen()->GetColour();
    } else {
        if( m_Colour == wxEmptyString ) {
            col = g_pRouteMan->GetRoutePen()->GetColour();
            
            //  For tracks, establish colour based on first icon name
            if(m_bIsTrack){
                wxRoutePointListNode *node = pRoutePointList->GetFirst();
                RoutePoint *prp = node->GetData();
                
                if( prp->GetIconName().StartsWith( _T("xmred") ) ) 
                    col = GetGlobalColor( _T ( "URED" ) );
                else if( prp->GetIconName().StartsWith( _T("xmblue") ) ) 
                    col = GetGlobalColor( _T ( "BLUE3" ) );
                else if( prp->GetIconName().StartsWith( _T("xmgreen") ) ) 
                    col = GetGlobalColor( _T ( "UGREN" ) );
                else 
                    col = GetGlobalColor( _T ( "CHMGD" ) );
            }
        } else {
            for( unsigned int i = 0; i < sizeof( ::GpxxColorNames ) / sizeof(wxString); i++ ) {
                if( m_Colour == ::GpxxColorNames[i] ) {
                    col = ::GpxxColors[i];
                    break;
                }
            }
        }
    }
        
    glColor3ub(col.Red(), col.Green(), col.Blue());
    glLineWidth(wxMax( g_GLMinSymbolLineWidth, width ));

    if( m_style != STYLE_UNDEFINED )
        glEnable( GL_LINE_STIPPLE );

    switch( m_style ) {
    case wxDOT:        glLineStipple( 1, 0x3333 ); break;
    case wxLONG_DASH:  glLineStipple( 1, 0xFFF8 ); break;
    case wxSHORT_DASH: glLineStipple( 1, 0x3F3F ); break;
    case wxDOT_DASH:   glLineStipple( 1, 0x8FF1 ); break;
    }

    DrawGLLines(VP, NULL);

    glDisable (GL_LINE_STIPPLE);
    
    /* direction arrows.. could probably be further optimized for opengl */
    if( !m_bIsTrack ) {
        wxRoutePointListNode *node = pRoutePointList->GetFirst();
        wxPoint2DDouble rpt1, rpt2;
        while(node) {
            RoutePoint *prp = node->GetData();
//            cc1->GetDoubleCanvasPointPix( prp->m_lat, prp->m_lon, &rpt2 );
            rpt2 = prp->m_screen_pos;
            if(node != pRoutePointList->GetFirst() && prp->m_pos_on_screen)
                RenderSegmentArrowsGL( rpt1.m_x, rpt1.m_y, rpt2.m_x, rpt2.m_y, cc1->GetVP() );
            rpt1 = rpt2;
            node = node->GetNext();
        }
    }

    /*  Route points  */
    for(wxRoutePointListNode *node = pRoutePointList->GetFirst(); node; node = node->GetNext()) {
        RoutePoint *prp = node->GetData();
        if ( m_bVisible || prp->m_bKeepXRoute )
            prp->DrawGL( VP, region, true );
    }        
#endif
}
bool GLBoxSelector::draw(GLenum which_colorbuffer)
{
	bool ret = false;
	
	if (!hidden) {
		glw->makeCurrent();
		GLint saved_dbuf;
		glGetIntegerv(GL_DRAW_BUFFER, &saved_dbuf);
		glDrawBuffer(which_colorbuffer);
		GLint matmode_saved;
		glGetIntegerv(GL_MATRIX_MODE, &matmode_saved);
		glMatrixMode(GL_PROJECTION);
		glPushMatrix();
		glLoadMatrixf(projmatrix);
		glMatrixMode(GL_MODELVIEW);
		glPushMatrix();
		
		GLint saved_polygonmode[2];
		GLint saved_sfactor, saved_dfactor;
		GLint savedPat(0), savedRepeat(0);
		GLfloat savedColor[4];
		GLfloat savedWidth;
		bool wasEnabled = glIsEnabled(GL_LINE_STIPPLE);
		bool hadBlend = glIsEnabled(GL_BLEND);
		bool hadSmooth = glIsEnabled(GL_LINE_SMOOTH);
		GLint hadca, hadva, hadta;
				
		glGetIntegerv(GL_POLYGON_MODE, saved_polygonmode);                 
		// save some values
		glGetFloatv(GL_CURRENT_COLOR, savedColor);
		glGetIntegerv(GL_LINE_STIPPLE_PATTERN, &savedPat);
		glGetIntegerv(GL_LINE_STIPPLE_REPEAT, &savedRepeat);
		glGetFloatv(GL_LINE_WIDTH, &savedWidth);
		glGetIntegerv(GL_BLEND_SRC, &saved_sfactor);
		glGetIntegerv(GL_BLEND_DST, &saved_dfactor);
		glGetIntegerv(GL_COLOR_ARRAY, &hadca);
		glGetIntegerv(GL_VERTEX_ARRAY, &hadva);
		glGetIntegerv(GL_TEXTURE_COORD_ARRAY, &hadta);
		if (!hadva) glEnableClientState(GL_VERTEX_ARRAY);
		if (hadta) glDisableClientState(GL_TEXTURE_COORD_ARRAY);
		if (hadca) glDisableClientState(GL_COLOR_ARRAY);
		if (!hadSmooth) glEnable(GL_LINE_SMOOTH);
		if (!hadBlend) glEnable(GL_BLEND);

		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

		
		// next, draw everything BUT the box with a flicker/gray area...
		glColor4f(.3f, .3f, .4f, .25f);
		if (wasEnabled) glDisable(GL_LINE_STIPPLE);
		glPolygonMode(GL_FRONT,GL_FILL);
		glLineWidth(1.f);
		glLineStipple(1,0xffff);
		
		const GLfloat verticesNonBox[] = {
			0.f,0.f, 1.f,0.f, 1.f,box.v2, 0.f,box.v2,  // bottom strip
			0.f,box.v2, box.v1,box.v2, box.v1,1.f, 0.f,1.f, // left strip
			box.v1,box.v4, 1.f,box.v4, 1.f,1.f, box.v1,1.f, // top strip
			box.v3,box.v2, 1.f,box.v2, 1.f,box.v4, box.v3,box.v4 // right strip
		};
		
		glVertexPointer(2, GL_FLOAT, 0, verticesNonBox);
		glDrawArrays(GL_QUADS,0,16);
		
		
		glEnable(GL_LINE_STIPPLE);
		//glPolygonMode(GL_FRONT, GL_LINE);
		// outline.. use normal alphas
		glLineWidth(4.0f);
		unsigned short pat = 0xcccc;
		int shift = static_cast<unsigned int>(Util::getTime() * 32.0) % 16;
		pat = ror(pat,shift);
			
		glLineStipple(1, pat);
		const GLfloat verticesBox[] = {
			box.v1, box.v2,
			box.v3, box.v2,
			box.v3, box.v4,
			box.v1, box.v4,
			box.v1, box.v2,
		};
		float dummy, colorscale = modff((Util::getTime() * 16.) / M_PI, &dummy);
		const float s = (sinf(colorscale)+1.f)/2.f, c = (sinf(colorscale*1.123)+1.f)/2.f,
		            d = (sinf(colorscale*.8123)+1.f)/2.f;

		// draw surrounding box
		glColor4f(c, s, d, .75);
		glVertexPointer(2, GL_FLOAT, 0, verticesBox);
		glDrawArrays(GL_LINE_LOOP, 0, 5); 
		
		// draw interior 'grid'
		glLineWidth(1.f);
		glLineStipple(1,0xaaaa);
		
		const GLfloat gw = (box.v3-box.v1)/3.f, gh = (box.v4-box.v2)/3.f;
		const GLfloat verticesGrid[] = {
			box.v1+gw, box.v2,
			box.v1+gw, box.v4,
			box.v1+(gw*2.f), box.v2,
			box.v1+(gw*2.f), box.v4,
			box.v1, box.v2+gh,
			box.v3, box.v2+gh,
			box.v1, box.v2+(2.f*gh),
			box.v3, box.v2+(2.f*gh),
		};
		glVertexPointer(2, GL_FLOAT, 0, verticesGrid);
		glDrawArrays(GL_LINES, 0, 8);
		
		// restore saved OpenGL state
		if (hadta) glEnableClientState(GL_TEXTURE_COORD_ARRAY);
		if (hadca) glEnableClientState(GL_COLOR_ARRAY);
		if (!hadva) glDisableClientState(GL_VERTEX_ARRAY);
		glBlendFunc(saved_sfactor, saved_dfactor);
		glPolygonMode(GL_FRONT, saved_polygonmode[0]);
		glColor4fv(savedColor);
		glLineStipple(savedRepeat, savedPat);
		glLineWidth(savedWidth);
		if (!wasEnabled) glDisable(GL_LINE_STIPPLE);
		if (!hadBlend) glDisable(GL_BLEND);
		if (!hadSmooth) glDisable(GL_LINE_SMOOTH);
		
		glPopMatrix();
		glMatrixMode(GL_PROJECTION);
		glPopMatrix();
		glMatrixMode(matmode_saved);
		
		glDrawBuffer(saved_dbuf);
		ret = true;
	} 
	return ret;
}
void CEndGameBox::Draw()
{
	if (disabled) {
		return;
	}

	float mx=MouseX(mouse->lastx);
	float my=MouseY(mouse->lasty);

	glDisable(GL_TEXTURE_2D);
	glEnable(GL_BLEND);
	glDisable(GL_ALPHA_TEST);

	// Large Box
	glColor4f(0.2f,0.2f,0.2f,guiAlpha);
	DrawBox(box);

	glColor4f(0.2f,0.2f,0.7f,guiAlpha);
	if(dispMode==0){
		DrawBox(box+playerBox);
	} else if(dispMode==1){
		DrawBox(box+sumBox);
	} else {
		DrawBox(box+difBox);
	}

	if(InBox(mx,my,box+exitBox)){
		glColor4f(0.7f,0.2f,0.2f,guiAlpha);
		DrawBox(box+exitBox);
	}
	if(InBox(mx,my,box+playerBox)){
		glColor4f(0.7f,0.2f,0.2f,guiAlpha);
		DrawBox(box+playerBox);
	}
	if(InBox(mx,my,box+sumBox)){
		glColor4f(0.7f,0.2f,0.2f,guiAlpha);
		DrawBox(box+sumBox);
	}
	if(InBox(mx,my,box+difBox)){
		glColor4f(0.7f,0.2f,0.2f,guiAlpha);
		DrawBox(box+difBox);
	}

	glEnable(GL_TEXTURE_2D);
	glColor4f(1,1,1,0.8f);
	font->glPrintAt(box.x1+exitBox.x1+0.025f,box.y1+exitBox.y1+0.005f,1,"Exit");
	font->glPrintAt(box.x1+playerBox.x1+0.015f,box.y1+playerBox.y1+0.005f,0.7f,"Player stats");
	font->glPrintAt(box.x1+sumBox.x1+0.015f,box.y1+sumBox.y1+0.005f,0.7f,"Team stats");
	font->glPrintAt(box.x1+difBox.x1+0.015f,box.y1+difBox.y1+0.005f,0.7f,"Team delta stats");

	if(gs->Team(gu->myTeam)->isDead){
		font->glPrintAt(box.x1+0.25f,box.y1+0.65f,1,"You lost the game");
	} else {
		font->glPrintAt(box.x1+0.25f,box.y1+0.65f,1,"You won the game");
	}

	if(dispMode==0){
		float xpos=0.01f;

		string headers[]={"Name","MC/m","MP/m","KP/m","Cmds/m","ACS"};

		for(int a=0;a<6;++a){
			font->glPrintAt(box.x1+xpos,box.y1+0.55f,0.8f,headers[a].c_str());
			xpos+=0.1f;
		}

		float ypos=0.5f;
		for(int a=0;a<gs->activePlayers;++a){
			if(gs->players[a]->currentStats->mousePixels==0)
				continue;
			char values[6][100];

			sprintf(values[0],"%s",	gs->players[a]->playerName.c_str());
			sprintf(values[1],"%i",(int)(gs->players[a]->currentStats->mouseClicks*60/game->totalGameTime));
			sprintf(values[2],"%i",(int)(gs->players[a]->currentStats->mousePixels*60/game->totalGameTime));
			sprintf(values[3],"%i",(int)(gs->players[a]->currentStats->keyPresses*60/game->totalGameTime));
			sprintf(values[4],"%i",(int)(gs->players[a]->currentStats->numCommands*60/game->totalGameTime));
			sprintf(values[5],"%i",(int)
				( gs->players[a]->currentStats->numCommands != 0 ) ?
				( gs->players[a]->currentStats->unitCommands/gs->players[a]->currentStats->numCommands) :
				( 0 ));

			float xpos=0.01f;
			for(int a=0;a<6;++a){
				font->glPrintAt(box.x1+xpos,box.y1+ypos,0.8f,values[a]);
				xpos+=0.1f;
			}

			ypos-=0.02f;
		}
	} else {
		if(stats.empty())
			FillTeamStats();

		glBindTexture(GL_TEXTURE_2D, graphTex);
		CVertexArray* va=GetVertexArray();
		va->Initialize();

		va->AddVertexT(float3(box.x1+0.15f, box.y1+0.08f, 0),0,0);
		va->AddVertexT(float3(box.x1+0.69f, box.y1+0.08f, 0),4,0);
		va->AddVertexT(float3(box.x1+0.69f, box.y1+0.62f, 0),4,4);
		va->AddVertexT(float3(box.x1+0.15f, box.y1+0.62f, 0),0,4);

		va->DrawArrayT(GL_QUADS);

		if(mx>box.x1+0.01f && mx<box.x1+0.12f && my<box.y1+0.57f && my>box.y1+0.571f-stats.size()*0.02f){

			int sel=(int)floor(-(my-box.y1-0.57f)*50);

			glColor4f(0.7f,0.2f,0.2f,guiAlpha);
			glDisable(GL_TEXTURE_2D);
			CVertexArray* va=GetVertexArray();
			va->Initialize();

			va->AddVertex0(float3(box.x1+0.01f, box.y1+0.55f-sel*0.02f , 0));
			va->AddVertex0(float3(box.x1+0.01f, box.y1+0.55f-sel*0.02f+0.02f , 0));
			va->AddVertex0(float3(box.x1+0.12f, box.y1+0.55f-sel*0.02f+0.02f , 0));
			va->AddVertex0(float3(box.x1+0.12f, box.y1+0.55f-sel*0.02f , 0));

			va->DrawArray0(GL_QUADS);
			glEnable(GL_TEXTURE_2D);
			glColor4f(1,1,1,0.8f);
		}
		float ypos=0.55f;
		for(int a=0;a<stats.size();++a){
			font->glPrintAt(box.x1+0.01f,box.y1+ypos,0.8f,stats[a].name.c_str());
			ypos-=0.02f;
		}
		float maxy=1;

		if(dispMode==1)
			maxy=std::max(stats[stat1].max,stat2!=-1?stats[stat2].max:0);
		else
			maxy=std::max(stats[stat1].maxdif,stat2!=-1?stats[stat2].maxdif:0)/CTeam::statsPeriod;

		int numPoints=stats[0].values[0].size();
		float scalex=0.54f/max(1.0f,numPoints-1.0f);
		float scaley=0.54f/maxy;

		for (int a = 0; a < 5; ++a) {
			font->glPrintAt(box.x1 + 0.12f, box.y1 + 0.07f + (a * 0.135f), 0.8f, "%s",
			                FloatToSmallString(maxy * 0.25f * a).c_str());
			font->glPrintAt(box.x1 + 0.135f + (a * 0.135f), box.y1 + 0.057f, 0.8f, "%i:%2i",
			                int(a * 0.25f * numPoints * CTeam::statsPeriod / 60),
			                int(a * 0.25f * (numPoints - 1) * CTeam::statsPeriod) % 60);
		}

		font->glPrintAt(box.x1+0.55f,box.y1+0.65f,0.8f,"%s",stats[stat1].name.c_str());
		font->glPrintAt(box.x1+0.55f,box.y1+0.63f,0.8f,"%s",stat2!=-1?stats[stat2].name.c_str():"");

		glDisable(GL_TEXTURE_2D);
		glBegin(GL_LINES);
				glVertex3f(box.x1+0.50f,box.y1+0.66f,0);
				glVertex3f(box.x1+0.55f,box.y1+0.66f,0);
		glEnd();

		glLineStipple(3,0x5555);
		glEnable(GL_LINE_STIPPLE);
		glBegin(GL_LINES);
				glVertex3f(box.x1+0.50f,box.y1+0.64f,0);
				glVertex3f(box.x1+0.55f,box.y1+0.64f,0);
		glEnd();
		glDisable(GL_LINE_STIPPLE);

		for(int team=0; team<gs->activeTeams; team++){
			if (gs->Team(team)->gaia) continue;
			glColor4ubv(gs->Team(team)->color);

			glBegin(GL_LINE_STRIP);
			for(int a=0;a<numPoints;++a){
				float value=0;
				if(dispMode==1)
					value=stats[stat1].values[team][a];
				else if(a>0)
					value=(stats[stat1].values[team][a]-stats[stat1].values[team][a-1])/CTeam::statsPeriod;

				glVertex3f(box.x1+0.15f+a*scalex,box.y1+0.08f+value*scaley,0);
			}
			glEnd();

			if (stat2!=-1) {
				glLineStipple(3,0x5555);
				glEnable(GL_LINE_STIPPLE);

				glBegin(GL_LINE_STRIP);
				for(int a=0;a<numPoints;++a){
					float value=0;
					if(dispMode==1)
						value=stats[stat2].values[team][a];
					else if(a>0)
						value=(stats[stat2].values[team][a]-stats[stat2].values[team][a-1])/CTeam::statsPeriod;

					glVertex3f(box.x1+0.15f+a*scalex,box.y1+0.08f+value*scaley,0);
				}
				glEnd();

				glDisable(GL_LINE_STIPPLE);
			}
		}
	}
}
static void
Init(void)
{
   static const char *fragShaderText =
      "uniform float StipplePattern[16]; \n"
      "varying vec2 stippleCoord; \n"
      "void main() \n"
      "{ \n"
      "   // check the stipple pattern and discard if value is zero \n"
      "   // TODO: we should really undo the perspective interpolation here \n"
      "   // so that it's linear. \n"
      "   float stip = StipplePattern[int(fract(stippleCoord.x) * 16.0)]; \n"
      "   if (stip == 0.0) \n"
      "      discard; \n"
      "   gl_FragColor = gl_Color; \n"
      "} \n";
   static const char *vertShaderText =
      "void main() \n"
      "{ \n"
      "   gl_FrontColor = gl_Color; \n"
      "   gl_Position = ftransform(); \n"
      "} \n";
   static const char *geomShaderText =
      "#version 150 \n"
      "#extension GL_ARB_geometry_shader4: enable \n"
      "uniform vec2 ViewportSize; \n"
      "uniform float StippleFactor; \n"
      "out vec2 stippleCoord; \n"
      "void main() \n"
      "{ \n"
      "   vec4 pos0 = gl_PositionIn[0]; \n"
      "   vec4 pos1 = gl_PositionIn[1]; \n"
      "   // Convert eye coords to window coords \n"
      "   // Note: we're off by a factor of two here, make up for that below \n"
      "   vec2 p0 = pos0.xy / pos0.w * ViewportSize; \n"
      "   vec2 p1 = pos1.xy / pos1.w * ViewportSize; \n"
      "   float len = length(p0.xy - p1.xy); \n"
      "   // Emit first vertex \n"
      "   gl_FrontColor = gl_FrontColorIn[0]; \n"
      "   gl_Position = pos0; \n"
      "   stippleCoord.x = 0.0; \n"
      "   EmitVertex(); \n"
      "   // Emit second vertex \n"
      "   gl_FrontColor = gl_FrontColorIn[1]; \n"
      "   gl_Position = pos1; \n"
      "   stippleCoord.x = len / StippleFactor / 32.0; // Note: not 16, see above \n"
      "   EmitVertex(); \n"
      "} \n";

   if (!ShadersSupported())
      exit(1);

   if (!glutExtensionSupported("GL_ARB_geometry_shader4")) {
      fprintf(stderr, "Sorry, GL_ARB_geometry_shader4 is not supported.\n");
      exit(1);
   }

   VertShader = CompileShaderText(GL_VERTEX_SHADER, vertShaderText);
   FragShader = CompileShaderText(GL_FRAGMENT_SHADER, fragShaderText);
   GeomShader = CompileShaderText(GL_GEOMETRY_SHADER_ARB, geomShaderText);
   assert(GeomShader);

   Program = LinkShaders3(VertShader, GeomShader, FragShader);
   assert(Program);
   CheckError(__LINE__);

   /*
    * The geometry shader accepts lines and produces lines.
    */
   glProgramParameteriARB(Program, GL_GEOMETRY_INPUT_TYPE_ARB,
                          GL_LINES);
   glProgramParameteriARB(Program, GL_GEOMETRY_OUTPUT_TYPE_ARB,
                          GL_LINE_STRIP);
   glProgramParameteriARB(Program, GL_GEOMETRY_VERTICES_OUT_ARB, 4);
   CheckError(__LINE__);

   glLinkProgramARB(Program);

   /* check link */
   {
      GLint stat;
      GetProgramiv(Program, GL_LINK_STATUS, &stat);
      if (!stat) {
         GLchar log[1000];
         GLsizei len;
         GetProgramInfoLog(Program, 1000, &len, log);
         fprintf(stderr, "Shader link error:\n%s\n", log);
      }
   }

   glUseProgram(Program);

   uViewportSize = glGetUniformLocation(Program, "ViewportSize");
   uStippleFactor = glGetUniformLocation(Program, "StippleFactor");
   uStipplePattern = glGetUniformLocation(Program, "StipplePattern");

   glUniform1f(uStippleFactor, StippleFactor);

   glClearColor(0.3f, 0.3f, 0.3f, 0.0f);

   printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER));

   assert(glIsProgram(Program));
   assert(glIsShader(FragShader));
   assert(glIsShader(VertShader));
   assert(glIsShader(GeomShader));


   glLineStipple(StippleFactor, StipplePattern);
   SetStippleUniform(StippleFactor, StipplePattern);

   MakePoints();
}
Esempio n. 7
0
/**
* Draws the axis in the OpenGL view
*@param length the length of the axis
*@param color the color to use to draw the axis
*@param style the index of the style to use to draw the axis
*@param width the width to use to draw the axis
*/
void ThreeDWidget::GLDrawAxes(double length, QColor AxisColor, int AxisStyle, int AxisWidth)
{
	double l = .6*length;

	glLineWidth((GLfloat)(AxisWidth));

	glColor3d(AxisColor.redF(),AxisColor.greenF(),AxisColor.blueF());

	glEnable (GL_LINE_STIPPLE);

	if     (AxisStyle == 1) glLineStipple (1, 0xCFCF);
	else if(AxisStyle == 2) glLineStipple (1, 0x6666);
	else if(AxisStyle == 3) glLineStipple (1, 0xFF18);
	else if(AxisStyle == 4) glLineStipple (1, 0x7E66);
	else                    glLineStipple (1, 0xFFFF);

	// X axis____________
	glBegin(GL_LINES);
		glVertex3d(-l, 0.0, 0.0);
		glVertex3d( l, 0.0, 0.0);
	glEnd();
	//Arrow
	glBegin(GL_LINES);
		glVertex3d( 1.0*l,   0.0,   0.0);
		glVertex3d( 0.98*l,  0.015*l, 0.015*l);
	glEnd();
	glBegin(GL_LINES);
		glVertex3d( 1.0*l,  0.0,    0.0);
		glVertex3d( 0.98*l,-0.015*l,-0.015*l);
	glEnd();
	glDisable (GL_LINE_STIPPLE);
	//XLabel
	renderText( l, 0.0, 0.0, "X", Settings::s_TextFont);


	// Y axis____________
	glEnable (GL_LINE_STIPPLE);
	glBegin(GL_LINES);
		glVertex3d(0.0, -l, 0.0);
		glVertex3d(0.0,  l, 0.0);
	glEnd();

	//Arrow
	glBegin(GL_LINES);
		glVertex3d( 0.0,     1.0*l,  0.0);
		glVertex3d( 0.015*l, 0.98*l, 0.015*l);
	glEnd();
	glBegin(GL_LINES);
		glVertex3d( 0.0,     1.0*l,  0.0);
		glVertex3d(-0.015*l, 0.98*l,-0.015*l);
	glEnd();
	glDisable (GL_LINE_STIPPLE);
	//Y Label
	renderText( 0.0, l, 0.0, "Y", Settings::s_TextFont);


	// Z axis____________
	glEnable (GL_LINE_STIPPLE);
	glBegin(GL_LINES);
		glVertex3d(0.0, 0.0, -l);
		glVertex3d(0.0, 0.0,  l);
	glEnd();

	//Arrow
	glBegin(GL_LINES);
		glVertex3d(  0.0,   0.0, 1.0*l);
		glVertex3d( 0.015*l,  0.015*l,  0.98*l);
	glEnd();
	glBegin(GL_LINES);
		glVertex3d( 0.0,    0.0, 1.0*l);
		glVertex3d(-0.015*l, -0.015*l,  0.98*l);
	glEnd();
	glDisable (GL_LINE_STIPPLE);
	//ZLabel
	renderText( 0.0, 0.0, l, "Z", Settings::s_TextFont);

	glDisable (GL_LINE_STIPPLE);
}
Esempio n. 8
0
void cal_render_bones(actor *act)
{
	float lines[1024][2][3];
	float points[1024][3];
	int nrLines;
	int nrPoints;
	int currLine;
	int currPoint;
	struct CalSkeleton *skel;

	skel=CalModel_GetSkeleton(act->calmodel);
	nrLines = CalSkeleton_GetBoneLines(skel,&lines[0][0][0]);

	glLineWidth(2.0f);
	glColor3f(1.0f, 1.0f, 1.0f);

	glLineStipple(1, 0x3030);
	glEnable(GL_LINE_STIPPLE);
	glBegin(GL_LINES);

	for(currLine = 0; currLine < nrLines; currLine++) {
    		glVertex3f(lines[currLine][0][0], lines[currLine][0][1], lines[currLine][0][2]);
    		glVertex3f(lines[currLine][1][0], lines[currLine][1][1], lines[currLine][1][2]);
	}

	glEnd();
	glDisable(GL_LINE_STIPPLE);

  	// draw the bone points
  	nrPoints = CalSkeleton_GetBonePoints(skel,&points[0][0]);

	glPointSize(4.0f);
	glColor3f(0.0f, 1.0f, 1.0f);
	glBegin(GL_POINTS);
	for(currPoint = 0; currPoint < nrPoints; currPoint++) {
		glVertex3f(points[currPoint][0], points[currPoint][1], points[currPoint][2]);
	}
	glEnd();

#ifdef DEBUG
	// draw the bones orientation
	if (render_bones_orientation) {
		float shift[3], pos[3];
		
		glLineWidth(3.0f);
		glBegin(GL_LINES);
		for (currPoint = nrPoints; currPoint--;) {
			shift[0] = 0.1; shift[1] = 0.0; shift[2] = 0.0;
			cal_get_actor_bone_local_position(act, currPoint, shift, pos);
			glColor3f(1.0, 0.0, 0.0);
			glVertex3f(points[currPoint][0], points[currPoint][1], points[currPoint][2]);
			glVertex3fv(pos);
			
			shift[0] = 0.0; shift[1] = 0.1; shift[2] = 0.0;
			cal_get_actor_bone_local_position(act, currPoint, shift, pos);
			glColor3f(0.0, 1.0, 0.0);
			glVertex3f(points[currPoint][0], points[currPoint][1], points[currPoint][2]);
			glVertex3fv(pos);
			
			shift[0] = 0.0; shift[1] = 0.0; shift[2] = 0.1;
			cal_get_actor_bone_local_position(act, currPoint, shift, pos);
			glColor3f(0.0, 0.0, 1.0);
			glVertex3f(points[currPoint][0], points[currPoint][1], points[currPoint][2]);
			glVertex3fv(pos);
		}
		glEnd();
	}

	// draw bones id
	if (render_bones_id) {
		GLdouble model[16], proj[16];
		GLint view[4];
		GLdouble px,py,pz;
		unsigned char buf[16];
		float font_size_x = SMALL_INGAME_FONT_X_LEN/ALT_INGAME_FONT_X_LEN;
		float font_size_y = SMALL_INGAME_FONT_Y_LEN/ALT_INGAME_FONT_X_LEN;

		glGetDoublev(GL_MODELVIEW_MATRIX, model);
		glGetDoublev(GL_PROJECTION_MATRIX, proj);
		glGetIntegerv(GL_VIEWPORT, view);
		
		glPushMatrix();
		glLoadIdentity();
		glMatrixMode(GL_PROJECTION);
		glPushMatrix();
		glLoadIdentity();
		
		glOrtho(view[0],view[2]+view[0],view[1],view[3]+view[1],0.0f,-1.0f);
		
		glPushAttrib(GL_ENABLE_BIT);
		
		glEnable(GL_TEXTURE_2D);
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
		
		glColor4f(1.0, 0.0, 1.0, 1.0);
		
		for (currPoint = nrPoints; currPoint--;) {
			struct CalBone *bone;
			bone = CalSkeleton_GetBone(skel, currPoint);
			
			sprintf((char*)buf, "%d", currPoint);
			gluProject(points[currPoint][0], points[currPoint][1], points[currPoint][2], model, proj, view, &px, &py, &pz);
			draw_ortho_ingame_string(px, py, pz, buf, 1, font_size_x, font_size_y);
		}
		
		glPopAttrib();
		
		glMatrixMode(GL_PROJECTION);
		glPopMatrix();
		glMatrixMode(GL_MODELVIEW);
		glPopMatrix();
	}
#endif // DEBUG

	glLineWidth(1.0f);

#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE

}
Esempio n. 9
0
void VectorView::on_display()
{
  set_ortho_projection();
  glDisable(GL_LIGHTING);
  glDisable(GL_DEPTH_TEST);
  glDisable(GL_TEXTURE_1D);
  glPolygonMode(GL_FRONT_AND_BACK, pmode ? GL_LINE : GL_FILL);

  // initial grid point and grid step
  double gt = gs;
  if (hexa) gt *= sqrt(3.0)/2.0;

  double max_length = 0.0;

  // transform all vertices
  vec.lock_data();
  int i;
  int nv = vec.get_num_vertices();
  double4* vert = vec.get_vertices();
  double2* tvert = new double2[nv];

  for (i = 0; i < nv; i++)
  {
    tvert[i][0] = transform_x(vert[i][0]);
    tvert[i][1] = transform_y(vert[i][1]);

    // find max length of vectors
    double length = sqr(vert[i][2]) + sqr(vert[i][3]);
    if (length > max_length) max_length = length;
  }
  max_length = sqrt(max_length);

  // value range
  double min = range_min, max = range_max;
  if (range_auto) { min = vec.get_min_value(); max = vec.get_max_value(); }
  double irange = 1.0 / (max - min);
  // special case: constant solution
  if (fabs(min - max) < 1e-8) { irange = 1.0; min -= 0.5; }

  // draw all triangles
  int3* xtris = vec.get_triangles();

  if (mode != 1) glEnable(GL_TEXTURE_1D);
  glBindTexture(GL_TEXTURE_1D, gl_pallete_tex_id);
  glBegin(GL_TRIANGLES);
  glColor3f(0.95f, 0.95f, 0.95f);
  for (i = 0; i < vec.get_num_triangles(); i++)
  {
    double mag = sqrt(sqr(vert[xtris[i][0]][2]) + sqr(vert[xtris[i][0]][3]));
    glTexCoord2d((mag -min) * irange * tex_scale + tex_shift, 0.0);
    glVertex2d(tvert[xtris[i][0]][0], tvert[xtris[i][0]][1]);

    mag = sqrt(sqr(vert[xtris[i][1]][2]) + sqr(vert[xtris[i][1]][3]));
    glTexCoord2d((mag -min) * irange * tex_scale + tex_shift, 0.0);
    glVertex2d(tvert[xtris[i][1]][0], tvert[xtris[i][1]][1]);

    mag = sqrt(sqr(vert[xtris[i][2]][2]) + sqr(vert[xtris[i][2]][3]));
    glTexCoord2d((mag -min) * irange * tex_scale + tex_shift, 0.0);
    glVertex2d(tvert[xtris[i][2]][0], tvert[xtris[i][2]][1]);
  }
  glEnd();
  glDisable(GL_TEXTURE_1D);

  // draw all edges
  /*if (mode == 0) glColor3f(0.3, 0.3, 0.3);
  else*/ glColor3f(0.5, 0.5, 0.5);
  glBegin(GL_LINES);
  int3* edges = vec.get_edges();
  for (i = 0; i < vec.get_num_edges(); i++)
  {
    if (lines || edges[i][2] != 0)
    {
      glVertex2d(tvert[edges[i][0]][0], tvert[edges[i][0]][1]);
      glVertex2d(tvert[edges[i][1]][0], tvert[edges[i][1]][1]);
    }
  }
  glEnd();

  // draw dashed edges
  if (lines)
  {
    glEnable(GL_LINE_STIPPLE);
    glLineStipple(1, 0xCCCC);
    glBegin(GL_LINES);
    int2* dashes = vec.get_dashes();
    for (i = 0; i < vec.get_num_dashes(); i++)
    {
      glVertex2d(tvert[dashes[i][0]][0], tvert[dashes[i][0]][1]);
      glVertex2d(tvert[dashes[i][1]][0], tvert[dashes[i][1]][1]);
    }
    glEnd();
    glDisable(GL_LINE_STIPPLE);
  }

  // draw arrows
  if (mode != 2)
  {
    for (i = 0; i < vec.get_num_triangles(); i++)
    {
      double miny = 1e100;
      int idx, k, l1, l2, r2, r1, s;
      double lry, x;
      double mr, ml, lx, rx, xval, yval;

      double wh = output_height + gt, ww = output_width + gs;
      if ((tvert[xtris[i][0]][0] < -gs) && (tvert[xtris[i][1]][0] < -gs) && (tvert[xtris[i][2]][0] < -gs)) continue;
      if ((tvert[xtris[i][0]][0] >  ww) && (tvert[xtris[i][1]][0] >  ww) && (tvert[xtris[i][2]][0] >  ww)) continue;
      if ((tvert[xtris[i][0]][1] < -gt) && (tvert[xtris[i][1]][1] < -gt) && (tvert[xtris[i][2]][1] < -gt)) continue;
      if ((tvert[xtris[i][0]][1] >  wh) && (tvert[xtris[i][1]][1] >  wh) && (tvert[xtris[i][2]][1] >  wh)) continue;

      // find vertex with min y-coordinate
      for (k = 0; k < 3; k++)
        if (tvert[xtris[i][k]][1] < miny)
          miny = tvert[xtris[i][idx = k]][1];
      l1 = r1 = xtris[i][idx];
      l2 = xtris[i][n_vert(idx)];
      r2 = xtris[i][p_vert(idx)];

      // plane of x and y values on triangle
      double a[2], b[2], c[2], d[2];
      for (int n = 0; n < 2; n++)
      {
        a[n] = (tvert[l1][1] - tvert[l2][1])*(vert[r1][2 +n] - vert[r2][2+n]) - (vert[l1][2+n] - vert[l2][2+n])*(tvert[r1][1] - tvert[r2][1]);
        b[n] = (vert[l1][2+n] - vert[l2][2+n])*(tvert[r1][0] - tvert[r2][0]) - (tvert[l1][0] - tvert[l2][0])*(vert[r1][2+n] - vert[r2][2+n]);
        c[n] = (tvert[l1][0] - tvert[l2][0])*(tvert[r1][1] - tvert[r2][1]) - (tvert[l1][1] - tvert[l2][1])*(tvert[r1][0] - tvert[r2][0]);
        d[n] = -a[n] * tvert[l1][0] - b[n] * tvert[l1][1] - c[n] * vert[l1][2+n];
        a[n] /= c[n]; b[n] /= c[n]; d[n] /= c[n];
      }

      s = (int) ceil((tvert[l1][1] - gy)/gt);  // first step
      lry = gy + s*gt;
      bool shift = hexa && (s & 1);

      // if there are two points with min y-coordinate, switch to the next segment
      if ((tvert[l1][1] == tvert[l2][1]) || (tvert[r1][1] == tvert[r2][1]))
        if (tvert[l1][1] == tvert[l2][1])
          {l1 = l2; l2 = r2;}
        else if (tvert[r1][1] == tvert[r2][1])
          {r1 = r2; r2 = l2;}

      // slope of the left and right segment
      ml = (tvert[l1][0] - tvert[l2][0])/(tvert[l1][1] - tvert[l2][1]);
      mr = (tvert[r1][0] - tvert[r2][0])/(tvert[r1][1] - tvert[r2][1]);
      // x-coordinates of the endpoints of the first line
      lx = tvert[l1][0] + ml * (lry - (tvert[l1][1]));
      rx = tvert[r1][0] + mr * (lry - (tvert[r1][1]));

      if (lry < -gt)
      {
        k = (int) floor(-lry/gt);
        lry += gt * k;
        lx += k * ml * gt;
        rx += k * mr * gt;
      }

      // while we are in triangle
      while (((lry < tvert[l2][1]) || (lry < tvert[r2][1])) && (lry < wh))
      {
        // while we are in the segment
        while (((lry <= tvert[l2][1]) && (lry <= tvert[r2][1])) && (lry < wh))
        {
          double gz = gx;
          if (shift) gz -= 0.5*gs;
          s = (int) ceil((lx - gz)/gs);
          x = gz + s*gs;
          if (hexa) shift = !shift;

          if (x < -gs)
          {
            k = (int) floor(-x/gs);
            x += gs * k;
          }
          // go along the line
          while ((x < rx) && (x < ww))
          {
            // plot the arrow
            xval = -a[0]*x - b[0]*lry - d[0];
            yval = -a[1]*x - b[1]*lry - d[1];
            plot_arrow(x, lry, xval, yval, max, min, gs);
            x += gs;
          }
          // move to the next line
          lx += ml*gt;
          rx += mr*gt;
          lry += gt;
        }
        // change segment
        if (lry >= tvert[l2][1]) {
          l1 = l2; l2 = r2;
          ml = (tvert[l1][0] - tvert[l2][0])/(tvert[l1][1] - tvert[l2][1]);
          lx = tvert[l1][0] + ml * (lry - (tvert[l1][1]));
        }
        else {
          r1 = r2; r2 = l2;
          mr = (tvert[r1][0] - tvert[r2][0])/(tvert[r1][1] - tvert[r2][1]);
          rx = tvert[r1][0] + mr * (lry - (tvert[r1][1]));
        }
      }
    }
  }

  delete [] tvert;
  vec.unlock_data();
}
Esempio n. 10
0
bool glWindow::ResetGL () {

    if (m_resetGLMode == RGM_RECREATEWINDOW) {
        RecreateWindow (m_fullScreen, m_border, m_width, m_height, m_bpp, m_stencil, m_title, m_allowResizing, m_fitToWorkArea);
        return true;
    }
    else if (m_resetGLMode == RGM_RECREATECONTEXT) {
        RecreateGLContext ();
        return true;
    }

    // Setup OpenGL defaults.
    // This should reset as much as possible back to the initial state of OpenGL.

    // Exceptions:
    //      * Projection matrix is initialised to a perspective transform

    // End current gl block
    try { glEnd ();                                                             } catch (...) { ; }    
    m_dontPaint = false;

    // Intialise matrices
    try { glMatrixMode (GL_PROJECTION);   ClearGLMatrix ();                     } catch (...) { ; }
    try { glMatrixMode (GL_TEXTURE);      ClearGLMatrix ();                     } catch (...) { ; }
    try { glMatrixMode (GL_MODELVIEW);    ClearGLMatrix ();                     } catch (...) { ; }

    // Initialise state
    int i;
    try { glColor4f (1, 1, 1, 1);                                               } catch (...) { ; }
    try { glIndexi (1);                                                         } catch (...) { ; }
    try { glTexCoord4f (0, 0, 0, 1);                                            } catch (...) { ; }
    try { glNormal3f (0, 0, 1);                                                 } catch (...) { ; }
//    try { glRasterPos4f (0, 0, 0, 1);                                           } catch (...) { ; }
    try { glEdgeFlag (GL_TRUE);                                                 } catch (...) { ; }
    try { glDisable (GL_VERTEX_ARRAY);                                          } catch (...) { ; }
    try { glDisable (GL_NORMAL_ARRAY);                                          } catch (...) { ; }
    try { glDisable (GL_COLOR_ARRAY);                                           } catch (...) { ; }
    try { glDisable (GL_INDEX_ARRAY);                                           } catch (...) { ; }
    try { glDisable (GL_TEXTURE_COORD_ARRAY);                                   } catch (...) { ; }
    try { glDisable (GL_EDGE_FLAG_ARRAY);                                       } catch (...) { ; }
    try { glDepthRange (0, 1);                                                  } catch (...) { ; }
    try { glDisable (GL_NORMALIZE);                                             } catch (...) { ; }
    for (i = 0; i < GL_MAX_CLIP_PLANES; i++)
        try { glDisable (GL_CLIP_PLANE0 + i);                                   } catch (...) { ; }
    GLfloat fog[] = {0, 0, 0, 0};
    try { glFogfv (GL_FOG_COLOR, fog);                                          } catch (...) { ; }
    try { glFogi (GL_FOG_INDEX, 0);                                             } catch (...) { ; }
    try { glFogf (GL_FOG_DENSITY, 1.0);                                         } catch (...) { ; }
    try { glFogf (GL_FOG_START, 0.0);                                           } catch (...) { ; }
    try { glFogf (GL_FOG_END, 1.0);                                             } catch (...) { ; }
    try { glFogi (GL_FOG_MODE, GL_EXP);                                         } catch (...) { ; }
    try { glDisable (GL_FOG);                                                   } catch (...) { ; }
    try { glShadeModel (GL_SMOOTH);                                             } catch (...) { ; }
    try { glDisable (GL_LIGHTING);                                              } catch (...) { ; }
    try { glDisable (GL_COLOR_MATERIAL);                                        } catch (...) { ; }
    try { glColorMaterial (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);          } catch (...) { ; }

    GLfloat ambient[]   = { 0.2, 0.2, 0.2, 1.0 },
            diffuse[]   = { 0.8, 0.8, 0.8, 1.0 },
            specular[]  = { 0.0, 0.0, 0.0, 1.0 },
            emission[]  = { 0.0, 0.0, 0.0, 1.0 },
            shininess[] = { 0.0 };
    try { glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT,    ambient);             } catch (...) { ; }
    try { glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE,    diffuse);             } catch (...) { ; }
    try { glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR,  specular);             } catch (...) { ; }
    try { glMaterialfv (GL_FRONT_AND_BACK, GL_EMISSION,   emission);            } catch (...) { ; }
    try { glMaterialfv (GL_FRONT_AND_BACK, GL_SHININESS,  shininess);           } catch (...) { ; }
    try { glLightModelfv (GL_LIGHT_MODEL_AMBIENT, ambient);                     } catch (...) { ; }
    try { glLightModeli (GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE);                } catch (...) { ; }
    try { glLightModeli (GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);                    } catch (...) { ; }
    GLfloat lambient[]      = { 0.0, 0.0, 0.0, 1.0 },
            ldiffuse0[]     = { 1.0, 1.0, 1.0, 1.0 },
            ldiffuse1[]     = { 0.0, 0.0, 0.0, 1.0 },
            lspecular0[]    = { 1.0, 1.0, 1.0, 1.0 },
            lspecular1[]    = { 0.0, 0.0, 0.0, 1.0 },
            lposition[]     = { 0.0, 0.0, 1.0, 0.0 };
    for (i = 0; i < 8; i++) {
        try { glLightfv (GL_LIGHT0 + i, GL_AMBIENT, lambient);                              } catch (...) { ; }
        try { glLightfv (GL_LIGHT0 + i, GL_DIFFUSE, i == 0 ? ldiffuse0 : ldiffuse1);        } catch (...) { ; }
        try { glLightfv (GL_LIGHT0 + i, GL_SPECULAR, i == 0 ? lspecular0 : lspecular1);     } catch (...) { ; }
        try { glLightfv (GL_LIGHT0 + i, GL_POSITION, lposition);                            } catch (...) { ; }
        try { glLightf (GL_LIGHT0 + i, GL_SPOT_EXPONENT, 0.0);                              } catch (...) { ; }
        try { glLightf (GL_LIGHT0 + i, GL_CONSTANT_ATTENUATION, 1.0);                       } catch (...) { ; }
        try { glLightf (GL_LIGHT0 + i, GL_LINEAR_ATTENUATION, 0.0);                         } catch (...) { ; }
        try { glLightf (GL_LIGHT0 + i, GL_QUADRATIC_ATTENUATION, 0.0);                      } catch (...) { ; }
        try { glDisable (GL_LIGHT0 + i);                                                    } catch (...) { ; }
    }

    try { glPointSize (1.0);                                                    } catch (...) { ; }
    try { glDisable (GL_POINT_SMOOTH);                                          } catch (...) { ; }
    try { glLineWidth (1.0);                                                    } catch (...) { ; }
    try { glDisable (GL_LINE_SMOOTH);                                           } catch (...) { ; }
    try { glLineStipple (1, 0xffff);                                            } catch (...) { ; }
    try { glDisable (GL_LINE_STIPPLE);                                          } catch (...) { ; }
    try { glDisable (GL_CULL_FACE);                                             } catch (...) { ; }
    try { glCullFace (GL_BACK);                                                 } catch (...) { ; }
    try { glFrontFace (GL_CCW);                                                 } catch (...) { ; }
    try { glDisable (GL_POLYGON_SMOOTH);                                        } catch (...) { ; }
    try { glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);                           } catch (...) { ; }
    try { glDisable (GL_TEXTURE_1D);                                            } catch (...) { ; }
    try { glDisable (GL_TEXTURE_2D);                                            } catch (...) { ; }

    try { glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); } catch (...) { ; }
    try { glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);                } catch (...) { ; }
    try { glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);                    } catch (...) { ; }
    try { glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);                    } catch (...) { ; }
    GLfloat texBorder[] = {0, 0, 0, 0};
    try { glTexParameterfv (GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, texBorder);             } catch (...) { ; }
    try { glDisable (GL_TEXTURE_GEN_T);                                                     } catch (...) { ; }
    try { glDisable (GL_TEXTURE_GEN_S);                                                     } catch (...) { ; }
    try { glDisable (GL_TEXTURE_GEN_R);                                                     } catch (...) { ; }
    try { glDisable (GL_TEXTURE_GEN_Q);                                                     } catch (...) { ; }
    for (i = 0; i < 4; i++) {
        GLenum coord;
        switch (i) {
        case 0: coord = GL_T; break;
        case 1: coord = GL_S; break;
        case 2: coord = GL_R; break;
        case 3: coord = GL_Q; break;
        }
        try { glTexGeni (coord, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);            } catch (...) { ; }
    }

    try { glDisable (GL_SCISSOR_TEST);                                          } catch (...) { ; }
    try { glDisable (GL_ALPHA_TEST);                                            } catch (...) { ; }
    try { glAlphaFunc (GL_ALWAYS, 0);                                           } catch (...) { ; }
    try { glDisable (GL_STENCIL_TEST);                                          } catch (...) { ; }
    try { glStencilFunc (GL_ALWAYS, 0, 0xffffffff);                             } catch (...) { ; }
    try { glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP);                              } catch (...) { ; }
    try { glDisable (GL_DEPTH_TEST);                                            } catch (...) { ; }
    try { glDepthFunc (GL_LESS);                                                } catch (...) { ; }
    try { glDisable (GL_BLEND);                                                 } catch (...) { ; }
    try { glBlendFunc (GL_ONE, GL_ZERO);                                        } catch (...) { ; }
    try { glDrawBuffer (GL_BACK);                                               } catch (...) { ; }
    try { glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);                     } catch (...) { ; }
    try { glDepthMask (GL_TRUE);                                                } catch (...) { ; }
    try { glClearAccum (0, 0, 0, 0);                                            } catch (...) { ; }
    try { glClearColor (0, 0, 0, 0);                                            } catch (...) { ; }
    try { glClearDepth (1);                                                     } catch (...) { ; }
    try { glClearIndex (0);                                                     } catch (...) { ; }
    try { glClearStencil (0);                                                   } catch (...) { ; }

    try { glPixelStorei (GL_PACK_SWAP_BYTES, GL_FALSE);                         } catch (...) { ; }
    try { glPixelStorei (GL_PACK_LSB_FIRST, GL_FALSE);                          } catch (...) { ; }
    try { glPixelStoref (GL_PACK_ROW_LENGTH, 0);                                } catch (...) { ; }
    try { glPixelStoref (GL_PACK_SKIP_PIXELS, 0);                               } catch (...) { ; }
    try { glPixelStorei (GL_PACK_ALIGNMENT, 4);                                 } catch (...) { ; }
    try { glPixelStorei (GL_UNPACK_SWAP_BYTES, GL_FALSE);                       } catch (...) { ; }
    try { glPixelStorei (GL_UNPACK_LSB_FIRST, GL_FALSE);                        } catch (...) { ; }
    try { glPixelStoref (GL_UNPACK_ROW_LENGTH, 0);                              } catch (...) { ; }
    try { glPixelStoref (GL_UNPACK_SKIP_PIXELS, 0);                             } catch (...) { ; }
    try { glPixelStorei (GL_UNPACK_ALIGNMENT, 4);                               } catch (...) { ; }
    try { glPixelTransferi (GL_MAP_COLOR, GL_FALSE);                            } catch (...) { ; }
    try { glPixelTransferi (GL_MAP_STENCIL, GL_FALSE);                          } catch (...) { ; }
    try { glPixelTransferi (GL_INDEX_SHIFT, 0);                                 } catch (...) { ; }
    try { glPixelTransferi (GL_INDEX_OFFSET, 0);                                } catch (...) { ; }
    try { glPixelTransferf (GL_RED_SCALE, 1.0);                                 } catch (...) { ; }
    try { glPixelTransferf (GL_GREEN_SCALE, 1.0);                               } catch (...) { ; }
    try { glPixelTransferf (GL_BLUE_SCALE, 1.0);                                } catch (...) { ; }
    try { glPixelTransferf (GL_ALPHA_SCALE, 1.0);                               } catch (...) { ; }
    try { glPixelTransferf (GL_DEPTH_SCALE, 1.0);                               } catch (...) { ; }
    try { glPixelTransferf (GL_RED_BIAS, 0.0);                                  } catch (...) { ; }
    try { glPixelTransferf (GL_GREEN_BIAS, 0.0);                                } catch (...) { ; }
    try { glPixelTransferf (GL_BLUE_BIAS, 0.0);                                 } catch (...) { ; }
    try { glPixelTransferf (GL_ALPHA_BIAS, 0.0);                                } catch (...) { ; }
    try { glPixelTransferf (GL_DEPTH_BIAS, 0.0);                                } catch (...) { ; }

    try { glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_DONT_CARE);                } catch (...) { ; }
    try { glHint (GL_POINT_SMOOTH_HINT, GL_DONT_CARE);                          } catch (...) { ; }
    try { glHint (GL_LINE_SMOOTH_HINT, GL_DONT_CARE);                           } catch (...) { ; }
    try { glHint (GL_POLYGON_SMOOTH_HINT, GL_DONT_CARE);                        } catch (...) { ; }
    try { glHint (GL_FOG_HINT, GL_DONT_CARE);                                   } catch (...) { ; }

    // Multitexturing
    if (ExtensionSupported ("GL_ARB_multitexture")) {

        // Disable texturing for all texture units
        int units;
        try { glGetIntegerv (GL_MAX_TEXTURE_UNITS_ARB, &units);                 } catch (...) { ; }
        for (int i = 0; i < units; i++) {
            if (glActiveTexture != NULL)
                glActiveTexture (GL_TEXTURE0_ARB + i);
            try { glDisable (GL_TEXTURE_2D);                                    } catch (...) { ; }
            try { glDisable (GL_TEXTURE_1D);                                    } catch (...) { ; }
            if (i == 0) try { glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); } catch (...) { ; }
            else        try { glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND);    } catch (...) { ; }
        }

        if (glActiveTexture != NULL)
            try { glActiveTexture (GL_TEXTURE0_ARB);                            } catch (...) { ; }
    }

    // Setup OpenGL defaults
    OpenGLDefaults ();

	return TRUE;									// Initialization Went OK
}
Esempio n. 11
0
//----------------------------------------------------------------------------------------------------------------------
void SMCAgentViz::update()
{
  glDisable(GL_DEPTH_TEST);
  
  // data
  const ci::Vec2f& pos = m_agent->getPosition();
  float angle = m_agent->getAngle();
  
  // Update trajectory
  if(!m_paused && m_steps % 2 == 0){
    m_traj.push_back(pos);
  
    if(m_traj.size() >= 800)
    {
      m_traj.pop_front();
    }
  }
  
  m_steps++;
  
  // pose
  m_pTM->setToIdentity();  
  m_pTM->setTranslate(ci::Vec3f(pos));  
  m_pTM->rotate(ci::Vec3f(0.0f, 0.0f, 1.0f), angle);

  NodeGroup::update();
  
  // draw
  glPushAttrib(GL_LIGHTING);
  glDisable(GL_LIGHTING);
  
  // Trajectory
  ci::ColorA trajCol (235.0/255.0, 89.0/255.0, 55.0/255.0, 1.0);
  glEnableClientState(GL_VERTEX_ARRAY);
  glEnableClientState(GL_COLOR_ARRAY);
  int numPoints =  m_traj.size();
  float lineVerts[numPoints*2];
  float colors[numPoints*4];
  glVertexPointer(2, GL_FLOAT, 0, lineVerts); // 2d positions
  glColorPointer(4, GL_FLOAT, 0, colors);     // 4d colors
  
  for(size_t i = 0; i < numPoints; i++)
  {
    lineVerts[i*2 + 0] = m_traj[i].x;
    lineVerts[i*2 + 1] = m_traj[i].y;
    float a = (float)i / (float)numPoints;
    
    colors[i*4 + 0] = trajCol[0];
    colors[i*4 + 1] = trajCol[1];
    colors[i*4 + 2] = trajCol[2];
    colors[i*4 + 3] = a;
  }
  glLineWidth(2.0);
  glDrawArrays( GL_LINE_STRIP, 0, numPoints);
  glDisableClientState(GL_VERTEX_ARRAY);
  glDisableClientState(GL_COLOR_ARRAY);
  glLineWidth(1.0);
  
  // This is in world space
  glColor3f(0, 0, 0);
  const float velScale = 0.1f;
  glLineWidth(2.0);
  ci::gl::drawLine(m_agent->getPosition(), m_agent->getPosition() + m_agent->getVelocity() * velScale);
  glLineWidth(1.0);
  
  if(m_agent->hasDistanceSensor())
  {
    DistanceSensor* sensor = m_agent->getDistanceSensor();
    float sensedDistance = sensor->getDistance();
    glEnable(GL_LINE_STIPPLE);
    glLineStipple(2, 0xAAAA);
    glColor3f(0.2, 0.2, 0.2);    
    ci::gl::drawLine(sensor->getPosition(), sensor->getPosition() + sensor->getDirection() * sensedDistance);
    glDisable(GL_LINE_STIPPLE);
    
    glColor3f(1,0,0);
    if(sensedDistance < sensor->getMaxDistance())
    {
      drawPoint(ci::Vec3f(sensor->getCollision()), 5.0f);
    }
    
    // Sensor in local space
    glPushMatrix();
    glMultMatrixf(*m_pTM);
    glTranslatef(m_agent->getRadius(), 0, 0.001);
    float act = m_agent->getDistanceSensor()->getDistanceProportional();
    glColor3f(act,act,act);
    drawDisk(m_agent->getRadius() / 4.0, 0, 16, 2, GLU_FILL);
    glColor3f(0,0,0);
    drawDisk(m_agent->getRadius() / 4.0, 0, 16, 2, GLU_SILHOUETTE);
    glPopMatrix();
  }
  
  if(m_agent->hasGradientSensor())
  {
    GradientSensor* sensor = m_agent->getGradientSensor();
    float s = 1.0f - sensor->getActivation();
    
    // Sensor in local space
    glPushMatrix();
    glTranslatef(sensor->getPosition().x, sensor->getPosition().y, 0.0);
    glColor3f(s,s,s);
    drawDisk(m_agent->getRadius() / 4.0, 0, 16, 2, GLU_FILL);
    glColor3f(0,0,0);
    drawDisk(m_agent->getRadius() / 4.0, 0, 16, 2, GLU_SILHOUETTE);
    glPopMatrix();
  }
  
  if(m_agent->hasTorusSensor())
  {
    Sensor* sensor = m_agent->getTorusSensor();
    float s = 1.0f - sensor->getActivation();
    
    // Sensor in local space
    glPushMatrix();
    glTranslatef(sensor->getPosition().x, sensor->getPosition().y, 0.0);
    glColor3f(s,s,s);
    drawDisk(m_agent->getRadius() / 4.0, 0, 16, 2, GLU_FILL);
    glColor3f(0,0,0);
    drawDisk(m_agent->getRadius() / 4.0, 0, 16, 2, GLU_SILHOUETTE);
    glPopMatrix();
  }

  
  // draw positional range
  if(m_agent->positionWraps())
  {
    float p = m_agent->getMaxPosition();
    ci::gl::drawStrokedRect(ci::Rectf(ci::Vec2f(-p,-p), ci::Vec2f(p,p)));
  }

  // Change body color depending on energy level
  ci::Vec3f col = getColorMapRainbow(m_agent->getEnergy() / 5);
  ci::Vec4f col4 = ci::Vec4f(col);
  col4[3] = 0.5;
  m_agentDisk->m_color = col4;
  
  glPopAttrib();
  glEnable(GL_DEPTH_TEST);
}
Esempio n. 12
0
void CRender::setLineStipple(unsigned int repeats, unsigned short pattern) {
	/* With opengl, repeats means the number of times a bit in the pattern will be used
	(repeated) before using the next one */
	glLineStipple(repeats, pattern);
}
Esempio n. 13
0
//--------------------------------------------------------------
void styleScene::draw() {
    ofPushStyle();

    for(int i = 0; i < drawableButtons.size(); i++) {
        drawableButtons[i]->draw();
    }

    if( groups.size() ) {
        renderer.render(groups.getVector());
        ofPushStyle();
        ofSetLineWidth(1);
        glLineStipple(1, 0x3F07 );
        glEnable( GL_LINE_STIPPLE );
        for(int i = 0; i < groups.size(); i++) {
            if( i == whichGroup || showAll) {
                ofSetColor(160, 160, 160);
                groups[i].drawBoundingRect();
            }
        }
        glDisable(GL_LINE_STIPPLE);
        ofPopStyle();
    }

    ofEnableAlphaBlending();
    if( state == STYLE_LETTER ) {
        selectLeft.draw(50.0);
        selectRight.draw(50.0);
    } else if (state == STYLE_STROKE) {
        strokeUp.draw(50.0);
        strokeDown.draw(50.0);
        pickColor.draw(50.0);
        brush.draw(50.0);
    } else if (state == STYLE_SHADOW) {
        shadowLeft.draw(50.0);
        shadowRight.draw(50.0);
        shadowUp.draw(50.0);
        shadowDown.draw(50.0);
        pickColor.draw(50.0);
        lighting.draw(50.0);
        hashes.draw(50.0);
    } else if (state == STYLE_FILL) {
        toggleFill.draw(75.0);
        toggleHoles.draw(75.0);
        pickColor.draw(50.0);
    } else if (state == STYLE_OUTLINE) {
        outlineUp.draw(50.0);
        outlineDown.draw(50.0);
        pickColor.draw(50.0);
    }

    if (drawColors) {
        ofPushStyle();
        cPicker.draw(pickColor.x + pickColor.width - 6*cPicker.width, pickColor.y+100);
        ofPopStyle();
    }


    if( mx < SIDE_GUI_X ) {
        ofPushStyle();
        ofFill();
        ofSetColor(255, 255, 255);
        ofCircle(mx, my, 9);
        ofSetColor(0,0,0);
        ofCircle(mx, my, 6);
        ofPopStyle();
    }
    else if( testState == BUTTON_NONE ) {
        ofSetColor(0, 0, 0);
        ofNoFill();
        ofCircle(mx, my, 9);
    } else if(testState == BUTTON_STARTED ) {
        ofFill();
        ofCircle(mx, my, 5);
    }

    ofPopStyle();
}
Esempio n. 14
0
static void display(void)
{
  unsigned int i;
  unsigned int N = 50;
  const char *help = "Press 's' to save image or 'q' to quit";

  glClearColor(0.3, 0.5, 0.8, 0.);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  /* draw a smooth-shaded torus */
  glPushMatrix();
  glRotatef(-60., 2., 0., 1.);
  glEnable(GL_LIGHTING);
  glutSolidTorus(0.3, 0.6, 30, 30);
  glDisable(GL_LIGHTING);
  glPopMatrix();


  /* draw three triangles on the same zplane and use polygon offset
     to order the layers: the grey triangle should be drawn on the
     middle layer */
  glEnable(GL_POLYGON_OFFSET_FILL);
  glPolygonOffset(1.0, 1.0);
  gl2psEnable(GL2PS_POLYGON_OFFSET_FILL);
  glColor3f(0.,0.,0.);
  glBegin(GL_TRIANGLES);
  glVertex3f(0.6, 0.8, 0);
  glVertex3f(0.8, 0.8, 0);
  glVertex3f(0.7, 0.92, 0);
  glEnd();

  glPolygonOffset(2.0, 2.0);
  gl2psEnable(GL2PS_POLYGON_OFFSET_FILL);
  glColor3f(1.,1.,1.);
  glBegin(GL_TRIANGLES);
  glVertex3f(0.7, 0.8, 0);
  glVertex3f(0.9, 0.8, 0);
  glVertex3f(0.8, 0.92, 0);
  glEnd();

  glPolygonOffset(1.5, 1.5);
  gl2psEnable(GL2PS_POLYGON_OFFSET_FILL);
  glColor3f(0.5,0.5,0.5);
  glBegin(GL_TRIANGLES);
  glVertex3f(0.65, 0.86, 0);
  glVertex3f(0.85, 0.86, 0);
  glVertex3f(0.75, 0.98, 0);
  glEnd();

  glDisable(GL_POLYGON_OFFSET_FILL);
  gl2psDisable(GL2PS_POLYGON_OFFSET_FILL);

  glColor3f(0.1,0.1,0.1);

  /* draw a stippled line with many small segments (this tests the
     ability of gl2ps to render lines using as few strokes as
     possible) */
  glEnable(GL_LINE_STIPPLE);
  glLineStipple(1, 0x087F);
  gl2psEnable(GL2PS_LINE_STIPPLE);
  glBegin(GL_LINE_STRIP);
  for(i = 0; i < N; i++)
    glVertex3f(-0.75 + 1.5 * (double)i/(double)(N - 1), 0.75, -0.9);
  glEnd();
  glDisable(GL_LINE_STIPPLE);
  gl2psDisable(GL2PS_LINE_STIPPLE);

  /* draw a text string */
  glRasterPos2d(-0.9,-0.9);
  gl2psText(help, "Times-Roman", 24);
  for (i = 0; i < strlen(help); i++)
    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, help[i]);

  glFlush();
}
Esempio n. 15
0
void extras()
{
  glColor3f(1., 0., 0.);

  glPointSize(1.);
  gl2psPointSize(1.);
  glBegin(GL_POINTS);
  glVertex3f(-1., 1.0, 0.);
  glEnd();

  glPointSize(3.);
  gl2psPointSize(3.);
  glBegin(GL_POINTS);
  glVertex3f(-0.8, 1.0, 0.);
  glEnd();

  glPointSize(5.);
  gl2psPointSize(5.);
  glBegin(GL_POINTS);
  glVertex3f(-0.6, 1.0, 0.);
  glEnd();

  glPointSize(7.);
  gl2psPointSize(7.);
  glBegin(GL_POINTS);
  glVertex3f(-0.4, 1.0, 0.);
  glEnd();

  glLineWidth(1.);
  gl2psLineWidth(1.);
  glBegin(GL_LINES);
  glVertex3f(-0.2, 1.05, 0.);
  glVertex3f(0.2, 1.05, 0.);
  glEnd();

  glEnable(GL_LINE_STIPPLE);
  glLineStipple(1, 0x087F);
  gl2psEnable(GL2PS_LINE_STIPPLE);
  glBegin(GL_LINES);
  glVertex3f(-0.2, 0.95, 0.);
  glVertex3f(0.2, 0.95, 0.);
  glEnd();
  glDisable(GL_LINE_STIPPLE);
  gl2psDisable(GL2PS_LINE_STIPPLE);

  glLineWidth(3.);
  gl2psLineWidth(3.);
  glBegin(GL_LINES);
  glVertex3f(0.4, 1.05, 0.);
  glVertex3f(0.8, 1.05, 0.);
  glEnd();

  glEnable(GL_LINE_STIPPLE);
  glLineStipple(2, 0x0F0F);
  /* glLineStipple(1, 0xAAAA); */
  gl2psEnable(GL2PS_LINE_STIPPLE);
  glBegin(GL_LINES);
  glVertex3f(0.4, 0.95, 0.);
  glVertex3f(0.8, 0.95, 0.);
  glEnd();
  glDisable(GL_LINE_STIPPLE);
  gl2psDisable(GL2PS_LINE_STIPPLE);

  glPointSize(1);
  gl2psPointSize(1);
  glLineWidth(1);
  gl2psLineWidth(1);
}
Esempio n. 16
0
void Entity::DrawOrGetDistance(void) {
    if(!IsVisible()) return;

    Group *g = SK.GetGroup(group);

    switch(type) {
        case POINT_N_COPY:
        case POINT_N_TRANS:
        case POINT_N_ROT_TRANS:
        case POINT_N_ROT_AA:
        case POINT_IN_3D:
        case POINT_IN_2D: {
            Vector v = PointGetNum();
            dogd.refp = v;

            if(dogd.drawing) {
                double s = 3.5;
                Vector r = SS.GW.projRight.ScaledBy(s/SS.GW.scale);
                Vector d = SS.GW.projUp.ScaledBy(s/SS.GW.scale);

                ssglColorRGB(Style::Color(Style::DATUM));
                ssglDepthRangeOffset(6);
                glBegin(GL_QUADS);
                    ssglVertex3v(v.Plus (r).Plus (d));
                    ssglVertex3v(v.Plus (r).Minus(d));
                    ssglVertex3v(v.Minus(r).Minus(d));
                    ssglVertex3v(v.Minus(r).Plus (d));
                glEnd();
                ssglDepthRangeOffset(0);
            } else {
                Point2d pp = SS.GW.ProjectPoint(v);
                dogd.dmin = pp.DistanceTo(dogd.mp) - 6;
            }
            break;
        }

        case NORMAL_N_COPY:
        case NORMAL_N_ROT:
        case NORMAL_N_ROT_AA:
        case NORMAL_IN_3D:
        case NORMAL_IN_2D: {
            int i;
            for(i = 0; i < 2; i++) {
                if(i == 0 && !SS.GW.showNormals) {
                    // When the normals are hidden, we will continue to show
                    // the coordinate axes at the bottom left corner, but
                    // not at the origin.
                    continue;
                }

                hRequest hr = h.request();
                // Always draw the x, y, and z axes in red, green, and blue;
                // brighter for the ones at the bottom left of the screen,
                // dimmer for the ones at the model origin.
                int f = (i == 0 ? 100 : 255);
                if(hr.v == Request::HREQUEST_REFERENCE_XY.v) {
                    ssglColorRGB(RGBi(0, 0, f));
                } else if(hr.v == Request::HREQUEST_REFERENCE_YZ.v) {
                    ssglColorRGB(RGBi(f, 0, 0));
                } else if(hr.v == Request::HREQUEST_REFERENCE_ZX.v) {
                    ssglColorRGB(RGBi(0, f, 0));
                } else {
                    ssglColorRGB(Style::Color(Style::NORMALS));
                    if(i > 0) break;
                }

                Quaternion q = NormalGetNum();
                Vector tail;
                if(i == 0) {
                    tail = SK.GetEntity(point[0])->PointGetNum();
                    glLineWidth(1);
                } else {
                    // Draw an extra copy of the x, y, and z axes, that's
                    // always in the corner of the view and at the front.
                    // So those are always available, perhaps useful.
                    double s = SS.GW.scale;
                    double h = 60 - SS.GW.height/2;
                    double w = 60 - SS.GW.width/2;
                    tail = SS.GW.projRight.ScaledBy(w/s).Plus(
                           SS.GW.projUp.   ScaledBy(h/s)).Minus(SS.GW.offset);
                    ssglDepthRangeLockToFront(true);
                    glLineWidth(2);
                }

                Vector v = (q.RotationN()).WithMagnitude(50/SS.GW.scale);
                Vector tip = tail.Plus(v);
                LineDrawOrGetDistance(tail, tip);

                v = v.WithMagnitude(12/SS.GW.scale);
                Vector axis = q.RotationV();
                LineDrawOrGetDistance(tip,tip.Minus(v.RotatedAbout(axis, 0.6)));
                LineDrawOrGetDistance(tip,tip.Minus(v.RotatedAbout(axis,-0.6)));
            }
            ssglDepthRangeLockToFront(false);
            break;
        }

        case DISTANCE:
        case DISTANCE_N_COPY:
            // These are used only as data structures, nothing to display.
            break;

        case WORKPLANE: {
            Vector p;
            p = SK.GetEntity(point[0])->PointGetNum();

            Vector u = Normal()->NormalU();
            Vector v = Normal()->NormalV();

            double s = (min(SS.GW.width, SS.GW.height))*0.45/SS.GW.scale;

            Vector us = u.ScaledBy(s);
            Vector vs = v.ScaledBy(s);

            Vector pp = p.Plus (us).Plus (vs);
            Vector pm = p.Plus (us).Minus(vs);
            Vector mm = p.Minus(us).Minus(vs), mm2 = mm;
            Vector mp = p.Minus(us).Plus (vs);

            glLineWidth(1);
            ssglColorRGB(Style::Color(Style::NORMALS));
            glEnable(GL_LINE_STIPPLE);
            glLineStipple(3, 0x1111);
            if(!h.isFromRequest()) {
                mm = mm.Plus(v.ScaledBy(60/SS.GW.scale));
                mm2 = mm2.Plus(u.ScaledBy(60/SS.GW.scale));
                LineDrawOrGetDistance(mm2, mm);
            }
            LineDrawOrGetDistance(pp, pm);
            LineDrawOrGetDistance(pm, mm2);
            LineDrawOrGetDistance(mm, mp);
            LineDrawOrGetDistance(mp, pp);
            glDisable(GL_LINE_STIPPLE);

            char *str = DescriptionString()+5;
            double th = DEFAULT_TEXT_HEIGHT;
            if(dogd.drawing) {
                ssglWriteText(str, th, mm2, u, v, NULL, NULL);
            } else {
                Vector pos = mm2.Plus(u.ScaledBy(ssglStrWidth(str, th)/2)).Plus(
                                      v.ScaledBy(ssglStrHeight(th)/2));
                Point2d pp = SS.GW.ProjectPoint(pos);
                dogd.dmin = min(dogd.dmin, pp.DistanceTo(dogd.mp) - 10);
                // If a line lies in a plane, then select the line, not
                // the plane.
                dogd.dmin += 3;
            }
            break;
        }

        case LINE_SEGMENT:
        case CIRCLE:
        case ARC_OF_CIRCLE:
        case CUBIC:
        case CUBIC_PERIODIC:
        case TTF_TEXT:
            // Nothing but the curve(s).
            break;

        case FACE_NORMAL_PT:
        case FACE_XPROD:
        case FACE_N_ROT_TRANS:
        case FACE_N_TRANS:
        case FACE_N_ROT_AA:
            // Do nothing; these are drawn with the triangle mesh
            break;

        default:
            oops();
    }

    // And draw the curves; generate the rational polynomial curves for
    // everything, then piecewise linearize them, and display those.
    SEdgeList sel;
    ZERO(&sel);
    GenerateEdges(&sel, true);
    int i;
    for(i = 0; i < sel.l.n; i++) {
        SEdge *se = &(sel.l.elem[i]);
        LineDrawOrGetDistance(se->a, se->b, true);
    }
    sel.Clear();
}
Esempio n. 17
0
void Marker::update(bool force)
{
	GLubyte g;

	bool markerflag = m_MarkerBufferControl.update();

	if( markerflag || force )
	{
		double value = m_Value.getPrimaryBuffer();
		const GraphState & state = m_Destination->getGraphState();
		const QRect & datarect = m_Destination->getDataPos();
		const MarkerDirection & type = m_Type.getPrimaryBuffer();

		// Remove Marker if out of range
		if( (type == Marker::M_V && (value <= state.xLow || value >= state.xHigh)) ||
			(type == Marker::M_H && (value <= state.yLow || value >= state.yHigh)))
		{
			glNewList( m_ListBase, GL_COMPILE );
			glEndList();
			return;
		}

		// Scale correctly
		double xRatio = datarect.width()/(double)(state.xHigh-state.xLow);
		double yRatio = datarect.height()/(double)(state.yHigh-state.yLow);
		double xOffset = -state.xLow;
		double yOffset = -state.yLow;

		glNewList( m_ListBase, GL_COMPILE );
		{
			glPushAttrib( GL_LINE_BIT );
			{
				if( m_LinePatternFactor > 0 )
				{
					glEnable( GL_LINE_STIPPLE );
					glLineStipple( m_LinePatternFactor, m_LinePattern );
				}
				g = m_GrayLevel.getPrimaryBuffer();
				glColor3ub( g, g, g );
				glLineWidth( m_LineWidth );

				glBegin( GL_LINES );
				{
					switch(type)
					{
					case Marker::M_V:
						glVertex2f( (value+xOffset)*xRatio, (state.yLow+yOffset)*yRatio );
						glVertex2f( (value+xOffset)*xRatio, (state.yHigh+yOffset)*yRatio );
						break;
					case Marker::M_H:
						glVertex2f( (state.xLow+xOffset)*xRatio, (value+yOffset)*yRatio );
						glVertex2f( (state.xHigh+xOffset)*xRatio, (value+yOffset)*yRatio );
						break;
					}
				}
				glEnd();
			}
			glPopAttrib();
		}
		glEndList();
	}
}
Esempio n. 18
0
//-----------------------------------------------------------------------------
// Name: DrawGrid()
// Desc: 
//-----------------------------------------------------------------------------
GLvoid 
COpenGL::DrawGrid(
    GLfloat left, 
    GLfloat right, 
    GLfloat bottom, 
    GLfloat top )
{
    GLfloat    fwidth = right - left;
    GLfloat    fheight = top - bottom;
    GLfloat    fdeltax = 1.0f;
    GLfloat    fdeltay = 1.0f;
    GLfloat    fgridw = ( fwidth - 2 * fdeltax ) / 12;
    GLfloat    fgridh = ( fheight - 2 * fdeltay ) / 6;

	glColor3ub( 0, 0, 0 );
	
    glBegin( GL_LINES );
    {
        glVertex2f( fdeltax,  fheight / 2 /*- 0.1*/ );
        glVertex2f( fwidth - fdeltax,  fheight / 2 /*- 0.1*/ );
		
		for ( int i = 1; i < 60 ; i++ )
		{
			glVertex2f( fdeltax + i * fgridw / 5.0f, fheight / 2.0f + 2.0f );
			glVertex2f( fdeltax + i * fgridw / 5.0f, fheight / 2.0f - 2.0f );
		}
    }
    glEnd();
    
    glBegin( GL_LINE_LOOP );
    {
        glVertex2f( fdeltax, fdeltay );
        glVertex2f( fdeltax, fheight - fdeltay );
        glVertex2f( fwidth - fdeltax, fheight - fdeltay );
        glVertex2f( fwidth - fdeltax, fdeltay );
    }
    glEnd();

    glColor3ub( 127, 127, 127 );
	glEnable( GL_LINE_STIPPLE );
	glLineStipple( 1, 0x0707 );
    glBegin( GL_LINES );
    {
        for ( char x = 1; x <= 11; x++ )
        {
            glVertex2f(  fdeltax + fgridw * x, fdeltay );
            glVertex2f(  fdeltax + fgridw * x, fheight - fdeltay );
        }
        
        for ( char y = 1; y <= 5; y++ )
        {
//             if( 3 == y )
//             {
//                 continue;
//             }
            glVertex2f( fdeltax, fdeltay + fgridh * y  );
            glVertex2f( fwidth - fdeltax, fdeltay + fgridh * y  );
        }
    }
    glEnd();
	glDisable( GL_LINE_STIPPLE );

//	glFinish();
}
Esempio n. 19
0
void
CVComplexShape::Draw()
{
//	logToFile((f, "CVComplexShape Draw\n"));
    if(!m_IsVisible) return;
    double *vertices = exact ? scrVertices : m_getVertices();
    if (arrays[aiIndices] != 0 && GetLength(arrays[aiIndices], 1) == 0 ||
            vertices == 0 || GetLength(vertices, 1) == 0)
        return;

    glPushMatrix();

    if(exact) {
        glMatrixMode (GL_MODELVIEW);
        glLoadIdentity();
        glTranslated(0.0, 0.0, m_dZ);
    }
    else {
        // Only get exact calibration location of center
        // and approximate the rest of the points
        /*
        float x = XPosToScreen((float)X,(float)Y);
        float y = YPosToScreen((float)X,(float)Y);

        m_nClipped = VISWIN_IS_CLIPPED(x,y);
        */
        float pix[2];
        g_TransformCoordinatesF( m_dX, m_dY, pix, pix+1 );
        m_nClipped = IS_OFF_WINDOW(pix[0],pix[1]);

        g_TransformGradientD(JAC,m_dX,m_dY);
        /* DPosToDScreen(JAC,x,y); */
        // Rot 4x4, allocated by column, as in matlab
        // Jac, though, is only the 2x2 Jacobian
        ROT[0]=m_dScale*JAC[0][0];
        ROT[1]=m_dScale*JAC[1][0];
        ROT[4]=m_dScale*JAC[0][1];
        ROT[5]=m_dScale*JAC[1][1];
        ROT[12]=pix[0];
        ROT[13]=pix[1];
        ROT[14]=m_dZ;



        glMatrixMode (GL_MODELVIEW);
        // glLoadIdentity();
        // glTranslatef((float)x,(float)y,Z);      // 3: Translate
        // glScalef((float)scx,(float)scy,1);      // 2: Scale
        glLoadMatrixd(ROT);              // 2: Translate and Scale
        glRotatef((float)m_dAngle,0,0,1);   // 1: Rotate About Z axis
    }

    glColor4d(m_fRGB[0],m_fRGB[1],m_fRGB[2],m_fAlpha);

    if (drawMode >= odmLines && drawMode <= odmLineLoop)
    {
        if (lineStipple != 0)
        {
            glLineStipple(lineStippleFactor, lineStipple);
            glEnable(GL_LINE_STIPPLE);
        }

        if (lineWidth != 1.0) glLineWidth((float)lineWidth);
    }

    if (drawMode == odmPoints && pointSize != 1.0) glPointSize((float)pointSize);

    if (drawMode >= odmTriangles && drawMode <= odmPolygon)
    {
        if (arrays[aiPolygonStipple] != 0)
        {
            glEnable(GL_POLYGON_STIPPLE);
            glPolygonStipple((unsigned char *)arrays[aiPolygonStipple]);
        }
    }

    if (vertices            != 0)   glEnableClientState(GL_VERTEX_ARRAY);
    if (arrays[aiColors   ] != 0)   glEnableClientState(GL_COLOR_ARRAY);
    if (arrays[aiEdgeFlags] != 0)   glEnableClientState(GL_EDGE_FLAG_ARRAY);

    if (arrays[aiIndices] != 0)
    {

        if (vertices != 0)
            glVertexPointer(GetLength(vertices, 0), GL_DOUBLE, 0, vertices);
        if (arrays[aiColors] != 0)
            glColorPointer (GetLength(arrays[aiColors], 0), GL_DOUBLE, 0, arrays[aiColors]);
//		if (arrays[aiEdgeFlags] != 0)
//			glEdgeFlagPointer(0, arrays[aiEdgeFlags]);

        if (GetDim(arrays[aiIndices]) == 1 || GetLength(arrays[aiIndices], 0) == 1)
            glDrawElements(glDrawModeMap[drawMode], GetLength(arrays[aiIndices]), GL_UNSIGNED_INT, arrays[aiIndices]);
        else
        {
            int len0 = GetLength(arrays[aiIndices], 0);
            int len1 = GetLength(arrays[aiIndices], 1);
            for (int i=0; i < len1; ++i)
                glDrawElements(glDrawModeMap[drawMode], len0, GL_UNSIGNED_INT, ((unsigned int *)arrays[aiIndices]) + len0 * i);
        }
    }
    else if (vertices != 0)
    {
        int len2 = GetDim(vertices) <= 2 ? 1 : GetLength(vertices, 2);
        for (int i=0; i < len2; ++i)
        {
            if (vertices != 0)
                glVertexPointer(GetLength(vertices, 0), GL_DOUBLE, 0, vertices + GetLength(vertices, 0) * GetLength(vertices, 1) * i);
            if (arrays[aiColors] != 0)
                glColorPointer (GetLength(arrays[aiColors], 0), GL_DOUBLE, 0, arrays[aiColors] + GetLength(arrays[aiColors], 0) * GetLength(arrays[aiColors], 1) * i);
//			if (arrays[aiEdgeFlags] != 0)
//				glEdgeFlagPointer(0, arrays[aiEdgeFlags]);
            glDrawArrays(glDrawModeMap[drawMode], 0, GetLength(vertices, 1));
        }
    }

    if (vertices            != 0)   glDisableClientState(GL_VERTEX_ARRAY);
    if (arrays[aiColors   ] != 0)   glDisableClientState(GL_COLOR_ARRAY);
    if (arrays[aiEdgeFlags] != 0)   glDisableClientState(GL_EDGE_FLAG_ARRAY);

    if (drawMode >= odmTriangles && drawMode <= odmPolygon)
    {
        if (arrays[aiPolygonStipple] != 0) glDisable(GL_POLYGON_STIPPLE);
    }

    if (drawMode >= odmLines && drawMode <= odmLineLoop)
    {
        if (lineStipple != 0) glDisable(GL_LINE_STIPPLE);
        if (lineWidth != 1.0) glLineWidth(1.0);
    }

    if (drawMode == odmPoints && pointSize != 1.0) glPointSize(1.0);

    glPopMatrix();
}
Esempio n. 20
0
M(void, glLineStipple, jint factor, jshort pattern) {
	glLineStipple(factor, pattern);
}
void liqCoordSysNode::draw(  M3dView & view, const MDagPath & /*path*/,
                             M3dView::DisplayStyle displaystyle,
                             M3dView::DisplayStatus displaystatus )
{
  // Get the type
  //
  MObject thisNode = thisMObject();
  MPlug typePlug( thisNode, aCoordType );
  CHECK_MSTATUS(typePlug.getValue( m_coordType ));
  MPlug colorPlug( thisNode, aCoordColor );
  CHECK_MSTATUS(colorPlug.child(0).getValue( m_coordColor.r ));
  CHECK_MSTATUS(colorPlug.child(1).getValue( m_coordColor.g ));
  CHECK_MSTATUS(colorPlug.child(2).getValue( m_coordColor.b ));
  MPlug opacityPlug( thisNode, aCoordOpacity );
  CHECK_MSTATUS(opacityPlug.getValue( m_coordColor.a ));

  view.beginGL();

  // Draw the arrows
  //

  glPushAttrib( GL_ALL_ATTRIB_BITS );

  glBegin( GL_LINES );

    glColor4f( 1.0f, 0.0f, 0.0f, 1.0f );
    glVertex3f(  0.00f,  0.00f,  0.00f );
    glVertex3f(  0.50f,  0.00f,  0.00f );
    glVertex3f(  0.50f,  0.00f,  0.00f );
    glVertex3f(  0.40f, -0.05f,  0.00f );
    glVertex3f(  0.40f, -0.05f,  0.00f );
    glVertex3f(  0.40f,  0.00f,  0.00f );

    glColor4f( 0.0f, 1.0f, 0.0f, 1.0f );
    glVertex3f(  0.00f,  0.00f,  0.00f  );
    glVertex3f(  0.00f,  0.50f,  0.00f  );
    glVertex3f(  0.00f,  0.50f,  0.00f  );
    glVertex3f(  0.05f,  0.40f,  0.00f  );
    glVertex3f(  0.05f,  0.40f,  0.00f  );
    glVertex3f(  0.00f,  0.40f,  0.00f  );

    glColor4f( 0.0f, 0.0f, 1.0f, 1.0f );
    glVertex3f(  0.00f,  0.00f,  0.00f   );
    glVertex3f(  0.00f,  0.00f,  0.50f   );
    glVertex3f(  0.00f,  0.00f,  0.50f   );
    glVertex3f(  0.00f, -0.05f,  0.40f   );
    glVertex3f(  0.00f, -0.05f,  0.40f   );
    glVertex3f(  0.00f,  0.00f,  0.40f   );

  glEnd();

  glPopAttrib();


  // draw the warious primitives
  //

  switch( m_coordType ) 
  {
    case 0:
      // PLANE
      glPushAttrib( GL_ALL_ATTRIB_BITS );
      if ( displaystatus == M3dView::kDormant ) 
        glColor4f( m_coordColor.r, m_coordColor.g, m_coordColor.b, 1.0f );
      glBegin( GL_LINES );
        glVertex3f( -0.50f,  0.50f,  0.00f );
        glVertex3f(  0.50f,  0.50f,  0.00f );
        glVertex3f(  0.50f,  0.50f,  0.00f );
        glVertex3f(  0.50f, -0.50f,  0.00f );
        glVertex3f(  0.50f, -0.50f,  0.00f );
        glVertex3f( -0.50f, -0.50f,  0.00f );
        glVertex3f( -0.50f, -0.50f,  0.00f );
        glVertex3f( -0.50f,  0.50f,  0.00f );
      glEnd();
      glPopAttrib();
      break;

    case 1:
      // SPHERE
      {
        glPushAttrib( GL_ALL_ATTRIB_BITS );
        if ( displaystatus == M3dView::kDormant ) 
          glColor4f( m_coordColor.r, m_coordColor.g, m_coordColor.b, 1.0f );
        glRotatef( -90.0f, 1.0f, 0.0f, 0.0f );
        GLUquadricObj* pQuadric = gluNewQuadric();
        gluQuadricDrawStyle( pQuadric, GLU_LINE);
        gluSphere( pQuadric, 0.5f , 10, 6);
        gluDeleteQuadric(pQuadric);
        glPopAttrib();
      }
      break;

    case 2:
      // CYLINDER
      {
        glPushAttrib( GL_ALL_ATTRIB_BITS );
        if ( displaystatus == M3dView::kDormant ) 
          glColor4f( m_coordColor.r, m_coordColor.g, m_coordColor.b, 1.0f );
        glTranslatef( 0.0f, -0.5f, 0.0f );
        glRotatef( -90.0f, 1.0f, 0.0f, 0.0f );
        GLUquadricObj* pQuadric = gluNewQuadric();
        gluQuadricDrawStyle( pQuadric, GLU_LINE);
        gluCylinder( pQuadric, 0.5f , 0.5f, 1.0f, 10, 2);
        gluDeleteQuadric(pQuadric);
        glPopAttrib();
      }
      break;

    case 3:
      // CUBE
      glPushAttrib( GL_ALL_ATTRIB_BITS );
      if ( displaystatus == M3dView::kDormant ) 
        glColor4f( m_coordColor.r, m_coordColor.g, m_coordColor.b, 1.0f );
      glBegin( GL_LINES );

        glVertex3f( -0.50f,  0.50f, -0.50f );
        glVertex3f(  0.50f,  0.50f, -0.50f );
        glVertex3f(  0.50f,  0.50f, -0.50f );
        glVertex3f(  0.50f,  0.50f,  0.50f );
        glVertex3f(  0.50f,  0.50f,  0.50f );
        glVertex3f( -0.50f,  0.50f,  0.50f );
        glVertex3f( -0.50f,  0.50f,  0.50f );
        glVertex3f( -0.50f,  0.50f, -0.50f );

        glVertex3f( -0.50f, -0.50f, -0.50f );
        glVertex3f(  0.50f, -0.50f, -0.50f );
        glVertex3f(  0.50f, -0.50f, -0.50f );
        glVertex3f(  0.50f, -0.50f,  0.50f );
        glVertex3f(  0.50f, -0.50f,  0.50f );
        glVertex3f( -0.50f, -0.50f,  0.50f );
        glVertex3f( -0.50f, -0.50f,  0.50f );
        glVertex3f( -0.50f, -0.50f, -0.50f );

        glVertex3f( -0.50f,  0.50f, -0.50f );
        glVertex3f( -0.50f, -0.50f, -0.50f );
        glVertex3f(  0.50f,  0.50f, -0.50f );
        glVertex3f(  0.50f, -0.50f, -0.50f );
        glVertex3f(  0.50f,  0.50f,  0.50f );
        glVertex3f(  0.50f, -0.50f,  0.50f );
        glVertex3f( -0.50f,  0.50f,  0.50f );
        glVertex3f( -0.50f, -0.50f,  0.50f );

      glEnd();
      glPopAttrib();
      break;

    case 4:
      // DEEP PLANE
      glPushAttrib( GL_ALL_ATTRIB_BITS );
      if ( displaystatus == M3dView::kDormant ) 
        glColor4f( m_coordColor.r, m_coordColor.g, m_coordColor.b, 1.0f );
      glBegin( GL_LINES );
        glVertex3f( -0.50f,  0.50f,  0.00f );
        glVertex3f(  0.50f,  0.50f,  0.00f );
        glVertex3f(  0.50f,  0.50f,  0.00f );
        glVertex3f(  0.50f, -0.50f,  0.00f );
        glVertex3f(  0.50f, -0.50f,  0.00f );
        glVertex3f( -0.50f, -0.50f,  0.00f );
        glVertex3f( -0.50f, -0.50f,  0.00f );
        glVertex3f( -0.50f,  0.50f,  0.00f );
      glEnd();
      glEnable( GL_LINE_STIPPLE);
      glLineStipple(1,0xff);
      glBegin( GL_LINES );
        glVertex3f( -0.50f,  0.50f,  1.00f );
        glVertex3f(  0.50f,  0.50f,  1.00f );
        glVertex3f(  0.50f,  0.50f,  1.00f );
        glVertex3f(  0.50f, -0.50f,  1.00f );
        glVertex3f(  0.50f, -0.50f,  1.00f );
        glVertex3f( -0.50f, -0.50f,  1.00f );
        glVertex3f( -0.50f, -0.50f,  1.00f );
        glVertex3f( -0.50f,  0.50f,  1.00f );
      glEnd();
      glPopAttrib();
      break;

    case 5:
      // CLIPPING PLANE
      glPushAttrib( GL_ALL_ATTRIB_BITS );

      glEnable( GL_LINE_STIPPLE);
      glLineStipple(1,0xff);
      if ( displaystatus == M3dView::kDormant ) 
        glColor4f( m_coordColor.r, m_coordColor.g, m_coordColor.b, 1.0f );

      glBegin( GL_LINES );

        glVertex3f( -1.0f,  1.0f,  0.0f );
        glVertex3f(  1.0f,  1.0f,  0.0f );
        glVertex3f(  1.0f,  1.0f,  0.0f );
        glVertex3f(  1.0f, -1.0f,  0.0f );
        glVertex3f(  1.0f, -1.0f,  0.0f );
        glVertex3f( -1.0f, -1.0f,  0.0f );
        glVertex3f( -1.0f, -1.0f,  0.0f );
        glVertex3f( -1.0f,  1.0f,  0.0f );

        glVertex3f( -1.0f,  1.0f,  0.0f );
        glVertex3f(  1.0f, -1.0f,  0.0f );
        glVertex3f(  1.0f,  1.0f,  0.0f );
        glVertex3f( -1.0f, -1.0f,  0.0f );

      glEnd();

      glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
      glEnable(GL_ALPHA_TEST);
      glAlphaFunc(GL_ALWAYS ,0.1);
      glEnable(GL_BLEND);
      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
      glEnable(GL_DEPTH_TEST);
      glDepthFunc(GL_LEQUAL);
      glDepthMask( GL_FALSE );
      glColor4f( m_coordColor.r, m_coordColor.g, m_coordColor.b, m_coordColor.a );
      glBegin( GL_QUADS );
        glVertex3f( -1.0f , 1.0f, 0.0f );
        glVertex3f(  1.0f , 1.0f, 0.0f );
        glVertex3f(  1.0f ,-1.0f, 0.0f );
        glVertex3f( -1.0f ,-1.0f, 0.0f );
      glEnd();

      glPopAttrib();
      break;
  }
  view.endGL();
}