GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
gsd_prim.c File Reference

OGSF library - primitive drawing functions (lower level functions) More...

#include <stdlib.h>
#include <string.h>
#include <grass/config.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glx.h>
#include <grass/gis.h>
#include <grass/ogsf.h>
#include <grass/glocale.h>
Include dependency graph for gsd_prim.c:

Go to the source code of this file.

Macros

#define USE_GL_NORMALIZE
 
#define RED_MASK   0x000000FF
 
#define GRN_MASK   0x0000FF00
 
#define BLU_MASK   0x00FF0000
 
#define ALP_MASK   0xFF000000
 
#define INT_TO_RED(i, r)   (r = (i & RED_MASK))
 
#define INT_TO_GRN(i, g)   (g = (i & GRN_MASK) >> 8)
 
#define INT_TO_BLU(i, b)   (b = (i & BLU_MASK) >> 16)
 
#define INT_TO_ALP(i, a)   (a = (i & ALP_MASK) >> 24)
 
#define MAX_OBJS   64
 
#define border   15
 

Functions

void gsd_flush (void)
 Mostly for flushing drawing commands across a network. More...
 
void gsd_colormode (int cm)
 Set color mode. More...
 
void show_colormode (void)
 Print color mode to stderr. More...
 
void gsd_circ (float x, float y, float rad)
 ADD. More...
 
void gsd_disc (float x, float y, float z, float rad)
 ADD. More...
 
void gsd_sphere (float *center, float siz)
 ADD. More...
 
void gsd_zwritemask (unsigned long n)
 Write out z-mask. More...
 
void gsd_backface (int n)
 ADD. More...
 
void gsd_linewidth (short n)
 Set width of rasterized lines. More...
 
void gsd_bgnqstrip (void)
 ADD. More...
 
void gsd_endqstrip (void)
 ADD. More...
 
void gsd_bgntmesh (void)
 ADD. More...
 
void gsd_endtmesh (void)
 ADD. More...
 
void gsd_bgntstrip (void)
 ADD. More...
 
void gsd_endtstrip (void)
 ADD. More...
 
void gsd_bgntfan (void)
 ADD. More...
 
void gsd_endtfan (void)
 ADD. More...
 
void gsd_swaptmesh (void)
 ADD. More...
 
void gsd_bgnpolygon (void)
 Delimit the vertices of a primitive or a group of like primitives. More...
 
void gsd_endpolygon (void)
 Delimit the vertices of a primitive or a group of like primitives. More...
 
void gsd_bgnline (void)
 Begin line. More...
 
void gsd_endline (void)
 End line. More...
 
void gsd_shademodel (int shade)
 Set shaded model. More...
 
int gsd_getshademodel (void)
 Get shaded model. More...
 
void gsd_bothbuffers (void)
 Draw to the front and back buffers. More...
 
void gsd_frontbuffer (void)
 Draw to the front buffer. More...
 
void gsd_backbuffer (void)
 Draw to the back buffer. More...
 
void gsd_swapbuffers (void)
 Swap buffers. More...
 
void gsd_popmatrix (void)
 Pop the current matrix stack. More...
 
void gsd_pushmatrix (void)
 Push the current matrix stack. More...
 
void gsd_scale (float xs, float ys, float zs)
 Multiply the current matrix by a general scaling matrix. More...
 
void gsd_translate (float dx, float dy, float dz)
 Multiply the current matrix by a translation matrix. More...
 
void gsd_getwindow (int *window, int *viewport, double *modelMatrix, double *projMatrix)
 Get viewport. More...
 
int gsd_checkpoint (float pt[4], int window[4], int viewport[4], double modelMatrix[16], double projMatrix[16])
 ADD. More...
 
void gsd_rot (float angle, char axis)
 ADD. More...
 
void gsd_litvert_func (float *norm, unsigned long col, float *pt)
 Set the current normal vector & specify vertex. More...
 
void gsd_litvert_func2 (float *norm, unsigned long col, float *pt)
 ADD. More...
 
void gsd_vert_func (float *pt)
 ADD. More...
 
void gsd_color_func (unsigned int col)
 Set current color. More...
 
void gsd_init_lightmodel (void)
 Initialize model light. More...
 
void gsd_set_material (int set_shin, int set_emis, float sh, float em, int emcolor)
 Set material. More...
 
