source: GTP/trunk/Lib/Vis/Preprocessing/src/mixkit/MxGLUtils.cxx @ 1097

Revision 1097, 3.3 KB checked in by mattausch, 18 years ago (diff)
Line 
1/************************************************************************
2
3  MxGLUtils
4
5  Copyright (C) 1998 Michael Garland.  See "COPYING.txt" for details.
6 
7  $Id: MxGLUtils.cxx,v 1.1 2002/09/24 16:53:54 wimmer Exp $
8
9 ************************************************************************/
10
11#include "stdmix.h"
12#include "MxGLUtils.h"
13
14
15void mxgl_default_texinit(MxRaster *tex, bool will_draw_texture)
16{
17    if( tex )
18    {
19        if( will_draw_texture ) glEnable(GL_TEXTURE_2D);
20        // glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
21        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
22        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
23        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
24//         glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
25//         glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
26        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
27        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
28
29        glTexImage(tex);
30        // gluMipmaps(tex);
31    }
32}
33
34void mxgl_default_init()
35{
36    glEnable(GL_DEPTH_TEST);
37    glEnable(GL_LIGHTING);
38    glEnable(GL_NORMALIZE);
39    glShadeModel(GL_SMOOTH);
40
41    glMatrixMode(GL_PROJECTION);
42    glLoadIdentity();
43    glMatrixMode(GL_MODELVIEW);
44
45    GLfloat mat_ambient[] = { 0.1f, 0.1f, 0.1f, 1.0f };
46    GLfloat mat_diffuse[] = { 0.5f, 0.5f, 0.5f, 1.0f };
47    GLfloat mat_specular[] = { 0.1f, 0.1f, 0.1f, 1.0f };
48    glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient);
49    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse);
50    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
51    glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, 40);
52
53    GLfloat light_pos[] = {0.0f, 0.0f, 1.0f, 0.0f};
54    glLightfv(GL_LIGHT0, GL_POSITION, light_pos);
55    glEnable(GL_LIGHT0);
56
57    glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
58    glEnable(GL_COLOR_MATERIAL);
59    glColor3f(0.5f, 0.5f, 0.5f);
60    glClearColor(0.3f, 0.3f, 1.0f, 0.0f);
61
62    CAREFUL(mxgl_check_errors("at end of mxgl_default_init()"));
63}
64
65
66GLenum mxgl_matrix_for_mode(GLenum mode)
67{
68    switch( mode )
69    {
70    case GL_MODELVIEW:  return GL_MODELVIEW_MATRIX;
71    case GL_PROJECTION: return GL_PROJECTION_MATRIX;
72    case GL_TEXTURE:    return GL_TEXTURE_MATRIX;
73    }
74
75    return GL_FALSE;
76}
77
78#define pick_zmax MXID_NIL
79
80
81MxGLPicker::MxGLPicker(int x, int y, double window)
82    : buffer(128)
83{
84    GLint vp[4];
85
86    glMatrixMode(GL_PROJECTION);
87    glGetIntegerv(GL_VIEWPORT, vp);
88    glSelectBuffer(128, buffer);
89    glRenderMode(GL_SELECT);
90
91    gluPickMatrix(x, vp[3] - y, window, window, vp);
92    glInitNames();
93    glPushName(MXID_NIL);
94}
95
96uint MxGLPicker::complete()
97{
98    glFlush();
99
100    GLint nhits = glRenderMode(GL_RENDER);
101    GLuint hit = MXID_NIL;
102    GLuint zmin = pick_zmax;
103    GLuint *ptr = buffer;
104
105    for(uint i=0; i<nhits; i++)
106    {
107        GLuint nnames = *ptr++;
108        assert( nnames==1 ); // assume name stack is always 1 deep
109
110        GLuint cur_zmin = *ptr++;
111        GLuint cur_zmax = *ptr++;
112
113        if( cur_zmin < zmin )
114        {
115            zmin = cur_zmin;
116            hit = *ptr;
117        }
118        ptr++;
119    }
120
121    glMatrixMode(GL_PROJECTION);
122    glLoadIdentity();   // get rid of the pick matrix
123
124    return hit;
125}
Note: See TracBrowser for help on using the repository browser.