void LICE_GL_ctx::Close() { ClearTex(); if (m_nurbs) { gluDeleteNurbsRenderer(m_nurbs); m_nurbs = 0; } if (m_glrc) { wglMakeCurrent(0, 0); wglDeleteContext(m_glrc); m_glrc = 0; } if (m_hwnd) { DestroyWindow(m_hwnd); m_hwnd = 0; } if (m_gldll) { FreeLibrary(m_gldll); m_gldll = 0; } }
static int luaglu_nurbs_gc(lua_State *L) { LuaGLUnurb * lnurb=luaglu_checknurb(L,1); #ifdef GLU_VERSION_1_3 luaL_unref(L,LUA_REGISTRYINDEX,lnurb->ref_cb); #endif if (lnurb->nurb) gluDeleteNurbsRenderer(lnurb->nurb); return 0; }
Quiddiards::~Quiddiards() { gluDeleteNurbsRenderer(nurbs); gluDeleteQuadric(quad); for (std::map<std::string, QOpenGLTexture*>::iterator it = textures.begin(); it != textures.end(); it++){ delete it->second; } delete timer; delete ps; delete ground; }
CMeter2DGraphView::~CMeter2DGraphView() { TRACE_FUN( Routine, "CMeter2DGraphView::~CMeter2DGraphView" ); killTimer( _timerId ); glDeleteLists( _meshList, 1 ); gluDeleteNurbsRenderer( _nurbsRenderer ); deviceView().mainWindow().menuBarManager().CloseSession( _menuSessionId ); }
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); }
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); }
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); }
static int tolua_glu_gluDeleteNurbsRenderer00(lua_State* tolua_S) { #ifndef TOLUA_RELEASE tolua_Error tolua_err; if ( !tolua_isusertype(tolua_S,1,"GLUnurbsObj",0,&tolua_err) || !tolua_isnoobj(tolua_S,2,&tolua_err) ) goto tolua_lerror; else #endif { GLUnurbsObj* nobj = ((GLUnurbsObj*) tolua_tousertype(tolua_S,1,0)); { gluDeleteNurbsRenderer(nobj); } } return 0; #ifndef TOLUA_RELEASE tolua_lerror: tolua_error(tolua_S,"#ferror in function 'gluDeleteNurbsRenderer'.",&tolua_err); return 0; #endif }
int main( int argc, const char *argv[] ) { // reads model into global glb_model; ON::Begin(); ON_TextLog error_log; ON_BOOL32 bOK; int window_width = 500; int window_height = 500; //double port_aspect = ((double)window_width)/((double)window_height); // read the file into model if ( argc != 2 ) { printf("Syntax: %s filename.3dm\n",argv[0] ); return 0; } const char* sFileName = argv[1]; printf("\nFile: %s\n", sFileName ); // read the file CModel model; if ( !model.Read( sFileName, &error_log ) ) { // read failed error_log.Print("Unable to read file %s\n",sFileName); return 1; } glb_model = &model; // set bbox = world bounding box of all the objects model.m_bbox = model.BoundingBox(); if ( !model.m_bbox.IsValid() ) { // nothing to look at in this model return 2; } // set model.m_view if ( model.m_settings.m_views.Count() > 0 ) { // use first viewport projection in file double angle; model.m_view.m_vp = model.m_settings.m_views[0].m_vp; model.m_view.m_target = model.m_settings.m_views[0].m_target; model.m_view.m_vp.GetCameraAngle( &angle ); model.m_view.m_vp.Extents( angle, model.m_bbox ); } else { GetDefaultView( model.m_bbox, model.m_view ); } // If needed, enlarge frustum so its aspect matches the window's aspect. // Since the Rhino file does not store the far frustum distance in the // file, viewports read from a Rhil file need to have the frustum's far // value set by inspecting the bounding box of the geometry to be // displayed. /////////////////////////////////////////////////////////////////// // // GL stuff starts here // for(;;) { #if defined(ON_EXAMPLE_GL_USE_GLAUX) wchar_t sWindowTitleString[256]; #endif #if defined(ON_EXAMPLE_GL_USE_GLUT) char sWindowTitleString[256]; #endif sWindowTitleString[255] = 0; if ( argv[0] && argv[0][0] ) { int i; for ( i = 0; i < 254 && argv[0][i]; i++ ) sWindowTitleString[i] = argv[0][i]; sWindowTitleString[i] = 0; } #if defined(ON_EXAMPLE_GL_USE_GLAUX) auxInitPosition( 0, 0, window_width, window_height ); auxInitDisplayMode( AUX_SINGLE | AUX_RGB | AUX_DEPTH ); auxInitWindow( sWindowTitleString ); // register event handler functions auxIdleFunc( 0 ); auxReshapeFunc( myGLAUX_Reshape ); auxMouseFunc( AUX_LEFTBUTTON, AUX_MOUSEDOWN, myGLAUX_MouseLeftEvent ); auxMouseFunc( AUX_LEFTBUTTON, AUX_MOUSEUP, myGLAUX_MouseLeftEvent ); auxMouseFunc( AUX_MIDDLEBUTTON, AUX_MOUSEDOWN, myGLAUX_MouseMiddleEvent ); auxMouseFunc( AUX_MIDDLEBUTTON, AUX_MOUSEUP, myGLAUX_MouseMiddleEvent ); auxMouseFunc( AUX_RIGHTBUTTON, AUX_MOUSEDOWN, myGLAUX_MouseRightEvent ); auxMouseFunc( AUX_RIGHTBUTTON, AUX_MOUSEUP, myGLAUX_MouseRightEvent ); auxKeyFunc( AUX_LEFT, myKeyLeftArrowEvent ); auxKeyFunc( AUX_RIGHT, myKeyRightArrowEvent ); auxKeyFunc( AUX_UP, myKeyUpArrowEvent ); auxKeyFunc( AUX_DOWN, myKeyDownArrowEvent ); auxKeyFunc( AUX_E, myKeyViewExtents ); auxKeyFunc( AUX_e, myKeyViewExtents ); auxKeyFunc( AUX_Z, myKeyViewExtents ); auxKeyFunc( AUX_z, myKeyViewExtents ); #endif #if defined(ON_EXAMPLE_GL_USE_GLUT) glutInit(&argc,(char**)argv); glutInitWindowPosition( 0, 0); glutInitWindowSize( window_width, window_height ); glutInitDisplayMode( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH ); glutCreateWindow( sWindowTitleString ); // register event handler functions glutIdleFunc( 0 ); glutReshapeFunc( myGLUT_Reshape ); glutMouseFunc( myGLUT_MouseEvent ); glutKeyboardFunc( myGLUT_KeyboardEvent ); glutSpecialFunc( myGLUT_SpecialKeyEvent ); glutDisplayFunc( myDisplay ); #endif // setup model view matrix, GL defaults, and the GL NURBS renderer GLUnurbsObj* pTheGLNURBSRender = NULL; // OpenGL NURBS rendering context bOK = myInitGL( model.m_view.m_vp, pTheGLNURBSRender ); if ( bOK ) { // build display list myBuildDisplayList( glb_display_list_number, pTheGLNURBSRender, model ); // look at it #if defined(ON_EXAMPLE_GL_USE_GLAUX) auxMainLoop( myDisplay ); #endif #if defined(ON_EXAMPLE_GL_USE_GLUT) glutMainLoop( ); #endif } gluDeleteNurbsRenderer( pTheGLNURBSRender ); break; } // // GL stuff ends here // /////////////////////////////////////////////////////////////////// ON::End(); return 0; }
void SoNurbsSurface::GLRender(SoGLRenderAction *action) // //////////////////////////////////////////////////////////////////////// { // First see if the object is visible and should be rendered now if (! shouldGLRender(action)) return; const SoCoordinateElement *ce = SoCoordinateElement::getInstance(action->getState()); GLfloat *sKnots, *tKnots, *dstCoords; GLenum type; float *fKnots; int32_t nCoords, uOffset, vOffset; int32_t nsKnots, ntKnots, nsCoords, ntCoords; int32_t nDstCoords; int32_t sOffset, tOffset; int i, j; // Check for 0 control points nCoords = ce->getNum(); if (nCoords == 0) return; // Make sure the first current material is sent to GL SoMaterialBundle mb(action); mb.sendFirst(); // // Find the number of steps required for object space tessellation and // the pixel tolerance used for screen space tessellation. // float val = SoComplexityElement::get(action->getState()); if (val < 0.0) val = 0.0; if (val > 1.0) val = 1.0; int steps; if (val < 0.10) steps = 2; else if (val < 0.25) steps = 3; else if (val < 0.40) steps = 4; else if (val < 0.55) steps = 5; else steps = (int)(powf(val, 3.32)*28) + 2; float pixTolerance = 104.0*val*val - 252.0*val + 150; // // If the surface is being cached, or if the tessellation is in object // space, use the software NURBS library. Create a software NURBS // rendering class and use it to make nurbs rendering calls. Since // the software NURBS library generates triangles, texture mapping // will happen automatically without having to render a separate // texture surface. // if (SoComplexityTypeElement::get(action->getState()) == SoComplexityTypeElement::OBJECT_SPACE) { _SoNurbsGLRender *GLRender = new _SoNurbsGLRender(); // // Set the sampling to be constant across the surface with the // tessellation to be 'steps' across the S and T parameters // GLRender->setnurbsproperty( N_T2D, N_SAMPLINGMETHOD, N_FIXEDRATE ); GLRender->setnurbsproperty( N_V3D, N_SAMPLINGMETHOD, N_FIXEDRATE ); GLRender->setnurbsproperty( N_V3DR, N_SAMPLINGMETHOD, N_FIXEDRATE ); GLRender->setnurbsproperty( N_T2D, N_S_STEPS, steps); GLRender->setnurbsproperty( N_T2D, N_T_STEPS, steps); GLRender->setnurbsproperty( N_V3D, N_S_STEPS, steps); GLRender->setnurbsproperty( N_V3D, N_T_STEPS, steps); GLRender->setnurbsproperty( N_V3DR, N_S_STEPS, steps); GLRender->setnurbsproperty( N_V3DR, N_T_STEPS, steps); // Determine whether a texture coordinate surface must be generated SbBool doTextures = SoGLTextureEnabledElement::get(action->getState()); // Draw the surface drawNURBS (GLRender, action->getState(), doTextures); delete GLRender; return; } if (SoDrawStyleElement::get(action->getState()) == SoDrawStyleElement::POINTS) { // // Render the control points of the surface. Rendering the points // of the surface would be very slow, as the Software NURBS library // would have to be used, and because of the view dependent // tessellation, points would not necessarily remain visible. // glBegin(GL_POINTS); if (ce->is3D()) { for (i=0; i<nCoords; i++) { const SbVec3f & coords3 = ce->get3((int)i); glVertex3f ((GLfloat)(coords3[0]), (GLfloat)(coords3[1]), (GLfloat)(coords3[2])); } } else { for (i=0; i<nCoords; i++) { const SbVec4f & coords4 = ce->get4((int)i); glVertex4f ((GLfloat)(coords4[0]), (GLfloat)(coords4[1]), (GLfloat)(coords4[2]), (GLfloat)(coords4[3])); } } glEnd(); return; } // // Render the NURBS surface using the GLU. // GLUnurbsObj *nurbsObj = gluNewNurbsRenderer(); switch (SoDrawStyleElement::get(action->getState())) { case SoDrawStyleElement::FILLED: gluNurbsProperty (nurbsObj, (GLenum)GLU_DISPLAY_MODE, GLU_FILL); break; case SoDrawStyleElement::LINES: gluNurbsProperty (nurbsObj, (GLenum)GLU_DISPLAY_MODE, GLU_OUTLINE_POLYGON); break; } gluNurbsProperty (nurbsObj, (GLenum)GLU_SAMPLING_TOLERANCE, (GLfloat)pixTolerance); // // Collect the control points and knot vectors into an array suitable // for sending to the GL. The control points and knot vectors must be // converted to double precision so that they can be passed to the // GL NURBS routines. // GLfloat *dCoords, *duKnots, *dvKnots; if (ce->is3D()) { dCoords = (GLfloat *)new GLfloat[3*nCoords]; for (i=0; i<nCoords; i++) { const SbVec3f &c3 = ce->get3((int)i); dCoords[3*i] = (GLfloat)c3[0]; dCoords[3*i+1] = (GLfloat)c3[1]; dCoords[3*i+2] = (GLfloat)c3[2]; } uOffset = 3; type = GL_MAP2_VERTEX_3; } else { dCoords = (GLfloat *)new GLfloat[4*nCoords]; for (i=0; i<nCoords; i++) { const SbVec4f &c4 = ce->get4((int)i); dCoords[4*i] = (GLfloat)c4[0]; dCoords[4*i+1] = (GLfloat)c4[1]; dCoords[4*i+2] = (GLfloat)c4[2]; dCoords[4*i+3] = (GLfloat)c4[3]; } uOffset = 4; type = GL_MAP2_VERTEX_4; } vOffset = uOffset * numUControlPoints.getValue(); fKnots = (float *)uKnotVector.getValues(0); duKnots = (GLfloat *)new GLfloat[uKnotVector.getNum()]; for (i=0; i<uKnotVector.getNum(); i++) duKnots[i] = (GLfloat)fKnots[i]; fKnots = (GLfloat *)vKnotVector.getValues(0); dvKnots = (GLfloat *)new GLfloat[vKnotVector.getNum()]; for (i=0; i<vKnotVector.getNum(); i++) dvKnots[i] = (GLfloat)fKnots[i]; // Texture mapping. If doTextures == TRUE // we are drawing textures. If the textureCoordinateBinding is // DEFAULT, we have to build a default NURBS surface for the texture // coordinates, otherwise we use the texture coordinates in the texture // element. // If there is a software texture function defined, then we have to // create a texture nurb surface with the same number of points and // knots as the original surface, and call the texture coordinate function // at each vertex. SbBool doTextures = SoGLTextureEnabledElement::get(action->getState()); if(doTextures) { switch (SoTextureCoordinateElement::getType(action->getState())) { // software texture functions case SoTextureCoordinateElement::FUNCTION: { // generate S and T coords from U and V coords SbVec3f coord; SbVec2f stCoord; int offset; SoTextureCoordinateBundle tb(action, TRUE); nsCoords = numUControlPoints.getValue(); ntCoords = numVControlPoints.getValue(); sKnots = duKnots; tKnots = dvKnots; nsKnots = uKnotVector.getNum(); ntKnots = vKnotVector.getNum(); nDstCoords = nsCoords * ntCoords; dstCoords = (GLfloat *)new GLfloat[nDstCoords * 2]; for(int v = 0; v < ntCoords; v++) { for(int u = 0; u < nsCoords; u++) { if (ce->is3D()) { offset = 3 * (v * (int)nsCoords + u); coord[0] = dCoords[offset + 0]; coord[1] = dCoords[offset + 1]; coord[2] = dCoords[offset + 2]; } else { offset = 4 * (v * (int)nsCoords + u); coord[0] = dCoords[offset + 0] / dCoords[offset + 3]; coord[1] = dCoords[offset + 1] / dCoords[offset + 3]; coord[2] = dCoords[offset + 2] / dCoords[offset + 3]; } const SbVec4f &tc = tb.get(coord, SbVec3f(0.0, 1.0, 0.0)); dstCoords[(v * (int)nsCoords + u) * 2 + 0] = tc[0]; dstCoords[(v * (int)nsCoords + u) * 2 + 1] = tc[1]; } } break; } // texture coordinates defined from texture node case SoTextureCoordinateElement::EXPLICIT: // get texture coordinates from texture node const SoTextureCoordinateElement *te = SoTextureCoordinateElement::getInstance(action->getState()); int32_t nstCoords = te->getNum(); if (nstCoords < 1) { // Default texture coordinates are computed by defining // a bezier surface that is defined in the same valid // parameter space as the geometric surface. The valid // parameter space is defined based on the order and knot // vector. The coordinates go from 0 to one and the knot // vectors span the valid range of the geometric surface. // The knot vectors default to 0 and 1 in the event of bogus // input data. int uOrder, vOrder; GLfloat sKnotVal1, sKnotVal2, tKnotVal1, tKnotVal2; uOrder = uKnotVector.getNum() - numUControlPoints.getValue(); vOrder = vKnotVector.getNum() - numVControlPoints.getValue(); if ((uOrder > 0) && (uOrder < uKnotVector.getNum())) sKnotVal1 = duKnots[uOrder-1]; else sKnotVal1 = 0; if ((uOrder > 0) && (uOrder < uKnotVector.getNum())) sKnotVal2 = duKnots[uKnotVector.getNum()-uOrder]; else sKnotVal2 = 1; if ((vOrder > 0) && (vOrder < vKnotVector.getNum())) tKnotVal1 = dvKnots[vOrder-1]; else tKnotVal1 = 0; if ((vOrder > 0) && (vOrder < vKnotVector.getNum())) tKnotVal2 = dvKnots[vKnotVector.getNum()-vOrder]; else tKnotVal2 = 1; // do a linear 2x2 array nsKnots = 4; ntKnots = 4; sKnots = (GLfloat *)new GLfloat[4]; tKnots = (GLfloat *)new GLfloat[4]; sKnots[0] = sKnots[1] = sKnotVal1; tKnots[0] = tKnots[1] = tKnotVal1; sKnots[2] = sKnots[3] = sKnotVal2; tKnots[2] = tKnots[3] = tKnotVal2; // allocate a 2 x 2 array of GLfloat[2]'s nsCoords = 2; ntCoords = 2; nDstCoords = nsCoords * ntCoords * 2; dstCoords = (GLfloat *)new GLfloat[nDstCoords]; for(i = 0; i < 2; i++) { for(j = 0; j < 2; j++) { dstCoords[(i * 2 + j) * 2 + 0] = j; dstCoords[(i * 2 + j) * 2 + 1] = i; } } } else { // get knot vectors from this node nsKnots = sKnotVector.getNum(); fKnots = (float *)sKnotVector.getValues(0); sKnots = (GLfloat *)new GLfloat[nsKnots]; for (i=0; i < nsKnots; i++) sKnots[i] = (GLfloat)fKnots[i]; ntKnots = tKnotVector.getNum(); fKnots = (float *)tKnotVector.getValues(0); tKnots = (GLfloat *)new GLfloat[ntKnots]; for (i=0; i < ntKnots; i++) tKnots[i] = (GLfloat)fKnots[i]; nsCoords = numSControlPoints.getValue(); ntCoords = numTControlPoints.getValue(); nDstCoords = 2 * nstCoords; dstCoords = (GLfloat *)new GLfloat[nDstCoords]; for(i = 0; i < nstCoords; i++) { const SbVec2f &tc2 = te->get2(i); dstCoords[2*i] = (GLfloat)tc2[0]; dstCoords[2*i+1] = (GLfloat)tc2[1]; } } break; } sOffset = 2; tOffset = sOffset * nsCoords; } // // Draw the NURBS surface. Begin the surface. Then load the texture // map as a nurbs surface. Then, draw the geometric surface followed // by all of its trim curves. Then, end the surface. // glEnable(GL_AUTO_NORMAL); // Get one camera based element so that this node will be registered // with the cache. If the camera changes, this element will cause // the cache to be blown for this node and the nurbs surface will be // regenerated. SbMatrix vMat = SoViewingMatrixElement::get (action->getState()); SbMatrix mMat = SoModelMatrixElement::get (action->getState()); // Begin the surface. gluBeginSurface(nurbsObj); // Draw the texture surface if(doTextures) { // send down nurbs surface, then free memory gluNurbsSurface(nurbsObj, (GLint)nsKnots, sKnots, (GLint)ntKnots, tKnots, (GLint)sOffset, (GLint)tOffset, dstCoords, (GLint)(nsKnots - nsCoords), (GLint)(ntKnots - ntCoords), GL_MAP2_TEXTURE_COORD_2); // delete knots if not sharing them with the surface description // (in the case of software texture coordinates only) if(sKnots != duKnots) { delete [] sKnots; delete [] tKnots; } delete [] dstCoords; } gluNurbsSurface (nurbsObj, (GLint)(uKnotVector.getNum()), duKnots, (GLint)(vKnotVector.getNum()), dvKnots, (GLint)uOffset, (GLint)vOffset, dCoords, (GLint)(uKnotVector.getNum() - numUControlPoints.getValue()), (GLint)(vKnotVector.getNum() - numVControlPoints.getValue()), type); // // Get all of the trim curves and use them to trim the surface. // SoProfile *profile; const SoNodeList &trimNodes = SoProfileElement::get(action->getState()); SbBool haveTrim = FALSE; float *trimCoords, *trimKnots; int32_t numTrimCoords, numKnots, offset; int numTrims = trimNodes.getLength(); int floatsPerVec; // // For each trim curve, check its linkage to find out if it should be // continued on to the previous trim curve or if it should begin a // new trim curve. Then, send the trim to the NURBS library. // for (i=0; i<numTrims; i++) { GLfloat *dTrimCoords; GLfloat *dtmp; float *ftmp; // Get the trim curve. profile = (SoProfile *)trimNodes[(int) i]; profile->getTrimCurve (action->getState(), numTrimCoords, trimCoords, floatsPerVec, numKnots, trimKnots); // Check for degenerate trim curves if (numTrimCoords == 0) continue; // Check the linkage. if ((profile->linkage.getValue() == SoProfileElement::START_FIRST) || (profile->linkage.getValue() == SoProfileElement::START_NEW)) { if (haveTrim) gluEndTrim(nurbsObj); gluBeginTrim(nurbsObj); haveTrim = TRUE; } // Set the data type of the control points to non-rational or rational if (floatsPerVec == 2) type = (GLenum)GLU_MAP1_TRIM_2; else type = (GLenum)GLU_MAP1_TRIM_3; offset = floatsPerVec; dTrimCoords = new GLfloat[numTrimCoords*floatsPerVec]; dtmp = dTrimCoords; ftmp = trimCoords; for (j=0; j<floatsPerVec*numTrimCoords; j++) *dtmp++ = (GLfloat)(*ftmp++); if (numKnots == 0) { // Send down a Piecewise Linear Trim Curve gluPwlCurve (nurbsObj, (GLint)numTrimCoords, dTrimCoords, (GLint)offset, type); } else { // Send down a NURBS Trim Curve GLfloat *dTrimKnots = new GLfloat[numKnots]; dtmp = dTrimKnots; ftmp = trimKnots; for (j=0; j<numKnots; j++) *dtmp++ = (GLfloat)(*ftmp++); gluNurbsCurve (nurbsObj, (GLint)numKnots, dTrimKnots, (GLint)offset, dTrimCoords, (GLint)(numKnots - numTrimCoords), type); delete[] dTrimKnots; delete[] trimKnots; } delete[] dTrimCoords; delete[] trimCoords; } if (haveTrim) gluEndTrim(nurbsObj); gluEndSurface(nurbsObj); gluDeleteNurbsRenderer(nurbsObj); glDisable(GL_AUTO_NORMAL); delete[] dvKnots; delete[] duKnots; delete[] dCoords; }
void Sample_12_7::restoreGL() { gluDeleteNurbsRenderer(m_theNurb); glPopAttrib(); }
/* Create all the objects, textures, geometry, etc, that we will use */ void InitialiseScene(void) { /* Create new lists, and store its ID number */ gTerrainList = glGenLists(1); gPacman = glGenLists(2); gLQGhost = glGenLists(3); gMQGhost = glGenLists(4); gHQGhost = glGenLists(5); gHQDot = glGenLists(6); gHQFruit = glGenLists(7); // create terrain glNewList(gTerrainList, GL_COMPILE); DrawTerrain(); glEndList(); // create pacman glNewList(gPacman, GL_COMPILE); DrawPacman(); glEndList(); // create ghosts from splines theGhostNurb = gluNewNurbsRenderer(); gluNurbsProperty(theGhostNurb, GLU_SAMPLING_METHOD, GLU_DOMAIN_DISTANCE); gluNurbsProperty(theGhostNurb, GLU_DISPLAY_MODE, GLU_FILL); gluNurbsProperty(theGhostNurb, GLU_CULLING, GL_TRUE); // high quality ghost gluNurbsProperty(theGhostNurb, GLU_U_STEP, 50.); gluNurbsProperty(theGhostNurb, GLU_V_STEP, 50.); glNewList(gHQGhost, GL_COMPILE); DrawGhost(); glEndList(); // medium quality ghost gluNurbsProperty(theGhostNurb, GLU_U_STEP, 20.); gluNurbsProperty(theGhostNurb, GLU_V_STEP, 20.); glNewList(gMQGhost, GL_COMPILE); DrawGhost(); glEndList(); // low quality ghost gluNurbsProperty(theGhostNurb, GLU_U_STEP, 5.); gluNurbsProperty(theGhostNurb, GLU_V_STEP, 5.); glNewList(gLQGhost, GL_COMPILE); DrawGhost(); glEndList(); gluDeleteNurbsRenderer(theGhostNurb); /* create the banana from nurb spline*/ theFruitNurb = gluNewNurbsRenderer(); gluNurbsProperty(theFruitNurb, GLU_SAMPLING_METHOD, GLU_DOMAIN_DISTANCE); gluNurbsProperty(theFruitNurb, GLU_DISPLAY_MODE, GLU_FILL); gluNurbsProperty(theFruitNurb, GLU_CULLING, GL_TRUE); gluNurbsProperty(theFruitNurb, GLU_U_STEP, 20.); gluNurbsProperty(theFruitNurb, GLU_V_STEP, 20.); glNewList(gHQFruit, GL_COMPILE); DrawFruit(); glEndList(); gluDeleteNurbsRenderer(theFruitNurb); /* create a dot */ glNewList(gHQDot, GL_COMPILE); DrawDot(10); glEndList(); }
int main(int argc, char** argv) { int status; SDL_WindowID window; SDL_GLContext glcontext=NULL; SDL_Event event; SDL_bool done=SDL_FALSE; status=SDL_Init(SDL_INIT_VIDEO); if (status<0) { fprintf(stderr, "Can't init default SDL video driver: %s\n", SDL_GetError()); exit(-1); } /* Select first display */ status=SDL_SelectVideoDisplay(0); if (status<0) { fprintf(stderr, "Can't attach to first display: %s\n", SDL_GetError()); exit(-1); } window=SDL_CreateWindow("SDL GLU ES Nurbs Trim test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN); if (window==0) { fprintf(stderr, "Can't create window: %s\n", SDL_GetError()); exit(-1); } glcontext=SDL_GL_CreateContext(window); if (glcontext==NULL) { fprintf(stderr, "Can't create OpenGL ES context: %s\n", SDL_GetError()); exit(-1); } status=SDL_GL_MakeCurrent(window, glcontext); if (status<0) { fprintf(stderr, "Can't set current OpenGL ES context: %s\n", SDL_GetError()); exit(-1); } init_scene(window_width, window_height); do { /* handle the events in the queue */ while (SDL_PollEvent(&event)) { switch(event.type) { case SDL_WINDOWEVENT: switch (event.window.event) { case SDL_WINDOWEVENT_CLOSE: done=SDL_TRUE; break; case SDL_WINDOWEVENT_RESIZED: resize(event.window.data1, event.window.data2); break; } break; case SDL_KEYDOWN: switch (event.key.keysym.sym) { case SDLK_ESCAPE: done=SDL_TRUE; break; } break; case SDL_QUIT: done=SDL_TRUE; break; } } if (done==SDL_TRUE) { break; } render_scene(); SDL_GL_SwapWindow(window); } while(1); /* Destroy NURBS renderer */ gluDeleteNurbsRenderer(nurb); SDL_GL_DeleteContext(glcontext); SDL_DestroyWindow(window); SDL_Quit(); return 0; }
void draw_solid(const k3d::gl::render_state& State, const k3d::double_t Radius, const k3d::double_t ZMin, const k3d::double_t ZMax, const k3d::double_t SweepAngle) { if(!Radius) return; const k3d::double_t zmin = ZMin; const k3d::double_t zmax = ZMax; const k3d::double_t thetamax = SweepAngle; const k3d::double_t phimin = (zmin > -1) ? asin(zmin) : -k3d::pi_over_2(); const k3d::double_t phimax = (zmax < 1) ? asin(zmax) : k3d::pi_over_2(); k3d::mesh::knots_t v_knots; k3d::mesh::weights_t v_weights; k3d::mesh::points_t v_arc_points; k3d::nurbs_curve::circular_arc(k3d::vector3(0, 1, 0), k3d::vector3(0, 0, 1), phimin, phimax, 2, v_knots, v_weights, v_arc_points); k3d::mesh::knots_t u_knots; k3d::mesh::weights_t u_weights; k3d::mesh::points_t u_arc_points; k3d::nurbs_curve::circular_arc(k3d::vector3(1, 0, 0), k3d::vector3(0, 1, 0), 0, thetamax, 4, u_knots, u_weights, u_arc_points); std::vector<GLfloat> gl_u_knot_vector(u_knots.begin(), u_knots.end()); std::vector<GLfloat> gl_v_knot_vector(v_knots.begin(), v_knots.end()); std::vector<GLfloat> gl_control_points; for(k3d::uint_t v = 0; v != v_arc_points.size(); ++v) { const k3d::point3 offset = v_arc_points[v][2] * k3d::point3(0, 0, 1); const k3d::double_t radius2 = v_arc_points[v][1]; const k3d::double_t v_weight = v_weights[v]; for(k3d::uint_t u = 0; u != u_arc_points.size(); ++u) { gl_control_points.push_back(v_weight * u_weights[u] * (radius2 * u_arc_points[u][0] + offset[0])); gl_control_points.push_back(v_weight * u_weights[u] * (radius2 * u_arc_points[u][1] + offset[1])); gl_control_points.push_back(v_weight * u_weights[u] * (radius2 * u_arc_points[u][2] + offset[2])); gl_control_points.push_back(v_weight * u_weights[u]); } } glPushMatrix(); k3d::gl::push_matrix(k3d::scale3(Radius)); 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, 3, GL_MAP2_VERTEX_4); gluEndSurface(nurbs_renderer); gluDeleteNurbsRenderer(nurbs_renderer); glPopMatrix(); }