void gsd_deflight (int num, struct lightdefs *vals)
 Define light. More...
 
void gsd_switchlight (int num, int on)
 Switch light on/off. More...
 
int gsd_getimage (unsigned char **pixbuf, unsigned int *xsize, unsigned int *ysize)
 Get image of current GL screen. More...
 
int gsd_getViewport (GLint tmp[4], GLint num[2])
 Get viewpoint. More...
 
int gsd_writeView (unsigned char **pixbuf, unsigned int xsize, unsigned int ysize)
 Write view. More...
 
void gsd_blend (int yesno)
 Specify pixel arithmetic. More...
 
void gsd_def_clipplane (int num, double *params)
 Define clip plane. More...
 
void gsd_set_clipplane (int num, int able)
 Set clip plane. More...
 
void gsd_finish (void)
 Finish. More...
 
void gsd_viewport (int l, int r, int b, int t)
 Set the viewport. More...
 
int gsd_makelist (void)
 ADD. More...
 
void gsd_bgnlist (int listno, int do_draw)
 ADD. More...
 
void gsd_endlist (void)
 End list. More...
 
void gsd_deletelist (GLuint listno, int range)
 Delete list. More...
 
void gsd_calllist (int listno)
 ADD. More...
 
void gsd_calllists (int listno)
 ADD. More...
 

Detailed Description

OGSF library - primitive drawing functions (lower level functions)

GRASS OpenGL gsurf OGSF Library

(C) 1999-2008, 2018 by the GRASS Development Team

This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.

Author
Bill Brown USACERL (January 1993)
Doxygenized by Martin Landa <landa.martin gmail.com> (May 2008)
Support for framebuffer objects by Huidae Cho <grass4u gmail.com> (July 2018)

Definition in file gsd_prim.c.

Macro Definition Documentation

◆ ALP_MASK

#define ALP_MASK   0xFF000000

Definition at line 50 of file gsd_prim.c.

◆ BLU_MASK

#define BLU_MASK   0x00FF0000

Definition at line 49 of file gsd_prim.c.

◆ border

#define border   15

Definition at line 61 of file gsd_prim.c.

◆ GRN_MASK

#define GRN_MASK   0x0000FF00

Definition at line 48 of file gsd_prim.c.

◆ INT_TO_ALP

#define INT_TO_ALP (   i,
 
)    (a = (i & ALP_MASK) >> 24)

Definition at line 55 of file gsd_prim.c.

◆ INT_TO_BLU

#define INT_TO_BLU (   i,
  b 
)    (b = (i & BLU_MASK) >> 16)

Definition at line 54 of file gsd_prim.c.

Referenced by GS_get_val_at_xy().

◆ INT_TO_GRN

#define INT_TO_GRN (   i,
  g 
)    (g = (i & GRN_MASK) >> 8)

Definition at line 53 of file gsd_prim.c.

Referenced by GS_get_val_at_xy().

◆ INT_TO_RED

#define INT_TO_RED (   i,
  r 
)    (r = (i & RED_MASK))

Definition at line 52 of file gsd_prim.c.

Referenced by GS_get_val_at_xy().

◆ MAX_OBJS

#define MAX_OBJS   64

Definition at line 57 of file gsd_prim.c.

Referenced by gsd_calllists(), and gsd_deletelist().

◆ RED_MASK

#define RED_MASK   0x000000FF

Definition at line 47 of file gsd_prim.c.

◆ USE_GL_NORMALIZE

#define USE_GL_NORMALIZE

Definition at line 45 of file gsd_prim.c.

Function Documentation

◆ gsd_backbuffer()

void gsd_backbuffer ( void  )

Draw to the back buffer.

Definition at line 469 of file gsd_prim.c.

◆ gsd_backface()

void gsd_backface ( int  n)

ADD.

Parameters
n

Definition at line 253 of file gsd_prim.c.

◆ gsd_bgnline()

◆ gsd_bgnlist()

void gsd_bgnlist ( int  listno,
int  do_draw 
)

ADD.

Parameters
listno
do_draw

Definition at line 1128 of file gsd_prim.c.

Referenced by gsd_put_legend().

◆ gsd_bgnpolygon()

void gsd_bgnpolygon ( void  )

Delimit the vertices of a primitive or a group of like primitives.

Definition at line 371 of file gsd_prim.c.

Referenced by gsd_box(), gsd_cube(), gsd_diamond(), gsd_north_arrow(), and gsd_scalebar().

