void OpenGLInitialization( void ) { // We're drawing on a white background glClearColor(1.0, 1.0, 1.0, 1.0); // Convert our xyz curves into vertex arrays for (uint i=0; i<curves.Size(); i++) drawableCurves.Add( CurveToVertexArray( curves[i] ) ); // Covert our xyz curves into difference arrays. TODO: This is hard coded (our difference is // computed from either curve #0 or curve #6) for (uint i=0; i<curves.Size(); i++) errorCurves.Add( DifferenceToVertexArray( curves[i], curves[ i<6?0:6 ] ) ); // Load the shaders to draw our curves; set some parameters draw = new IGLUShaderProgram( "shaders/drawXYZCurve.vert.glsl", "shaders/drawXYZCurve.geom.glsl", "shaders/drawXYZCurve.frag.glsl" ); draw["xRange"] = vec2( 330.0f, 843.0f ); draw["yRange"] = vec2( -0.13f, 2.05f ); // Load the shader to draw our axes drawAxes = new IGLUShaderProgram( "shaders/drawAxes.vert.glsl", "shaders/drawAxes.frag.glsl" ); // Create the geometry for our axes axes = new IGLUVertexArray(); float axesData[] = { -0.90f, -0.88f, 0.95f, -0.88f, // x-axis line -0.88f, -0.88f, -0.88f, 0.95f, // y-axis line -0.90f, -0.6513f, -0.88f, -0.6513f, // 0.25 tick -0.90f, -0.4225f, -0.88f, -0.4225f, // 0.5 tick -0.90f, -0.1938f, -0.88f, -0.1938f, // 0.75 tick -0.90f, 0.035f, -0.88f, 0.035f, // 1.0 tick -0.90f, 0.2638f, -0.88f, 0.2638f, // 1.25 tick -0.90f, 0.4925f, -0.88f, 0.4925f, // 1.5 tick -0.90f, 0.7213f, -0.88f, 0.7213f, // 1.75 tick -0.90f, 0.95f, -0.88f, 0.95f, // 2.0 tick -0.7243f, -0.88f, -0.7243f, -0.91f, // 400 nm tick -0.5296f, -0.88f, -0.5296f, -0.91f, // 450 nm tick -0.3349f, -0.88f, -0.3349f, -0.91f, // 500 nm tick -0.1402f, -0.88f, -0.1402f, -0.91f, // 550 nm tick 0.0545f, -0.88f, 0.0545f, -0.91f, // 600 nm tick 0.24915f, -0.88f, 0.24915f, -0.91f, // 650 nm tick 0.4438f, -0.88f, 0.4438f, -0.91f, // 700 nm tick 0.6385f, -0.88f, 0.6385f, -0.91f, // 750 nm tick 0.8332f, -0.88f, 0.8332f, -0.91f, // 800 nm tick }; axes->SetVertexArray( sizeof( axesData ), axesData ); axes->EnableAttribute( IGLU_ATTRIB_VERTEX, 2, GL_FLOAT ); }
IGLUVertexArray *iglu::IGLUGeometry::CreateQuad( uint type, uint matlid ) { float *vptr = xyplane; if ( type & IGLU_GEOM_XZ_PLANE ) vptr = xzplane; if ( type & IGLU_GEOM_YZ_PLANE ) vptr = yzplane; IGLUVertexArray::Ptr tmp = new IGLUVertexArray(); tmp->SetVertexArray( sizeof( xyplane ), vptr, IGLU_STATIC|IGLU_DRAW ); tmp->EnableAttribute( IGLU_ATTRIB_VERTEX, 3, GL_FLOAT, 9 * sizeof(float), BUFFER_OFFSET(6*sizeof(float)) ); if (type & IGLU_GEOM_USE_NORMAL) tmp->EnableAttribute( IGLU_ATTRIB_NORMAL, 3, GL_FLOAT, 9 * sizeof(float), BUFFER_OFFSET(3*sizeof(float)) ); if (type & IGLU_GEOM_USE_TEXCOORD) tmp->EnableAttribute( IGLU_ATTRIB_TEXCOORD, 2, GL_FLOAT, 9 * sizeof(float), BUFFER_OFFSET(1*sizeof(float)) ); return tmp; }
// Do a pointwise difference between two XYZ curves and store into a renderable vertex array IGLUVertexArray::Ptr DifferenceToVertexArray( XYZAbstract *approx, XYZAbstract *curve ) { IGLUVertexArray::Ptr vArr = new IGLUVertexArray(); float *arrData = (float *)malloc( sizeof(float) * 4 * 471 ); float *fptr = arrData; for (int i=360; i<=830; i++) { *(fptr++) = float(i); *(fptr++) = approx->X(float(i))-curve->X(float(i)); *(fptr++) = approx->Y(float(i))-curve->Y(float(i)); *(fptr++) = approx->Z(float(i))-curve->Z(float(i)); } vArr->SetVertexArray( sizeof(float) * 4 * 471, arrData ); vArr->EnableAttribute( IGLU_ATTRIB_VERTEX, 4, GL_FLOAT ); free( arrData ); return vArr; }