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