◆ gsd_bgnqstrip()

void gsd_bgnqstrip ( void  )

ADD.

Definition at line 276 of file gsd_prim.c.

Referenced by gsd_fringe_horiz_poly(), and gsd_fringe_vert_poly().

◆ gsd_bgntfan()

void gsd_bgntfan ( void  )

ADD.

Definition at line 336 of file gsd_prim.c.

◆ gsd_bgntmesh()

void gsd_bgntmesh ( void  )

ADD.

Definition at line 296 of file gsd_prim.c.

Referenced by gsd_diamond().

◆ gsd_bgntstrip()

void gsd_bgntstrip ( void  )

ADD.

Definition at line 316 of file gsd_prim.c.

◆ gsd_blend()

void gsd_blend ( int  yesno)

Specify pixel arithmetic.

Parameters
yesnoturn on/off

Definition at line 996 of file gsd_prim.c.

◆ gsd_bothbuffers()

void gsd_bothbuffers ( void  )

Draw to the front and back buffers.

Definition at line 445 of file gsd_prim.c.

◆ gsd_calllist()

void gsd_calllist ( int  listno)

ADD.

Parameters
listno

Definition at line 1176 of file gsd_prim.c.

Referenced by GS_draw_list().

◆ gsd_calllists()

void gsd_calllists ( int  listno)

ADD.

Parameters
listno

Definition at line 1189 of file gsd_prim.c.

References gsd_pushmatrix(), and MAX_OBJS.

Referenced by GS_draw_all_list().

◆ gsd_checkpoint()

int gsd_checkpoint ( float  pt[4],
int  window[4],
int  viewport[4],
double  modelMatrix[16],
double  projMatrix[16] 
)

ADD.

Parameters
pt
widnow
viewport
doubleMatrix
projMatrix
Returns
0
1

Definition at line 585 of file gsd_prim.c.

◆ gsd_circ()

void gsd_circ ( float  x,
float  y,
float  rad 
)

ADD.

Parameters
x,y
rad

Definition at line 166 of file gsd_prim.c.

Referenced by gsd_draw_gyro().

◆ gsd_color_func()

void gsd_color_func ( unsigned int  col)

◆ gsd_colormode()

void gsd_colormode ( int  cm)

Set color mode.

Call glColorMaterial before enabling the GL_COLOR_MATERIAL

Parameters
cmcolor mode value

Definition at line 97 of file gsd_prim.c.

References CM_AD, CM_COLOR, CM_DIFFUSE, CM_EMISSION, and CM_NULL.

Referenced by gpd_obj(), gsd_bgn_legend_viewport(), gsd_display_fringe(), gsd_wire_arrows(), gsd_wire_surf_const(), gsd_wire_surf_map(), and gvld_wind3_box().

◆ gsd_def_clipplane()

void gsd_def_clipplane ( int  num,
double *  params 
)

Define clip plane.

Parameters
num
params

Definition at line 1016 of file gsd_prim.c.

◆ gsd_deflight()

void gsd_deflight ( int  num,
struct lightdefs vals 
)

Define light.

Parameters
numlight id (starts with 1)
valsposition(x,y,z,w), color, ambientm, emission

Definition at line 839 of file gsd_prim.c.

References MAX_LIGHTS.

◆ gsd_deletelist()

void gsd_deletelist ( GLuint  listno,
int  range 
)

Delete list.

Parameters
listno
range

Definition at line 1156 of file gsd_prim.c.

References MAX_OBJS.

Referenced by GS_delete_list().

◆ gsd_disc()

void gsd_disc ( float  x,
float  y,
float  z,
float  rad 
)

ADD.

Parameters
x,y,z
rad

Definition at line 186 of file gsd_prim.c.

◆ gsd_endline()

◆ gsd_endlist()

void gsd_endlist ( void  )

End list.

Definition at line 1143 of file gsd_prim.c.

◆ gsd_endpolygon()

void gsd_endpolygon ( void  )

Delimit the vertices of a primitive or a group of like primitives.

Definition at line 386 of file gsd_prim.c.

Referenced by gsd_box(), gsd_cube(), gsd_diamond(), gsd_north_arrow(), and gsd_scalebar().

◆ gsd_endqstrip()

void gsd_endqstrip ( void  )

ADD.

Definition at line 286 of file gsd_prim.c.

