/******************************************************************************* * * Name: gra_cylinder * * Purpose: draw cylinder between points given * * Parameters: * * Input: (double x0,y0,z0) first end point coordinates * (double f0) first end point color * (double x1,y1,z1)) second end point coordinates * (double f1) second end point color * (double R) cylinder radius * * Output: graphics * * Return value: void * ******************************************************************************/ void gra_cylinder(double x0,double y0,double z0,double f0,double x1,double y1,double z1,double f1,double R) { double ax,ay,az,s; int i,j; if ( !GRA_SphereInitDone ) gra_sphere_quality( GRA_SphereQuality ); ax = x1; ay = y1; az = z1; x1 = ax - x0; y1 = ay - y0; z1 = az - z0; s = sqrt( x1*x1+y1*y1+z1*z1 ); if ( s < 1.0e-10 ) return; gra_vector_to_angles( x0,y0,z0,&ax,&ay,&az,1/s ); glPushMatrix(); glTranslated( x0,y0,z0 ); glRotated( ax,1.0,0.0,0.0 ); glRotated( ay,0.0,1.0,0.0 ); glScaled( s,R,R ); glBegin(GL_QUAD_STRIP); glTexCoord1d( f0 ); glNormal3d( 0.0,0.0,1.0 ); glVertex3d( 0.0,0.0,1.0 ); glTexCoord1d( f1 ); glVertex3d( 1.0,0.0,1.0 ); for( j=1; j<=GRA_SphereQuality*4;j++ ) { y0 = GRA_SinA[j]; z0 = GRA_CosA[j]; glTexCoord1d( f0 ); glNormal3d( 0.0,y0,z0 ); glVertex3d( 0.0,y0,z0 ); glTexCoord1d( f1 ); glVertex3d( 1.0,y0,z0 ); } glEnd(); glPopMatrix(); glNormal3d( 0.0,0.0,1.0 ); }
/******************************************************************************* * * Name: gra_sphere * * Purpose: draw sphere centered at a point, with given color and * radius * * Parameters: * * Input: (double x,y,z) sphere center point * (double f) color * (double r) radius * * Output: graphics * * Return value: void * ******************************************************************************/ void gra_sphere(double x,double y,double z,double f,double r) { int Division = 4*GRA_SphereQuality; int i,j; if ( !GRA_SphereInitDone ) gra_sphere_quality( GRA_SphereQuality ); glPushMatrix(); glTranslatef(x,y,z); glScalef(r,r,r); for( i=0; i<Division/2; i++ ) { glBegin(GL_QUAD_STRIP); x = GRA_CosB[i]; y = 0.0; z = GRA_SinB[i]; glTexCoord1d( f ); glNormal3f(-x,-y,-z); glVertex3f(x,y,z); x = GRA_CosB[i+1]; y = 0.0; z = GRA_SinB[i+1]; glTexCoord1d( f ); glNormal3d( -x,-y,-z ); glVertex3d( x,y,z ); for( j=1; j<=Division; j++ ) { x = GRA_CosA[j]*GRA_CosB[i]; y = GRA_SinA[j]*GRA_CosB[i]; z = GRA_SinB[i]; glTexCoord1d( f ); glNormal3d( -x,-y,-z ); glVertex3d( x,y,z ); x = GRA_CosA[j]*GRA_CosB[i+1]; y = GRA_SinA[j]*GRA_CosB[i+1]; z = GRA_SinB[i+1]; glTexCoord1d( f ); glNormal3d( -x,-y,-z ); glVertex3d( x,y,z ); } glEnd(); } glPopMatrix(); glNormal3d( 0.0,0.0,1.0 ); }
void ColorMapEditor::paintGL () { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if (colors_need_update) { update_colors(); colors_need_update = false; } //draw scale int scale_delta = 8; //while( scale_delta / 255.0 * height() * zoom < 20 ) scale_delta++; glColor4f(0,0,0,0.5); for(size_t i = 0; i < resolution; i += scale_delta) { glBegin(GL_LINES); glVertex2f( i/(float)resolution , 0); glVertex2f( i/(float)resolution , 1); glEnd(); } glEnable(GL_LINE_SMOOTH); //draw function double res = resolution; glEnable(GL_TEXTURE_1D); glBindTexture(GL_TEXTURE_1D,color_tex); glBegin(GL_QUADS); glTexCoord1d( 0.5 / (res-1.0) ); glVertex2d ( 0, 0 ); glVertex2d ( 0, 1 ); glTexCoord1d( 0.5 / (res-1.0) + (res-1.0)/res ); glVertex2d ( 1, 1 ); glVertex2d ( 1, 0 ); glEnd(); glDisable(GL_TEXTURE_1D); glColor3f(0,0,0); glLineWidth(2); draw_channel(channel); }
//////////////////////////////////////////////////////////////// // // plot the high light // void Highlight(int n, vector* P, vector* N, vector A, vector H, real hl_step, int highlight_type) { real func[40]; int i; // calculate the highlight values according to point and normal for(i = 0; i<n; i++) { if(highlight_type == HIGHLIGHTLINE) { func[i] = calc_D( P[i], N[i], A, H); //if (calc_D( P[i], N[i], A, H, &func[i])) if (hl_error) return; // return if the patch is numerically unstable, } else { func[i] = calc_ref_line( P[i], N[i], A, H); //if (calc_ref_line( P[i], N[i], A, H, eye, &func[i])) if (hl_error) return; // return if the patch is numerically unstable, } } glEnable(GL_TEXTURE_1D); glDisable(GL_LIGHTING); glEnable(GL_LIGHTING); glBegin(GL_POLYGON); for(i=0;i<n;i++) { real f = func[i]; real color; color = f/hl_step; glTexCoord1d(color); glNormal3dv(N[i]); glVertex4dv(P[i]); } glEnd(); glEnable(GL_LIGHTING); glDisable(GL_TEXTURE_1D); }
/** * Renders the beam tree, showing all paths. * * @param root The beam tree root. * @param p1 The end point of the first ray. * @param p2 The end point of the second ray. */ void renderTree( TreeNode* root, int depth) { if (depth != 0) { if (depth == 1) { glColor3f( 1, 1, 1 ); glBegin( GL_LINES ); // First ray glVertex2f( env.getSource().getPosition().x, env.getSource().getPosition().y ); glVertex2f( root->getPoint(1).x, root->getPoint(1).y ); // Second ray glVertex2f( env.getSource().getPosition().x, env.getSource().getPosition().y ); glVertex2f( root->getPoint(2).x, root->getPoint(2).y ); glEnd( ); } glEnable( GL_TEXTURE_1D ); { glTexCoord1d( (double) depth / maximumDepth ); glBegin( GL_LINES ); // First ray glVertex2f( root->getSourcePosition().x, root->getSourcePosition().y ); glVertex2f( root->getPoint(1).x, root->getPoint(1).y ); // Second ray glVertex2f( root->getSourcePosition().x, root->getSourcePosition().y ); glVertex2f( root->getPoint(2).x, root->getPoint(2).y ); glEnd( ); } glDisable( GL_TEXTURE_1D ); } std::vector<TreeNode*> c = root->getChildren(); for (unsigned int i = 0; i < c.size(); i++) { renderTree(c[i], depth+1); } }
void View::draw_continuous_scale(char* title, bool righttext) { int i; double y0 = scale_y + scale_height; set_ortho_projection(true); glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glDisable(GL_TEXTURE_1D); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); // background const int b = 5; glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(1.0f, 1.0f, 1.0f, 0.65f); int rt = righttext ? 0 : labels_width + 8; glBegin(GL_QUADS); glVertex2d(scale_x - b - rt, y0 + 5 + b); glVertex2d(scale_x + scale_width + 8 + labels_width + b - rt, y0 + 5 + b); glVertex2d(scale_x + scale_width + 8 + labels_width + b - rt, scale_y - 5 - b); glVertex2d(scale_x - b - rt, scale_y - 5 - b); glEnd(); // palette glDisable(GL_BLEND); glColor3f(0.0f, 0.0f, 0.0f); glBegin(GL_QUADS); glVertex2d(scale_x, scale_y); glVertex2d(scale_x, scale_y + scale_height + 1); glVertex2d(scale_x + scale_width + 1, scale_y + scale_height + 1); glVertex2d(scale_x + scale_width + 1, scale_y); glEnd(); glEnable(GL_TEXTURE_1D); glBindTexture(GL_TEXTURE_1D, gl_pallete_tex_id); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); glBegin(GL_QUADS); glTexCoord1d(tex_scale + tex_shift); glVertex2d(scale_x + 1, scale_y + 1); glVertex2d(scale_x + scale_width, scale_y + 1); glTexCoord1d(tex_shift); glVertex2d(scale_x + scale_width, scale_y + scale_height); glVertex2d(scale_x + 1, scale_y + scale_height); glEnd(); // focus glDisable(GL_TEXTURE_1D); if (scale_focused) { glEnable(GL_BLEND); glColor4f(1.0f, 1.0f, 1.0f, 0.3f); glBegin(GL_QUADS); glVertex2d(scale_x + 1, scale_y + 1); glVertex2d(scale_x + scale_width, scale_y + 1); glVertex2d(scale_x + scale_width, scale_y + scale_height); glVertex2d(scale_x + 1, scale_y + scale_height); glEnd(); } // ticks glColor3f(0, 0, 0); glDisable(GL_BLEND); glDisable(GL_LINE_STIPPLE); glLineWidth(1.0); glBegin(GL_LINES); for (i = 0; i < scale_numticks; i++) { y0 = scale_y + scale_height - (double) (i+1) * scale_height / (scale_numticks+1); glVertex2d(scale_x, y0); glVertex2d(scale_x + 0.2 * scale_width + 1, y0); glVertex2d(scale_x + 0.8 * scale_width, y0); glVertex2d(scale_x + scale_width, y0); } glEnd(); // labels for (i = 0; i <= scale_numticks+1; i++) { double value = range_min + (double) i * (range_max - range_min) / (scale_numticks+1); if (fabs(value) < 1e-8) value = 0.0; char text[50]; sprintf(text, scale_fmt, value); y0 = scale_y + scale_height - (double) i * scale_height / (scale_numticks+1); if (righttext) draw_text(scale_x + scale_width + 8, y0, text); else draw_text(scale_x - 8, y0, text, 1); } }
template< > inline void glTexCoord1< LDOUBL > ( LDOUBL s ) { glTexCoord1d((double)s); };
template< > inline void glTexCoord1< double > ( double s ) { glTexCoord1d(s); };
/******************************************************************************* * * Name: gra_cone * * Purpose: draw a cone between points given * * Parameters: * * Input: (double x0,y0,z0) first end point coordinates * (double f0) first end point color * (double R0) first end point radius * (double x1,y1,z1)) second end point coordinates * (double f1) second end point color * (double R1) second end point radius * * Output: graphics * * Return value: void * ******************************************************************************/ void gra_cone(double x0,double y0,double z0,double f0,double R0,double x1,double y1,double z1,double f1,double R1) { double ax,ay,az,r,s; int i,j; if ( !GRA_SphereInitDone ) gra_sphere_quality(GRA_SphereQuality); ax = x1; ay = y1; az = z1; x1 = ax - x0; y1 = ay - y0; z1 = az - z0; r = sqrt( x1*x1+y1*y1+z1*z1 ); if ( r < 1.0E-10 ) return; gra_vector_to_angles( x0,y0,z0,&ax,&ay,&az,1/r ); glPushMatrix(); glTranslated(x0,y0,z0); glRotated( ax,1.0,0.0,0.0 ); glRotated( ay,0.0,1.0,0.0 ); glScaled( r,1.0,1.0 ); s = sqrt(1+(R0-R1)*(R0-R1)); s = 1/s; #define NORMAL(x,y,z) glNormal3d(s*(x),s*(y),s*(z)) glBegin(GL_QUAD_STRIP); NORMAL( R0-R1,0.0,1.0 ); glTexCoord1d( f0 ); glVertex3d( 0.0,0.0,R0 ); NORMAL( R0-R1,0.0,1.0 ); glTexCoord1d( f1 ); glVertex3d( 1.0,0.0,R1 ); for( j=1; j<=GRA_SphereQuality*4;j++ ) { y0 = GRA_SinA[j]; z0 = GRA_CosA[j]; NORMAL( R0-R1,y0,z0 ); glTexCoord1d( f0 ); glVertex3d( 0.0,R0*y0,R0*z0 ); glTexCoord1d( f1 ); glVertex3d( 1.0,R1*y0,R1*z0 ); } glEnd(); #undef NORMAL glPopMatrix(); glNormal3d( 0.0,0.0,1.0 ); }
/******************************************************************************* * * Name: gra_point * * Purpose: draw point with given color and radius * * Parameters: * * Input: (double x,y,z) sphere center point * (double f) color * (double r) radius * * Output: graphics * * Return value: void * ******************************************************************************/ void gra_point(double x,double y,double z,double f,double r) { glTexCoord1d( f ); glVertex3d( x,y,z ); }
inline void glTexCoord( const GLdouble & s ) { glTexCoord1d( s ); }
M(void, glTexCoord1d, jdouble s) { glTexCoord1d(s); }
void ColorBar::draw(GLContextData& contextData) const { /* Retrieve the context data item: */ DataItem* dataItem=contextData.retrieveDataItem<DataItem>(this); /* Draw parent class decorations: */ Widget::draw(contextData); /* Draw the widget margin: */ glColor(backgroundColor); glBegin(GL_TRIANGLE_FAN); glNormal3f(0.0f,0.0f,1.0f); glVertex(getInterior().getCorner(0)); glVertex(getInterior().getCorner(1)); for(int i=numTickMarks-1;i>=0;--i) { glVertex(tickMarks[i].labelBox.getCorner(1)); glVertex(tickMarks[i].labelBox.getCorner(0)); } glVertex(tickMarks[0].labelBox.getCorner(2)); glVertex(tickMarkLabelBox.getCorner(2)); glVertex(colorBarBox.getCorner(0)); glVertex(colorBarBox.getCorner(2)); glVertex(getInterior().getCorner(2)); glEnd(); glBegin(GL_TRIANGLE_FAN); glVertex(getInterior().getCorner(3)); glVertex(getInterior().getCorner(2)); glVertex(colorBarBox.getCorner(2)); glVertex(colorBarBox.getCorner(3)); glVertex(colorBarBox.getCorner(1)); glVertex(tickMarkLabelBox.getCorner(3)); glVertex(tickMarks[numTickMarks-1].labelBox.getCorner(3)); glVertex(tickMarks[numTickMarks-1].labelBox.getCorner(1)); glVertex(getInterior().getCorner(1)); glEnd(); /* Draw the spaces between the tick mark labels: */ glBegin(GL_QUADS); for(int i=1;i<numTickMarks;++i) { glVertex(tickMarks[i-1].labelBox.getCorner(3)); glVertex(tickMarks[i-1].labelBox.getCorner(1)); glVertex(tickMarks[i].labelBox.getCorner(0)); glVertex(tickMarks[i].labelBox.getCorner(2)); } glEnd(); /* Draw the border between tick marks and tick mark labels: */ glBegin(GL_QUAD_STRIP); GLfloat tickBot=tickMarkLabelBox.origin[1]+tickMarkLabelBox.size[1]; glVertex(tickMarkLabelBox.getCorner(2)); glVertex(tickMarks[0].labelBox.getCorner(2)); glVertex3f(tickMarkLabelBox.origin[0]+tickMarkWidth,tickBot,tickMarkLabelBox.origin[2]); glVertex(tickMarks[0].labelBox.getCorner(3)); for(int i=1;i<numTickMarks-1;++i) { GLfloat x=colorBarBox.origin[0]+colorBarBox.size[0]*GLfloat(i)/GLfloat(numTickMarks-1); glVertex3f(x-tickMarkWidth*0.5f,tickBot,tickMarkLabelBox.origin[2]); glVertex(tickMarks[i].labelBox.getCorner(2)); glVertex3f(x+tickMarkWidth*0.5f,tickBot,tickMarkLabelBox.origin[2]); glVertex(tickMarks[i].labelBox.getCorner(3)); } glVertex3f(tickMarkLabelBox.origin[0]+tickMarkLabelBox.size[0]-tickMarkWidth,tickBot,tickMarkLabelBox.origin[2]); glVertex(tickMarks[numTickMarks-1].labelBox.getCorner(2)); glVertex(tickMarkLabelBox.getCorner(3)); glVertex(tickMarks[numTickMarks-1].labelBox.getCorner(3)); glEnd(); /* Draw the spaces between tick marks: */ glBegin(GL_QUADS); GLfloat tickTop=colorBarBox.origin[1]; glVertex(colorBarBox.getCorner(0)); glVertex3f(tickMarkLabelBox.origin[0]+tickMarkWidth,tickBot,tickMarkLabelBox.origin[2]); for(int i=1;i<numTickMarks-1;++i) { GLfloat x=colorBarBox.origin[0]+colorBarBox.size[0]*GLfloat(i)/GLfloat(numTickMarks-1); glVertex3f(x-tickMarkWidth*0.5f,tickBot,tickMarkLabelBox.origin[2]); glVertex3f(x,tickTop,colorBarBox.origin[2]); glVertex3f(x,tickTop,colorBarBox.origin[2]); glVertex3f(x+tickMarkWidth*0.5f,tickBot,tickMarkLabelBox.origin[2]); } glVertex3f(tickMarkLabelBox.origin[0]+tickMarkLabelBox.size[0]-tickMarkWidth,tickBot,tickMarkLabelBox.origin[2]); glVertex(colorBarBox.getCorner(1)); glEnd(); /* Draw the tick marks: */ glBegin(GL_TRIANGLES); glColor(foregroundColor); glVertex(tickMarkLabelBox.getCorner(2)); glVertex3f(tickMarkLabelBox.origin[0]+tickMarkWidth,tickBot,tickMarkLabelBox.origin[2]); glVertex(colorBarBox.getCorner(0)); for(int i=1;i<numTickMarks-1;++i) { GLfloat x=colorBarBox.origin[0]+colorBarBox.size[0]*GLfloat(i)/GLfloat(numTickMarks-1); glVertex3f(x-tickMarkWidth*0.5f,tickBot,tickMarkLabelBox.origin[2]); glVertex3f(x+tickMarkWidth*0.5f,tickBot,tickMarkLabelBox.origin[2]); glVertex3f(x,tickTop,colorBarBox.origin[2]); } glVertex3f(tickMarkLabelBox.origin[0]+tickMarkLabelBox.size[0]-tickMarkWidth,tickBot,tickMarkLabelBox.origin[2]); glVertex(tickMarkLabelBox.getCorner(3)); glVertex(colorBarBox.getCorner(1)); glEnd(); /* Set up OpenGL state for color bar rendering: */ GLboolean lightingEnabled=glIsEnabled(GL_LIGHTING); if(lightingEnabled) glDisable(GL_LIGHTING); GLboolean texture1DEnabled=glIsEnabled(GL_TEXTURE_1D); if(!texture1DEnabled) glEnable(GL_TEXTURE_1D); GLboolean texture2DEnabled=glIsEnabled(GL_TEXTURE_2D); if(texture2DEnabled) glDisable(GL_TEXTURE_2D); GLboolean texture3DEnabled=glIsEnabled(GL_TEXTURE_3D); if(texture3DEnabled) glDisable(GL_TEXTURE_3D); /* Upload the color map as a 1D texture: */ glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_BASE_LEVEL,0); glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_MAX_LEVEL,0); glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexImage1D(GL_TEXTURE_1D,0,GL_RGBA8,256,0,GL_RGBA,GL_FLOAT,colorMap->getColors()); glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE); GLint matrixMode; glGetIntegerv(GL_MATRIX_MODE,&matrixMode); if(matrixMode!=GL_TEXTURE) glMatrixMode(GL_TEXTURE); glPushMatrix(); glLoadIdentity(); glScaled(1.0/(valueMax-valueMin),1.0,1.0); glTranslated(-valueMin,0.0,0.0); /* Draw the color bar: */ glBegin(GL_TRIANGLE_FAN); glColor4f(1.0f,1.0f,1.0f,1.0f); glTexCoord1d(valueMin); glVertex(colorBarBox.getCorner(2)); glVertex(colorBarBox.getCorner(0)); for(int i=1;i<numTickMarks-1;++i) { GLfloat x=colorBarBox.origin[0]+colorBarBox.size[0]*GLfloat(i)/GLfloat(numTickMarks-1); glTexCoord1d(valueMin+(valueMax-valueMin)*double(i)/double(numTickMarks-1)); glVertex3f(x,tickTop,colorBarBox.origin[2]); } glTexCoord1d(valueMax); glVertex(colorBarBox.getCorner(1)); glVertex(colorBarBox.getCorner(3)); glEnd(); /* Reset OpenGL state: */ glPopMatrix(); if(matrixMode!=GL_TEXTURE) glMatrixMode(matrixMode); if(texture3DEnabled) glEnable(GL_TEXTURE_3D); if(texture2DEnabled) glEnable(GL_TEXTURE_2D); if(!texture1DEnabled) glDisable(GL_TEXTURE_1D); if(lightingEnabled) glEnable(GL_LIGHTING); /* Draw the tick mark labels: */ glPushAttrib(GL_TEXTURE_BIT); GLint lightModelColorControl; glGetIntegerv(GL_LIGHT_MODEL_COLOR_CONTROL,&lightModelColorControl); glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL,GL_SEPARATE_SPECULAR_COLOR); glEnable(GL_TEXTURE_2D); for(int i=0;i<numTickMarks;++i) { glBindTexture(GL_TEXTURE_2D,dataItem->textureObjectIds[i]); if(dataItem->tickMarksVersion!=tickMarksVersion) // Have the tick marks changed? { /* Upload the tick mark label string texture again: */ font->uploadStringTexture(tickMarks[i].label,backgroundColor,foregroundColor); } glTexEnvMode(GLTexEnvEnums::TEXTURE_ENV,GLTexEnvEnums::MODULATE); glColor4f(1.0f,1.0f,1.0f,backgroundColor[3]); glBegin(GL_QUADS); glNormal3f(0.0f,0.0f,1.0f); glTexCoord(tickMarks[i].labelTexCoords.getCorner(0)); glVertex(tickMarks[i].labelBox.getCorner(0)); glTexCoord(tickMarks[i].labelTexCoords.getCorner(1)); glVertex(tickMarks[i].labelBox.getCorner(1)); glTexCoord(tickMarks[i].labelTexCoords.getCorner(3)); glVertex(tickMarks[i].labelBox.getCorner(3)); glTexCoord(tickMarks[i].labelTexCoords.getCorner(2)); glVertex(tickMarks[i].labelBox.getCorner(2)); glEnd(); } dataItem->tickMarksVersion=tickMarksVersion; glBindTexture(GL_TEXTURE_2D,0); glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL,lightModelColorControl); glPopAttrib(); }