Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

...

...

...

Table of Contents
stylenone

GiD_OpenGL register | unregister | registercondition | unregistercondition | draw | drawtext | project | unproject | get | doscrzoffset | drawentity | pgffont | gid_draw

This command is a Tcl wrapper of some OpenGL functions. It allows to use OpenGL commands directly from GiD-Tcl.
For example, for the C/C++ is usedto draw a line will be like this:

Code Block
languagecpp
glBegin(GL_LINES);
glVertex(x1,y1,z1);
glVertex(x2,y2,z2);
glEnd();


For The GiD-Tcl must useversion is:

Code Block
GiD_OpenGL draw -begin lines
GiD_OpenGL draw -vertex [list $x1 $y1 $z1]
GiD_OpenGL draw -vertex [list $x2 $y2 $z2]
GiD_OpenGL draw -end


The standard syntax must be changed according to these rules: -

  • OpenGL constants: "GL" prefix and underscore character '_' must be removed; the command must be written in lowercase.
    Example:

...

  • GL_COLOR_MATERIAL

...

  • colormaterial

  • OpenGL functions: "GL" prefix must be removed

...

  • , and substituted by a '-'. Pass parameters as list, without using parentheses ()
    Example:
    glBegin(GL_LINES)

...

  • → GiD_OpenGL draw -begin lines
    glVertex( x1, x2, x3) → GiD_OpenGL draw -vertex [ list $x1 $x2 $x3]


The subcommand "GiD_OpenGL draw" provides access to standard OpenGL commands, but other "GiD_OpenGL" special GiD subcommands also exists:

register <tclfunc>

Register a Tcl procedure to be invoked automatically when redrawing the scene. It returns a handle to unregister.


Example:

Code Block
proc MyRedrawProcedure { } { ...body... }
set id [GiD_OpenGL register MyRedrawProcedure]

unregister <handle>

Unregister a procedure previously registered with register.


Example:

Code Block
GiD_OpenGL unregister $id

registercondition <tclfunc> <condition>

Register a Tcl procedure to be invoked automatically when redrawing the specified condition.

The tcl Tcl funcion must have this prototype:

...


The supplied parameters are:

  • condition :the condition name, defined in the .cnd file of the problemtype

  • use: GEOMETRYUSE, MESHUSE or POSTUSE

  • entity_id: the integer number that identity the entity where the condition is applied. The kind of entity is known because it is declared in the
    definition of the condition in the .cnd, depending if the current state is geometry or mesh

  • values: a list of the field's values applied to this entity. The amount of values must match the amount of fields of the condition definition.
    The return value of this procedure is important:
    return 0: then the standard representation of the condition is also invoked after the procedure
    return 1: the standard representation of the condition is avoided.

unregistercondition <condition>

Unregister a procedure previously registered with registercondition.

draw <-cmd args -cmd args>

This is the most important subcommand, it calls standard OpenGL commands. See the list of supported OpenGL functions.

drawtext <text> ?–check_non_latin?

Draw a text more easily than using standard OpenGL commands (draw in the current 2D location, see rasterpos OpenGL command).

If -check_non_latin flag is provided, then the text is checked to detect non-latin characters, like a Japanese string, to be drawn properly (otherwise it is considered as a latin string). The flag must be provided only if <text> could potentially be non-latin, like translated strings. In case of numbers for example it is unneeded (more efficient without the extra check)
Example:

Code Block
GiD_OpenGL draw -rasterpos [list $x $y $z]
GiD_OpenGL drawtext "hello world"

drawentity ?-mode normal | filled? point | line | surface | volume | node | element | dimension <id list>

To draw an internal GiD preprocess entity.


Example:

Code Block
GiD_OpenGL drawentity -mode filled surface {1 5 6}

...

Code Block
GiD_OpenGL drawentity -mode filled element {{1 1} {5 1} {6 3}}

project <x y z>

Given three world coordinates, this returns the corresponding three window coordinates.

unproject <x y z>

Given three window coordinates, this returns the corresponding three world coordinates.

get modelviewmatrix | projectionmatrix | viewport | highresolutionprinting | highresolutionscalefactor

return a list of values:modelviewmatrix

  • ModelviewMatrix : 16 doubles

...

  • ProjectionMatrix : 16 doubles

  • viewport : 4 integers

  • HighResolutionPrinting : returns true if registered Tcl procedure is called when a high-resolution capture is being done.

  • HighResolutionScaleFactor : returns the scale factor between the screen and the high resolution capture, used to scale point sizes, line widths, font sizes, etc…

  • LastError : returns the last generated OpenGL error code

  • LastErrorString : returns the error string corresponding to the last generated OpenGL error code

doscrzoffset <boolean>

Special trick to avoid the lines on surfaces hidden by the surfaces.

pgffont pushfont | popfont | print | dimensions | foreground | background

Command

...

to use GiD fonts on OpenGL ( TrueType and Bitmap).

  • pgffont pushfont <font_type>

    Push sets the current Pushes current font category to stack and selects OpenGL font and add to stackcategory to be used from now on.
    font types: defaultfont font_type are font categories used in GiD, valid values are: 
    defaultfont | axisfont | legendfont | labelfont | graphfont | asianfont | tkdrawoglfont | pmfont
    pmfont is a bitmap font, the other ones are TrueType / FreeType

  • pgffont popfont

Restores Removes current used font category and restores the previous font and remove from stack. Commands push/pop must be called always paired.

  • pgffont print <text>

To draw a <text> in the current 3D location (set by GiD_OpenGL draw -rasterpos [list $x $y $z]). It is similar to GiD_OpenGL drawtext

  • pgffont dimensions <text>

