示例#1
0
文件: nurbs.c 项目: lubosz/smalldemo
/*  Initialize material property, light source, lighting model,
 *  and depth buffer.
 */
static void myinit(void)
{
    GLfloat mat_ambient[] = { 1.0, 1.0, 1.0, 1.0 };
    GLfloat mat_diffuse[] = { 1.0, 0.2, 1.0, 1.0 };
    GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
    GLfloat mat_shininess[] = { 50.0 };

    GLfloat light0_position[] = { 1.0, 0.1, 1.0, 0.0 };
    GLfloat light1_position[] = { -1.0, 0.1, 1.0, 0.0 };

    GLfloat lmodel_ambient[] = { 0.3, 0.3, 0.3, 1.0 };

    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
    glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
    glLightfv(GL_LIGHT0, GL_POSITION, light0_position);
    glLightfv(GL_LIGHT1, GL_POSITION, light1_position);
    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);

    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glEnable(GL_LIGHT1);
    glDepthFunc(GL_LESS);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_AUTO_NORMAL);

    theNurb = gluNewNurbsRenderer();

    gluNurbsProperty(theNurb, GLU_SAMPLING_TOLERANCE, 25.0);
    gluNurbsProperty(theNurb, GLU_DISPLAY_MODE, GLU_FILL);
}
示例#2
0
/* Opens a square window, and initializes the window, interesting devices,
 * viewing volume, material, and lights.
 */
static void
initialize(void) {

    GLfloat mat_diffuse[] = { .8, .1, .8, 1. };
    GLfloat mat_specular[] = { .6, .6, .6, 1. };
    GLfloat mat_ambient[] = { .1, .1, .1, 1. };

    glClearColor(.58, .58, .58, 0.);
    glClearDepth(1.);
    glEnable(GL_DEPTH_TEST);

    glMatrixMode(GL_PROJECTION);
    gluPerspective(60,1.0,1.0,10.0);
    glMatrixMode(GL_MODELVIEW);
    glTranslatef(0., 0., -6.);
    
    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse);
    glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient);
    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
    glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 32.0);
    glEnable(GL_LIGHT0);
    glEnable(GL_LIGHTING);
    glEnable(GL_AUTO_NORMAL);
    glEnable(GL_NORMALIZE);

    nurbsflag = gluNewNurbsRenderer();
    gluNurbsProperty(nurbsflag, GLU_SAMPLING_TOLERANCE, 100.0);
    gluNurbsProperty(nurbsflag, GLU_DISPLAY_MODE, GLU_FILL);

    init_trims();
}
示例#3
0
void init(void)
{
   GLfloat mat_diffuse[] = { 0.7, 0.7, 0.7, 1.0 };
   GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
   GLfloat mat_shininess[] = { 100.0 };

   glClearColor (0.0, 0.0, 0.0, 0.0);
   glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
   glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
   glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);

   glEnable(GL_LIGHTING);
   glEnable(GL_LIGHT0);
   glEnable(GL_DEPTH_TEST);
   glEnable(GL_AUTO_NORMAL);
   glEnable(GL_NORMALIZE);

   init_surface();

   theNurb = gluNewNurbsRenderer();
   gluNurbsProperty(theNurb, GLU_SAMPLING_TOLERANCE, 25.0);
   gluNurbsProperty(theNurb, GLU_DISPLAY_MODE, GLU_FILL);
   gluNurbsCallback(theNurb, GLU_ERROR, 
                    (GLvoid (*)()) nurbsError);
}
示例#4
0
文件: NURBT.C 项目: HintonBR/scratch
// This function does any needed initialization on the rendering
// context.  Here it sets up and initializes the lighting for
// the scene.
void SetupRC()
	{
	// Light values and coordinates
	GLfloat  whiteLight[] = {0.7f, 0.7f, 0.7f, 1.0f };
	GLfloat  specular[] = { 0.7f, 0.7f, 0.7f, 1.0f};
	GLfloat  shine[] = { 100.0f };

	// Clear Window to white
	glClearColor(1.0f, 1.0f, 1.0f, 1.0f );

	// Enable lighting
	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);

	// Enable color tracking
	glEnable(GL_COLOR_MATERIAL);
	
	// Set Material properties to follow glColor values
	glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
	glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
	glMaterialfv(GL_FRONT, GL_SHININESS, shine);
	
	// Automatically generate normals for evaluated surfaces
	glEnable(GL_AUTO_NORMAL);


	// Setup the Nurbs object
    pNurb = gluNewNurbsRenderer();
    gluNurbsProperty(pNurb, GLU_SAMPLING_TOLERANCE, 25.0f);
	gluNurbsProperty(pNurb, GLU_DISPLAY_MODE, (GLfloat)GLU_FILL);
	}
