示例#1
0
void RBSwingControl::RenderTracks()
{
	glDisable(GL_TEXTURE_2D);
	RGL.EnableClient(kVertexArray, true);
	RGL.EnableClient(kColorArray, true);
	RGL.EnableClient(kTextureCoordArray, false);
	
	for(int i = 1; i < m_curSwingPoint; i++)
	{
		RudeScreenVertex &p0 = m_swingPoints[i-1].m_p;
		RudeScreenVertex &p1 = m_swingPoints[i].m_p;
		
		const float kPointSize = 6;
		
		GLfloat point[] = {
			p0.m_x, p0.m_y,
			p0.m_x + kPointSize, p0.m_y,
			p1.m_x + kPointSize, p1.m_y,
			p1.m_x, p1.m_y,
		};
		
		float r1,g1,b1,a1 = 1.0f;
		float r2,g2,b2,a2 = 1.0f;
		
		if(m_swingPoints[i-1].m_state == kDownStroke)
			PickColor(m_swingPoints[i-1].m_time, r1, g1, b1);
		else
		{
			r1 = g1 = b1 = 1.0f;
			a1 = 0.7f;
		}
		
		if(m_swingPoints[i].m_state == kDownStroke)
			PickColor(m_swingPoints[i].m_time, r2, g2, b2);
		else
		{
			r2 = g2 = b2 = 1.0f;
			a2 = 0.7f;
		}
		
		
		GLfloat colors[] = {
			r1, g1, b1, a1,
			r1, g1, b1, a1,
			r2, g2, b2, a2,
			r2, g2, b2, a2,
		};
		
		
		glVertexPointer(2, GL_FLOAT, 0, point);
		
		glColorPointer(4, GL_FLOAT, 0, colors);
		
		
		
		glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
	}
	
}
示例#2
0
文件: picking.cpp 项目: brownman/VGL
void PickingRenderer::pickableCube(BufType itemType)
{
  vgl::Vec3f lo(-0.5, -0.5, -0.5);
  vgl::Vec3f hi( 0.5,  0.5,  0.5);

  const float kVerts[24][3] = {
    { lo.x, lo.y, lo.z },
    { hi.x, lo.y, lo.z },
    { hi.x, hi.y, lo.z },
    { lo.x, hi.y, lo.z },

    { lo.x, lo.y, hi.z },
    { hi.x, lo.y, hi.z },
    { hi.x, hi.y, hi.z },
    { lo.x, hi.y, hi.z },

    { lo.x, lo.y, lo.z },
    { lo.x, lo.y, hi.z },
    { lo.x, hi.y, hi.z },
    { lo.x, hi.y, lo.z },

    { hi.x, lo.y, lo.z },
    { hi.x, lo.y, hi.z },
    { hi.x, hi.y, hi.z },
    { hi.x, hi.y, lo.z },

    { lo.x, lo.y, lo.z },
    { hi.x, lo.y, lo.z },
    { hi.x, lo.y, hi.z },
    { lo.x, lo.y, hi.z },

    { lo.x, hi.y, lo.z },
    { hi.x, hi.y, lo.z },
    { hi.x, hi.y, hi.z },
    { lo.x, hi.y, hi.z }
  };

  switch (itemType) {
  case 1: // Faces
    glBegin(GL_QUADS);
    for (unsigned int i = 0; i < 6; ++i) {
      PickColor(itemType << kTypeShift, 0, i << kIDShift);
      for (int f = i * 4; f < (i + 1) * 4; ++f)
        glVertex3fv(kVerts[f]);
    }
    glEnd();
    break;
  case 2: // Edges
    glBegin(GL_LINES);
    for (unsigned int i = 0; i < 6; ++i) {
      int prev = i * 4 + 3;
      for (unsigned int f = i * 4; f < (i + 1) * 4; ++f) {
        PickColor(itemType << kTypeShift, 0, f << kIDShift);
        glVertex3fv(kVerts[prev]);
        glVertex3fv(kVerts[f]);
        prev = f;
      }
    }
    glEnd();
    break;
  case 3: // Verts
    glBegin(GL_QUADS);
    for (unsigned int i = 0; i < 24; ++i) {
      PickColor(itemType << kTypeShift, 0, i << kIDShift);
      glVertex3fv(kVerts[i]);
    }
    glEnd();
    break;
  default: // Regular drawing.
    break;
  }
}
示例#3
0
QRgb macGetRgba( QRgb initial, bool *ok, QWidget *parent, const char* )
{
    Point p = { -1, -1 };
    const uchar *pstr = p_str("Choose a color");
    static const int sw = 420, sh = 300;
    if(parent) {
	parent = parent->topLevelWidget();
	p.h = (parent->x() + (parent->width() / 2)) - (sw / 2);
	p.v = (parent->y() + (parent->height() / 2)) - (sh / 2);
	QRect r = QApplication::desktop()->screenGeometry(QApplication::desktop()->screenNumber(parent));
	if(p.h + sw > r.right())
	    p.h -= (p.h + sw) - r.right() + 10;
	if(p.v + sh > r.bottom())
	    p.v -= (p.v + sh) - r.bottom() + 10;
    } else if(QWidget *w = qApp->mainWidget()) {
	static int last_screen = -1;
	int scr = QApplication::desktop()->screenNumber(w);
	if(last_screen != scr) {
	    QRect r = QApplication::desktop()->screenGeometry(scr);
	    p.h = (r.x() + (r.width() / 2)) - (sw / 2);
	    p.v = (r.y() + (r.height() / 2)) - (sh / 2);
	}
    }
    RGBColor rgb, rgbout;
    rgb.red = qRed(initial) * 256;
    rgb.blue = qBlue(initial) * 256;
    rgb.green = qGreen(initial) * 256;
#if 1
    Point place;
    place.h = p.h == -1 ? 0 : p.h;
    place.v = p.v == -1 ? 0 : p.v;
    Boolean rval = FALSE;
    {
	QMacBlockingFunction block;
	QWidget modal_widg(parent, __FILE__ "__modal_dlg",
			   Qt::WType_TopLevel | Qt::WStyle_Customize | Qt::WStyle_DialogBorder);
	qt_enter_modal(&modal_widg);
	rval = GetColor(place, pstr, &rgb, &rgbout);
	qt_leave_modal(&modal_widg);
    }
#else
    ColorPickerInfo     cpInfo;
    // Set the input color to be an RGB color in system space.
    cpInfo.theColor.color.rgb.red = rgb.red;
    cpInfo.theColor.color.rgb.green = rgb.green;
    cpInfo.theColor.color.rgb.blue = rgb.blue;
    cpInfo.theColor.profile = 0L;
    cpInfo.dstProfile = 0L;
    cpInfo.flags = kColorPickerAppIsColorSyncAware | kColorPickerCanModifyPalette |
		   kColorPickerCanAnimatePalette;
    // Place dialog
    cpInfo.placeWhere = kCenterOnMainScreen;
    if(p.h != -1 || p.v != -1) {
	cpInfo.placeWhere = kAtSpecifiedOrigin;
	cpInfo.dialogOrigin = p;
    }
    cpInfo.pickerType = 0L; // Use the default picker.
    cpInfo.eventProc = 0L;
    cpInfo.colorProc = 0L;
    cpInfo.colorProcData = 0L;
    memcpy(cpInfo.prompt, pstr, pstr[0]+1);
    Boolean rval = FALSE;
    {
	QMacBlockingFunction block;
	rval = (PickColor(&cpInfo) == noErr && cpInfo.newColorChosen);
    }
    if(rval) {
	rval = TRUE;
	if(!cpInfo.theColor.profile) {
	    rgbout.red = cpInfo.theColor.color.rgb.red;
	    rgbout.green = cpInfo.theColor.color.rgb.green;
	    rgbout.blue = cpInfo.theColor.color.rgb.blue;
	} else {
	    qDebug("not sure how to handle..");
	}
    }
#endif
    free((void *)pstr);
    if(ok)
	(*ok) = rval;
    if(!rval)
	return initial;
    initial = qRgba(rgbout.red / 256, rgbout.green / 256,
		    rgbout.blue / 256, qAlpha(initial));
    return initial;
}