Referenced by gsd_fringe_horiz_poly(), and gsd_fringe_vert_poly().

◆ gsd_endtfan()

void gsd_endtfan ( void  )

ADD.

Definition at line 346 of file gsd_prim.c.

◆ gsd_endtmesh()

void gsd_endtmesh ( void  )

ADD.

Definition at line 306 of file gsd_prim.c.

Referenced by gsd_diamond().

◆ gsd_endtstrip()

void gsd_endtstrip ( void  )

ADD.

Definition at line 326 of file gsd_prim.c.

◆ gsd_finish()

void gsd_finish ( void  )

Finish.

Does nothing, only called from src.contrib/GMSL/NVIZ2.2/src/glwrappers.c

Definition at line 1061 of file gsd_prim.c.

◆ gsd_flush()

void gsd_flush ( void  )

Mostly for flushing drawing commands across a network.

glFlush doesn't block, so if blocking is desired use glFinish.

Definition at line 83 of file gsd_prim.c.

Referenced by GS_draw_X(), gsd_fringe_horiz_line(), gsd_fringe_horiz_line2(), gsd_fringe_horiz_poly(), gsd_fringe_vert_line(), gsd_fringe_vert_poly(), gsd_north_arrow(), gsd_scalebar(), and gsd_scalebar_v2().

◆ gsd_frontbuffer()

void gsd_frontbuffer ( void  )

Draw to the front buffer.

Definition at line 457 of file gsd_prim.c.

◆ gsd_getimage()

int gsd_getimage ( unsigned char **  pixbuf,
unsigned int *  xsize,
unsigned int *  ysize 
)

Get image of current GL screen.

Parameters
pixbufdata buffer
[out]xsize,ysizepicture dimension
Returns
0 on failure
1 on success

Definition at line 905 of file gsd_prim.c.

References b, l, r, and t.

Referenced by GS_write_ppm(), and GS_write_tif().

◆ gsd_getshademodel()

int gsd_getshademodel ( void  )

Get shaded model.

Returns
shade

Definition at line 437 of file gsd_prim.c.

Referenced by gsd_box(), gsd_cube(), and gsd_diamond().

◆ gsd_getViewport()

int gsd_getViewport ( GLint  tmp[4],
GLint  num[2] 
)

Get viewpoint.

Parameters
tmp
num
Returns
1

Definition at line 952 of file gsd_prim.c.

◆ gsd_getwindow()

void gsd_getwindow ( int *  window,
int *  viewport,
double *  modelMatrix,
double *  projMatrix 
)

Get viewport.

Parameters
[out]window
viewport
modelMatrixmodel matrix
projMatrixprojection matrix

Definition at line 553 of file gsd_prim.c.

◆ gsd_init_lightmodel()

void gsd_init_lightmodel ( void  )

Initialize model light.

Definition at line 722 of file gsd_prim.c.

Referenced by GS_new_light().

◆ gsd_linewidth()

void gsd_linewidth ( short  n)

Set width of rasterized lines.

Parameters
nline width

Definition at line 266 of file gsd_prim.c.

Referenced by GS_draw_X(), gsd_bgn_legend_viewport(), gsd_display_fringe(), and gsd_scalebar_v2().

◆ gsd_litvert_func()

void gsd_litvert_func ( float *  norm,
unsigned long  col,
float *  pt 
)

Set the current normal vector & specify vertex.

Parameters
normnormal vector
colcolor value
ptpoint (model coordinates)

Definition at line 660 of file gsd_prim.c.

Referenced by gsd_box(), gsd_cube(), and gsd_diamond().

◆ gsd_litvert_func2()

void gsd_litvert_func2 ( float *  norm,
unsigned long  col,
float *  pt 
)

ADD.

Parameters
norm
col
pt

Definition at line 676 of file gsd_prim.c.

◆ gsd_makelist()

int gsd_makelist ( void  )

ADD.

First time called, gets a bunch of objects, then hands them back when needed

Returns
-1 on failure
number of objects

Definition at line 1096 of file gsd_prim.c.

Referenced by gsd_put_legend().

◆ gsd_popmatrix()

◆ gsd_pushmatrix()

◆ gsd_rot()

void gsd_rot ( float  angle,
char  axis 
)

ADD.

Parameters
angle
axis

Definition at line 609 of file gsd_prim.c.

References _, G_warning(), and x.