示例#5
0
//-*****************************************************************************
INuPatchDrw::INuPatchDrw( INuPatch &iNuPatch )
  : IObjectDrw( iNuPatch, false )
  , m_nuPatch( iNuPatch )
{
    // create our nurb renderer.
    nurb = gluNewNurbsRenderer();

    gluNurbsProperty(nurb, GLU_SAMPLING_TOLERANCE, 25.0);
    gluNurbsProperty(nurb, GLU_DISPLAY_MODE, GLU_FILL);

    // Get out if problems.
    if ( !m_nuPatch.valid() )
    {
        return;
    }


    // The object has already set up the min time and max time of
    // all the children.
    // if we have a non-constant time sampling, we should get times
    // out of it.
    TimeSamplingPtr iTsmp = m_nuPatch.getSchema().getTimeSampling();
    if ( !m_nuPatch.getSchema().isConstant() )
    {
        size_t numSamps = m_nuPatch.getSchema().getNumSamples();
        if ( numSamps > 0 )
        {
            chrono_t minTime = iTsmp->getSampleTime( 0 );
            m_minTime = std::min( m_minTime, minTime );
            chrono_t maxTime = iTsmp->getSampleTime( numSamps-1 );
            m_maxTime = std::max( m_maxTime, maxTime );
        }
    }
}
示例#6
0
GLUnurbsObj* LICE_GL_ctx::GetNurbsObj(int linetol)
{
    if (!IsValid()) return 0;
    if (!m_nurbs) m_nurbs = gluNewNurbsRenderer();
    if (m_nurbs) gluNurbsProperty(m_nurbs, GLU_SAMPLING_TOLERANCE, (float)linetol);
    return m_nurbs;
}
示例#7
0
void Sample_12_7::initGL()
{
	glPushAttrib(GL_ALL_ATTRIB_BITS);

	GLfloat mat_diffuse[] = { 0.7, 0.7, 0.7, 1.0 };
	GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
	GLfloat mat_shininess[] = { 100.0 };

	glClearColor (0.0, 0.0, 0.0, 0.0);
	glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
	glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
	glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);

	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_AUTO_NORMAL);
	glEnable(GL_NORMALIZE);

	m_theNurb = gluNewNurbsRenderer();
	gluNurbsProperty(m_theNurb, GLU_NURBS_MODE,
			GLU_NURBS_TESSELLATOR);
	gluNurbsProperty(m_theNurb, GLU_SAMPLING_TOLERANCE, 25.0);
	gluNurbsProperty(m_theNurb, GLU_DISPLAY_MODE, GLU_FILL);
	gluNurbsCallback(m_theNurb, GLU_ERROR, (GLvoid (*) ()) &errorCallbackNURBS);
	gluNurbsCallback(m_theNurb, GLU_NURBS_BEGIN, (GLvoid (*) ()) &beginCallbackNURBS);
	gluNurbsCallback(m_theNurb, GLU_NURBS_VERTEX, (GLvoid (*) ()) &vertexCallbackNURBS);
	gluNurbsCallback(m_theNurb, GLU_NURBS_NORMAL, (GLvoid (*) ()) &normalCallbackNURBS);
	gluNurbsCallback(m_theNurb, GLU_NURBS_END, endCallbackNURBS);
}
示例#8
0
/*  Initialize material property and depth buffer.
 */
static void init(void)
{
   GLfloat mat_diffuse[] = { 0.7, 0.7, 0.7, 1.0 };
   GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
   GLfloat mat_shininess[] = { 100.0 };

   glClearColor (0.0, 0.0, 0.0, 0.0);
   glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
   glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
   glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);

   glEnable(GL_LIGHTING);
   glEnable(GL_LIGHT0);
   glEnable(GL_DEPTH_TEST);
   glEnable(GL_AUTO_NORMAL);
   glEnable(GL_NORMALIZE);

   init_surface();

   theNurb = gluNewNurbsRenderer();
   gluNurbsProperty(theNurb, GLU_NURBS_MODE, 
		    GLU_NURBS_TESSELLATOR);
   gluNurbsProperty(theNurb, GLU_SAMPLING_TOLERANCE, 25.0);
   gluNurbsProperty(theNurb, GLU_DISPLAY_MODE, GLU_FILL);
   gluNurbsCallback(theNurb, GLU_ERROR, nurbsError);
   gluNurbsCallback(theNurb, GLU_NURBS_BEGIN, beginCallback);
   gluNurbsCallback(theNurb, GLU_NURBS_VERTEX, vertexCallback);
   gluNurbsCallback(theNurb, GLU_NURBS_NORMAL, normalCallback);
   gluNurbsCallback(theNurb, GLU_NURBS_END, endCallback);

}
示例#9
0
void SetupRC()
{
  GLfloat  whiteLight[] = {0.7f, 0.7f, 0.7f, 1.0f };
  GLfloat  specular[] = { 0.7f, 0.7f, 0.7f, 1.0f};
  GLfloat  shine[] = { 100.0f };

  glClearColor(1.0f, 1.0f, 1.0f, 1.0f );

  //开启光照
  glEnable(GL_LIGHTING);
  glEnable(GL_LIGHT0);

  // 开启颜色追踪
  glEnable(GL_COLOR_MATERIAL);

  //设置材料属性
  glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
  glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
  glMaterialfv(GL_FRONT, GL_SHININESS, shine);

  //自动生成法线
  glEnable(GL_AUTO_NORMAL);

  //创建NURBS渲染器
  pNurb = gluNewNurbsRenderer();
  //设置NURBS出错处理函数
  gluNurbsCallback(pNurb, GLU_ERROR, (CallBack)NurbsErrorHandler);
  //设置采样容差
  gluNurbsProperty(pNurb, GLU_SAMPLING_TOLERANCE, 25.0f);
  //设置显示模式
  gluNurbsProperty(pNurb, GLU_DISPLAY_MODE, GLU_FILL);
}
示例#10
0
/*  Initialize material property and depth buffer.
 */