Return the width of <text> and <height> of current font. Sizes in pixels, but result are float, not int as could be expected.

To convert to 3D sizes must be multiplied by a factor, an approximate value of this factor could be calculated like this:

Code Block
proc GetApproximateFactorPixelToWorld { } {
    lassign [GiD_Project view clip_planes_x] left_ortho right_ortho
    lassign [GidUtils::GetMainDrawAreaSize] w h
    set factor [expr double($right_ortho-$left_ortho)/$w]
    return $factor
}
  • pgffont foreground <red> <green> <blue> <alpha>

  • pgffont background <red> <green> <blue> <alpha>

Example:

Code Block
GiD_OpenGL pgffont push labelfont
GiD_OpenGL drawtext "hello world"
GiD_OpenGL pgffont pop

gid_draw <-cmd args>

Some draw <-cmd ards> OpenGL command modified to be used for high resolution printing.
High resolution printing is achieved by doing tile rendering. For instance, If GiD is running using a 3D OpenGL window of 1000 x 1000 pixels, in order to create a 10k by 10k image, GiD renders the 3D model 100 times on this window, but changing the 3D view. To be able to render each piece correctly, instead of using GiD_OpenGL draw -ortho [ list …] the command GiD_OpenGL gid_draw -ortho [ list …] should be used, so that the proper 3D view is set for the Tcl opengl code.

gid_draw subcommands are:

  • gid_draw -ortho [ list left right top bottom ?near far?] : similar to draw -ortho

  • gid_draw -viewport [ list x y width height] : similar to draw -viewport

  • gid_draw -scissor [ list x y width height] : similar to draw -scissor

  • gid_draw -rasterpos [ list x y ?z?] : similar to draw -rasterpos - to position the screen raster position for the next pixel / bitmap usage.

  • gid_draw -linewidth <width> : sets the width of the lines, scaled accordingly for high resolution capture. draw -linewidth does not scale line width for high resolution captures.

  • gid_draw -pointsize <size> : sets the size of the points, scaled accordingly for high resolution captures.


List of supported OpenGL functions:

Code Block
accum alphafunc begin bindtexture blendfunc call calllist clear clearaccum clearcolor cleardepth clearstencil clipplane color colormask colormaterial copypixels cullface deletelists deletetextures depthfunc depthmask dfactorBlendTable disable drawbuffer drawpixels edgeflag enable end endlist evalcoord1 evalcoord2 evalmesh1 evalmesh2 finish flush fog frontface frustum genlists gentextures getstring hint hintModeTable initnames light lightmodel linestipple linewidth loadidentity loadmatrix loadname lookat map1 map2 mapgrid1 mapgrid2 material matrixmode modeColorMatTable multmatrix newlist newListTable normal opStencilTable opStencilTable ortho perspective pickmatrix pixeltransfer pixelzoom pointsize polygonmode popattrib popmatrix popname pushattrib pushmatrix pushname rasterpos readbuffer readpixels rect rendermode rotate scale scissor selectbuffer shademodel stencilfunc stencilmask stencilop texcoord texenv texgen teximage1d teximage2d texparameter translate vertex viewport


List of special non OpenGL standard functions:

Code Block
getselection


List of supported OpenGL constants:

Code Block
accum accumbuffer accumbufferbit add alphatest always allattrib allattribbits ambient ambientanddiffuse autonormal aux0 aux1 aux2 aux3 back backleft backright blend bluebias bluescale ccw clamp clipplane0 clipplane1 clipplane2 clipplane3 clipplane4 clipplane5 colorbuffer colorbufferbit colorindex colormaterial compile compileandexecute constantattenuation cullface current currentbit cw decal decr depthbuffer depthbufferbit depthtest diffuse dither dstalpha dstcolor enable enablebit emission equal eval evalbit exp exp2 extensions eyelinear eyeplane feedback fill flat fog fogbit fogcolor fogdensity fogend fogmode fogstart front frontandback frontleft frontright gequal greater greenbias greenscale hint hintbit incr invert keep left lequal less light0 light1 light2 light3 light4 light5 light6 light7 lighting lightingbit lightmodelambient lightmodellocalviewer lightmodeltwoside line linebit linear linearattenuation lineloop lines linesmooth linestipple linestrip list listbit load map1color4 map1normal map1texturecoord1 map1texturecoord2 map1texturecoord3 map1texturecoord4 map1vertex3 map1vertex4 map2color4 map2normal map2texturecoord1 map2texturecoord2 map2texturecoord3 map2texturecoord4 map2vertex3 map2vertex4 modelview modulate mult nearest never none normalize notequal objectlinear objectplane one oneminusdstalpha oneminusdstcolor oneminussrcalpha oneminussrccolor packalignment packlsbfirst packrowlength packskippixels packskiprows packswapbytes pixelmode pixelmodebit point pointbit points polygon polygonbit polygonoffsetfill polygonstipple polygonstipplebit position projection q quadraticattenuation quads quadstrip r redbias redscale render renderer repeat replace return right s scissor scissorbit select shininess smooth specular spheremap spotcutoff spotdirecion spotexponent srcalpha srcalphasaturate srccolor stenciltest stencilbuffer stencilbufferbit t texture texture1d texture2d texturebit texturebordercolor textureenv textureenvcolor textureenvmode texturegenmode texturegens texturegent texturemagfilter textureminfilter texturewraps texturewrapt transform transformbit triangles trianglefan trianglestrip unpackalignment unpacklsbfirst unpackrowlength unpackskippixels unpackskiprows unpackswapbytes vendor version viewport viewportbit zero

...