]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - contrib/bobtoolz/DVisDrawer.cpp
ok
[xonotic/netradiant.git] / contrib / bobtoolz / DVisDrawer.cpp
1 /*
2 BobToolz plugin for GtkRadiant
3 Copyright (C) 2001 Gordon Biggans
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18 */
19
20 // BobView.cpp: implementation of the DVisDrawer class.
21 //
22 //////////////////////////////////////////////////////////////////////
23
24 #include "StdAfx.h"
25
26 #include "gtkr_list.h"
27 #include "str.h"
28
29 #include "DPoint.h"
30 #include "DWinding.h"
31 #include "DVisDrawer.h"
32
33 #include "misc.h"
34 #include "funchandlers.h"
35
36 //////////////////////////////////////////////////////////////////////
37 // Construction/Destruction
38 //////////////////////////////////////////////////////////////////////
39
40 DVisDrawer::DVisDrawer()
41 {
42         refCount = 1;
43         m_bHooked = FALSE;
44         m_list = NULL;
45 }
46
47 DVisDrawer::~DVisDrawer()
48 {
49         if(m_bHooked)
50                 UnRegister();
51
52         g_VisView = NULL;
53 }
54
55 //////////////////////////////////////////////////////////////////////
56 // Implementation
57 //////////////////////////////////////////////////////////////////////
58
59 void DVisDrawer::Draw2D(VIEWTYPE vt)
60 {
61         if(!m_list)
62                 return;
63
64         __QGLTABLENAME.m_pfn_qglPushAttrib(GL_ALL_ATTRIB_BITS);
65
66         __QGLTABLENAME.m_pfn_qglDisable(GL_BLEND);
67         __QGLTABLENAME.m_pfn_qglDisable(GL_LINE_SMOOTH);
68
69         __QGLTABLENAME.m_pfn_qglPushMatrix();
70         
71         switch(vt)
72         {
73         case XY:
74                 break;
75         case XZ:
76                 __QGLTABLENAME.m_pfn_qglRotatef(270.0f, 1.0f, 0.0f, 0.0f);
77                 break;
78         case YZ:
79                 __QGLTABLENAME.m_pfn_qglRotatef(270.0f, 1.0f, 0.0f, 0.0f);
80                 __QGLTABLENAME.m_pfn_qglRotatef(270.0f, 0.0f, 0.0f, 1.0f);
81                 break;
82         }
83
84         __QGLTABLENAME.m_pfn_qglLineWidth(1.0f);
85         __QGLTABLENAME.m_pfn_qglColor4f(1.0f, 0.0f, 0.0f, 0.5f);
86
87         __QGLTABLENAME.m_pfn_qglEnable(GL_BLEND);
88         __QGLTABLENAME.m_pfn_qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
89         __QGLTABLENAME.m_pfn_qglDisable(GL_POLYGON_SMOOTH);
90
91         __QGLTABLENAME.m_pfn_qglDepthFunc(GL_ALWAYS);
92
93         //bleh
94         list<DWinding *>::const_iterator l=m_list->begin();
95
96         for(; l != m_list->end(); l++)
97         {
98                 DWinding* w = *l;
99
100                 __QGLTABLENAME.m_pfn_qglColor4f(w->clr[0], w->clr[1], w->clr[2], 0.5f);
101
102                 __QGLTABLENAME.m_pfn_qglBegin(GL_POLYGON);
103                 for(int i = 0; i < w->numpoints; i++) {
104                         __QGLTABLENAME.m_pfn_qglVertex3f((w->p[i])[0], (w->p[i])[1], (w->p[i])[2]);
105                 }
106                 __QGLTABLENAME.m_pfn_qglEnd();
107         }
108
109         
110         __QGLTABLENAME.m_pfn_qglPopMatrix();
111
112         __QGLTABLENAME.m_pfn_qglPopAttrib();
113 }
114
115 void DVisDrawer::Draw3D()
116 {
117         if(!m_list)
118                 return;
119
120         __QGLTABLENAME.m_pfn_qglPushAttrib(GL_ALL_ATTRIB_BITS);
121
122         __QGLTABLENAME.m_pfn_qglColor4f(1.0, 0.0, 0.0, 0.5f);
123
124 //      __QGLTABLENAME.m_pfn_qglHint(GL_FOG_HINT, GL_NICEST);
125         
126 //      __QGLTABLENAME.m_pfn_qglDisable(GL_CULL_FACE);
127         __QGLTABLENAME.m_pfn_qglDisable(GL_LINE_SMOOTH);
128
129 //      __QGLTABLENAME.m_pfn_qglPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
130 //      __QGLTABLENAME.m_pfn_qglShadeModel(GL_SMOOTH);
131
132         __QGLTABLENAME.m_pfn_qglEnable(GL_BLEND);
133         __QGLTABLENAME.m_pfn_qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
134         __QGLTABLENAME.m_pfn_qglDisable(GL_POLYGON_SMOOTH);
135
136         __QGLTABLENAME.m_pfn_qglDepthFunc(GL_ALWAYS);
137
138         //bleh
139         list<DWinding *>::const_iterator l=m_list->begin();
140
141         for(; l != m_list->end(); l++)
142         {
143                 DWinding* w = *l;
144
145                 __QGLTABLENAME.m_pfn_qglColor4f(w->clr[0], w->clr[1], w->clr[2], 0.5f);
146
147                 __QGLTABLENAME.m_pfn_qglBegin(GL_POLYGON);
148                 for(int i = 0; i < w->numpoints; i++) {
149                         __QGLTABLENAME.m_pfn_qglVertex3f((w->p[i])[0], (w->p[i])[1], (w->p[i])[2]);
150                 }
151                 __QGLTABLENAME.m_pfn_qglEnd();
152         }
153
154         __QGLTABLENAME.m_pfn_qglPopAttrib();
155 }
156
157 void DVisDrawer::Register()
158 {
159         __QGLTABLENAME.m_pfnHookGL2DWindow( this );
160         __QGLTABLENAME.m_pfnHookGL3DWindow( this );
161         m_bHooked = TRUE;
162 }
163
164 void DVisDrawer::UnRegister()
165 {
166         __QGLTABLENAME.m_pfnUnHookGL2DWindow( this );
167         __QGLTABLENAME.m_pfnUnHookGL3DWindow( this );
168         m_bHooked = FALSE;
169 }
170
171 void DVisDrawer::SetList(std::list<DWinding*> *pointList)
172 {
173         if(m_list)
174                 ClearPoints();
175
176         m_list = pointList;
177 }
178
179 void DVisDrawer::ClearPoints()
180 {
181   list<DWinding *>::const_iterator deadPoint=m_list->begin();
182         for(; deadPoint!=m_list->end(); deadPoint++)
183                 delete *deadPoint;
184         m_list->clear();
185 }