void myinit(void)
{
    GLfloat mat_diffuse[] = { 0.7, 0.7, 0.7, 1.0 };
    GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
    GLfloat mat_shininess[] = { 100.0 };

    glClearColor (0.0, 0.0, 0.0, 1.0);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
    glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);

    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glDepthFunc(GL_LESS);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_AUTO_NORMAL);
    glEnable(GL_NORMALIZE);

    init_surface();

    theNurb = gluNewNurbsRenderer();
    gluNurbsProperty(theNurb, GLU_SAMPLING_TOLERANCE, 25.0);
    gluNurbsProperty(theNurb, GLU_DISPLAY_MODE, GLU_FILL);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glTranslatef (0.0, 0.0, -5.0);
}
示例#11
0
void create_nurbs()
{
    
    nrb_obj = gluNewNurbsRenderer();
    gluNurbsProperty(nrb_obj, GLU_SAMPLING_TOLERANCE, 100.0);
    gluNurbsProperty(nrb_obj, GLU_DISPLAY_MODE, GLU_FILL);
}
示例#12
0
ON_BOOL32 myInitGL( const ON_Viewport& viewport, GLUnurbsObj*& nobj )
{
  // set the model view transform
  SetGLModelViewMatrix( viewport );

  // this stuff works with MSVC 4.2's Open GL. Changes may be needed for other
  // GLs.
  //ON_Color background_color(0,128,128);
  ON_Color background_color(0,63,127);
  //background_color = glb_model->m_settings.m_RenderSettings.m_background_color;
  glClearColor( (float)background_color.FractionRed(), 
                (float)background_color.FractionGreen(), 
                (float)background_color.FractionBlue(), 
                1.0f
                );

  glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE );
  glDisable( GL_CULL_FACE );
  
  // Rhino viewports have camera "Z" pointing at the camera in a right
  // handed coordinate system.
  glClearDepth( 0.0f );
  glEnable( GL_DEPTH_TEST );
  glDepthFunc( GL_GEQUAL );

  glEnable( GL_LIGHTING );
  glEnable( GL_DITHER );
  //glEnable( GL_AUTO_NORMAL );
  //glEnable( GL_NORMALIZE );

  // default material
  ON_GL( (ON_Material*)NULL );


  // GL rendering of NURBS objects requires a GLUnurbsObj.
  nobj = gluNewNurbsRenderer();
  if ( !nobj )
    return false;
  
  gluNurbsProperty( nobj, GLU_SAMPLING_TOLERANCE,   20.0f );
  gluNurbsProperty( nobj, GLU_PARAMETRIC_TOLERANCE, 0.5f );
  gluNurbsProperty( nobj, GLU_DISPLAY_MODE,         (GLfloat)GLU_FILL );
  //gluNurbsProperty( nobj, GLU_DISPLAY_MODE,         GLU_OUTLINE_POLYGON );
  //gluNurbsProperty( nobj, GLU_DISPLAY_MODE,         GLU_OUTLINE_PATCH );
  gluNurbsProperty( nobj, GLU_SAMPLING_METHOD,      (GLfloat)GLU_PATH_LENGTH );
  //gluNurbsProperty( nobj, GLU_SAMPLING_METHOD,      GLU_PARAMETRIC_ERROR );
  //gluNurbsProperty( nobj, GLU_SAMPLING_METHOD,      GLU_DOMAIN_DISTANCE );
  gluNurbsProperty( nobj, GLU_CULLING,              (GLfloat)GL_FALSE );

  // register GL NURBS error callback
  {
    // hack to get around C vs C++ type checking trauma
    RHINO_GL_NURBS_ERROR fn;
    fn = (RHINO_GL_NURBS_ERROR)myNurbsErrorCallback;
    gluNurbsCallback( nobj, GLU_ERROR, fn );
  }

  return true;
}
void init(void){
  glClearColor(0.0, 0.0, 0.0, 0.0);
  spline=NURBS;
  nc= gluNewNurbsRenderer();
  gluNurbsProperty(nc, GLU_SAMPLING_TOLERANCE, 5.0);
  glEnable(GL_MAP1_VERTEX_3);
  display();
}
示例#14
0
void init_scene(int width, int height)
{
   int u, v;

   /* Setup our viewport for OpenGL ES */
   glViewport(0, 0, (GLint)width, (GLint)height);
   /* Setup our viewport for GLU ES (required when using OpenGL ES 1.0 only) */
   gluViewport(0, 0, (GLint)width, (GLint)height);

   /* Set black background color */
   glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

   glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse);
   glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);
   glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient);

   glEnable(GL_LIGHTING);
   glEnable(GL_LIGHT0);
   glEnable(GL_DEPTH_TEST);
   glEnable(GL_NORMALIZE);

   /* Since GL ES has no GL_AUTO_NORMAL, we implement it in GLU */
   gluEnable(GLU_AUTO_NORMAL);

   nurb=gluNewNurbsRenderer();
   gluNurbsProperty(nurb, GLU_SAMPLING_TOLERANCE, 25.0f);
   gluNurbsProperty(nurb, GLU_DISPLAY_MODE, GLU_FILL);

   for (u=0; u<4; u++)
   {
      for (v=0; v<4; v++)
      {
         ctlpoints[u][v][0]=2.0f*((GLfloat)u-1.5f);
         ctlpoints[u][v][1]=2.0f*((GLfloat)v-1.5f);

         if ((u==1 || u==2) && (v==1 || v==2))
         {
            ctlpoints[u][v][2]=3.0f;
         }
         else
         {
            ctlpoints[u][v][2]=-3.0f;
         }
      }
   }

   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   gluPerspective(45.0f, (GLfloat)window_width/(GLfloat)window_height, 3.0f, 24.0f);

   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
   glTranslatef(0.0f, 0.5f, -9.0f);
   glRotatef(330.0f, 1.0f, 0.0f, 0.0f);
}
示例#15
0
void init(void)
{
	glClearColor (0.0, 0.0, 0.0, 0.0);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	theNurb = gluNewNurbsRenderer();
	gluNurbsProperty (theNurb, GLU_SAMPLING_TOLERANCE, 10.0);
	gluNurbsCallback(theNurb, GLU_ERROR, (GLvoid (*)()) nurbsError);
	setup();
}
示例#16
0
// This function does any needed initialization on the rendering
// context.  Here it sets up and initializes the lighting for
// the scene.
void SetupRC()
{
    // Clear Window to white
    glClearColor(1.0f, 1.0f, 1.0f, 1.0f );

    // Setup the Nurbs object
    pNurb = gluNewNurbsRenderer();
    gluNurbsProperty(pNurb, GLU_SAMPLING_TOLERANCE, 25.0f);
    gluNurbsProperty(pNurb, GLU_DISPLAY_MODE, (GLfloat)GLU_FILL);
}
示例#17
0
void GraphicsPainter::drawNurbsSurface(const QVector<Point3f> &controlPoints, const QVector<float> &uKnots, const QVector<float> &vKnots, int uOrder, int vOrder)
{
    // nurbs control points
    QVector<float> points(controlPoints.size() * 3);
    for(int i = 0; i < controlPoints.size(); i++){
        points[i*3+0] = controlPoints[i].x();
        points[i*3+1] = controlPoints[i].y();
        points[i*3+2] = controlPoints[i].z();
    }

    // nurbs knot vectors
    QVector<float> uKnotVector(uKnots.size());
    for(int i = 0; i < uKnots.size(); i++)
        uKnotVector[i] = uKnots[i];

    QVector<float> vKnotVector(vKnots.size());
    for(int i = 0; i < vKnots.size(); i++)
        vKnotVector[i] = vKnots[i];

    int uStride = 3 * (vKnotVector.size() - vOrder);
    int vStride = 3;

    glEnable(GL_AUTO_NORMAL);
    GLUnurbsObj *nurb = gluNewNurbsRenderer();
    gluNurbsProperty(nurb, GLU_CULLING, GL_TRUE); // only render visible parts of the surface
    gluNurbsProperty(nurb, GLU_V_STEP, 4);
    gluNurbsProperty(nurb, GLU_U_STEP, 10);
    gluNurbsProperty(nurb, GLU_SAMPLING_METHOD, GLU_DOMAIN_DISTANCE);

#ifdef Q_OS_WIN
    gluNurbsCallback(nurb, GLU_ERROR, (void (__stdcall *)()) nurbsErrorCallback);
#else
    gluNurbsCallback(nurb, GLU_ERROR, (void (*)()) nurbsErrorCallback);
#endif

    gluBeginSurface(nurb);

    gluNurbsSurface(nurb,
                    uKnotVector.size(),
                    uKnotVector.data(),
                    vKnotVector.size(),
                    vKnotVector.data(),
                    uStride,
                    vStride,
                    points.data(),
                    uOrder,
                    vOrder,
                    GL_MAP2_VERTEX_3);

    gluEndSurface(nurb);
    gluDeleteNurbsRenderer(nurb);
    glDisable(GL_AUTO_NORMAL);
}
示例#18
0
void Quiddiards::initializeGL(){
	glClearColor(0.0, 0.0, 0.0, 0.0);
	glClearDepth(1.0);
	glEnable(GL_AUTO_NORMAL);
	glShadeModel(GL_SMOOTH);
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);

	//glDisable(GL_BLEND);
	//glBlendFunc(GL_ONE, GL_ZERO);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

	/* camera */
	camera = FOLLOW;
	theta = 45;
	phi = 45;
	radius = MAXRANGE / 2;

	initObjects();	// init objects first, since others may base on them
	loadResources();
	initLights();


	ambLight = true;
	sunLight = true;
	spotLight = true;
	pause = false;

	/* flag nurbs object */
	nurbs = gluNewNurbsRenderer();
	gluNurbsProperty(nurbs, GLU_SAMPLING_TOLERANCE, 25.0);
	gluNurbsProperty(nurbs, GLU_DISPLAY_MODE, GLU_FILL);
	/* quadric object */
	quad = gluNewQuadric();
	gluQuadricDrawStyle(quad, GLU_FILL);
	gluQuadricNormals(quad, GLU_SMOOTH);
	gluQuadricTexture(quad, true);

	timer = new QTimer;
	connect(timer, SIGNAL(timeout()), SLOT(animate()));
	timer->start(interval);
	msec = clock();

	/* particle system */
	ps = new ParticleSystem(200, -10.0f);
}
示例#19
0
void CMeter2DGraphView::initializeGL()
{
   TRACE_FUN( Routine, "CMeter2DGraphView::initializeGL" );

   CAbstractMeterView::initializeGL();
   
   _meshList = glGenLists( 1 );
   
   _nurbsRenderer = gluNewNurbsRenderer();
   
   gluNurbsProperty( _nurbsRenderer, GLU_SAMPLING_TOLERANCE, 5. );
   gluNurbsProperty( _nurbsRenderer, GLU_DISPLAY_MODE, GLU_FILL );
}
示例#20
0
void Initial()
{
	glClearColor(1.0f, 1.0f, 1.0f, 1.0f );

	glLineWidth(3.0f);

	//初始化NURBS对象
    pNurb = gluNewNurbsRenderer();
	//采样的最大长度为25
    gluNurbsProperty(pNurb, GLU_SAMPLING_TOLERANCE, 25.0f);
	//显示模式为GLU_FILL
	gluNurbsProperty(pNurb, GLU_DISPLAY_MODE, (GLfloat)GLU_FILL);
}
示例#21
0
void init(void)
{
  if (!pNurb2)
  {
    pNurb2 = gluNewNurbsRenderer();
    gluNurbsProperty(pNurb2, GLU_SAMPLING_TOLERANCE, 5.0f);
    gluNurbsProperty(pNurb2, GLU_DISPLAY_MODE, GLU_OUTLINE_POLYGON);
/*     gluNurbsProperty(pNurb2, GLU_DISPLAY_MODE, GLU_FILL); */
    gluNurbsCallback(pNurb2, GLU_ERROR, (GLvoid (*) ()) nurbsError);
  }
  glClearColor(1.0, 1.0, 1.0, 0.0);
  glShadeModel(GL_SMOOTH);
  glLineWidth(7.0);
  glTranslatef(0., 0., -1.5);
}
示例#22
0
	void draw_solid(const k3d::gl::render_state& State, const k3d::double_t Height, const k3d::double_t Radius, const k3d::double_t SweepAngle)
	{
		if(!Radius)
			return;

		k3d::mesh::knots_t knots;
		k3d::mesh::weights_t weights;
		k3d::mesh::points_t arc_points;
		k3d::nurbs_curve::circular_arc(k3d::vector3(1, 0, 0), k3d::vector3(0, 1, 0), 0, SweepAngle, 4, knots, weights, arc_points);

		std::vector<GLfloat> gl_u_knot_vector(knots.begin(), knots.end());
		std::vector<GLfloat> gl_v_knot_vector;
		std::vector<GLfloat> gl_control_points;

		gl_v_knot_vector.insert(gl_v_knot_vector.end(), 2, 0);
		gl_v_knot_vector.insert(gl_v_knot_vector.end(), 1);
		gl_v_knot_vector.insert(gl_v_knot_vector.end(), 2, 2);

		const k3d::point3 offset = Height * k3d::point3(0, 0, 1);

		for(k3d::uint_t i = 0; i <= 2; ++i)
		{
			const k3d::double_t radius2 = k3d::mix(Radius, 0.001 * Radius, static_cast<k3d::double_t>(i) / static_cast<k3d::double_t>(2));
			for(k3d::uint_t j = 0; j != arc_points.size(); ++j)
			{
				gl_control_points.push_back(weights[j] * (radius2 * arc_points[j][0] + offset[0]));
				gl_control_points.push_back(weights[j] * (radius2 * arc_points[j][1] + offset[1]));
				gl_control_points.push_back(weights[j] * (radius2 * arc_points[j][2] + offset[2]));
				gl_control_points.push_back(weights[j]);
			}
		}

		GLUnurbsObj* const nurbs_renderer = gluNewNurbsRenderer();

		// Important!  We load our own matrices for efficiency (saves round-trips to the server) and to prevent problems with selection
		gluNurbsProperty(nurbs_renderer, GLU_AUTO_LOAD_MATRIX, GL_FALSE);
		gluNurbsProperty(nurbs_renderer, GLU_CULLING, GL_TRUE);
		GLfloat gl_modelview_matrix[16];
		glGetFloatv(GL_MODELVIEW_MATRIX, gl_modelview_matrix);
		gluLoadSamplingMatrices(nurbs_renderer, gl_modelview_matrix, State.gl_projection_matrix, State.gl_viewport);

		gluBeginSurface(nurbs_renderer);
		gluNurbsSurface(nurbs_renderer, gl_u_knot_vector.size(), &gl_u_knot_vector[0], gl_v_knot_vector.size(), &gl_v_knot_vector[0], 4, 36, &gl_control_points[0], 3, 2, GL_MAP2_VERTEX_4);
		gluEndSurface(nurbs_renderer);

		gluDeleteNurbsRenderer(nurbs_renderer);
	}
