]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - contrib/bobtoolz/DVisDrawer.cpp
This is a major change that updates the 3rd party libs on Windows builds.
[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 #include "DPoint.h"
26 #include "DVisDrawer.h"
27 #include "misc.h"
28 #include "funchandlers.h"
29
30 //////////////////////////////////////////////////////////////////////
31 // Construction/Destruction
32 //////////////////////////////////////////////////////////////////////
33
34 DVisDrawer::DVisDrawer()
35 {
36         refCount = 1;
37         m_bHooked = FALSE;
38         m_list = NULL;
39 }
40
41 DVisDrawer::~DVisDrawer()
42 {
43         if(m_bHooked)
44                 UnRegister();
45
46         g_VisView = NULL;
47 }
48
49 //////////////////////////////////////////////////////////////////////
50 // Implementation
51 //////////////////////////////////////////////////////////////////////
52
53 void DVisDrawer::Draw2D(VIEWTYPE vt)
54 {
55         if(!m_list)
56                 return;
57
58         g_QglTable.m_pfn_qglPushAttrib(GL_ALL_ATTRIB_BITS);
59
60         g_QglTable.m_pfn_qglDisable(GL_BLEND);
61         g_QglTable.m_pfn_qglDisable(GL_LINE_SMOOTH);
62
63         g_QglTable.m_pfn_qglPushMatrix();
64         
65         switch(vt)
66         {
67         case XY:
68                 break;
69         case XZ:
70                 g_QglTable.m_pfn_qglRotatef(270.0f, 1.0f, 0.0f, 0.0f);
71                 break;
72         case YZ:
73                 g_QglTable.m_pfn_qglRotatef(270.0f, 1.0f, 0.0f, 0.0f);
74                 g_QglTable.m_pfn_qglRotatef(270.0f, 0.0f, 0.0f, 1.0f);
75                 break;
76         }
77
78         g_QglTable.m_pfn_qglLineWidth(1.0f);
79         g_QglTable.m_pfn_qglColor4f(1.0f, 0.0f, 0.0f, 0.5f);
80
81         g_QglTable.m_pfn_qglEnable(GL_BLEND);
82         g_QglTable.m_pfn_qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
83         g_QglTable.m_pfn_qglDisable(GL_POLYGON_SMOOTH);
84
85         g_QglTable.m_pfn_qglDepthFunc(GL_ALWAYS);
86
87         //bleh
88         list<DWinding *>::const_iterator l=m_list->begin();
89
90         for(; l != m_list->end(); l++)
91         {
92                 DWinding* w = *l;
93
94                 g_QglTable.m_pfn_qglColor4f(w->clr[0], w->clr[1], w->clr[2], 0.5f);
95
96                 g_QglTable.m_pfn_qglBegin(GL_POLYGON);
97                 for(int i = 0; i < w->numpoints; i++) {
98                         g_QglTable.m_pfn_qglVertex3f((w->p[i])[0], (w->p[i])[1], (w->p[i])[2]);
99                 }
100                 g_QglTable.m_pfn_qglEnd();
101         }
102
103         
104         g_QglTable.m_pfn_qglPopMatrix();
105
106         g_QglTable.m_pfn_qglPopAttrib();
107 }
108
109 void DVisDrawer::Draw3D()
110 {
111         if(!m_list)
112                 return;
113
114         g_QglTable.m_pfn_qglPushAttrib(GL_ALL_ATTRIB_BITS);
115
116         g_QglTable.m_pfn_qglColor4f(1.0, 0.0, 0.0, 0.5f);
117
118 //      g_QglTable.m_pfn_qglHint(GL_FOG_HINT, GL_NICEST);
119         
120 //      g_QglTable.m_pfn_qglDisable(GL_CULL_FACE);
121         g_QglTable.m_pfn_qglDisable(GL_LINE_SMOOTH);
122
123 //      g_QglTable.m_pfn_qglPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
124 //      g_QglTable.m_pfn_qglShadeModel(GL_SMOOTH);
125
126         g_QglTable.m_pfn_qglEnable(GL_BLEND);
127         g_QglTable.m_pfn_qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
128         g_QglTable.m_pfn_qglDisable(GL_POLYGON_SMOOTH);
129
130         g_QglTable.m_pfn_qglDepthFunc(GL_ALWAYS);
131
132         //bleh
133         list<DWinding *>::const_iterator l=m_list->begin();
134
135         for(; l != m_list->end(); l++)
136         {
137                 DWinding* w = *l;
138
139                 g_QglTable.m_pfn_qglColor4f(w->clr[0], w->clr[1], w->clr[2], 0.5f);
140
141                 g_QglTable.m_pfn_qglBegin(GL_POLYGON);
142                 for(int i = 0; i < w->numpoints; i++) {
143                         g_QglTable.m_pfn_qglVertex3f((w->p[i])[0], (w->p[i])[1], (w->p[i])[2]);
144                 }
145                 g_QglTable.m_pfn_qglEnd();
146         }
147
148         g_QglTable.m_pfn_qglPopAttrib();
149 }
150
151 void DVisDrawer::Register()
152 {
153         g_QglTable.m_pfnHookGL2DWindow( this );
154         g_QglTable.m_pfnHookGL3DWindow( this );
155         m_bHooked = TRUE;
156 }
157
158 void DVisDrawer::UnRegister()
159 {
160         g_QglTable.m_pfnUnHookGL2DWindow( this );
161         g_QglTable.m_pfnUnHookGL3DWindow( this );
162         m_bHooked = FALSE;
163 }
164
165 void DVisDrawer::SetList(std::list<DWinding*> *pointList)
166 {
167         if(m_list)
168                 ClearPoints();
169
170         m_list = pointList;
171 }
172
173 void DVisDrawer::ClearPoints()
174 {
175   list<DWinding *>::const_iterator deadPoint=m_list->begin();
176         for(; deadPoint!=m_list->end(); deadPoint++)
177                 delete *deadPoint;
178         m_list->clear();
179 }