26 #if defined(OPENGL_X11)
30 #elif defined(OPENGL_AQUA)
31 #include <OpenGL/gl.h>
32 #include <OpenGL/glu.h>
33 #if defined(OPENGL_AGL)
36 #elif defined(OPENGL_WINDOWS)
46 #define USE_GL_NORMALIZE
48 #define RED_MASK 0x000000FF
49 #define GRN_MASK 0x0000FF00
50 #define BLU_MASK 0x00FF0000
51 #define ALP_MASK 0xFF000000
53 #define INT_TO_RED(i, r) (r = (i & RED_MASK))
54 #define INT_TO_GRN(i, g) (g = (i & GRN_MASK) >> 8)
55 #define INT_TO_BLU(i, b) (b = (i & BLU_MASK) >> 16)
56 #define INT_TO_ALP(i, a) (a = (i & ALP_MASK) >> 24)
65 static int numobjs = 0;
73 static float ogl_mat_amb[4];
74 static float ogl_mat_diff[4];
75 static float ogl_mat_spec[4];
76 static float ogl_mat_emis[4];
77 static float ogl_mat_shin;
103 glDisable(GL_COLOR_MATERIAL);
104 glDisable(GL_LIGHTING);
109 glColorMaterial(GL_FRONT_AND_BACK, GL_EMISSION);
110 glEnable(GL_COLOR_MATERIAL);
111 glEnable(GL_LIGHTING);
116 glColorMaterial(GL_FRONT, GL_DIFFUSE);
117 glEnable(GL_COLOR_MATERIAL);
118 glEnable(GL_LIGHTING);
123 glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
124 glEnable(GL_COLOR_MATERIAL);
125 glEnable(GL_LIGHTING);
135 glDisable(GL_COLOR_MATERIAL);
136 glEnable(GL_LIGHTING);
141 glDisable(GL_COLOR_MATERIAL);
155 glGetIntegerv(GL_COLOR_MATERIAL_PARAMETER, &mat);
169 GLUquadricObj *qobj = gluNewQuadric();
171 gluQuadricDrawStyle(qobj, GLU_SILHOUETTE);
173 glTranslatef(
x, y, 0.);
174 gluDisk(qobj, 0., rad, 32, 1);
176 gluDeleteQuadric(qobj);
189 GLUquadricObj *qobj = gluNewQuadric();
191 gluQuadricDrawStyle(qobj, GLU_FILL);
193 glTranslatef(
x, y, z);
194 gluDisk(qobj, 0., rad, 32, 1);
196 gluDeleteQuadric(qobj);
209 static int first = 1;
210 static GLUquadricObj *QOsphere;
213 QOsphere = gluNewQuadric();
216 gluQuadricNormals(QOsphere, GLU_SMOOTH);
217 gluQuadricTexture(QOsphere, GL_FALSE);
218 gluQuadricOrientation(QOsphere, GLU_OUTSIDE);
219 gluQuadricDrawStyle(QOsphere, GLU_FILL);
226 glTranslatef(center[0], center[1], center[2]);
227 gluSphere(QOsphere, (
double)siz, 24, 24);
244 glDepthMask((GLboolean)(n));
257 (n) ? glEnable(GL_CULL_FACE) : glDisable(GL_CULL_FACE);
269 glLineWidth((GLfloat)(n));
279 glBegin(GL_QUAD_STRIP);
299 glBegin(GL_TRIANGLE_STRIP);
319 glBegin(GL_TRIANGLE_STRIP);
339 glBegin(GL_TRIANGLE_FAN);
400 glBegin(GL_LINE_STRIP);
424 glShadeModel(GL_SMOOTH);
427 glShadeModel(GL_FLAT);
448 #if !defined(OPENGL_FBO)
450 glDrawBuffer(GL_FRONT_AND_BACK);
460 #if !defined(OPENGL_FBO)
462 glDrawBuffer(GL_FRONT);
472 #if !defined(OPENGL_FBO)
474 glDrawBuffer(GL_BACK);
484 #if !defined(OPENGL_FBO)
487 #if defined(OPENGL_X11)
488 glXSwapBuffers(glXGetCurrentDisplay(), glXGetCurrentDrawable());
489 #elif defined(OPENGL_AQUA)
490 aglSwapBuffers(aglGetCurrentContext());
491 #elif defined(OPENGL_WINDOWS)
492 SwapBuffers(wglGetCurrentDC());
527 glScalef(xs, ys, zs);
541 glTranslatef(dx, dy, dz);
560 glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix);
561 glGetDoublev(GL_PROJECTION_MATRIX, projMatrix);
562 glGetIntegerv(GL_VIEWPORT, viewport);
565 window[0] = viewport[1] + viewport[3] +
border;
566 window[1] = viewport[1] -
border;
567 window[2] = viewport[0] -
border;
568 window[3] = viewport[0] + viewport[2] +
border;
586 double modelMatrix[16],
double projMatrix[16])
590 gluProject((GLdouble)pt[
X], (GLdouble)pt[
Y], (GLdouble)pt[
Z], modelMatrix,
591 projMatrix, viewport, &fx, &fy, &fz);
593 if (fx < window[2] || fx > window[3] || fy < window[1] || fy > window[0])
638 G_warning(
_(
"gsd_rot(): %c is an invalid axis "
639 "specification. Rotation ignored. "
640 "Please advise GRASS developers of this error"),
645 glRotatef((GLfloat)angle,
x, y, z);
711 glColor4ub(
r,
g,
b, a);
722 glEnable(GL_LIGHTING);
725 #ifdef USE_GL_NORMALIZE
727 glEnable(GL_NORMALIZE);
740 ogl_mat_amb[0] = 0.1;
741 ogl_mat_amb[1] = 0.1;
742 ogl_mat_amb[2] = 0.1;
743 ogl_mat_amb[3] = 1.0;
745 ogl_mat_diff[0] = 0.8;
746 ogl_mat_diff[1] = 0.8;
747 ogl_mat_diff[2] = 0.8;
748 ogl_mat_diff[3] = 0.8;
750 ogl_mat_spec[0] = 0.8;
751 ogl_mat_spec[1] = 0.8;
752 ogl_mat_spec[2] = 0.8;
753 ogl_mat_spec[3] = 0.8;
755 ogl_mat_emis[0] = 0.0;
756 ogl_mat_emis[1] = 0.0;
757 ogl_mat_emis[2] = 0.0;
758 ogl_mat_emis[3] = 0.0;
778 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ogl_mat_amb);
779 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, ogl_mat_diff);
780 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, ogl_mat_spec);
781 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, ogl_mat_emis);
782 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, ogl_mat_shin);
807 ogl_mat_spec[0] = sh;
808 ogl_mat_spec[1] = sh;
809 ogl_mat_spec[2] = sh;
810 ogl_mat_spec[3] = sh;
812 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, ogl_mat_spec);
814 ogl_mat_shin = 60. + (int)(sh * 68.);
816 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, ogl_mat_shin);
820 ogl_mat_emis[0] = (em * (emcolor & 0x0000FF)) / 255.;
821 ogl_mat_emis[1] = (em * ((emcolor & 0x00FF00) >> 8)) / 255.;
822 ogl_mat_emis[2] = (em * ((emcolor & 0xFF0000) >> 16)) / 255.;
824 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, ogl_mat_emis);
839 ogl_light_pos[num - 1][0] = vals->
position[
X];
840 ogl_light_pos[num - 1][1] = vals->
position[
Y];
841 ogl_light_pos[num - 1][2] = vals->
position[
Z];
842 ogl_light_pos[num - 1][3] = vals->
position[
W];
844 glLightfv(GL_LIGHT0 + num, GL_POSITION, ogl_light_pos[num - 1]);
846 ogl_light_diff[num - 1][0] = vals->
color[0];
847 ogl_light_diff[num - 1][1] = vals->
color[1];
848 ogl_light_diff[num - 1][2] = vals->
color[2];
849 ogl_light_diff[num - 1][3] = .3;
851 glLightfv(GL_LIGHT0 + num, GL_DIFFUSE, ogl_light_diff[num - 1]);
853 ogl_light_amb[num - 1][0] = vals->
ambient[0];
854 ogl_light_amb[num - 1][1] = vals->
ambient[1];
855 ogl_light_amb[num - 1][2] = vals->
ambient[2];
856 ogl_light_amb[num - 1][3] = .3;
858 glLightfv(GL_LIGHT0 + num, GL_AMBIENT, ogl_light_amb[num - 1]);
860 ogl_light_spec[num - 1][0] = vals->
color[0];
861 ogl_light_spec[num - 1][1] = vals->
color[1];
862 ogl_light_spec[num - 1][2] = vals->
color[2];
863 ogl_light_spec[num - 1][3] = .3;
865 glLightfv(GL_LIGHT0 + num, GL_SPECULAR, ogl_light_spec[num - 1]);
881 defin = on ? num : 0;
884 glEnable(GL_LIGHT0 + num);
887 glDisable(GL_LIGHT0 + num);
913 glGetIntegerv(GL_VIEWPORT, tmp);
915 r = tmp[0] + tmp[2] - 1;
917 t = tmp[1] + tmp[3] - 1;
922 if (!*xsize || !*ysize)
926 (
unsigned char *)
G_malloc((*xsize) * (*ysize) * 4);
931 #if !defined(OPENGL_FBO)
932 glReadBuffer(GL_FRONT);
936 glReadPixels(
l,
b, (
r) - (
l) + 1, (
t) - (
b) + 1, GL_RGBA, GL_UNSIGNED_BYTE,
954 glGetIntegerv(GL_VIEWPORT, tmp);
955 glGetIntegerv(GL_MAX_VIEWPORT_DIMS, num);
974 *pixbuf = (
unsigned char *)
G_malloc(xsize * ysize * 4);
979 #if !defined(OPENGL_FBO)
981 glReadBuffer(GL_FRONT);
985 glReadPixels(0, 0, xsize, ysize, GL_RGBA, GL_UNSIGNED_BYTE, *pixbuf);
998 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1001 glDisable(GL_BLEND);
1002 glBlendFunc(GL_ONE, GL_ZERO);
1019 if (glIsEnabled(GL_CLIP_PLANE0 + (num))) {
1023 glClipPlane(GL_CLIP_PLANE0 + (num), params);
1026 glEnable(GL_CLIP_PLANE0 + (num));
1029 glDisable(GL_CLIP_PLANE0 + (num));
1045 glEnable(GL_CLIP_PLANE0 + (num));
1048 glDisable(GL_CLIP_PLANE0 + (num));
1080 glViewport(
l,
b,
r,
t);
1111 ObjList[i] = ObjList[0] + i;
1128 glNewList(ObjList[listno], GL_COMPILE_AND_EXECUTE);
1131 glNewList(ObjList[listno], GL_COMPILE);
1159 glDeleteLists(ObjList[i], 1);
1175 glCallList(ObjList[listno]);
1191 glCallList(ObjList[i]);
void G_warning(const char *,...) __attribute__((format(printf
void G_message(const char *,...) __attribute__((format(printf
void gsd_do_scale(int)
Set current scale.
void gsd_call_label(void)
Call display list and draw defined labels – called from gsd_prim (gsd_call_lists)
#define UNUSED
A macro for an attribute, if attached to a variable, indicating that the variable is not used.
void gsd_set_clipplane(int num, int able)
Set clip plane.
void gsd_endlist(void)
End list.
void gsd_viewport(int l, int r, int b, int t)
Set the viewport.
void gsd_endtstrip(void)
ADD.
void gsd_endtfan(void)
ADD.
void gsd_endtmesh(void)
ADD.
void gsd_swaptmesh(void)
ADD.
void gsd_backface(int n)
ADD.
void gsd_pushmatrix(void)
Push the current matrix stack.
void gsd_litvert_func2(float *norm, unsigned long col UNUSED, float *pt)
ADD.
int gsd_getViewport(GLint tmp[4], GLint num[2])
Get viewpoint.
void gsd_calllist(int listno)
ADD.
void gsd_zwritemask(unsigned long n)
Write out z-mask.
void gsd_deflight(int num, struct lightdefs *vals)
Define light.
void gsd_vert_func(float *pt)
ADD.
void gsd_bgnqstrip(void)
ADD.
void gsd_switchlight(int num, int on)
Switch light on/off.
void gsd_litvert_func(float *norm, unsigned long col, float *pt)
Set the current normal vector & specify vertex.
void gsd_colormode(int cm)
Set color mode.
void gsd_bgnpolygon(void)
Delimit the vertices of a primitive or a group of like primitives.
void gsd_calllists(int listno UNUSED)
ADD.
int gsd_writeView(unsigned char **pixbuf, unsigned int xsize, unsigned int ysize)
Write view.
void gsd_bgntstrip(void)
ADD.
void gsd_blend(int yesno)
Specify pixel arithmetic.
void gsd_init_lightmodel(void)
Initialize model light.
int gsd_getshademodel(void)
Get shaded model.
void gsd_bgnlist(int listno, int do_draw)
ADD.
int gsd_makelist(void)
ADD.
void gsd_swapbuffers(void)
Swap buffers.
void gsd_endqstrip(void)
ADD.
void gsd_sphere(float *center, float siz)
ADD.
void show_colormode(void)
Print color mode to stderr.
int gsd_getimage(unsigned char **pixbuf, unsigned int *xsize, unsigned int *ysize)
Get image of current GL screen.
void gsd_backbuffer(void)
Draw to the back buffer.
void gsd_popmatrix(void)
Pop the current matrix stack.
void gsd_flush(void)
Mostly for flushing drawing commands across a network.
void gsd_def_clipplane(int num, double *params)
Define clip plane.
void gsd_endline(void)
End line.
void gsd_finish(void)
Finish.
void gsd_circ(float x, float y, float rad)
ADD.
void gsd_bgntfan(void)
ADD.
int gsd_checkpoint(float pt[4], int window[4], int viewport[4], double modelMatrix[16], double projMatrix[16])
ADD.
void gsd_rot(float angle, char axis)
ADD.
void gsd_bgnline(void)
Begin line.
void gsd_scale(float xs, float ys, float zs)
Multiply the current matrix by a general scaling matrix.
void gsd_deletelist(GLuint listno, int range UNUSED)
Delete list.
void gsd_translate(float dx, float dy, float dz)
Multiply the current matrix by a translation matrix.
void gsd_bgntmesh(void)
ADD.
void gsd_disc(float x, float y, float z, float rad)
ADD.
void gsd_getwindow(int *window, int *viewport, double *modelMatrix, double *projMatrix)
Get viewport.
void gsd_color_func(unsigned int col)
Set current color.
void gsd_shademodel(int shade)
Set shaded model.
void gsd_bothbuffers(void)
Draw to the front and back buffers.
void gsd_frontbuffer(void)
Draw to the front buffer.
void gsd_endpolygon(void)
Delimit the vertices of a primitive or a group of like primitives.
void gsd_linewidth(short n)
Set width of rasterized lines.
void gsd_set_material(int set_shin, int set_emis, float sh, float em, int emcolor)
Set material.