示例#23
0
void init_scene(int width, int height)
{
   int knot;

   /* Setup our viewport for OpenGL ES */
   glViewport(0, 0, (GLint)width, (GLint)height);
   /* Setup our viewport for GLU ES (required when using OpenGL ES 1.0 only) */
   gluViewport(0, 0, (GLint)width, (GLint)height);

   /* setup a perspective projection */
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glFrustumf(-1.0f, 1.0f, -0.75f, 0.75f, 1.0f, 100.0f);

   /* set the modelview matrix */
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();

   /* set point size for the cv rendering */
   glPointSize(4.0f);

   /* set the clear colour to black */
   glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

   /* no lighting needed */
   glDisable(GL_LIGHTING);

   /* position the camera in the world */
   glTranslatef(0.0f, 0.0f, -1.0f);
   glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
   glRotatef(90.0f, 0.0f, 0.0f, 1.0f);

   /* now, make the nurbs tesselator we are going to use */
   mynurbs=gluNewNurbsRenderer();

   /* these lines set how to tesselate the curve -    */
   /* simply by chopping it up into 100 line segments */
   gluNurbsProperty(mynurbs, GLU_SAMPLING_METHOD, GLU_DOMAIN_DISTANCE);
   gluNurbsProperty(mynurbs, GLU_U_STEP, 100);
   gluNurbsProperty(mynurbs, GLU_DISPLAY_MODE, GLU_FILL);

   /* set up the knot vector - make it continuous */
   for (knot=0; knot<numknots; knot++)
   {
      knots[knot]=knot;
   }
}
示例#24
0
static void Init(void)
{

    theNurbs = gluNewNurbsRenderer();
    gluNurbsCallback(theNurbs, GLU_ERROR, ErrorCallback);

    gluNurbsProperty(theNurbs, GLU_SAMPLING_TOLERANCE, 15.0);
    gluNurbsProperty(theNurbs, GLU_DISPLAY_MODE, GLU_OUTLINE_PATCH);

    expectedError = GLU_INVALID_ENUM;
    gluNurbsProperty(theNurbs, ~0, 15.0);
    expectedError = GLU_NURBS_ERROR13;
    gluEndSurface(theNurbs);
    expectedError = 0;

    glColor3f(1.0, 1.0, 1.0);
}
示例#25
0
文件: branch.c 项目: netscruff/ceiba
void nurbsInit(void)
{
    theNurbs = gluNewNurbsRenderer();
    gluNurbsCallback(theNurbs, GLU_ERROR, ErrorCallback);
    gluNurbsProperty(theNurbs,GLU_NURBS_MODE,GLU_NURBS_TESSELLATOR);
    gluNurbsCallback(theNurbs,GLU_NURBS_BEGIN,beginCallback);
    gluNurbsCallback(theNurbs,GLU_NURBS_END,endCallback);
    gluNurbsCallback(theNurbs,GLU_NURBS_VERTEX,vertexCallback);
    gluNurbsProperty(theNurbs, GLU_SAMPLING_TOLERANCE, 15.0);
    gluNurbsProperty(theNurbs, GLU_DISPLAY_MODE, GLU_OUTLINE_PATCH);
    expectedError = GLU_INVALID_ENUM;
    gluNurbsProperty(theNurbs, ~0, 15.0);
    expectedError = GLU_NURBS_ERROR13;
    gluEndSurface(theNurbs);
    expectedError = 0;

}
示例#26
0
文件: tutorials.hpp 项目: ghl3/luview
    void draw_local()
    {
        int i,j;
        GLfloat knots[8] = {0,1,2,3,4,5,6,7};

        GLfloat mat_diffuse[] = { 0.7, 0.7, 0.7, 1.0 };
        GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
        GLfloat mat_shininess[] = { 100.0 };

        glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
        glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
        glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);

        theNurb = gluNewNurbsRenderer();
        gluNurbsProperty(theNurb, GLU_SAMPLING_TOLERANCE, 25.0);
        gluNurbsProperty(theNurb, GLU_DISPLAY_MODE, GLU_FILL);
        gluNurbsCallback(theNurb, GLU_ERROR, (GLvoid (*)()) nurbsError);

        gluBeginSurface(theNurb);
        gluNurbsSurface(theNurb,
                        8, knots, 8, knots,
                        3*6, 3, &ctlpoints[0][0][0],
                        2, 2, GL_MAP2_VERTEX_3);
        gluEndSurface(theNurb);

        if (showPoints) {
            glPointSize(5.0);
            glDisable(GL_LIGHTING);
            glColor3f(1.0, 1.0, 0.0);
            glBegin(GL_POINTS);

            for (i=0; i<6; i++) {
                for (j=0; j<6; j++) {
                    glVertex3f(ctlpoints[i][j][0],
                               ctlpoints[i][j][1],
                               ctlpoints[i][j][2]);
                }
            }
            glEnd();
            glEnable(GL_LIGHTING);
        }

        gluDeleteNurbsRenderer(theNurb);
    }
