22 #include <grass/config.h>
24 #if defined(OPENGL_X11) || defined(OPENGL_WINDOWS)
27 #elif defined(OPENGL_AQUA)
28 #include <OpenGL/gl.h>
29 #include <OpenGL/glu.h>
32 #include <grass/gis.h>
33 #include <grass/gstypes.h>
34 #include <grass/glocale.h>
36 #define USE_GL_NORMALIZE
38 #define RED_MASK 0x000000FF
39 #define GRN_MASK 0x0000FF00
40 #define BLU_MASK 0x00FF0000
41 #define ALP_MASK 0xFF000000
43 #define INT_TO_RED(i, r) (r = (i & RED_MASK))
44 #define INT_TO_GRN(i, g) (g = (i & GRN_MASK) >> 8)
45 #define INT_TO_BLU(i, b) (b = (i & BLU_MASK) >> 16)
46 #define INT_TO_ALP(i, a) (a = (i & ALP_MASK) >> 24)
55 static int numobjs = 0;
59 static float ogl_light_amb[MAX_LIGHTS][4];
60 static float ogl_light_diff[MAX_LIGHTS][4];
61 static float ogl_light_spec[MAX_LIGHTS][4];
62 static float ogl_light_pos[MAX_LIGHTS][4];
63 static float ogl_mat_amb[4];
64 static float ogl_mat_diff[4];
65 static float ogl_mat_spec[4];
66 static float ogl_mat_emis[4];
67 static float ogl_mat_shin;
93 glDisable(GL_COLOR_MATERIAL);
94 glDisable(GL_LIGHTING);
99 glColorMaterial(GL_FRONT_AND_BACK, GL_EMISSION);
100 glEnable(GL_COLOR_MATERIAL);
101 glEnable(GL_LIGHTING);
106 glColorMaterial(GL_FRONT, GL_DIFFUSE);
107 glEnable(GL_COLOR_MATERIAL);
108 glEnable(GL_LIGHTING);
113 glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
114 glEnable(GL_COLOR_MATERIAL);
115 glEnable(GL_LIGHTING);
125 glDisable(GL_COLOR_MATERIAL);
126 glEnable(GL_LIGHTING);
131 glDisable(GL_COLOR_MATERIAL);
145 glGetIntegerv(GL_COLOR_MATERIAL_PARAMETER, &mat);
159 GLUquadricObj *qobj = gluNewQuadric();
161 gluQuadricDrawStyle(qobj, GLU_SILHOUETTE);
163 glTranslatef(x, y, 0.);
164 gluDisk(qobj, 0., rad, 32, 1);
166 gluDeleteQuadric(qobj);
179 GLUquadricObj *qobj = gluNewQuadric();
181 gluQuadricDrawStyle(qobj, GLU_FILL);
183 glTranslatef(x, y, z);
184 gluDisk(qobj, 0., rad, 32, 1);
186 gluDeleteQuadric(qobj);
199 static int first = 1;
200 static GLUquadricObj *QOsphere;
203 QOsphere = gluNewQuadric();
206 gluQuadricNormals(QOsphere, GLU_SMOOTH);
207 gluQuadricTexture(QOsphere, GL_FALSE);
208 gluQuadricOrientation(QOsphere, GLU_OUTSIDE);
209 gluQuadricDrawStyle(QOsphere, GLU_FILL);
216 glTranslatef(center[0], center[1], center[2]);
217 gluSphere(QOsphere, (
double)siz, 24, 24);
234 glDepthMask((GLboolean) (n));
247 (
n) ? glEnable(GL_CULL_FACE) : glDisable(GL_CULL_FACE);
259 glLineWidth((GLfloat) (n));
269 glBegin(GL_QUAD_STRIP);
289 glBegin(GL_TRIANGLE_STRIP);
309 glBegin(GL_TRIANGLE_STRIP);
329 glBegin(GL_TRIANGLE_FAN);
390 glBegin(GL_LINE_STRIP);
414 glShadeModel(GL_SMOOTH);
417 glShadeModel(GL_FLAT);
439 glDrawBuffer(GL_FRONT_AND_BACK);
453 glDrawBuffer((
bool) ? GL_FRONT : GL_BACK);
467 glDrawBuffer((
bool) ? GL_BACK : GL_FRONT);
514 glScalef(xs, ys, zs);
528 glTranslatef(dx, dy, dz);
547 glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix);
548 glGetDoublev(GL_PROJECTION_MATRIX, projMatrix);
549 glGetIntegerv(GL_VIEWPORT, viewport);
552 window[0] = viewport[1] + viewport[3] +
border;
553 window[1] = viewport[1] -
border;
554 window[2] = viewport[0] -
border;
555 window[3] = viewport[0] + viewport[2] +
border;
576 double modelMatrix[16],
double projMatrix[16])
580 gluProject((GLdouble) pt[
X], (GLdouble) pt[
Y], (GLdouble) pt[Z],
581 modelMatrix, projMatrix, viewport, &fx, &fy, &fz);
583 if (fx < window[2] || fx > window[3]
584 || fy < window[1] || fy > window[0])
630 G_warning(_(
"gsd_rot(): %c is an invalid axis "
631 "specification. Rotation ignored. "
632 "Please advise GRASS developers of this error"), axis);
636 glRotatef((GLfloat) angle, x, y, z);
702 glColor4ub(r, g, b, a);
713 glEnable(GL_LIGHTING);
716 #ifdef USE_GL_NORMALIZE
718 glEnable(GL_NORMALIZE);
731 ogl_mat_amb[0] = 0.1;
732 ogl_mat_amb[1] = 0.1;
733 ogl_mat_amb[2] = 0.1;
734 ogl_mat_amb[3] = 1.0;
736 ogl_mat_diff[0] = 0.8;
737 ogl_mat_diff[1] = 0.8;
738 ogl_mat_diff[2] = 0.8;
739 ogl_mat_diff[3] = 0.8;
741 ogl_mat_spec[0] = 0.8;
742 ogl_mat_spec[1] = 0.8;
743 ogl_mat_spec[2] = 0.8;
744 ogl_mat_spec[3] = 0.8;
746 ogl_mat_emis[0] = 0.0;
747 ogl_mat_emis[1] = 0.0;
748 ogl_mat_emis[2] = 0.0;
749 ogl_mat_emis[3] = 0.0;
769 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ogl_mat_amb);
770 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, ogl_mat_diff);
771 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, ogl_mat_spec);
772 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, ogl_mat_emis);
773 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, ogl_mat_shin);
798 ogl_mat_spec[0] = sh;
799 ogl_mat_spec[1] = sh;
800 ogl_mat_spec[2] = sh;
801 ogl_mat_spec[3] = sh;
803 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, ogl_mat_spec);
805 ogl_mat_shin = 60. + (
int)(sh * 68.);
807 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, ogl_mat_shin);
811 ogl_mat_emis[0] = (em * (emcolor & 0x0000FF)) / 255.;
812 ogl_mat_emis[1] = (em * ((emcolor & 0x00FF00) >> 8)) / 255.;
813 ogl_mat_emis[2] = (em * ((emcolor & 0xFF0000) >> 16)) / 255.;
815 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, ogl_mat_emis);
829 if (num > 0 && num <= MAX_LIGHTS) {
830 ogl_light_pos[num - 1][0] = vals->position[
X];
831 ogl_light_pos[num - 1][1] = vals->position[
Y];
832 ogl_light_pos[num - 1][2] = vals->position[Z];
833 ogl_light_pos[num - 1][3] = vals->position[W];
835 glLightfv(GL_LIGHT0 + num, GL_POSITION, ogl_light_pos[num - 1]);
837 ogl_light_diff[num - 1][0] = vals->color[0];
838 ogl_light_diff[num - 1][1] = vals->color[1];
839 ogl_light_diff[num - 1][2] = vals->color[2];
840 ogl_light_diff[num - 1][3] = .3;
842 glLightfv(GL_LIGHT0 + num, GL_DIFFUSE, ogl_light_diff[num - 1]);
844 ogl_light_amb[num - 1][0] = vals->ambient[0];
845 ogl_light_amb[num - 1][1] = vals->ambient[1];
846 ogl_light_amb[num - 1][2] = vals->ambient[2];
847 ogl_light_amb[num - 1][3] = .3;
849 glLightfv(GL_LIGHT0 + num, GL_AMBIENT, ogl_light_amb[num - 1]);
851 ogl_light_spec[num - 1][0] = vals->color[0];
852 ogl_light_spec[num - 1][1] = vals->color[1];
853 ogl_light_spec[num - 1][2] = vals->color[2];
854 ogl_light_spec[num - 1][3] = .3;
856 glLightfv(GL_LIGHT0 + num, GL_SPECULAR, ogl_light_spec[num - 1]);
872 defin = on ? num : 0;
875 glEnable(GL_LIGHT0 + num);
878 glDisable(GL_LIGHT0 + num);
904 glGetIntegerv(GL_VIEWPORT, tmp);
906 r = tmp[0] + tmp[2] - 1;
908 t = tmp[1] + tmp[3] - 1;
913 *pixbuf = (
unsigned char *)G_malloc((*xsize) * (*ysize) * 4);
918 glReadBuffer(GL_FRONT);
921 glReadPixels(l, b, (r) - (l) + 1, (t) - (b) + 1, GL_RGBA,
922 GL_UNSIGNED_BYTE, *pixbuf);
939 glGetIntegerv(GL_VIEWPORT, tmp);
940 glGetIntegerv(GL_MAX_VIEWPORT_DIMS, num);
956 *pixbuf = (
unsigned char *)G_malloc(xsize * ysize * 4);
962 glReadBuffer(GL_FRONT);
965 glReadPixels(0, 0, xsize, ysize, GL_RGBA, GL_UNSIGNED_BYTE, *pixbuf);
978 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
982 glBlendFunc(GL_ONE, GL_ZERO);
999 if (glIsEnabled(GL_CLIP_PLANE0 + (num))) {
1003 glClipPlane(GL_CLIP_PLANE0 + (num), params);
1006 glEnable(GL_CLIP_PLANE0 + (num));
1009 glDisable(GL_CLIP_PLANE0 + (num));
1025 glEnable(GL_CLIP_PLANE0 + (num));
1028 glDisable(GL_CLIP_PLANE0 + (num));
1060 glViewport(l, b, r, t);
1091 ObjList[i] = ObjList[0] + i;
1109 glNewList(ObjList[listno], GL_COMPILE_AND_EXECUTE);
1112 glNewList(ObjList[listno], GL_COMPILE);
1140 glDeleteLists(ObjList[i], 1);
1156 glCallList(ObjList[listno]);
1173 glCallList(ObjList[i]);
void gsd_zwritemask(unsigned long n)
Write out z-mask.
void gsd_endtstrip(void)
ADD.
void gsd_calllist(int listno)
ADD.
void gsd_endlist(void)
End list.
void gsd_endqstrip(void)
ADD.
void gsd_bgntmesh(void)
ADD.
void gsd_circ(float x, float y, float rad)
ADD.
void gsd_def_clipplane(int num, double *params)
Define clip plane.
void gsd_do_scale(int doexag)
Set current scale.
void gsd_sphere(float *center, float siz)
ADD.
int gsd_makelist(void)
ADD.
void gsd_bgnpolygon(void)
Delimit the vertices of a primitive or a group of like primitives.
void gsd_set_material(int set_shin, int set_emis, float sh, float em, int emcolor)
Set material.
void gsd_colormode(int cm)
Set color mode.
void gsd_color_func(unsigned int col)
Set current color.
void gsd_endtmesh(void)
ADD.
void gsd_translate(float dx, float dy, float dz)
Multiply the current matrix by a translation matrix.
void gsd_finish(void)
Finish.
void gsd_litvert_func(float *norm, unsigned long col, float *pt)
Set the current normal vector & specify vertex.
void gsd_shademodel(int bool)
Set shaded model.
void gsd_call_label(void)
Call display list and draw defined labels – called from gsd_prim (gsd_call_lists) ...
void gsd_swaptmesh(void)
ADD.
void gsd_bgntfan(void)
ADD.
void gsd_pushmatrix(void)
Push the current matrix stack.
void gsd_bgnqstrip(void)
ADD.
void gsd_backface(int n)
ADD.
void gsd_bgnlist(int listno, int do_draw)
ADD.
void gsd_backbuffer(int bool)
Specify which color buffers are to be drawn into.
void gsd_endline(void)
End line.
void G_message(const char *msg,...)
Print a message to stderr.
void gsd_switchlight(int num, int on)
Switch light on/off.
void gsd_endtfan(void)
ADD.
int gsd_checkpoint(float pt[4], int window[4], int viewport[4], double modelMatrix[16], double projMatrix[16])
ADD.
void gsd_getwindow(int *window, int *viewport, double *modelMatrix, double *projMatrix)
Get viewport.
void gsd_deletelist(GLuint listno, int range)
Delete list.
void gsd_disc(float x, float y, float z, float rad)
ADD.
void gsd_rot(float angle, char axis)
ADD.
void gsd_swapbuffers(void)
Swap buffers.
void gsd_blend(int yesno)
Specify pixel arithmetic.
void gsd_litvert_func2(float *norm, unsigned long col, float *pt)
ADD.
void gsd_frontbuffer(int bool)
Specify which color buffers are to be drawn into.
void gsd_vert_func(float *pt)
ADD.
void gsd_viewport(int l, int r, int b, int t)
Set the viewport.
void gsd_init_lightmodel(void)
Initialize model light.
void gsd_endpolygon(void)
Delimit the vertices of a primitive or a group of like primitives.
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
void show_colormode(void)
Print color mode to stderr.
void gsd_bgntstrip(void)
ADD.
void gsd_linewidth(short n)
Set width of rasterized lines.
void gsd_bothbuffer(void)
ADD.
void gsd_flush(void)
Mostly for flushing drawing commands accross a network.
int gsd_getimage(unsigned char **pixbuf, unsigned int *xsize, unsigned int *ysize)
Get image of current GL screen.
int gsd_getViewport(GLint *, GLint *)
void gsd_popmatrix(void)
Pop the current matrix stack.
int gsd_getshademodel(void)
Get shaded model.
int gsd_writeView(unsigned char **pixbuf, unsigned int xsize, unsigned int ysize)
Write view.
void gsd_deflight(int num, struct lightdefs *vals)
Define light.
void gsd_scale(float xs, float ys, float zs)
Multiply the current matrix by a general scaling matrix.
void gsd_bgnline(void)
Begin line.
void gsd_calllists(int listno)
ADD.
void gsd_set_clipplane(int num, int able)
Set clip plane.