Referenced by gsd_draw_asterisk(), and gsd_draw_gyro().

◆ gsd_scale()

void gsd_scale ( float  xs,
float  ys,
float  zs 
)

Multiply the current matrix by a general scaling matrix.

Parameters
xsx scale value
ysy scale value
zsz scale value

Definition at line 524 of file gsd_prim.c.

Referenced by gpd_obj(), gsd_box(), gsd_cube(), gsd_diamond(), gsd_do_scale(), gsd_draw_asterisk(), gsd_draw_box(), and gsd_draw_gyro().

◆ gsd_set_clipplane()

void gsd_set_clipplane ( int  num,
int  able 
)

Set clip plane.

Parameters
num
able

Definition at line 1043 of file gsd_prim.c.

Referenced by gsd_cplane_off().

◆ gsd_set_material()

void gsd_set_material ( int  set_shin,
int  set_emis,
float  sh,
float  em,
int  emcolor 
)

Set material.

Parameters
set_shin,set_emisflags
sh,emshould be 0. - 1.
emcolorpacked colors to use for emission

Definition at line 806 of file gsd_prim.c.

◆ gsd_shademodel()

void gsd_shademodel ( int  shade)

Set shaded model.

Parameters
shadenon-zero for GL_SMOOTH otherwise GL_FLAT

Definition at line 418 of file gsd_prim.c.

Referenced by GS_draw_surf(), gsd_box(), gsd_cube(), gsd_diamond(), and gvld_wind3_box().

◆ gsd_sphere()

void gsd_sphere ( float *  center,
float  siz 
)

ADD.

Parameters
centercenter-point
sizsize value

Definition at line 206 of file gsd_prim.c.

Referenced by gpd_obj(), and gsd_drawsphere().

◆ gsd_swapbuffers()

void gsd_swapbuffers ( void  )

Swap buffers.

Definition at line 481 of file gsd_prim.c.

◆ gsd_swaptmesh()

void gsd_swaptmesh ( void  )

ADD.

Definition at line 356 of file gsd_prim.c.

Referenced by gsd_diamond().

◆ gsd_switchlight()

void gsd_switchlight ( int  num,
int  on 
)

Switch light on/off.

Parameters
num
on1 for 'on', 0 turns them off

Definition at line 880 of file gsd_prim.c.

◆ gsd_translate()

void gsd_translate ( float  dx,
float  dy,
float  dz 
)

Multiply the current matrix by a translation matrix.

Parameters
dxx translation value
dyy translation value
dzz translation value

Definition at line 538 of file gsd_prim.c.

Referenced by GS_draw_X(), gsd_box(), gsd_cube(), gsd_diamond(), gsd_do_scale(), gsd_draw_asterisk(), gsd_draw_box(), gsd_draw_gyro(), gsd_fringe_horiz_line(), gsd_fringe_horiz_line2(), gsd_fringe_horiz_poly(), gsd_fringe_vert_line(), gsd_fringe_vert_poly(), gsd_wire_arrows(), gsd_wire_surf_const(), gsd_wire_surf_map(), and gvld_wind3_box().

◆ gsd_vert_func()

◆ gsd_viewport()

void gsd_viewport ( int  l,
int  r,
int  b,
int  t 
)

Set the viewport.

l, b specify the lower left corner of the viewport rectangle, in pixels.

r, t specify the width and height of the viewport.

Parameters
lleft
rright
bbottom
ttop

Definition at line 1079 of file gsd_prim.c.

Referenced by GS_set_viewport().

◆ gsd_writeView()

int gsd_writeView ( unsigned char **  pixbuf,
unsigned int  xsize,
unsigned int  ysize 
)

Write view.

Parameters
pixbufdata buffer
xsize,ysizepicture dimension
Returns
0 on failure
1 on success

Definition at line 971 of file gsd_prim.c.

References G_malloc.

Referenced by GS_write_zoom().

◆ gsd_zwritemask()

void gsd_zwritemask ( unsigned long  n)

Write out z-mask.

Enable or disable writing into the depth buffer

Parameters
nSpecifies whether the depth buffer is enabled for writing

Definition at line 240 of file gsd_prim.c.

Referenced by gsd_display_fringe().

◆ show_colormode()

void show_colormode ( void  )

Print color mode to stderr.

Definition at line 150 of file gsd_prim.c.

References _, and G_message().