示例#27
0
/* glu.NewNurbsRenderer() -> nurb */
static int luaglu_new_nurbs(lua_State *L) 
{
  LuaGLUnurb *lnurb;
  GLUnurbs* nurb = gluNewNurbsRenderer();
  if (!nurb) 
    luaL_error(L, "glu.NewNurbsRenderer failed");

  lnurb= luaglu_pushnurb(L);
  lnurb->nurb=nurb;
  lnurb->L=L;
#ifdef GLU_VERSION_1_3
  /* set callback data as userdata object */
  gluNurbsCallbackData(lnurb->nurb,(GLvoid*)lnurb);

  /* create callback table */
  lua_newtable(L);
  lnurb->ref_cb=luaL_ref(L,LUA_REGISTRYINDEX);
#endif
  return 1;
}
示例#28
0
static int tolua_glu_gluNewNurbsRenderer00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
 tolua_Error tolua_err;
 if (
     !tolua_isnoobj(tolua_S,1,&tolua_err)
 )
  goto tolua_lerror;
 else
#endif
 {
  {
   GLUnurbsObj* tolua_ret = (GLUnurbsObj*)  gluNewNurbsRenderer();
    tolua_pushusertype(tolua_S,(void*)tolua_ret,"GLUnurbsObj");
  }
 }
 return 1;
#ifndef TOLUA_RELEASE
 tolua_lerror:
 tolua_error(tolua_S,"#ferror in function 'gluNewNurbsRenderer'.",&tolua_err);
 return 0;
#endif
}
示例#29
0
void init(void) {
    GLfloat mat_diffuse[] = { 0.7, 0.7, 0.7, 1.0 };
    GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
    GLfloat mat_shininess[] = { 100.0 };
    GLfloat light_position[] = { 1.0, 1.0, 8.0, 1.0};
    GLfloat light_ambient[] =  { 0.2, 0.2, 0.2, 1.0};
    glClearColor (0.0, 0.0, 0.0, 1.0);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
    glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);

    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);

    glDepthFunc(GL_LESS);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_AUTO_NORMAL);
    glEnable(GL_NORMALIZE);

    gera_superficie();

    nc= gluNewNurbsRenderer();
    gluNurbsProperty(nc, GLU_SAMPLING_TOLERANCE, 5.0);
    gluNurbsProperty(nc, GLU_DISPLAY_MODE, GLU_FILL);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glTranslatef (0.0, 0.0, -5.0);

    spline=NURBS;
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glShadeModel(GL_SMOOTH);
    glEnable(GL_MAP2_VERTEX_3);
    display();
}
示例#30
0
文件: nurbs.c 项目: gsjaardema/CGNS
int
NurbsSurface (Tcl_Interp *interp, int argc, char* argv [])
{
    int result = TCL_OK;
    GLint uOrder = 4;
    GLint vOrder = 4;
    GLenum type = GL_MAP2_VERTEX_3;
    int nCoords = 3;
    FloatArray uKnot = NewFloatArray ();
    FloatArray vKnot = NewFloatArray ();
    FloatArray cPoint = NewFloatArray ();
    GLfloat samplingTolerance = 50.0;
    GLfloat displayMode = GLU_FILL;
    GLfloat culling = GL_FALSE;
    int iarg;
    int dlist = 0;

    for (iarg = 2; iarg < argc; iarg++) {
        int len = (int)strlen (argv [iarg]);
        if (strncmp (argv [iarg], "-uorder", len) == 0) {
            int val;
            iarg++;
            if (iarg >= argc) ERRMSG ("No value given for -uorder");
            if (Tcl_GetInt (interp, argv [iarg], &val) != TCL_OK ||
                    val < 2 || val > 8)
                ERRMSG2 ("\nInvalid value for -uorder:", argv [iarg]);
            uOrder = val;
        }
        else if (strncmp (argv [iarg], "-vorder", len) == 0) {
            int val;
            iarg++;
            if (iarg >= argc) ERRMSG ("No value given for -vorder");
            if (Tcl_GetInt (interp, argv [iarg], &val) != TCL_OK ||
                    val < 2 || val > 8)
                ERRMSG2 ("\nInvalid value for -vorder:", argv [iarg]);
            vOrder = val;
        }
        else if (strncmp (argv [iarg], "-uknots", len) == 0) {
            if (uKnot->count != 0) ERRMSG ("uknot values already given");
            iarg++;
            while (iarg < argc &&
                    !(argv [iarg][0] == '-' && isalpha(argv [iarg][1]))) {
                double val;
                if (Tcl_GetDouble (interp, argv [iarg], &val) != TCL_OK)
                    ERRMSG ("\nError parsing uknot value");
                if (uKnot->count > 0 &&
                        uKnot->value [uKnot->count-1] > val)
                    ERRMSG ("uknot values not in non-descending order");
                AddFloat (uKnot, (GLfloat)val);
                iarg++;
            }
            iarg--;
        }
        else if (strncmp (argv [iarg], "-vknots", len) == 0) {
            if (vKnot->count != 0) ERRMSG ("vknot values already given");
            iarg++;
            while (iarg < argc &&
                    !(argv [iarg][0] == '-' && isalpha(argv [iarg][1]))) {
                double val;
                if (Tcl_GetDouble (interp, argv [iarg], &val) != TCL_OK)
                    ERRMSG ("\nError parsing uknot value");
                if (vKnot->count > 0 &&
                        vKnot->value [vKnot->count-1] > val)
                    ERRMSG ("vknot values not in non-descending order");
                AddFloat (vKnot, (GLfloat)val);
                iarg++;
            }
            iarg--;
        }
        else if (strncmp (argv [iarg], "-controlpoints", len) == 0) {
            if (cPoint->count != 0) ERRMSG ("controlpoint values already given");
            iarg++;
            while (iarg < argc &&
                    !(argv [iarg][0] == '-' && isalpha(argv [iarg][1]))) {
                double val;
                if (Tcl_GetDouble (interp, argv [iarg], &val) != TCL_OK)
                    ERRMSG ("\nError parsing uknot value");
                AddFloat (cPoint, (GLfloat)val);
                iarg++;
            }
            iarg--;
        }
        else if (strncmp (argv [iarg], "-type", len) == 0) {
            iarg++;
            if (iarg >= argc) ERRMSG ("No -type value given");
            if (strcmp (argv [iarg], "map2vertex3") ==0) {
                type = GL_MAP2_VERTEX_3;
                nCoords = 3;
            } else if (strcmp (argv [iarg], "map2vertex4") == 0) {
                type = GL_MAP2_VERTEX_4;
                nCoords = 4;
            } else if (strcmp (argv [iarg], "map2color4") == 0) {
                type = GL_MAP2_COLOR_4;
                nCoords = 4;
            } else if (strcmp (argv [iarg], "map2normal") == 0) {
                type = GL_MAP2_NORMAL;
                nCoords = 3;
            } else if (strcmp (argv [iarg], "map2texturecoord1") == 0) {
                type = GL_MAP2_TEXTURE_COORD_1;
                nCoords = 1;
            } else if (strcmp (argv [iarg], "map2texturecoord2") == 0) {
                type = GL_MAP2_TEXTURE_COORD_2;
                nCoords = 2;
            } else if (strcmp (argv [iarg], "map2texturecoord3") == 0) {
                type = GL_MAP2_TEXTURE_COORD_3;
                nCoords = 3;
            } else if (strcmp (argv [iarg], "map2texturecoord4") == 0) {
                type = GL_MAP2_TEXTURE_COORD_4;
                nCoords = 4;
            } else
                ERRMSG2 ("not a valid type:", argv [iarg]);
        }
        else if (strncmp (argv [iarg], "-samplingtolerance", len) == 0) {
            double val;
            iarg++;
            if (iarg >= argc) ERRMSG ("No -samplingtolerance value given");
            if (Tcl_GetDouble (interp, argv [iarg], &val) != TCL_OK)
                ERRMSG ("\nError parsing sampling tolerance");
            samplingTolerance = (GLfloat)val;
        }
        else if (strncmp (argv [iarg], "-displaymode", len) == 0) {
            iarg++;
            if (iarg >= argc) ERRMSG ("No -displaymode value given");
            if (strcmp (argv [iarg], "fill") == 0) {
                displayMode = GLU_FILL;
            } else if (strcmp (argv [iarg], "outlinepolygon") == 0) {
                displayMode = GLU_OUTLINE_POLYGON;
            } else if (strcmp (argv [iarg], "outlinepatch") == 0) {
                displayMode = GLU_OUTLINE_PATCH;
            } else {
                ERRMSG2 ("not a valid display mode:", argv [iarg]);
            }
        }
        else if (strncmp (argv [iarg], "-culling", len) == 0) {
            int val;
            iarg++;
            if (iarg >= argc) ERRMSG ("No -culling value given");
            if (Tcl_GetBoolean (interp, argv [iarg], &val) != TCL_OK)
                ERRMSG ("\nError parsing culling value");
            culling = (GLfloat)val;
        }
        else {
            ERRMSG2 ("invalid option:", argv [iarg]);
        }
    }

    if (vKnot->count == 0 || uKnot->count == 0 || cPoint->count == 0)
        ERRMSG ("All of -uknot, -vknot and -cpoint options must be specified");

    /* Now try to guess the remaining arguments and call gluNurbsSurface */
    {
        GLint uKnotCount = uKnot->count;
        GLint vKnotCount = vKnot->count;
        GLint vStride = nCoords;
        GLint uStride = nCoords * (vKnotCount - vOrder);
        static GLUnurbsObj* obj = NULL;
        if (uStride * (uKnotCount - uOrder) != cPoint->count) {
            char buf [80];
            sprintf (buf, "%d", uStride * (uKnotCount - uOrder));
            ERRMSG2 ("Incorrect number of controlpoint coordinates. Expected ",
                     buf);
        }
        /* Theoretically, a nurbs object could be allocated for each
        invocation of NurbsSurface and then freed after the creation
         of the display list. However, this produces a segmentation
         violation on AIX OpenGL 1.0. Thus, only one nurbs object is
         ever allocated and never freed.
            */
        if (obj == NULL) obj = gluNewNurbsRenderer();
        dlist = glGenLists (1);
        gluNurbsProperty (obj, GLU_SAMPLING_TOLERANCE, samplingTolerance);
        gluNurbsProperty (obj, GLU_DISPLAY_MODE, displayMode);
        gluNurbsProperty (obj, GLU_CULLING, culling);
        glNewList (dlist, GL_COMPILE);
        gluBeginSurface (obj);
        gluNurbsSurface (obj, uKnotCount, uKnot->value,
                         vKnotCount, vKnot->value,
                         uStride, vStride, cPoint->value,
                         uOrder, vOrder, type);
        gluEndSurface (obj);
        /* This is never used because of a bug in AIX OpenGL 1.0.
        gluDeleteNurbsObj (obj);
            */
        glEndList();
        glFlush();
    }

done:

    DestroyFloatArray (uKnot);
    DestroyFloatArray (vKnot);
    DestroyFloatArray (cPoint);

    if (result == TCL_OK) {
        char tmp[128];
        sprintf (tmp, "%d", dlist);
        Tcl_SetResult(interp, tmp, TCL_VOLATILE);
    }

    return result;
}